Make "authKey" a constant

This commit is contained in:
Kristoffer Dalby 2021-11-18 08:49:55 +00:00
parent 35c3fe9608
commit a8a8f01429
9 changed files with 36 additions and 33 deletions

View file

@ -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),
}

7
api.go
View file

@ -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

View file

@ -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),
}

View file

@ -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)

View file

@ -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),
}

View file

@ -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),
}

View file

@ -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),
}

View file

@ -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),
}

View file

@ -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)