diff --git a/acls_test.go b/acls_test.go index 3e051f5f..629ce1da 100644 --- a/acls_test.go +++ b/acls_test.go @@ -100,7 +100,7 @@ func (s *Suite) TestPortNamespace(c *check.C) { Name: "testmachine", NamespaceID: namespace.ID, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, IPAddress: ip.String(), AuthKeyID: uint(pak.ID), } @@ -142,7 +142,7 @@ func (s *Suite) TestPortGroup(c *check.C) { Name: "testmachine", NamespaceID: namespace.ID, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, IPAddress: ip.String(), AuthKeyID: uint(pak.ID), } diff --git a/api.go b/api.go index 367a0031..45b59d3c 100644 --- a/api.go +++ b/api.go @@ -18,7 +18,10 @@ import ( "tailscale.com/types/wgkey" ) -const reservedResponseHeaderSize = 4 +const ( + reservedResponseHeaderSize = 4 + RegisterMethodAuthKey = "authKey" +) // KeyHandler provides the Headscale pub key // Listens in /key. @@ -536,7 +539,7 @@ func (h *Headscale) handleAuthKey( HexString() // we update it just in case machine.Registered = true - machine.RegisterMethod = "authKey" + machine.RegisterMethod = RegisterMethodAuthKey h.db.Save(&machine) pak.Used = true diff --git a/dns_test.go b/dns_test.go index a2f7a652..92f7476f 100644 --- a/dns_test.go +++ b/dns_test.go @@ -123,7 +123,7 @@ func (s *Suite) TestDNSConfigMapResponseWithMagicDNS(c *check.C) { NamespaceID: namespaceShared1.ID, Namespace: *namespaceShared1, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, IPAddress: "100.64.0.1", AuthKeyID: uint(preAuthKeyInShared1.ID), } @@ -141,7 +141,7 @@ func (s *Suite) TestDNSConfigMapResponseWithMagicDNS(c *check.C) { NamespaceID: namespaceShared2.ID, Namespace: *namespaceShared2, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, IPAddress: "100.64.0.2", AuthKeyID: uint(preAuthKeyInShared2.ID), } @@ -159,7 +159,7 @@ func (s *Suite) TestDNSConfigMapResponseWithMagicDNS(c *check.C) { NamespaceID: namespaceShared3.ID, Namespace: *namespaceShared3, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, IPAddress: "100.64.0.3", AuthKeyID: uint(preAuthKeyInShared3.ID), } @@ -177,7 +177,7 @@ func (s *Suite) TestDNSConfigMapResponseWithMagicDNS(c *check.C) { NamespaceID: namespaceShared1.ID, Namespace: *namespaceShared1, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, IPAddress: "100.64.0.4", AuthKeyID: uint(PreAuthKey2InShared1.ID), } @@ -272,7 +272,7 @@ func (s *Suite) TestDNSConfigMapResponseWithoutMagicDNS(c *check.C) { NamespaceID: namespaceShared1.ID, Namespace: *namespaceShared1, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, IPAddress: "100.64.0.1", AuthKeyID: uint(preAuthKeyInShared1.ID), } @@ -290,7 +290,7 @@ func (s *Suite) TestDNSConfigMapResponseWithoutMagicDNS(c *check.C) { NamespaceID: namespaceShared2.ID, Namespace: *namespaceShared2, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, IPAddress: "100.64.0.2", AuthKeyID: uint(preAuthKeyInShared2.ID), } @@ -308,7 +308,7 @@ func (s *Suite) TestDNSConfigMapResponseWithoutMagicDNS(c *check.C) { NamespaceID: namespaceShared3.ID, Namespace: *namespaceShared3, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, IPAddress: "100.64.0.3", AuthKeyID: uint(preAuthKeyInShared3.ID), } @@ -326,7 +326,7 @@ func (s *Suite) TestDNSConfigMapResponseWithoutMagicDNS(c *check.C) { NamespaceID: namespaceShared1.ID, Namespace: *namespaceShared1, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, IPAddress: "100.64.0.4", AuthKeyID: uint(preAuthKey2InShared1.ID), } diff --git a/machine_test.go b/machine_test.go index cf367403..fdbc3cb5 100644 --- a/machine_test.go +++ b/machine_test.go @@ -25,7 +25,7 @@ func (s *Suite) TestGetMachine(c *check.C) { Name: "testmachine", NamespaceID: namespace.ID, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, AuthKeyID: uint(pak.ID), } app.db.Save(machine) @@ -55,7 +55,7 @@ func (s *Suite) TestGetMachineByID(c *check.C) { Name: "testmachine", NamespaceID: namespace.ID, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, AuthKeyID: uint(pak.ID), } app.db.Save(&machine) @@ -78,7 +78,7 @@ func (s *Suite) TestDeleteMachine(c *check.C) { Name: "testmachine", NamespaceID: namespace.ID, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, AuthKeyID: uint(1), } app.db.Save(&machine) @@ -113,7 +113,7 @@ func (s *Suite) TestHardDeleteMachine(c *check.C) { Name: "testmachine3", NamespaceID: namespace.ID, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, AuthKeyID: uint(1), } app.db.Save(&machine) @@ -144,7 +144,7 @@ func (s *Suite) TestGetDirectPeers(c *check.C) { Name: "testmachine" + strconv.Itoa(index), NamespaceID: namespace.ID, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, AuthKeyID: uint(pak.ID), } app.db.Save(&machine) diff --git a/namespaces_test.go b/namespaces_test.go index bbae98f9..9793e608 100644 --- a/namespaces_test.go +++ b/namespaces_test.go @@ -53,7 +53,7 @@ func (s *Suite) TestDestroyNamespaceErrors(c *check.C) { Name: "testmachine", NamespaceID: namespace.ID, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, AuthKeyID: uint(pak.ID), } app.db.Save(&machine) @@ -145,7 +145,7 @@ func (s *Suite) TestGetMapResponseUserProfiles(c *check.C) { NamespaceID: namespaceShared1.ID, Namespace: *namespaceShared1, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, IPAddress: "100.64.0.1", AuthKeyID: uint(preAuthKeyShared1.ID), } @@ -163,7 +163,7 @@ func (s *Suite) TestGetMapResponseUserProfiles(c *check.C) { NamespaceID: namespaceShared2.ID, Namespace: *namespaceShared2, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, IPAddress: "100.64.0.2", AuthKeyID: uint(preAuthKeyShared2.ID), } @@ -181,7 +181,7 @@ func (s *Suite) TestGetMapResponseUserProfiles(c *check.C) { NamespaceID: namespaceShared3.ID, Namespace: *namespaceShared3, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, IPAddress: "100.64.0.3", AuthKeyID: uint(preAuthKeyShared3.ID), } @@ -199,7 +199,7 @@ func (s *Suite) TestGetMapResponseUserProfiles(c *check.C) { NamespaceID: namespaceShared1.ID, Namespace: *namespaceShared1, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, IPAddress: "100.64.0.4", AuthKeyID: uint(preAuthKey2Shared1.ID), } diff --git a/preauth_keys_test.go b/preauth_keys_test.go index fd0feb03..f8cf276d 100644 --- a/preauth_keys_test.go +++ b/preauth_keys_test.go @@ -81,7 +81,7 @@ func (*Suite) TestAlreadyUsedKey(c *check.C) { Name: "testest", NamespaceID: namespace.ID, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, AuthKeyID: uint(pak.ID), } app.db.Save(&machine) @@ -106,7 +106,7 @@ func (*Suite) TestReusableBeingUsedKey(c *check.C) { Name: "testest", NamespaceID: namespace.ID, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, AuthKeyID: uint(pak.ID), } app.db.Save(&machine) @@ -144,7 +144,7 @@ func (*Suite) TestEphemeralKey(c *check.C) { Name: "testest", NamespaceID: namespace.ID, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, LastSeen: &now, AuthKeyID: uint(pak.ID), } diff --git a/routes_test.go b/routes_test.go index 18cb0ceb..94bda45b 100644 --- a/routes_test.go +++ b/routes_test.go @@ -36,7 +36,7 @@ func (s *Suite) TestGetRoutes(c *check.C) { Name: "test_get_route_machine", NamespaceID: namespace.ID, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, AuthKeyID: uint(pak.ID), HostInfo: datatypes.JSON(hostinfo), } @@ -90,7 +90,7 @@ func (s *Suite) TestGetEnableRoutes(c *check.C) { Name: "test_enable_route_machine", NamespaceID: namespace.ID, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, AuthKeyID: uint(pak.ID), HostInfo: datatypes.JSON(hostinfo), } diff --git a/sharing_test.go b/sharing_test.go index 7ec1b0ee..fd7634da 100644 --- a/sharing_test.go +++ b/sharing_test.go @@ -25,7 +25,7 @@ func CreateNodeNamespace( Name: node, NamespaceID: namespace.ID, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, IPAddress: ip, AuthKeyID: uint(pak1.ID), } @@ -213,7 +213,7 @@ func (s *Suite) TestComplexSharingAcrossNamespaces(c *check.C) { Name: "test_get_shared_nodes_4", NamespaceID: namespace1.ID, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, IPAddress: "100.64.0.4", AuthKeyID: uint(pak4.ID), } @@ -293,7 +293,7 @@ func (s *Suite) TestDeleteSharedMachine(c *check.C) { Name: "test_get_shared_nodes_4", NamespaceID: namespace1.ID, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, IPAddress: "100.64.0.4", AuthKeyID: uint(pak4n1.ID), } diff --git a/utils_test.go b/utils_test.go index dcda6130..95722a83 100644 --- a/utils_test.go +++ b/utils_test.go @@ -36,7 +36,7 @@ func (s *Suite) TestGetUsedIps(c *check.C) { Name: "testmachine", NamespaceID: namespace.ID, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, AuthKeyID: uint(pak.ID), IPAddress: ip.String(), } @@ -78,7 +78,7 @@ func (s *Suite) TestGetMultiIp(c *check.C) { Name: "testmachine", NamespaceID: namespace.ID, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, AuthKeyID: uint(pak.ID), IPAddress: ip.String(), } @@ -151,7 +151,7 @@ func (s *Suite) TestGetAvailableIpMachineWithoutIP(c *check.C) { Name: "testmachine", NamespaceID: namespace.ID, Registered: true, - RegisterMethod: "authKey", + RegisterMethod: RegisterMethodAuthKey, AuthKeyID: uint(pak.ID), } app.db.Save(&machine)