(t *testing.T)
| 722 | } |
| 723 | |
| 724 | func TestUpdateUsersChangesAllowedIP(t *testing.T) { |
| 725 | cfg, err := NewConfig(`{ |
| 726 | "interface_name":"wg-test", |
| 727 | "listen_port":51820, |
| 728 | "address":["10.70.0.1/24"] |
| 729 | }`) |
| 730 | if err != nil { |
| 731 | t.Fatalf("failed to create config: %v", err) |
| 732 | } |
| 733 | |
| 734 | _, key, _ := GenerateKeyPair() |
| 735 | |
| 736 | ps := NewPeerStore() |
| 737 | ps.ReplaceAll([]*PeerInfo{mustPeerInfo("keep@example.com", key, []string{"10.70.0.2/32"})}) |
| 738 | |
| 739 | applyCalls := 0 |
| 740 | wg := &WireGuard{ |
| 741 | config: cfg, |
| 742 | peerStore: ps, |
| 743 | statsTracker: stats.New(), |
| 744 | manager: &Manager{ |
| 745 | iFaceName: "wg-test", |
| 746 | client: &fakeWGClient{ |
| 747 | configureDeviceFn: func(interfaceName string, cfg wgtypes.Config) error { |
| 748 | applyCalls++ |
| 749 | if cfg.Peers[0].AllowedIPs[0].String() != "10.70.0.3/32" { |
| 750 | t.Fatal("expected new IP in config") |
| 751 | } |
| 752 | return nil |
| 753 | }, |
| 754 | }, |
| 755 | }, |
| 756 | state: lifecycleRunning, |
| 757 | } |
| 758 | |
| 759 | users := []*common.User{ |
| 760 | { |
| 761 | Email: "keep@example.com", |
| 762 | Inbounds: []string{"wg-test"}, |
| 763 | Proxies: &common.Proxy{ |
| 764 | Wireguard: &common.Wireguard{ |
| 765 | PublicKey: key, PeerIps: []string{"10.70.0.3/32"}, |
| 766 | }, |
| 767 | }, |
| 768 | }, |
| 769 | } |
| 770 | |
| 771 | if err := wg.UpdateUsers(context.Background(), users); err != nil { |
| 772 | t.Fatalf("UpdateUsers failed: %v", err) |
| 773 | } |
| 774 | |
| 775 | if applyCalls != 1 { |
| 776 | t.Fatalf("expected one ConfigureDevice calls for IP change partial sync, got %d", applyCalls) |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | func TestUpdateUsersAndRestartReappliesKeepaliveToAllPeers(t *testing.T) { |
| 781 | privateKey, _, err := GenerateKeyPair() |
nothing calls this directly
no test coverage detected