Refactor unit tests

This commit is contained in:
Juan Font 2023-05-01 14:53:23 +00:00
parent 851da9d674
commit 9f7c25e853
8 changed files with 483 additions and 483 deletions

View File

@ -54,7 +54,7 @@ func (s *Suite) TestBasicRule(c *check.C) {
err := app.LoadACLPolicy("./tests/acls/acl_policy_basic_1.hujson")
c.Assert(err, check.IsNil)
rules, err := generateACLRules([]Machine{}, *app.aclPolicy, false)
rules, err := generateACLRules([]Node{}, *app.aclPolicy, false)
c.Assert(err, check.IsNil)
c.Assert(rules, check.NotNil)
}
@ -83,27 +83,27 @@ func (s *Suite) TestSshRules(c *check.C) {
pak, err := app.CreatePreAuthKey(user.Name, false, false, nil, nil)
c.Assert(err, check.IsNil)
_, err = app.GetMachine("user1", "testmachine")
_, err = app.GetNode("user1", "testnode")
c.Assert(err, check.NotNil)
hostInfo := tailcfg.Hostinfo{
OS: "centos",
Hostname: "testmachine",
Hostname: "testnode",
RequestTags: []string{"tag:test"},
}
machine := Machine{
node := Node{
ID: 0,
MachineKey: "foo",
NodeKey: "bar",
DiscoKey: "faa",
Hostname: "testmachine",
IPAddresses: MachineAddresses{netip.MustParseAddr("100.64.0.1")},
Hostname: "testnode",
IPAddresses: NodeAddresses{netip.MustParseAddr("100.64.0.1")},
UserID: user.ID,
RegisterMethod: RegisterMethodAuthKey,
AuthKeyID: uint(pak.ID),
HostInfo: HostInfo(hostInfo),
}
app.db.Save(&machine)
app.db.Save(&node)
app.aclPolicy = &ACLPolicy{
Groups: Groups{
@ -193,27 +193,27 @@ func (s *Suite) TestValidExpandTagOwnersInSources(c *check.C) {
pak, err := app.CreatePreAuthKey(user.Name, false, false, nil, nil)
c.Assert(err, check.IsNil)
_, err = app.GetMachine("user1", "testmachine")
_, err = app.GetNode("user1", "testnode")
c.Assert(err, check.NotNil)
hostInfo := tailcfg.Hostinfo{
OS: "centos",
Hostname: "testmachine",
Hostname: "testnode",
RequestTags: []string{"tag:test"},
}
machine := Machine{
node := Node{
ID: 0,
MachineKey: "foo",
NodeKey: "bar",
DiscoKey: "faa",
Hostname: "testmachine",
IPAddresses: MachineAddresses{netip.MustParseAddr("100.64.0.1")},
Hostname: "testnode",
IPAddresses: NodeAddresses{netip.MustParseAddr("100.64.0.1")},
UserID: user.ID,
RegisterMethod: RegisterMethodAuthKey,
AuthKeyID: uint(pak.ID),
HostInfo: HostInfo(hostInfo),
}
app.db.Save(&machine)
app.db.Save(&node)
app.aclPolicy = &ACLPolicy{
Groups: Groups{"group:test": []string{"user1", "user2"}},
@ -243,27 +243,27 @@ func (s *Suite) TestValidExpandTagOwnersInDestinations(c *check.C) {
pak, err := app.CreatePreAuthKey(user.Name, false, false, nil, nil)
c.Assert(err, check.IsNil)
_, err = app.GetMachine("user1", "testmachine")
_, err = app.GetNode("user1", "testnode")
c.Assert(err, check.NotNil)
hostInfo := tailcfg.Hostinfo{
OS: "centos",
Hostname: "testmachine",
Hostname: "testnode",
RequestTags: []string{"tag:test"},
}
machine := Machine{
node := Node{
ID: 1,
MachineKey: "12345",
NodeKey: "bar",
DiscoKey: "faa",
Hostname: "testmachine",
IPAddresses: MachineAddresses{netip.MustParseAddr("100.64.0.1")},
Hostname: "testnode",
IPAddresses: NodeAddresses{netip.MustParseAddr("100.64.0.1")},
UserID: user.ID,
RegisterMethod: RegisterMethodAuthKey,
AuthKeyID: uint(pak.ID),
HostInfo: HostInfo(hostInfo),
}
app.db.Save(&machine)
app.db.Save(&node)
app.aclPolicy = &ACLPolicy{
Groups: Groups{"group:test": []string{"user1", "user2"}},
@ -293,27 +293,27 @@ func (s *Suite) TestInvalidTagValidUser(c *check.C) {
pak, err := app.CreatePreAuthKey(user.Name, false, false, nil, nil)
c.Assert(err, check.IsNil)
_, err = app.GetMachine("user1", "testmachine")
_, err = app.GetNode("user1", "testnode")
c.Assert(err, check.NotNil)
hostInfo := tailcfg.Hostinfo{
OS: "centos",
Hostname: "testmachine",
Hostname: "testnode",
RequestTags: []string{"tag:foo"},
}
machine := Machine{
node := Node{
ID: 1,
MachineKey: "12345",
NodeKey: "bar",
DiscoKey: "faa",
Hostname: "testmachine",
IPAddresses: MachineAddresses{netip.MustParseAddr("100.64.0.1")},
Hostname: "testnode",
IPAddresses: NodeAddresses{netip.MustParseAddr("100.64.0.1")},
UserID: user.ID,
RegisterMethod: RegisterMethodAuthKey,
AuthKeyID: uint(pak.ID),
HostInfo: HostInfo(hostInfo),
}
app.db.Save(&machine)
app.db.Save(&node)
app.aclPolicy = &ACLPolicy{
TagOwners: TagOwners{"tag:test": []string{"user1"}},
@ -342,7 +342,7 @@ func (s *Suite) TestValidTagInvalidUser(c *check.C) {
pak, err := app.CreatePreAuthKey(user.Name, false, false, nil, nil)
c.Assert(err, check.IsNil)
_, err = app.GetMachine("user1", "webserver")
_, err = app.GetNode("user1", "webserver")
c.Assert(err, check.NotNil)
hostInfo := tailcfg.Hostinfo{
OS: "centos",
@ -350,38 +350,38 @@ func (s *Suite) TestValidTagInvalidUser(c *check.C) {
RequestTags: []string{"tag:webapp"},
}
machine := Machine{
node := Node{
ID: 1,
MachineKey: "12345",
NodeKey: "bar",
DiscoKey: "faa",
Hostname: "webserver",
IPAddresses: MachineAddresses{netip.MustParseAddr("100.64.0.1")},
IPAddresses: NodeAddresses{netip.MustParseAddr("100.64.0.1")},
UserID: user.ID,
RegisterMethod: RegisterMethodAuthKey,
AuthKeyID: uint(pak.ID),
HostInfo: HostInfo(hostInfo),
}
app.db.Save(&machine)
_, err = app.GetMachine("user1", "user")
app.db.Save(&node)
_, err = app.GetNode("user1", "user")
hostInfo2 := tailcfg.Hostinfo{
OS: "debian",
Hostname: "Hostname",
}
c.Assert(err, check.NotNil)
machine = Machine{
node = Node{
ID: 2,
MachineKey: "56789",
NodeKey: "bar2",
DiscoKey: "faab",
Hostname: "user",
IPAddresses: MachineAddresses{netip.MustParseAddr("100.64.0.2")},
IPAddresses: NodeAddresses{netip.MustParseAddr("100.64.0.2")},
UserID: user.ID,
RegisterMethod: RegisterMethodAuthKey,
AuthKeyID: uint(pak.ID),
HostInfo: HostInfo(hostInfo2),
}
app.db.Save(&machine)
app.db.Save(&node)
app.aclPolicy = &ACLPolicy{
TagOwners: TagOwners{"tag:webapp": []string{"user1"}},
@ -411,7 +411,7 @@ func (s *Suite) TestPortRange(c *check.C) {
err := app.LoadACLPolicy("./tests/acls/acl_policy_basic_range.hujson")
c.Assert(err, check.IsNil)
rules, err := generateACLRules([]Machine{}, *app.aclPolicy, false)
rules, err := generateACLRules([]Node{}, *app.aclPolicy, false)
c.Assert(err, check.IsNil)
c.Assert(rules, check.NotNil)
@ -425,7 +425,7 @@ func (s *Suite) TestProtocolParsing(c *check.C) {
err := app.LoadACLPolicy("./tests/acls/acl_policy_basic_protocols.hujson")
c.Assert(err, check.IsNil)
rules, err := generateACLRules([]Machine{}, *app.aclPolicy, false)
rules, err := generateACLRules([]Node{}, *app.aclPolicy, false)
c.Assert(err, check.IsNil)
c.Assert(rules, check.NotNil)
@ -439,7 +439,7 @@ func (s *Suite) TestPortWildcard(c *check.C) {
err := app.LoadACLPolicy("./tests/acls/acl_policy_basic_wildcards.hujson")
c.Assert(err, check.IsNil)
rules, err := generateACLRules([]Machine{}, *app.aclPolicy, false)
rules, err := generateACLRules([]Node{}, *app.aclPolicy, false)
c.Assert(err, check.IsNil)
c.Assert(rules, check.NotNil)
@ -455,7 +455,7 @@ func (s *Suite) TestPortWildcardYAML(c *check.C) {
err := app.LoadACLPolicy("./tests/acls/acl_policy_basic_wildcards.yaml")
c.Assert(err, check.IsNil)
rules, err := generateACLRules([]Machine{}, *app.aclPolicy, false)
rules, err := generateACLRules([]Node{}, *app.aclPolicy, false)
c.Assert(err, check.IsNil)
c.Assert(rules, check.NotNil)
@ -474,31 +474,31 @@ func (s *Suite) TestPortUser(c *check.C) {
pak, err := app.CreatePreAuthKey(user.Name, false, false, nil, nil)
c.Assert(err, check.IsNil)
_, err = app.GetMachine("testuser", "testmachine")
_, err = app.GetNode("testuser", "testnode")
c.Assert(err, check.NotNil)
ips, _ := app.getAvailableIPs()
machine := Machine{
node := Node{
ID: 0,
MachineKey: "12345",
NodeKey: "bar",
DiscoKey: "faa",
Hostname: "testmachine",
Hostname: "testnode",
UserID: user.ID,
RegisterMethod: RegisterMethodAuthKey,
IPAddresses: ips,
AuthKeyID: uint(pak.ID),
}
app.db.Save(&machine)
app.db.Save(&node)
err = app.LoadACLPolicy(
"./tests/acls/acl_policy_basic_user_as_user.hujson",
)
c.Assert(err, check.IsNil)
machines, err := app.ListMachines()
nodes, err := app.ListNodes()
c.Assert(err, check.IsNil)
rules, err := generateACLRules(machines, *app.aclPolicy, false)
rules, err := generateACLRules(nodes, *app.aclPolicy, false)
c.Assert(err, check.IsNil)
c.Assert(rules, check.NotNil)
@ -519,29 +519,29 @@ func (s *Suite) TestPortGroup(c *check.C) {
pak, err := app.CreatePreAuthKey(user.Name, false, false, nil, nil)
c.Assert(err, check.IsNil)
_, err = app.GetMachine("testuser", "testmachine")
_, err = app.GetNode("testuser", "testnode")
c.Assert(err, check.NotNil)
ips, _ := app.getAvailableIPs()
machine := Machine{
node := Node{
ID: 0,
MachineKey: "foo",
NodeKey: "bar",
DiscoKey: "faa",
Hostname: "testmachine",
Hostname: "testnode",
UserID: user.ID,
RegisterMethod: RegisterMethodAuthKey,
IPAddresses: ips,
AuthKeyID: uint(pak.ID),
}
app.db.Save(&machine)
app.db.Save(&node)
err = app.LoadACLPolicy("./tests/acls/acl_policy_basic_groups.hujson")
c.Assert(err, check.IsNil)
machines, err := app.ListMachines()
nodes, err := app.ListNodes()
c.Assert(err, check.IsNil)
rules, err := generateACLRules(machines, *app.aclPolicy, false)
rules, err := generateACLRules(nodes, *app.aclPolicy, false)
c.Assert(err, check.IsNil)
c.Assert(rules, check.NotNil)
@ -843,47 +843,47 @@ func Test_expandPorts(t *testing.T) {
}
}
func Test_listMachinesInUser(t *testing.T) {
func Test_listNodesInUser(t *testing.T) {
type args struct {
machines []Machine
user string
nodes []Node
user string
}
tests := []struct {
name string
args args
want []Machine
want []Node
}{
{
name: "1 machine in user",
name: "1 node in user",
args: args{
machines: []Machine{
nodes: []Node{
{User: User{Name: "joe"}},
},
user: "joe",
},
want: []Machine{
want: []Node{
{User: User{Name: "joe"}},
},
},
{
name: "3 machines, 2 in user",
name: "3 nodes, 2 in user",
args: args{
machines: []Machine{
nodes: []Node{
{ID: 1, User: User{Name: "joe"}},
{ID: 2, User: User{Name: "marc"}},
{ID: 3, User: User{Name: "marc"}},
},
user: "marc",
},
want: []Machine{
want: []Node{
{ID: 2, User: User{Name: "marc"}},
{ID: 3, User: User{Name: "marc"}},
},
},
{
name: "5 machines, 0 in user",
name: "5 nodes, 0 in user",
args: args{
machines: []Machine{
nodes: []Node{
{ID: 1, User: User{Name: "joe"}},
{ID: 2, User: User{Name: "marc"}},
{ID: 3, User: User{Name: "marc"}},
@ -892,16 +892,16 @@ func Test_listMachinesInUser(t *testing.T) {
},
user: "mickael",
},
want: []Machine{},
want: []Node{},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
if got := filterMachinesByUser(test.args.machines, test.args.user); !reflect.DeepEqual(
if got := filterNodesByUser(test.args.nodes, test.args.user); !reflect.DeepEqual(
got,
test.want,
) {
t.Errorf("listMachinesInUser() = %v, want %v", got, test.want)
t.Errorf("listNodesInUser() = %v, want %v", got, test.want)
}
})
}
@ -909,7 +909,7 @@ func Test_listMachinesInUser(t *testing.T) {
func Test_expandAlias(t *testing.T) {
type args struct {
machines []Machine
nodes []Node
aclPolicy ACLPolicy
alias string
stripEmailDomain bool
@ -924,10 +924,10 @@ func Test_expandAlias(t *testing.T) {
name: "wildcard",
args: args{
alias: "*",
machines: []Machine{
{IPAddresses: MachineAddresses{netip.MustParseAddr("100.64.0.1")}},
nodes: []Node{
{IPAddresses: NodeAddresses{netip.MustParseAddr("100.64.0.1")}},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.78.84.227"),
},
},
@ -942,27 +942,27 @@ func Test_expandAlias(t *testing.T) {
name: "simple group",
args: args{
alias: "group:accountant",
machines: []Machine{
nodes: []Node{
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.1"),
},
User: User{Name: "joe"},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.2"),
},
User: User{Name: "joe"},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.3"),
},
User: User{Name: "marc"},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.4"),
},
User: User{Name: "mickael"},
@ -980,27 +980,27 @@ func Test_expandAlias(t *testing.T) {
name: "wrong group",
args: args{
alias: "group:hr",
machines: []Machine{
nodes: []Node{
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.1"),
},
User: User{Name: "joe"},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.2"),
},
User: User{Name: "joe"},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.3"),
},
User: User{Name: "marc"},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.4"),
},
User: User{Name: "mickael"},
@ -1018,7 +1018,7 @@ func Test_expandAlias(t *testing.T) {
name: "simple ipaddress",
args: args{
alias: "10.0.0.3",
machines: []Machine{},
nodes: []Node{},
aclPolicy: ACLPolicy{},
stripEmailDomain: true,
},
@ -1029,7 +1029,7 @@ func Test_expandAlias(t *testing.T) {
name: "simple host by ip passed through",
args: args{
alias: "10.0.0.1",
machines: []Machine{},
nodes: []Node{},
aclPolicy: ACLPolicy{},
stripEmailDomain: true,
},
@ -1040,9 +1040,9 @@ func Test_expandAlias(t *testing.T) {
name: "simple host by ipv4 single ipv4",
args: args{
alias: "10.0.0.1",
machines: []Machine{
nodes: []Node{
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("10.0.0.1"),
},
User: User{Name: "mickael"},
@ -1058,9 +1058,9 @@ func Test_expandAlias(t *testing.T) {
name: "simple host by ipv4 single dual stack",
args: args{
alias: "10.0.0.1",
machines: []Machine{
nodes: []Node{
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("10.0.0.1"),
netip.MustParseAddr("fd7a:115c:a1e0:ab12:4843:2222:6273:2222"),
},
@ -1077,9 +1077,9 @@ func Test_expandAlias(t *testing.T) {
name: "simple host by ipv6 single dual stack",
args: args{
alias: "fd7a:115c:a1e0:ab12:4843:2222:6273:2222",
machines: []Machine{
nodes: []Node{
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("10.0.0.1"),
netip.MustParseAddr("fd7a:115c:a1e0:ab12:4843:2222:6273:2222"),
},
@ -1095,8 +1095,8 @@ func Test_expandAlias(t *testing.T) {
{
name: "simple host by hostname alias",
args: args{
alias: "testy",
machines: []Machine{},
alias: "testy",
nodes: []Node{},
aclPolicy: ACLPolicy{
Hosts: Hosts{
"testy": netip.MustParsePrefix("10.0.0.132/32"),
@ -1110,8 +1110,8 @@ func Test_expandAlias(t *testing.T) {
{
name: "private network",
args: args{
alias: "homeNetwork",
machines: []Machine{},
alias: "homeNetwork",
nodes: []Node{},
aclPolicy: ACLPolicy{
Hosts: Hosts{
"homeNetwork": netip.MustParsePrefix("192.168.1.0/24"),
@ -1126,7 +1126,7 @@ func Test_expandAlias(t *testing.T) {
name: "simple CIDR",
args: args{
alias: "10.0.0.0/16",
machines: []Machine{},
nodes: []Node{},
aclPolicy: ACLPolicy{},
stripEmailDomain: true,
},
@ -1137,9 +1137,9 @@ func Test_expandAlias(t *testing.T) {
name: "simple tag",
args: args{
alias: "tag:hr-webserver",
machines: []Machine{
nodes: []Node{
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.1"),
},
User: User{Name: "joe"},
@ -1150,7 +1150,7 @@ func Test_expandAlias(t *testing.T) {
},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.2"),
},
User: User{Name: "joe"},
@ -1161,13 +1161,13 @@ func Test_expandAlias(t *testing.T) {
},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.3"),
},
User: User{Name: "marc"},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.4"),
},
User: User{Name: "joe"},
@ -1185,27 +1185,27 @@ func Test_expandAlias(t *testing.T) {
name: "No tag defined",
args: args{
alias: "tag:hr-webserver",
machines: []Machine{
nodes: []Node{
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.1"),
},
User: User{Name: "joe"},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.2"),
},
User: User{Name: "joe"},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.3"),
},
User: User{Name: "marc"},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.4"),
},
User: User{Name: "mickael"},
@ -1226,29 +1226,29 @@ func Test_expandAlias(t *testing.T) {
name: "Forced tag defined",
args: args{
alias: "tag:hr-webserver",
machines: []Machine{
nodes: []Node{
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.1"),
},
User: User{Name: "joe"},
ForcedTags: []string{"tag:hr-webserver"},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.2"),
},
User: User{Name: "joe"},
ForcedTags: []string{"tag:hr-webserver"},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.3"),
},
User: User{Name: "marc"},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.4"),
},
User: User{Name: "mickael"},
@ -1264,16 +1264,16 @@ func Test_expandAlias(t *testing.T) {
name: "Forced tag with legitimate tagOwner",
args: args{
alias: "tag:hr-webserver",
machines: []Machine{
nodes: []Node{
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.1"),
},
User: User{Name: "joe"},
ForcedTags: []string{"tag:hr-webserver"},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.2"),
},
User: User{Name: "joe"},
@ -1284,13 +1284,13 @@ func Test_expandAlias(t *testing.T) {
},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.3"),
},
User: User{Name: "marc"},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.4"),
},
User: User{Name: "mickael"},
@ -1310,9 +1310,9 @@ func Test_expandAlias(t *testing.T) {
name: "list host in user without correctly tagged servers",
args: args{
alias: "joe",
machines: []Machine{
nodes: []Node{
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.1"),
},
User: User{Name: "joe"},
@ -1323,7 +1323,7 @@ func Test_expandAlias(t *testing.T) {
},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.2"),
},
User: User{Name: "joe"},
@ -1334,13 +1334,13 @@ func Test_expandAlias(t *testing.T) {
},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.3"),
},
User: User{Name: "marc"},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.4"),
},
User: User{Name: "joe"},
@ -1358,7 +1358,7 @@ func Test_expandAlias(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := expandAlias(
test.args.machines,
test.args.nodes,
test.args.aclPolicy,
test.args.alias,
test.args.stripEmailDomain,
@ -1378,14 +1378,14 @@ func Test_expandAlias(t *testing.T) {
func Test_excludeCorrectlyTaggedNodes(t *testing.T) {
type args struct {
aclPolicy ACLPolicy
nodes []Machine
nodes []Node
user string
stripEmailDomain bool
}
tests := []struct {
name string
args args
want []Machine
want []Node
wantErr bool
}{
{
@ -1394,9 +1394,9 @@ func Test_excludeCorrectlyTaggedNodes(t *testing.T) {
aclPolicy: ACLPolicy{
TagOwners: TagOwners{"tag:accountant-webserver": []string{"joe"}},
},
nodes: []Machine{
nodes: []Node{
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.1"),
},
User: User{Name: "joe"},
@ -1407,7 +1407,7 @@ func Test_excludeCorrectlyTaggedNodes(t *testing.T) {
},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.2"),
},
User: User{Name: "joe"},
@ -1418,7 +1418,7 @@ func Test_excludeCorrectlyTaggedNodes(t *testing.T) {
},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.4"),
},
User: User{Name: "joe"},
@ -1427,9 +1427,9 @@ func Test_excludeCorrectlyTaggedNodes(t *testing.T) {
user: "joe",
stripEmailDomain: true,
},
want: []Machine{
want: []Node{
{
IPAddresses: MachineAddresses{netip.MustParseAddr("100.64.0.4")},
IPAddresses: NodeAddresses{netip.MustParseAddr("100.64.0.4")},
User: User{Name: "joe"},
},
},
@ -1445,9 +1445,9 @@ func Test_excludeCorrectlyTaggedNodes(t *testing.T) {
"tag:accountant-webserver": []string{"group:accountant"},
},
},
nodes: []Machine{
nodes: []Node{
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.1"),
},
User: User{Name: "joe"},
@ -1458,7 +1458,7 @@ func Test_excludeCorrectlyTaggedNodes(t *testing.T) {
},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.2"),
},
User: User{Name: "joe"},
@ -1469,7 +1469,7 @@ func Test_excludeCorrectlyTaggedNodes(t *testing.T) {
},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.4"),
},
User: User{Name: "joe"},
@ -1478,9 +1478,9 @@ func Test_excludeCorrectlyTaggedNodes(t *testing.T) {
user: "joe",
stripEmailDomain: true,
},
want: []Machine{
want: []Node{
{
IPAddresses: MachineAddresses{netip.MustParseAddr("100.64.0.4")},
IPAddresses: NodeAddresses{netip.MustParseAddr("100.64.0.4")},
User: User{Name: "joe"},
},
},
@ -1491,9 +1491,9 @@ func Test_excludeCorrectlyTaggedNodes(t *testing.T) {
aclPolicy: ACLPolicy{
TagOwners: TagOwners{"tag:accountant-webserver": []string{"joe"}},
},
nodes: []Machine{
nodes: []Node{
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.1"),
},
User: User{Name: "joe"},
@ -1504,14 +1504,14 @@ func Test_excludeCorrectlyTaggedNodes(t *testing.T) {
},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.2"),
},
User: User{Name: "joe"},
ForcedTags: []string{"tag:accountant-webserver"},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.4"),
},
User: User{Name: "joe"},
@ -1520,9 +1520,9 @@ func Test_excludeCorrectlyTaggedNodes(t *testing.T) {
user: "joe",
stripEmailDomain: true,
},
want: []Machine{
want: []Node{
{
IPAddresses: MachineAddresses{netip.MustParseAddr("100.64.0.4")},
IPAddresses: NodeAddresses{netip.MustParseAddr("100.64.0.4")},
User: User{Name: "joe"},
},
},
@ -1533,9 +1533,9 @@ func Test_excludeCorrectlyTaggedNodes(t *testing.T) {
aclPolicy: ACLPolicy{
TagOwners: TagOwners{"tag:accountant-webserver": []string{"joe"}},
},
nodes: []Machine{
nodes: []Node{
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.1"),
},
User: User{Name: "joe"},
@ -1546,7 +1546,7 @@ func Test_excludeCorrectlyTaggedNodes(t *testing.T) {
},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.2"),
},
User: User{Name: "joe"},
@ -1557,7 +1557,7 @@ func Test_excludeCorrectlyTaggedNodes(t *testing.T) {
},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.4"),
},
User: User{Name: "joe"},
@ -1566,9 +1566,9 @@ func Test_excludeCorrectlyTaggedNodes(t *testing.T) {
user: "joe",
stripEmailDomain: true,
},
want: []Machine{
want: []Node{
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.1"),
},
User: User{Name: "joe"},
@ -1579,7 +1579,7 @@ func Test_excludeCorrectlyTaggedNodes(t *testing.T) {
},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.2"),
},
User: User{Name: "joe"},
@ -1590,7 +1590,7 @@ func Test_excludeCorrectlyTaggedNodes(t *testing.T) {
},
},
{
IPAddresses: MachineAddresses{
IPAddresses: NodeAddresses{
netip.MustParseAddr("100.64.0.4"),
},
User: User{Name: "joe"},

View File

@ -51,7 +51,7 @@ type AutoApprovers struct {
ExitNode []string `json:"exitNode" yaml:"exitNode"`
}
// SSH controls who can ssh into which machines.
// SSH controls who can ssh into which nodes.
type SSH struct {
Action string `json:"action" yaml:"action"`
Sources []string `json:"src" yaml:"src"`

View File

@ -157,10 +157,10 @@ func (s *Suite) TestDNSConfigMapResponseWithMagicDNS(c *check.C) {
)
c.Assert(err, check.IsNil)
_, err = app.GetMachine(userShared1.Name, "test_get_shared_nodes_1")
_, err = app.GetNode(userShared1.Name, "test_get_shared_nodes_1")
c.Assert(err, check.NotNil)
machineInShared1 := &Machine{
nodesInShared1 := &Node{
ID: 1,
MachineKey: "686824e749f3b7f2a5927ee6c1e422aee5292592d9179a271ed7b3e659b44a66",
NodeKey: "686824e749f3b7f2a5927ee6c1e422aee5292592d9179a271ed7b3e659b44a66",
@ -172,12 +172,12 @@ func (s *Suite) TestDNSConfigMapResponseWithMagicDNS(c *check.C) {
IPAddresses: []netip.Addr{netip.MustParseAddr("100.64.0.1")},
AuthKeyID: uint(preAuthKeyInShared1.ID),
}
app.db.Save(machineInShared1)
app.db.Save(nodesInShared1)
_, err = app.GetMachine(userShared1.Name, machineInShared1.Hostname)
_, err = app.GetNode(userShared1.Name, nodesInShared1.Hostname)
c.Assert(err, check.IsNil)
machineInShared2 := &Machine{
nodesInShared2 := &Node{
ID: 2,
MachineKey: "dec46ef9dc45c7d2f03bfcd5a640d9e24e3cc68ce3d9da223867c9bc6d5e9863",
NodeKey: "dec46ef9dc45c7d2f03bfcd5a640d9e24e3cc68ce3d9da223867c9bc6d5e9863",
@ -189,12 +189,12 @@ func (s *Suite) TestDNSConfigMapResponseWithMagicDNS(c *check.C) {
IPAddresses: []netip.Addr{netip.MustParseAddr("100.64.0.2")},
AuthKeyID: uint(preAuthKeyInShared2.ID),
}
app.db.Save(machineInShared2)
app.db.Save(nodesInShared2)
_, err = app.GetMachine(userShared2.Name, machineInShared2.Hostname)
_, err = app.GetNode(userShared2.Name, nodesInShared2.Hostname)
c.Assert(err, check.IsNil)
machineInShared3 := &Machine{
nodesInShared3 := &Node{
ID: 3,
MachineKey: "dec46ef9dc45c7d2f03bfcd5a640d9e24e3cc68ce3d9da223867c9bc6d5e9863",
NodeKey: "dec46ef9dc45c7d2f03bfcd5a640d9e24e3cc68ce3d9da223867c9bc6d5e9863",
@ -206,12 +206,12 @@ func (s *Suite) TestDNSConfigMapResponseWithMagicDNS(c *check.C) {
IPAddresses: []netip.Addr{netip.MustParseAddr("100.64.0.3")},
AuthKeyID: uint(preAuthKeyInShared3.ID),
}
app.db.Save(machineInShared3)
app.db.Save(nodesInShared3)
_, err = app.GetMachine(userShared3.Name, machineInShared3.Hostname)
_, err = app.GetNode(userShared3.Name, nodesInShared3.Hostname)
c.Assert(err, check.IsNil)
machine2InShared1 := &Machine{
nodes2InShared1 := &Node{
ID: 4,
MachineKey: "dec46ef9dc45c7d2f03bfcd5a640d9e24e3cc68ce3d9da223867c9bc6d5e9863",
NodeKey: "dec46ef9dc45c7d2f03bfcd5a640d9e24e3cc68ce3d9da223867c9bc6d5e9863",
@ -223,7 +223,7 @@ func (s *Suite) TestDNSConfigMapResponseWithMagicDNS(c *check.C) {
IPAddresses: []netip.Addr{netip.MustParseAddr("100.64.0.4")},
AuthKeyID: uint(PreAuthKey2InShared1.ID),
}
app.db.Save(machine2InShared1)
app.db.Save(nodes2InShared1)
baseDomain := "foobar.headscale.net"
dnsConfigOrig := tailcfg.DNSConfig{
@ -232,14 +232,14 @@ func (s *Suite) TestDNSConfigMapResponseWithMagicDNS(c *check.C) {
Proxied: true,
}
peersOfMachineInShared1, err := app.getPeers(machineInShared1)
peersOfNodeInShared1, err := app.getPeers(nodesInShared1)
c.Assert(err, check.IsNil)
dnsConfig := getMapResponseDNSConfig(
&dnsConfigOrig,
baseDomain,
*machineInShared1,
peersOfMachineInShared1,
*nodesInShared1,
peersOfNodeInShared1,
)
c.Assert(dnsConfig, check.NotNil)
@ -304,10 +304,10 @@ func (s *Suite) TestDNSConfigMapResponseWithoutMagicDNS(c *check.C) {
)
c.Assert(err, check.IsNil)
_, err = app.GetMachine(userShared1.Name, "test_get_shared_nodes_1")
_, err = app.GetNode(userShared1.Name, "test_get_shared_nodes_1")
c.Assert(err, check.NotNil)
machineInShared1 := &Machine{
nodesInShared1 := &Node{
ID: 1,
MachineKey: "686824e749f3b7f2a5927ee6c1e422aee5292592d9179a271ed7b3e659b44a66",
NodeKey: "686824e749f3b7f2a5927ee6c1e422aee5292592d9179a271ed7b3e659b44a66",
@ -319,12 +319,12 @@ func (s *Suite) TestDNSConfigMapResponseWithoutMagicDNS(c *check.C) {
IPAddresses: []netip.Addr{netip.MustParseAddr("100.64.0.1")},
AuthKeyID: uint(preAuthKeyInShared1.ID),
}
app.db.Save(machineInShared1)
app.db.Save(nodesInShared1)
_, err = app.GetMachine(userShared1.Name, machineInShared1.Hostname)
_, err = app.GetNode(userShared1.Name, nodesInShared1.Hostname)
c.Assert(err, check.IsNil)
machineInShared2 := &Machine{
nodesInShared2 := &Node{
ID: 2,
MachineKey: "dec46ef9dc45c7d2f03bfcd5a640d9e24e3cc68ce3d9da223867c9bc6d5e9863",
NodeKey: "dec46ef9dc45c7d2f03bfcd5a640d9e24e3cc68ce3d9da223867c9bc6d5e9863",
@ -336,12 +336,12 @@ func (s *Suite) TestDNSConfigMapResponseWithoutMagicDNS(c *check.C) {
IPAddresses: []netip.Addr{netip.MustParseAddr("100.64.0.2")},
AuthKeyID: uint(preAuthKeyInShared2.ID),
}
app.db.Save(machineInShared2)
app.db.Save(nodesInShared2)
_, err = app.GetMachine(userShared2.Name, machineInShared2.Hostname)
_, err = app.GetNode(userShared2.Name, nodesInShared2.Hostname)
c.Assert(err, check.IsNil)
machineInShared3 := &Machine{
nodesInShared3 := &Node{
ID: 3,
MachineKey: "dec46ef9dc45c7d2f03bfcd5a640d9e24e3cc68ce3d9da223867c9bc6d5e9863",
NodeKey: "dec46ef9dc45c7d2f03bfcd5a640d9e24e3cc68ce3d9da223867c9bc6d5e9863",
@ -353,12 +353,12 @@ func (s *Suite) TestDNSConfigMapResponseWithoutMagicDNS(c *check.C) {
IPAddresses: []netip.Addr{netip.MustParseAddr("100.64.0.3")},
AuthKeyID: uint(preAuthKeyInShared3.ID),
}
app.db.Save(machineInShared3)
app.db.Save(nodesInShared3)
_, err = app.GetMachine(userShared3.Name, machineInShared3.Hostname)
_, err = app.GetNode(userShared3.Name, nodesInShared3.Hostname)
c.Assert(err, check.IsNil)
machine2InShared1 := &Machine{
nodes2InShared1 := &Node{
ID: 4,
MachineKey: "dec46ef9dc45c7d2f03bfcd5a640d9e24e3cc68ce3d9da223867c9bc6d5e9863",
NodeKey: "dec46ef9dc45c7d2f03bfcd5a640d9e24e3cc68ce3d9da223867c9bc6d5e9863",
@ -370,7 +370,7 @@ func (s *Suite) TestDNSConfigMapResponseWithoutMagicDNS(c *check.C) {
IPAddresses: []netip.Addr{netip.MustParseAddr("100.64.0.4")},
AuthKeyID: uint(preAuthKey2InShared1.ID),
}
app.db.Save(machine2InShared1)
app.db.Save(nodes2InShared1)
baseDomain := "foobar.headscale.net"
dnsConfigOrig := tailcfg.DNSConfig{
@ -379,14 +379,14 @@ func (s *Suite) TestDNSConfigMapResponseWithoutMagicDNS(c *check.C) {
Proxied: false,
}
peersOfMachine1Shared1, err := app.getPeers(machineInShared1)
peersOfNode1Shared1, err := app.getPeers(nodesInShared1)
c.Assert(err, check.IsNil)
dnsConfig := getMapResponseDNSConfig(
&dnsConfigOrig,
baseDomain,
*machineInShared1,
peersOfMachine1Shared1,
*nodesInShared1,
peersOfNode1Shared1,
)
c.Assert(dnsConfig, check.NotNil)
c.Assert(len(dnsConfig.Routes), check.Equals, 0)

File diff suppressed because it is too large Load Diff

View File

@ -73,7 +73,7 @@ func (*Suite) TestAlreadyUsedKey(c *check.C) {
pak, err := app.CreatePreAuthKey(user.Name, false, false, nil, nil)
c.Assert(err, check.IsNil)
machine := Machine{
node := Node{
ID: 0,
MachineKey: "foo",
NodeKey: "bar",
@ -83,7 +83,7 @@ func (*Suite) TestAlreadyUsedKey(c *check.C) {
RegisterMethod: RegisterMethodAuthKey,
AuthKeyID: uint(pak.ID),
}
app.db.Save(&machine)
app.db.Save(&node)
key, err := app.checkKeyValidity(pak.Key)
c.Assert(err, check.Equals, ErrSingleUseAuthKeyHasBeenUsed)
@ -97,7 +97,7 @@ func (*Suite) TestReusableBeingUsedKey(c *check.C) {
pak, err := app.CreatePreAuthKey(user.Name, true, false, nil, nil)
c.Assert(err, check.IsNil)
machine := Machine{
node := Node{
ID: 1,
MachineKey: "foo",
NodeKey: "bar",
@ -107,7 +107,7 @@ func (*Suite) TestReusableBeingUsedKey(c *check.C) {
RegisterMethod: RegisterMethodAuthKey,
AuthKeyID: uint(pak.ID),
}
app.db.Save(&machine)
app.db.Save(&node)
key, err := app.checkKeyValidity(pak.Key)
c.Assert(err, check.IsNil)
@ -134,7 +134,7 @@ func (*Suite) TestEphemeralKey(c *check.C) {
c.Assert(err, check.IsNil)
now := time.Now()
machine := Machine{
node := Node{
ID: 0,
MachineKey: "foo",
NodeKey: "bar",
@ -145,19 +145,19 @@ func (*Suite) TestEphemeralKey(c *check.C) {
LastSeen: &now,
AuthKeyID: uint(pak.ID),
}
app.db.Save(&machine)
app.db.Save(&node)
_, err = app.checkKeyValidity(pak.Key)
// Ephemeral keys are by definition reusable
c.Assert(err, check.IsNil)
_, err = app.GetMachine("test7", "testest")
_, err = app.GetNode("test7", "testest")
c.Assert(err, check.IsNil)
app.expireEphemeralNodesWorker()
// The machine record should have been deleted
_, err = app.GetMachine("test7", "testest")
// The node record should have been deleted
_, err = app.GetNode("test7", "testest")
c.Assert(err, check.NotNil)
}

View File

@ -16,7 +16,7 @@ func (s *Suite) TestGetRoutes(c *check.C) {
pak, err := app.CreatePreAuthKey(user.Name, false, false, nil, nil)
c.Assert(err, check.IsNil)
_, err = app.GetMachine("test", "test_get_route_machine")
_, err = app.GetNode("test", "test_get_route_machine")
c.Assert(err, check.NotNil)
route, err := netip.ParsePrefix("10.0.0.0/24")
@ -26,7 +26,7 @@ func (s *Suite) TestGetRoutes(c *check.C) {
RoutableIPs: []netip.Prefix{route},
}
machine := Machine{
machine := Node{
ID: 0,
MachineKey: "foo",
NodeKey: "bar",
@ -39,7 +39,7 @@ func (s *Suite) TestGetRoutes(c *check.C) {
}
app.db.Save(&machine)
err = app.processMachineRoutes(&machine)
err = app.processNodeRoutes(&machine)
c.Assert(err, check.IsNil)
advertisedRoutes, err := app.GetAdvertisedRoutes(&machine)
@ -60,7 +60,7 @@ func (s *Suite) TestGetEnableRoutes(c *check.C) {
pak, err := app.CreatePreAuthKey(user.Name, false, false, nil, nil)
c.Assert(err, check.IsNil)
_, err = app.GetMachine("test", "test_enable_route_machine")
_, err = app.GetNode("test", "test_enable_route_machine")
c.Assert(err, check.NotNil)
route, err := netip.ParsePrefix(
@ -77,7 +77,7 @@ func (s *Suite) TestGetEnableRoutes(c *check.C) {
RoutableIPs: []netip.Prefix{route, route2},
}
machine := Machine{
machine := Node{
ID: 0,
MachineKey: "foo",
NodeKey: "bar",
@ -90,7 +90,7 @@ func (s *Suite) TestGetEnableRoutes(c *check.C) {
}
app.db.Save(&machine)
err = app.processMachineRoutes(&machine)
err = app.processNodeRoutes(&machine)
c.Assert(err, check.IsNil)
availableRoutes, err := app.GetAdvertisedRoutes(&machine)
@ -135,7 +135,7 @@ func (s *Suite) TestIsUniquePrefix(c *check.C) {
pak, err := app.CreatePreAuthKey(user.Name, false, false, nil, nil)
c.Assert(err, check.IsNil)
_, err = app.GetMachine("test", "test_enable_route_machine")
_, err = app.GetNode("test", "test_enable_route_machine")
c.Assert(err, check.NotNil)
route, err := netip.ParsePrefix(
@ -151,7 +151,7 @@ func (s *Suite) TestIsUniquePrefix(c *check.C) {
hostInfo1 := tailcfg.Hostinfo{
RoutableIPs: []netip.Prefix{route, route2},
}
machine1 := Machine{
machine1 := Node{
ID: 1,
MachineKey: "foo",
NodeKey: "bar",
@ -164,7 +164,7 @@ func (s *Suite) TestIsUniquePrefix(c *check.C) {
}
app.db.Save(&machine1)
err = app.processMachineRoutes(&machine1)
err = app.processNodeRoutes(&machine1)
c.Assert(err, check.IsNil)
err = app.enableRoutes(&machine1, route.String())
@ -176,7 +176,7 @@ func (s *Suite) TestIsUniquePrefix(c *check.C) {
hostInfo2 := tailcfg.Hostinfo{
RoutableIPs: []netip.Prefix{route2},
}
machine2 := Machine{
machine2 := Node{
ID: 2,
MachineKey: "foo",
NodeKey: "bar",
@ -189,7 +189,7 @@ func (s *Suite) TestIsUniquePrefix(c *check.C) {
}
app.db.Save(&machine2)
err = app.processMachineRoutes(&machine2)
err = app.processNodeRoutes(&machine2)
c.Assert(err, check.IsNil)
err = app.enableRoutes(&machine2, route2.String())
@ -203,11 +203,11 @@ func (s *Suite) TestIsUniquePrefix(c *check.C) {
c.Assert(err, check.IsNil)
c.Assert(len(enabledRoutes2), check.Equals, 1)
routes, err := app.getMachinePrimaryRoutes(&machine1)
routes, err := app.getNodePrimaryRoutes(&machine1)
c.Assert(err, check.IsNil)
c.Assert(len(routes), check.Equals, 2)
routes, err = app.getMachinePrimaryRoutes(&machine2)
routes, err = app.getNodePrimaryRoutes(&machine2)
c.Assert(err, check.IsNil)
c.Assert(len(routes), check.Equals, 0)
}
@ -219,7 +219,7 @@ func (s *Suite) TestSubnetFailover(c *check.C) {
pak, err := app.CreatePreAuthKey(user.Name, false, false, nil, nil)
c.Assert(err, check.IsNil)
_, err = app.GetMachine("test", "test_enable_route_machine")
_, err = app.GetNode("test", "test_enable_route_machine")
c.Assert(err, check.NotNil)
prefix, err := netip.ParsePrefix(
@ -237,7 +237,7 @@ func (s *Suite) TestSubnetFailover(c *check.C) {
}
now := time.Now()
machine1 := Machine{
machine1 := Node{
ID: 1,
MachineKey: "foo",
NodeKey: "bar",
@ -251,7 +251,7 @@ func (s *Suite) TestSubnetFailover(c *check.C) {
}
app.db.Save(&machine1)
err = app.processMachineRoutes(&machine1)
err = app.processNodeRoutes(&machine1)
c.Assert(err, check.IsNil)
err = app.enableRoutes(&machine1, prefix.String())
@ -269,12 +269,12 @@ func (s *Suite) TestSubnetFailover(c *check.C) {
route, err := app.getPrimaryRoute(prefix)
c.Assert(err, check.IsNil)
c.Assert(route.MachineID, check.Equals, machine1.ID)
c.Assert(route.NodeID, check.Equals, machine1.ID)
hostInfo2 := tailcfg.Hostinfo{
RoutableIPs: []netip.Prefix{prefix2},
}
machine2 := Machine{
machine2 := Node{
ID: 2,
MachineKey: "foo",
NodeKey: "bar",
@ -288,7 +288,7 @@ func (s *Suite) TestSubnetFailover(c *check.C) {
}
app.db.Save(&machine2)
err = app.processMachineRoutes(&machine2)
err = app.processNodeRoutes(&machine2)
c.Assert(err, check.IsNil)
err = app.enableRoutes(&machine2, prefix2.String())
@ -305,11 +305,11 @@ func (s *Suite) TestSubnetFailover(c *check.C) {
c.Assert(err, check.IsNil)
c.Assert(len(enabledRoutes2), check.Equals, 1)
routes, err := app.getMachinePrimaryRoutes(&machine1)
routes, err := app.getNodePrimaryRoutes(&machine1)
c.Assert(err, check.IsNil)
c.Assert(len(routes), check.Equals, 2)
routes, err = app.getMachinePrimaryRoutes(&machine2)
routes, err = app.getNodePrimaryRoutes(&machine2)
c.Assert(err, check.IsNil)
c.Assert(len(routes), check.Equals, 0)
@ -322,11 +322,11 @@ func (s *Suite) TestSubnetFailover(c *check.C) {
err = app.handlePrimarySubnetFailover()
c.Assert(err, check.IsNil)
routes, err = app.getMachinePrimaryRoutes(&machine1)
routes, err = app.getNodePrimaryRoutes(&machine1)
c.Assert(err, check.IsNil)
c.Assert(len(routes), check.Equals, 1)
routes, err = app.getMachinePrimaryRoutes(&machine2)
routes, err = app.getNodePrimaryRoutes(&machine2)
c.Assert(err, check.IsNil)
c.Assert(len(routes), check.Equals, 1)
@ -336,7 +336,7 @@ func (s *Suite) TestSubnetFailover(c *check.C) {
err = app.db.Save(&machine2).Error
c.Assert(err, check.IsNil)
err = app.processMachineRoutes(&machine2)
err = app.processNodeRoutes(&machine2)
c.Assert(err, check.IsNil)
err = app.enableRoutes(&machine2, prefix.String())
@ -345,11 +345,11 @@ func (s *Suite) TestSubnetFailover(c *check.C) {
err = app.handlePrimarySubnetFailover()
c.Assert(err, check.IsNil)
routes, err = app.getMachinePrimaryRoutes(&machine1)
routes, err = app.getNodePrimaryRoutes(&machine1)
c.Assert(err, check.IsNil)
c.Assert(len(routes), check.Equals, 0)
routes, err = app.getMachinePrimaryRoutes(&machine2)
routes, err = app.getNodePrimaryRoutes(&machine2)
c.Assert(err, check.IsNil)
c.Assert(len(routes), check.Equals, 2)
}
@ -364,7 +364,7 @@ func (s *Suite) TestAllowedIPRoutes(c *check.C) {
pak, err := app.CreatePreAuthKey(user.Name, false, false, nil, nil)
c.Assert(err, check.IsNil)
_, err = app.GetMachine("test", "test_enable_route_machine")
_, err = app.GetNode("test", "test_enable_route_machine")
c.Assert(err, check.NotNil)
prefix, err := netip.ParsePrefix(
@ -396,7 +396,7 @@ func (s *Suite) TestAllowedIPRoutes(c *check.C) {
machineKey := key.NewMachine()
now := time.Now()
machine1 := Machine{
machine1 := Node{
ID: 1,
MachineKey: MachinePublicKeyStripPrefix(machineKey.Public()),
NodeKey: NodePublicKeyStripPrefix(nodeKey.Public()),
@ -410,7 +410,7 @@ func (s *Suite) TestAllowedIPRoutes(c *check.C) {
}
app.db.Save(&machine1)
err = app.processMachineRoutes(&machine1)
err = app.processNodeRoutes(&machine1)
c.Assert(err, check.IsNil)
err = app.enableRoutes(&machine1, prefix.String())
@ -420,7 +420,7 @@ func (s *Suite) TestAllowedIPRoutes(c *check.C) {
// err = app.enableRoutes(&machine1, prefix2.String())
// c.Assert(err, check.IsNil)
routes, err := app.GetMachineRoutes(&machine1)
routes, err := app.GetNodeRoutes(&machine1)
c.Assert(err, check.IsNil)
for _, route := range routes {
if route.isExitRoute() {
@ -466,7 +466,7 @@ func (s *Suite) TestDeleteRoutes(c *check.C) {
pak, err := app.CreatePreAuthKey(user.Name, false, false, nil, nil)
c.Assert(err, check.IsNil)
_, err = app.GetMachine("test", "test_enable_route_machine")
_, err = app.GetNode("test", "test_enable_route_machine")
c.Assert(err, check.NotNil)
prefix, err := netip.ParsePrefix(
@ -484,7 +484,7 @@ func (s *Suite) TestDeleteRoutes(c *check.C) {
}
now := time.Now()
machine1 := Machine{
machine1 := Node{
ID: 1,
MachineKey: "foo",
NodeKey: "bar",
@ -498,7 +498,7 @@ func (s *Suite) TestDeleteRoutes(c *check.C) {
}
app.db.Save(&machine1)
err = app.processMachineRoutes(&machine1)
err = app.processNodeRoutes(&machine1)
c.Assert(err, check.IsNil)
err = app.enableRoutes(&machine1, prefix.String())
@ -507,7 +507,7 @@ func (s *Suite) TestDeleteRoutes(c *check.C) {
err = app.enableRoutes(&machine1, prefix2.String())
c.Assert(err, check.IsNil)
routes, err := app.GetMachineRoutes(&machine1)
routes, err := app.GetNodeRoutes(&machine1)
c.Assert(err, check.IsNil)
err = app.DeleteRoute(uint64(routes[0].ID))

View File

@ -47,17 +47,17 @@ func (s *Suite) TestDestroyUserErrors(c *check.C) {
pak, err = app.CreatePreAuthKey(user.Name, false, false, nil, nil)
c.Assert(err, check.IsNil)
machine := Machine{
node := Node{
ID: 0,
MachineKey: "foo",
NodeKey: "bar",
DiscoKey: "faa",
Hostname: "testmachine",
Hostname: "testnode",
UserID: user.ID,
RegisterMethod: RegisterMethodAuthKey,
AuthKeyID: uint(pak.ID),
}
app.db.Save(&machine)
app.db.Save(&node)
err = app.DestroyUser("test")
c.Assert(err, check.Equals, ErrUserStillHasNodes)
@ -138,10 +138,10 @@ func (s *Suite) TestGetMapResponseUserProfiles(c *check.C) {
)
c.Assert(err, check.IsNil)
_, err = app.GetMachine(userShared1.Name, "test_get_shared_nodes_1")
_, err = app.GetNode(userShared1.Name, "test_get_shared_nodes_1")
c.Assert(err, check.NotNil)
machineInShared1 := &Machine{
nodeInShared1 := &Node{
ID: 1,
MachineKey: "686824e749f3b7f2a5927ee6c1e422aee5292592d9179a271ed7b3e659b44a66",
NodeKey: "686824e749f3b7f2a5927ee6c1e422aee5292592d9179a271ed7b3e659b44a66",
@ -153,12 +153,12 @@ func (s *Suite) TestGetMapResponseUserProfiles(c *check.C) {
IPAddresses: []netip.Addr{netip.MustParseAddr("100.64.0.1")},
AuthKeyID: uint(preAuthKeyShared1.ID),
}
app.db.Save(machineInShared1)
app.db.Save(nodeInShared1)
_, err = app.GetMachine(userShared1.Name, machineInShared1.Hostname)
_, err = app.GetNode(userShared1.Name, nodeInShared1.Hostname)
c.Assert(err, check.IsNil)
machineInShared2 := &Machine{
nodeInShared2 := &Node{
ID: 2,
MachineKey: "dec46ef9dc45c7d2f03bfcd5a640d9e24e3cc68ce3d9da223867c9bc6d5e9863",
NodeKey: "dec46ef9dc45c7d2f03bfcd5a640d9e24e3cc68ce3d9da223867c9bc6d5e9863",
@ -170,12 +170,12 @@ func (s *Suite) TestGetMapResponseUserProfiles(c *check.C) {
IPAddresses: []netip.Addr{netip.MustParseAddr("100.64.0.2")},
AuthKeyID: uint(preAuthKeyShared2.ID),
}
app.db.Save(machineInShared2)
app.db.Save(nodeInShared2)
_, err = app.GetMachine(userShared2.Name, machineInShared2.Hostname)
_, err = app.GetNode(userShared2.Name, nodeInShared2.Hostname)
c.Assert(err, check.IsNil)
machineInShared3 := &Machine{
nodeInShared3 := &Node{
ID: 3,
MachineKey: "dec46ef9dc45c7d2f03bfcd5a640d9e24e3cc68ce3d9da223867c9bc6d5e9863",
NodeKey: "dec46ef9dc45c7d2f03bfcd5a640d9e24e3cc68ce3d9da223867c9bc6d5e9863",
@ -187,12 +187,12 @@ func (s *Suite) TestGetMapResponseUserProfiles(c *check.C) {
IPAddresses: []netip.Addr{netip.MustParseAddr("100.64.0.3")},
AuthKeyID: uint(preAuthKeyShared3.ID),
}
app.db.Save(machineInShared3)
app.db.Save(nodeInShared3)
_, err = app.GetMachine(userShared3.Name, machineInShared3.Hostname)
_, err = app.GetNode(userShared3.Name, nodeInShared3.Hostname)
c.Assert(err, check.IsNil)
machine2InShared1 := &Machine{
node2InShared1 := &Node{
ID: 4,
MachineKey: "dec46ef9dc45c7d2f03bfcd5a640d9e24e3cc68ce3d9da223867c9bc6d5e9863",
NodeKey: "dec46ef9dc45c7d2f03bfcd5a640d9e24e3cc68ce3d9da223867c9bc6d5e9863",
@ -204,14 +204,14 @@ func (s *Suite) TestGetMapResponseUserProfiles(c *check.C) {
IPAddresses: []netip.Addr{netip.MustParseAddr("100.64.0.4")},
AuthKeyID: uint(preAuthKey2Shared1.ID),
}
app.db.Save(machine2InShared1)
app.db.Save(node2InShared1)
peersOfMachine1InShared1, err := app.getPeers(machineInShared1)
peersOfNode1InShared1, err := app.getPeers(nodeInShared1)
c.Assert(err, check.IsNil)
userProfiles := app.getMapResponseUserProfiles(
*machineInShared1,
peersOfMachine1InShared1,
*nodeInShared1,
peersOfNode1InShared1,
)
c.Assert(len(userProfiles), check.Equals, 3)
@ -377,7 +377,7 @@ func TestCheckForFQDNRules(t *testing.T) {
}
}
func (s *Suite) TestSetMachineUser(c *check.C) {
func (s *Suite) TestSetNodeUser(c *check.C) {
oldUser, err := app.CreateUser("old")
c.Assert(err, check.IsNil)
@ -387,29 +387,29 @@ func (s *Suite) TestSetMachineUser(c *check.C) {
pak, err := app.CreatePreAuthKey(oldUser.Name, false, false, nil, nil)
c.Assert(err, check.IsNil)
machine := Machine{
node := Node{
ID: 0,
MachineKey: "foo",
NodeKey: "bar",
DiscoKey: "faa",
Hostname: "testmachine",
Hostname: "testnode",
UserID: oldUser.ID,
RegisterMethod: RegisterMethodAuthKey,
AuthKeyID: uint(pak.ID),
}
app.db.Save(&machine)
c.Assert(machine.UserID, check.Equals, oldUser.ID)
app.db.Save(&node)
c.Assert(node.UserID, check.Equals, oldUser.ID)
err = app.SetMachineUser(&machine, newUser.Name)
err = app.SetNodeUser(&node, newUser.Name)
c.Assert(err, check.IsNil)
c.Assert(machine.UserID, check.Equals, newUser.ID)
c.Assert(machine.User.Name, check.Equals, newUser.Name)
c.Assert(node.UserID, check.Equals, newUser.ID)
c.Assert(node.User.Name, check.Equals, newUser.Name)
err = app.SetMachineUser(&machine, "non-existing-user")
err = app.SetNodeUser(&node, "non-existing-user")
c.Assert(err, check.Equals, ErrUserNotFound)
err = app.SetMachineUser(&machine, newUser.Name)
err = app.SetNodeUser(&node, newUser.Name)
c.Assert(err, check.IsNil)
c.Assert(machine.UserID, check.Equals, newUser.ID)
c.Assert(machine.User.Name, check.Equals, newUser.Name)
c.Assert(node.UserID, check.Equals, newUser.ID)
c.Assert(node.User.Name, check.Equals, newUser.Name)
}

View File

@ -28,21 +28,21 @@ func (s *Suite) TestGetUsedIps(c *check.C) {
pak, err := app.CreatePreAuthKey(user.Name, false, false, nil, nil)
c.Assert(err, check.IsNil)
_, err = app.GetMachine("test", "testmachine")
_, err = app.GetNode("test", "testnode")
c.Assert(err, check.NotNil)
machine := Machine{
node := Node{
ID: 0,
MachineKey: "foo",
NodeKey: "bar",
DiscoKey: "faa",
Hostname: "testmachine",
Hostname: "testnode",
UserID: user.ID,
RegisterMethod: RegisterMethodAuthKey,
AuthKeyID: uint(pak.ID),
IPAddresses: ips,
}
app.db.Save(&machine)
app.db.Save(&node)
usedIps, err := app.getUsedIPs()
@ -56,11 +56,11 @@ func (s *Suite) TestGetUsedIps(c *check.C) {
c.Assert(usedIps.Equal(expectedIPSet), check.Equals, true)
c.Assert(usedIps.Contains(expected), check.Equals, true)
machine1, err := app.GetMachineByID(0)
node1, err := app.GetNodeByID(0)
c.Assert(err, check.IsNil)
c.Assert(len(machine1.IPAddresses), check.Equals, 1)
c.Assert(machine1.IPAddresses[0], check.Equals, expected)
c.Assert(len(node1.IPAddresses), check.Equals, 1)
c.Assert(node1.IPAddresses[0], check.Equals, expected)
}
func (s *Suite) TestGetMultiIp(c *check.C) {
@ -76,21 +76,21 @@ func (s *Suite) TestGetMultiIp(c *check.C) {
pak, err := app.CreatePreAuthKey(user.Name, false, false, nil, nil)
c.Assert(err, check.IsNil)
_, err = app.GetMachine("test", "testmachine")
_, err = app.GetNode("test", "testnode")
c.Assert(err, check.NotNil)
machine := Machine{
node := Node{
ID: uint64(index),
MachineKey: "foo",
NodeKey: "bar",
DiscoKey: "faa",
Hostname: "testmachine",
Hostname: "testnode",
UserID: user.ID,
RegisterMethod: RegisterMethodAuthKey,
AuthKeyID: uint(pak.ID),
IPAddresses: ips,
}
app.db.Save(&machine)
app.db.Save(&node)
app.ipAllocationMutex.Unlock()
}
@ -117,20 +117,20 @@ func (s *Suite) TestGetMultiIp(c *check.C) {
c.Assert(usedIps.Contains(expected300), check.Equals, true)
// Check that we can read back the IPs
machine1, err := app.GetMachineByID(1)
node1, err := app.GetNodeByID(1)
c.Assert(err, check.IsNil)
c.Assert(len(machine1.IPAddresses), check.Equals, 1)
c.Assert(len(node1.IPAddresses), check.Equals, 1)
c.Assert(
machine1.IPAddresses[0],
node1.IPAddresses[0],
check.Equals,
netip.MustParseAddr("10.27.0.1"),
)
machine50, err := app.GetMachineByID(50)
node50, err := app.GetNodeByID(50)
c.Assert(err, check.IsNil)
c.Assert(len(machine50.IPAddresses), check.Equals, 1)
c.Assert(len(node50.IPAddresses), check.Equals, 1)
c.Assert(
machine50.IPAddresses[0],
node50.IPAddresses[0],
check.Equals,
netip.MustParseAddr("10.27.0.50"),
)
@ -151,7 +151,7 @@ func (s *Suite) TestGetMultiIp(c *check.C) {
c.Assert(nextIP2[0].String(), check.Equals, expectedNextIP.String())
}
func (s *Suite) TestGetAvailableIpMachineWithoutIP(c *check.C) {
func (s *Suite) TestGetAvailableIpNodeWithoutIP(c *check.C) {
ips, err := app.getAvailableIPs()
c.Assert(err, check.IsNil)
@ -166,20 +166,20 @@ func (s *Suite) TestGetAvailableIpMachineWithoutIP(c *check.C) {
pak, err := app.CreatePreAuthKey(user.Name, false, false, nil, nil)
c.Assert(err, check.IsNil)
_, err = app.GetMachine("test", "testmachine")
_, err = app.GetNode("test", "testnode")
c.Assert(err, check.NotNil)
machine := Machine{
node := Node{
ID: 0,
MachineKey: "foo",
NodeKey: "bar",
DiscoKey: "faa",
Hostname: "testmachine",
Hostname: "testnode",
UserID: user.ID,
RegisterMethod: RegisterMethodAuthKey,
AuthKeyID: uint(pak.ID),
}
app.db.Save(&machine)
app.db.Save(&node)
ips2, err := app.getAvailableIPs()
c.Assert(err, check.IsNil)