(t *testing.T)
| 158 | } |
| 159 | |
| 160 | func TestSyncUsersSkipsEmptyEmailUser(t *testing.T) { |
| 161 | cfg, err := NewConfig(`{ |
| 162 | "interface_name":"wg-test", |
| 163 | "listen_port":51820, |
| 164 | "address":["10.62.0.1/24"] |
| 165 | }`) |
| 166 | if err != nil { |
| 167 | t.Fatalf("failed to create config: %v", err) |
| 168 | } |
| 169 | |
| 170 | _, validKey, err := GenerateKeyPair() |
| 171 | if err != nil { |
| 172 | t.Fatalf("failed to generate key pair: %v", err) |
| 173 | } |
| 174 | |
| 175 | configureCalls := 0 |
| 176 | wg := &WireGuard{ |
| 177 | config: cfg, |
| 178 | peerStore: NewPeerStore(), |
| 179 | statsTracker: stats.New(), |
| 180 | manager: &Manager{ |
| 181 | iFaceName: "wg-test", |
| 182 | client: &fakeWGClient{ |
| 183 | configureDeviceFn: func(interfaceName string, cfg wgtypes.Config) error { |
| 184 | configureCalls++ |
| 185 | return nil |
| 186 | }, |
| 187 | }, |
| 188 | }, |
| 189 | state: lifecycleRunning, |
| 190 | } |
| 191 | |
| 192 | users := []*common.User{ |
| 193 | { |
| 194 | Email: "", |
| 195 | Inbounds: []string{"wg-test"}, |
| 196 | Proxies: &common.Proxy{ |
| 197 | Wireguard: &common.Wireguard{ |
| 198 | PublicKey: validKey, PeerIps: []string{"10.62.0.4/32"}, |
| 199 | }, |
| 200 | }, |
| 201 | }, |
| 202 | } |
| 203 | |
| 204 | // normalizeUsers drops users with empty email before they reach any sync logic. |
| 205 | if err = wg.SyncUsers(context.Background(), users); err != nil { |
| 206 | t.Fatalf("expected SyncUsers to succeed when normalizeUsers drops empty-email user, got: %v", err) |
| 207 | } |
| 208 | // No effective desired peers → no kernel call. |
| 209 | if configureCalls != 0 { |
| 210 | t.Fatalf("expected no ConfigureDevice call when the only user was quarantined, got %d", configureCalls) |
| 211 | } |
| 212 | // Nothing should have been added to the store. |
| 213 | if peer := wg.peerStore.GetByKey(validKey); peer != nil { |
| 214 | t.Fatal("expected quarantined user not to appear in the peer store") |
| 215 | } |
| 216 | } |
| 217 |
nothing calls this directly
no test coverage detected