修复局域网连接问题
This commit is contained in:
@@ -56,3 +56,60 @@ func TestRegisterReusesKnownDeviceOnlyWithValidToken(t *testing.T) {
|
||||
t.Fatal("expected rotated device token to validate")
|
||||
}
|
||||
}
|
||||
|
||||
func TestListCandidatesOnlyReturnsSameNetworkDevices(t *testing.T) {
|
||||
memStore := store.NewMemoryStore(model.RuntimeConfig{})
|
||||
deviceService := NewDeviceService(memStore, nil, nil)
|
||||
|
||||
current, _ := deviceService.Register(RegisterDeviceInput{
|
||||
DeviceID: "current",
|
||||
Name: "Current",
|
||||
Type: "desktop",
|
||||
NetworkGroupKey: "192.168.1.10",
|
||||
}, "ua/1.0", "")
|
||||
|
||||
sameNetwork, _ := deviceService.Register(RegisterDeviceInput{
|
||||
DeviceID: "same-network",
|
||||
Name: "Same Network",
|
||||
Type: "phone",
|
||||
NetworkGroupKey: "192.168.1.10",
|
||||
}, "ua/1.0", "")
|
||||
|
||||
_, _ = deviceService.Register(RegisterDeviceInput{
|
||||
DeviceID: "other-network",
|
||||
Name: "Other Network",
|
||||
Type: "phone",
|
||||
NetworkGroupKey: "10.0.0.5",
|
||||
}, "ua/1.0", "")
|
||||
|
||||
candidates := deviceService.ListCandidates(current.ID)
|
||||
if len(candidates) != 1 {
|
||||
t.Fatalf("expected 1 same-network candidate, got %d", len(candidates))
|
||||
}
|
||||
if candidates[0].ID != sameNetwork.ID {
|
||||
t.Fatalf("expected candidate %q, got %q", sameNetwork.ID, candidates[0].ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListCandidatesReturnsEmptyWithoutNetworkGroupKey(t *testing.T) {
|
||||
memStore := store.NewMemoryStore(model.RuntimeConfig{})
|
||||
deviceService := NewDeviceService(memStore, nil, nil)
|
||||
|
||||
current, _ := deviceService.Register(RegisterDeviceInput{
|
||||
DeviceID: "current",
|
||||
Name: "Current",
|
||||
Type: "desktop",
|
||||
}, "ua/1.0", "")
|
||||
|
||||
_, _ = deviceService.Register(RegisterDeviceInput{
|
||||
DeviceID: "same-network",
|
||||
Name: "Same Network",
|
||||
Type: "phone",
|
||||
NetworkGroupKey: "192.168.1.10",
|
||||
}, "ua/1.0", "")
|
||||
|
||||
candidates := deviceService.ListCandidates(current.ID)
|
||||
if len(candidates) != 0 {
|
||||
t.Fatalf("expected no candidates without a local network group key, got %d", len(candidates))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user