From 9f7c25e8536ca0f666566df9ee4f7a7e02a99789 Mon Sep 17 00:00:00 2001 From: Juan Font Date: Mon, 1 May 2023 14:53:23 +0000 Subject: [PATCH] Refactor unit tests --- acls_test.go | 290 ++++++++++++++--------------- acls_types.go | 2 +- dns_test.go | 60 +++--- node_test.go | 424 +++++++++++++++++++++---------------------- preauth_keys_test.go | 18 +- routes_test.go | 68 +++---- users_test.go | 60 +++--- utils_test.go | 44 ++--- 8 files changed, 483 insertions(+), 483 deletions(-) diff --git a/acls_test.go b/acls_test.go index eaac2a7c..f9cfb052 100644 --- a/acls_test.go +++ b/acls_test.go @@ -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"}, diff --git a/acls_types.go b/acls_types.go index 4f318ddc..36639453 100644 --- a/acls_types.go +++ b/acls_types.go @@ -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"` diff --git a/dns_test.go b/dns_test.go index eb96bbe9..1220cee5 100644 --- a/dns_test.go +++ b/dns_test.go @@ -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) diff --git a/node_test.go b/node_test.go index c25f32da..efef8e76 100644 --- a/node_test.go +++ b/node_test.go @@ -15,95 +15,95 @@ import ( "tailscale.com/types/key" ) -func (s *Suite) TestGetMachine(c *check.C) { +func (s *Suite) TestGetNode(c *check.C) { user, err := app.CreateUser("test") c.Assert(err, check.IsNil) 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) - _, err = app.GetMachine("test", "testmachine") + _, err = app.GetNode("test", "testnode") c.Assert(err, check.IsNil) } -func (s *Suite) TestGetMachineByID(c *check.C) { +func (s *Suite) TestGetNodeByID(c *check.C) { user, err := app.CreateUser("test") c.Assert(err, check.IsNil) pak, err := app.CreatePreAuthKey(user.Name, false, false, nil, nil) c.Assert(err, check.IsNil) - _, err = app.GetMachineByID(0) + _, err = app.GetNodeByID(0) 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) - _, err = app.GetMachineByID(0) + _, err = app.GetNodeByID(0) c.Assert(err, check.IsNil) } -func (s *Suite) TestGetMachineByNodeKey(c *check.C) { +func (s *Suite) TestGetNodeByNodeKey(c *check.C) { user, err := app.CreateUser("test") c.Assert(err, check.IsNil) pak, err := app.CreatePreAuthKey(user.Name, false, false, nil, nil) c.Assert(err, check.IsNil) - _, err = app.GetMachineByID(0) + _, err = app.GetNodeByID(0) c.Assert(err, check.NotNil) nodeKey := key.NewNode() machineKey := key.NewMachine() - machine := Machine{ + node := Node{ ID: 0, MachineKey: MachinePublicKeyStripPrefix(machineKey.Public()), NodeKey: NodePublicKeyStripPrefix(nodeKey.Public()), 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.GetMachineByNodeKey(nodeKey.Public()) + _, err = app.GetNodeByNodeKey(nodeKey.Public()) c.Assert(err, check.IsNil) } -func (s *Suite) TestGetMachineByAnyNodeKey(c *check.C) { +func (s *Suite) TestGetNodeByAnyNodeKey(c *check.C) { user, err := app.CreateUser("test") c.Assert(err, check.IsNil) pak, err := app.CreatePreAuthKey(user.Name, false, false, nil, nil) c.Assert(err, check.IsNil) - _, err = app.GetMachineByID(0) + _, err = app.GetNodeByID(0) c.Assert(err, check.NotNil) nodeKey := key.NewNode() @@ -111,63 +111,63 @@ func (s *Suite) TestGetMachineByAnyNodeKey(c *check.C) { machineKey := key.NewMachine() - machine := Machine{ + node := Node{ ID: 0, MachineKey: MachinePublicKeyStripPrefix(machineKey.Public()), NodeKey: NodePublicKeyStripPrefix(nodeKey.Public()), 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.GetMachineByAnyKey(machineKey.Public(), nodeKey.Public(), oldNodeKey.Public()) + _, err = app.GetNodeByAnyKey(machineKey.Public(), nodeKey.Public(), oldNodeKey.Public()) c.Assert(err, check.IsNil) } -func (s *Suite) TestDeleteMachine(c *check.C) { +func (s *Suite) TestDeleteNode(c *check.C) { user, err := app.CreateUser("test") 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(1), } - app.db.Save(&machine) + app.db.Save(&node) - err = app.DeleteMachine(&machine) + err = app.DeleteNode(&node) c.Assert(err, check.IsNil) - _, err = app.GetMachine(user.Name, "testmachine") + _, err = app.GetNode(user.Name, "testnode") c.Assert(err, check.NotNil) } -func (s *Suite) TestHardDeleteMachine(c *check.C) { +func (s *Suite) TestHardDeleteNode(c *check.C) { user, err := app.CreateUser("test") c.Assert(err, check.IsNil) - machine := Machine{ + node := Node{ ID: 0, MachineKey: "foo", NodeKey: "bar", DiscoKey: "faa", - Hostname: "testmachine3", + Hostname: "testnode3", UserID: user.ID, RegisterMethod: RegisterMethodAuthKey, AuthKeyID: uint(1), } - app.db.Save(&machine) + app.db.Save(&node) - err = app.HardDeleteMachine(&machine) + err = app.HardDeleteNode(&node) c.Assert(err, check.IsNil) - _, err = app.GetMachine(user.Name, "testmachine3") + _, err = app.GetNode(user.Name, "testnode3") c.Assert(err, check.NotNil) } @@ -178,33 +178,33 @@ func (s *Suite) TestListPeers(c *check.C) { pak, err := app.CreatePreAuthKey(user.Name, false, false, nil, nil) c.Assert(err, check.IsNil) - _, err = app.GetMachineByID(0) + _, err = app.GetNodeByID(0) c.Assert(err, check.NotNil) for index := 0; index <= 10; index++ { - machine := Machine{ + node := Node{ ID: uint64(index), MachineKey: "foo" + strconv.Itoa(index), NodeKey: "bar" + strconv.Itoa(index), DiscoKey: "faa" + strconv.Itoa(index), - Hostname: "testmachine" + strconv.Itoa(index), + Hostname: "testnode" + strconv.Itoa(index), UserID: user.ID, RegisterMethod: RegisterMethodAuthKey, AuthKeyID: uint(pak.ID), } - app.db.Save(&machine) + app.db.Save(&node) } - machine0ByID, err := app.GetMachineByID(0) + node0ByID, err := app.GetNodeByID(0) c.Assert(err, check.IsNil) - peersOfMachine0, err := app.ListPeers(machine0ByID) + peersOfNode0, err := app.ListPeers(node0ByID) c.Assert(err, check.IsNil) - c.Assert(len(peersOfMachine0), check.Equals, 9) - c.Assert(peersOfMachine0[0].Hostname, check.Equals, "testmachine2") - c.Assert(peersOfMachine0[5].Hostname, check.Equals, "testmachine7") - c.Assert(peersOfMachine0[8].Hostname, check.Equals, "testmachine10") + c.Assert(len(peersOfNode0), check.Equals, 9) + c.Assert(peersOfNode0[0].Hostname, check.Equals, "testnode2") + c.Assert(peersOfNode0[5].Hostname, check.Equals, "testnode7") + c.Assert(peersOfNode0[8].Hostname, check.Equals, "testnode10") } func (s *Suite) TestGetACLFilteredPeers(c *check.C) { @@ -223,24 +223,24 @@ func (s *Suite) TestGetACLFilteredPeers(c *check.C) { stor = append(stor, base{user, pak}) } - _, err := app.GetMachineByID(0) + _, err := app.GetNodeByID(0) c.Assert(err, check.NotNil) for index := 0; index <= 10; index++ { - machine := Machine{ + node := Node{ ID: uint64(index), MachineKey: "foo" + strconv.Itoa(index), NodeKey: "bar" + strconv.Itoa(index), DiscoKey: "faa" + strconv.Itoa(index), - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr(fmt.Sprintf("100.64.0.%v", strconv.Itoa(index+1))), }, - Hostname: "testmachine" + strconv.Itoa(index), + Hostname: "testnode" + strconv.Itoa(index), UserID: stor[index%2].user.ID, RegisterMethod: RegisterMethodAuthKey, AuthKeyID: uint(stor[index%2].key.ID), } - app.db.Save(&machine) + app.db.Save(&node) } app.aclPolicy = &ACLPolicy{ @@ -267,70 +267,70 @@ func (s *Suite) TestGetACLFilteredPeers(c *check.C) { err = app.UpdateACLRules() c.Assert(err, check.IsNil) - adminMachine, err := app.GetMachineByID(1) - c.Logf("Machine(%v), user: %v", adminMachine.Hostname, adminMachine.User) + adminNode, err := app.GetNodeByID(1) + c.Logf("Node(%v), user: %v", adminNode.Hostname, adminNode.User) c.Assert(err, check.IsNil) - testMachine, err := app.GetMachineByID(2) - c.Logf("Machine(%v), user: %v", testMachine.Hostname, testMachine.User) + testNode, err := app.GetNodeByID(2) + c.Logf("Node(%v), user: %v", testNode.Hostname, testNode.User) c.Assert(err, check.IsNil) - machines, err := app.ListMachines() + nodes, err := app.ListNodes() c.Assert(err, check.IsNil) - peersOfTestMachine := app.filterMachinesByACL(testMachine, machines) - peersOfAdminMachine := app.filterMachinesByACL(adminMachine, machines) + peersOfTestNode := app.filterNodesByACL(testNode, nodes) + peersOfAdminNode := app.filterNodesByACL(adminNode, nodes) - c.Log(peersOfTestMachine) - c.Assert(len(peersOfTestMachine), check.Equals, 9) - c.Assert(peersOfTestMachine[0].Hostname, check.Equals, "testmachine1") - c.Assert(peersOfTestMachine[1].Hostname, check.Equals, "testmachine3") - c.Assert(peersOfTestMachine[3].Hostname, check.Equals, "testmachine5") + c.Log(peersOfTestNode) + c.Assert(len(peersOfTestNode), check.Equals, 9) + c.Assert(peersOfTestNode[0].Hostname, check.Equals, "testnode1") + c.Assert(peersOfTestNode[1].Hostname, check.Equals, "testnode3") + c.Assert(peersOfTestNode[3].Hostname, check.Equals, "testnode5") - c.Log(peersOfAdminMachine) - c.Assert(len(peersOfAdminMachine), check.Equals, 9) - c.Assert(peersOfAdminMachine[0].Hostname, check.Equals, "testmachine2") - c.Assert(peersOfAdminMachine[2].Hostname, check.Equals, "testmachine4") - c.Assert(peersOfAdminMachine[5].Hostname, check.Equals, "testmachine7") + c.Log(peersOfAdminNode) + c.Assert(len(peersOfAdminNode), check.Equals, 9) + c.Assert(peersOfAdminNode[0].Hostname, check.Equals, "testnode2") + c.Assert(peersOfAdminNode[2].Hostname, check.Equals, "testnode4") + c.Assert(peersOfAdminNode[5].Hostname, check.Equals, "testnode7") } -func (s *Suite) TestExpireMachine(c *check.C) { +func (s *Suite) TestExpireNode(c *check.C) { user, err := app.CreateUser("test") c.Assert(err, check.IsNil) 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), Expiry: &time.Time{}, } - app.db.Save(machine) + app.db.Save(node) - machineFromDB, err := app.GetMachine("test", "testmachine") + nodeFromDB, err := app.GetNode("test", "testnode") c.Assert(err, check.IsNil) - c.Assert(machineFromDB, check.NotNil) + c.Assert(nodeFromDB, check.NotNil) - c.Assert(machineFromDB.isExpired(), check.Equals, false) + c.Assert(nodeFromDB.isExpired(), check.Equals, false) - err = app.ExpireMachine(machineFromDB) + err = app.ExpireNode(nodeFromDB) c.Assert(err, check.IsNil) - c.Assert(machineFromDB.isExpired(), check.Equals, true) + c.Assert(nodeFromDB.isExpired(), check.Equals, true) } func (s *Suite) TestSerdeAddressStrignSlice(c *check.C) { - input := MachineAddresses([]netip.Addr{ + input := NodeAddresses([]netip.Addr{ netip.MustParseAddr("192.0.2.1"), netip.MustParseAddr("2001:db8::1"), }) @@ -340,7 +340,7 @@ func (s *Suite) TestSerdeAddressStrignSlice(c *check.C) { c.Assert(serial, check.Equals, "192.0.2.1,2001:db8::1") } - var deserialized MachineAddresses + var deserialized NodeAddresses err = deserialized.Scan(serialized) c.Assert(err, check.IsNil) @@ -357,12 +357,12 @@ func (s *Suite) TestGenerateGivenName(c *check.C) { pak, err := app.CreatePreAuthKey(user1.Name, false, false, nil, nil) c.Assert(err, check.IsNil) - _, err = app.GetMachine("user-1", "testmachine") + _, err = app.GetNode("user-1", "testnode") c.Assert(err, check.NotNil) - machine := &Machine{ + node := &Node{ ID: 0, - MachineKey: "machine-key-1", + MachineKey: "node-key-1", NodeKey: "node-key-1", DiscoKey: "disco-key-1", Hostname: "hostname-1", @@ -371,27 +371,27 @@ func (s *Suite) TestGenerateGivenName(c *check.C) { RegisterMethod: RegisterMethodAuthKey, AuthKeyID: uint(pak.ID), } - app.db.Save(machine) + app.db.Save(node) - givenName, err := app.GenerateGivenName("machine-key-2", "hostname-2") - comment := check.Commentf("Same user, unique machines, unique hostnames, no conflict") + givenName, err := app.GenerateGivenName("node-key-2", "hostname-2") + comment := check.Commentf("Same user, unique nodes, unique hostnames, no conflict") c.Assert(err, check.IsNil, comment) c.Assert(givenName, check.Equals, "hostname-2", comment) - givenName, err = app.GenerateGivenName("machine-key-1", "hostname-1") - comment = check.Commentf("Same user, same machine, same hostname, no conflict") + givenName, err = app.GenerateGivenName("node-key-1", "hostname-1") + comment = check.Commentf("Same user, same node, same hostname, no conflict") c.Assert(err, check.IsNil, comment) c.Assert(givenName, check.Equals, "hostname-1", comment) - givenName, err = app.GenerateGivenName("machine-key-2", "hostname-1") - comment = check.Commentf("Same user, unique machines, same hostname, conflict") + givenName, err = app.GenerateGivenName("node-key-2", "hostname-1") + comment = check.Commentf("Same user, unique nodes, same hostname, conflict") c.Assert(err, check.IsNil, comment) - c.Assert(givenName, check.Matches, fmt.Sprintf("^hostname-1-[a-z0-9]{%d}$", MachineGivenNameHashLength), comment) + c.Assert(givenName, check.Matches, fmt.Sprintf("^hostname-1-[a-z0-9]{%d}$", NodeGivenNameHashLength), comment) - givenName, err = app.GenerateGivenName("machine-key-2", "hostname-1") - comment = check.Commentf("Unique users, unique machines, same hostname, conflict") + givenName, err = app.GenerateGivenName("node-key-2", "hostname-1") + comment = check.Commentf("Unique users, unique nodes, same hostname, conflict") c.Assert(err, check.IsNil, comment) - c.Assert(givenName, check.Matches, fmt.Sprintf("^hostname-1-[a-z0-9]{%d}$", MachineGivenNameHashLength), comment) + c.Assert(givenName, check.Matches, fmt.Sprintf("^hostname-1-[a-z0-9]{%d}$", NodeGivenNameHashLength), comment) } func (s *Suite) TestSetTags(c *check.C) { @@ -401,37 +401,37 @@ func (s *Suite) TestSetTags(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) // assign simple tags sTags := []string{"tag:test", "tag:foo"} - err = app.SetTags(machine, sTags) + err = app.SetTags(node, sTags) c.Assert(err, check.IsNil) - machine, err = app.GetMachine("test", "testmachine") + node, err = app.GetNode("test", "testnode") c.Assert(err, check.IsNil) - c.Assert(machine.ForcedTags, check.DeepEquals, StringList(sTags)) + c.Assert(node.ForcedTags, check.DeepEquals, StringList(sTags)) // assign duplicat tags, expect no errors but no doubles in DB eTags := []string{"tag:bar", "tag:test", "tag:unknown", "tag:test"} - err = app.SetTags(machine, eTags) + err = app.SetTags(node, eTags) c.Assert(err, check.IsNil) - machine, err = app.GetMachine("test", "testmachine") + node, err = app.GetNode("test", "testnode") c.Assert(err, check.IsNil) c.Assert( - machine.ForcedTags, + node.ForcedTags, check.DeepEquals, StringList([]string{"tag:bar", "tag:test", "tag:unknown"}), ) @@ -440,7 +440,7 @@ func (s *Suite) TestSetTags(c *check.C) { func Test_getTags(t *testing.T) { type args struct { aclPolicy *ACLPolicy - machine Machine + node Node stripEmailDomain bool } tests := []struct { @@ -450,14 +450,14 @@ func Test_getTags(t *testing.T) { wantValid []string }{ { - name: "valid tag one machine", + name: "valid tag one node", args: args{ aclPolicy: &ACLPolicy{ TagOwners: TagOwners{ "tag:valid": []string{"joe"}, }, }, - machine: Machine{ + node: Node{ User: User{ Name: "joe", }, @@ -471,14 +471,14 @@ func Test_getTags(t *testing.T) { wantInvalid: nil, }, { - name: "invalid tag and valid tag one machine", + name: "invalid tag and valid tag one node", args: args{ aclPolicy: &ACLPolicy{ TagOwners: TagOwners{ "tag:valid": []string{"joe"}, }, }, - machine: Machine{ + node: Node{ User: User{ Name: "joe", }, @@ -499,7 +499,7 @@ func Test_getTags(t *testing.T) { "tag:valid": []string{"joe"}, }, }, - machine: Machine{ + node: Node{ User: User{ Name: "joe", }, @@ -524,7 +524,7 @@ func Test_getTags(t *testing.T) { "tag:valid": []string{"joe"}, }, }, - machine: Machine{ + node: Node{ User: User{ Name: "joe", }, @@ -541,7 +541,7 @@ func Test_getTags(t *testing.T) { name: "empty ACLPolicy should return empty tags and should not panic", args: args{ aclPolicy: nil, - machine: Machine{ + node: Node{ User: User{ Name: "joe", }, @@ -559,7 +559,7 @@ func Test_getTags(t *testing.T) { t.Run(test.name, func(t *testing.T) { gotValid, gotInvalid := getTags( test.args.aclPolicy, - test.args.machine, + test.args.node, test.args.stripEmailDomain, ) for _, valid := range gotValid { @@ -590,36 +590,36 @@ func Test_getTags(t *testing.T) { func Test_getFilteredByACLPeers(t *testing.T) { type args struct { - machines []Machine - rules []tailcfg.FilterRule - machine *Machine + nodes []Node + rules []tailcfg.FilterRule + node *Node } tests := []struct { name string args args - want Machines + want Nodes }{ { name: "all hosts can talk to each other", args: args{ - machines: []Machine{ // list of all machines in the database + nodes: []Node{ // list of all nodes in the database { ID: 1, - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.1"), }, User: User{Name: "joe"}, }, { ID: 2, - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.2"), }, User: User{Name: "marc"}, }, { ID: 3, - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.3"), }, User: User{Name: "mickael"}, @@ -633,21 +633,21 @@ func Test_getFilteredByACLPeers(t *testing.T) { }, }, }, - machine: &Machine{ // current machine + node: &Node{ // current node ID: 1, - IPAddresses: MachineAddresses{netip.MustParseAddr("100.64.0.1")}, + IPAddresses: NodeAddresses{netip.MustParseAddr("100.64.0.1")}, User: User{Name: "joe"}, }, }, - want: Machines{ + want: Nodes{ { ID: 2, - IPAddresses: MachineAddresses{netip.MustParseAddr("100.64.0.2")}, + IPAddresses: NodeAddresses{netip.MustParseAddr("100.64.0.2")}, User: User{Name: "marc"}, }, { ID: 3, - IPAddresses: MachineAddresses{netip.MustParseAddr("100.64.0.3")}, + IPAddresses: NodeAddresses{netip.MustParseAddr("100.64.0.3")}, User: User{Name: "mickael"}, }, }, @@ -655,24 +655,24 @@ func Test_getFilteredByACLPeers(t *testing.T) { { name: "One host can talk to another, but not all hosts", args: args{ - machines: []Machine{ // list of all machines in the database + nodes: []Node{ // list of all nodes in the database { ID: 1, - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.1"), }, User: User{Name: "joe"}, }, { ID: 2, - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.2"), }, User: User{Name: "marc"}, }, { ID: 3, - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.3"), }, User: User{Name: "mickael"}, @@ -686,16 +686,16 @@ func Test_getFilteredByACLPeers(t *testing.T) { }, }, }, - machine: &Machine{ // current machine + node: &Node{ // current node ID: 1, - IPAddresses: MachineAddresses{netip.MustParseAddr("100.64.0.1")}, + IPAddresses: NodeAddresses{netip.MustParseAddr("100.64.0.1")}, User: User{Name: "joe"}, }, }, - want: Machines{ + want: Nodes{ { ID: 2, - IPAddresses: MachineAddresses{netip.MustParseAddr("100.64.0.2")}, + IPAddresses: NodeAddresses{netip.MustParseAddr("100.64.0.2")}, User: User{Name: "marc"}, }, }, @@ -703,24 +703,24 @@ func Test_getFilteredByACLPeers(t *testing.T) { { name: "host cannot directly talk to destination, but return path is authorized", args: args{ - machines: []Machine{ // list of all machines in the database + nodes: []Node{ // list of all nodes in the database { ID: 1, - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.1"), }, User: User{Name: "joe"}, }, { ID: 2, - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.2"), }, User: User{Name: "marc"}, }, { ID: 3, - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.3"), }, User: User{Name: "mickael"}, @@ -734,16 +734,16 @@ func Test_getFilteredByACLPeers(t *testing.T) { }, }, }, - machine: &Machine{ // current machine + node: &Node{ // current node ID: 2, - IPAddresses: MachineAddresses{netip.MustParseAddr("100.64.0.2")}, + IPAddresses: NodeAddresses{netip.MustParseAddr("100.64.0.2")}, User: User{Name: "marc"}, }, }, - want: Machines{ + want: Nodes{ { ID: 3, - IPAddresses: MachineAddresses{netip.MustParseAddr("100.64.0.3")}, + IPAddresses: NodeAddresses{netip.MustParseAddr("100.64.0.3")}, User: User{Name: "mickael"}, }, }, @@ -751,24 +751,24 @@ func Test_getFilteredByACLPeers(t *testing.T) { { name: "rules allows all hosts to reach one destination", args: args{ - machines: []Machine{ // list of all machines in the database + nodes: []Node{ // list of all nodes in the database { ID: 1, - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.1"), }, User: User{Name: "joe"}, }, { ID: 2, - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.2"), }, User: User{Name: "marc"}, }, { ID: 3, - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.3"), }, User: User{Name: "mickael"}, @@ -782,18 +782,18 @@ func Test_getFilteredByACLPeers(t *testing.T) { }, }, }, - machine: &Machine{ // current machine + node: &Node{ // current node ID: 1, - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.1"), }, User: User{Name: "joe"}, }, }, - want: Machines{ + want: Nodes{ { ID: 2, - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.2"), }, User: User{Name: "marc"}, @@ -803,24 +803,24 @@ func Test_getFilteredByACLPeers(t *testing.T) { { name: "rules allows all hosts to reach one destination, destination can reach all hosts", args: args{ - machines: []Machine{ // list of all machines in the database + nodes: []Node{ // list of all nodes in the database { ID: 1, - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.1"), }, User: User{Name: "joe"}, }, { ID: 2, - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.2"), }, User: User{Name: "marc"}, }, { ID: 3, - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.3"), }, User: User{Name: "mickael"}, @@ -834,25 +834,25 @@ func Test_getFilteredByACLPeers(t *testing.T) { }, }, }, - machine: &Machine{ // current machine + node: &Node{ // current node ID: 2, - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.2"), }, User: User{Name: "marc"}, }, }, - want: Machines{ + want: Nodes{ { ID: 1, - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.1"), }, User: User{Name: "joe"}, }, { ID: 3, - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.3"), }, User: User{Name: "mickael"}, @@ -862,24 +862,24 @@ func Test_getFilteredByACLPeers(t *testing.T) { { name: "rule allows all hosts to reach all destinations", args: args{ - machines: []Machine{ // list of all machines in the database + nodes: []Node{ // list of all nodes in the database { ID: 1, - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.1"), }, User: User{Name: "joe"}, }, { ID: 2, - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.2"), }, User: User{Name: "marc"}, }, { ID: 3, - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.3"), }, User: User{Name: "mickael"}, @@ -893,23 +893,23 @@ func Test_getFilteredByACLPeers(t *testing.T) { }, }, }, - machine: &Machine{ // current machine + node: &Node{ // current node ID: 2, - IPAddresses: MachineAddresses{netip.MustParseAddr("100.64.0.2")}, + IPAddresses: NodeAddresses{netip.MustParseAddr("100.64.0.2")}, User: User{Name: "marc"}, }, }, - want: Machines{ + want: Nodes{ { ID: 1, - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.1"), }, User: User{Name: "joe"}, }, { ID: 3, - IPAddresses: MachineAddresses{netip.MustParseAddr("100.64.0.3")}, + IPAddresses: NodeAddresses{netip.MustParseAddr("100.64.0.3")}, User: User{Name: "mickael"}, }, }, @@ -917,24 +917,24 @@ func Test_getFilteredByACLPeers(t *testing.T) { { name: "without rule all communications are forbidden", args: args{ - machines: []Machine{ // list of all machines in the database + nodes: []Node{ // list of all nodes in the database { ID: 1, - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.1"), }, User: User{Name: "joe"}, }, { ID: 2, - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.2"), }, User: User{Name: "marc"}, }, { ID: 3, - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.3"), }, User: User{Name: "mickael"}, @@ -942,26 +942,26 @@ func Test_getFilteredByACLPeers(t *testing.T) { }, rules: []tailcfg.FilterRule{ // list of all ACLRules registered }, - machine: &Machine{ // current machine + node: &Node{ // current node ID: 2, - IPAddresses: MachineAddresses{netip.MustParseAddr("100.64.0.2")}, + IPAddresses: NodeAddresses{netip.MustParseAddr("100.64.0.2")}, User: User{Name: "marc"}, }, }, - want: Machines{}, + want: Nodes{}, }, { // Investigating 699 - // Found some machines: [ts-head-8w6paa ts-unstable-lys2ib ts-head-upcrmb ts-unstable-rlwpvr] machine=ts-head-8w6paa + // Found some nodes: [ts-head-8w6paa ts-unstable-lys2ib ts-head-upcrmb ts-unstable-rlwpvr] node=ts-head-8w6paa // ACL rules generated ACL=[{"DstPorts":[{"Bits":null,"IP":"*","Ports":{"First":0,"Last":65535}}],"SrcIPs":["fd7a:115c:a1e0::3","100.64.0.3","fd7a:115c:a1e0::4","100.64.0.4"]}] // ACL Cache Map={"100.64.0.3":{"*":{}},"100.64.0.4":{"*":{}},"fd7a:115c:a1e0::3":{"*":{}},"fd7a:115c:a1e0::4":{"*":{}}} name: "issue-699-broken-star", args: args{ - machines: Machines{ // + nodes: Nodes{ // { ID: 1, Hostname: "ts-head-upcrmb", - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.3"), netip.MustParseAddr("fd7a:115c:a1e0::3"), }, @@ -970,7 +970,7 @@ func Test_getFilteredByACLPeers(t *testing.T) { { ID: 2, Hostname: "ts-unstable-rlwpvr", - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.4"), netip.MustParseAddr("fd7a:115c:a1e0::4"), }, @@ -979,7 +979,7 @@ func Test_getFilteredByACLPeers(t *testing.T) { { ID: 3, Hostname: "ts-head-8w6paa", - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.1"), netip.MustParseAddr("fd7a:115c:a1e0::1"), }, @@ -988,7 +988,7 @@ func Test_getFilteredByACLPeers(t *testing.T) { { ID: 4, Hostname: "ts-unstable-lys2ib", - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.2"), netip.MustParseAddr("fd7a:115c:a1e0::2"), }, @@ -1009,21 +1009,21 @@ func Test_getFilteredByACLPeers(t *testing.T) { }, }, }, - machine: &Machine{ // current machine + node: &Node{ // current node ID: 3, Hostname: "ts-head-8w6paa", - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.1"), netip.MustParseAddr("fd7a:115c:a1e0::1"), }, User: User{Name: "user2"}, }, }, - want: Machines{ + want: Nodes{ { ID: 1, Hostname: "ts-head-upcrmb", - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.3"), netip.MustParseAddr("fd7a:115c:a1e0::3"), }, @@ -1032,7 +1032,7 @@ func Test_getFilteredByACLPeers(t *testing.T) { { ID: 2, Hostname: "ts-unstable-rlwpvr", - IPAddresses: MachineAddresses{ + IPAddresses: NodeAddresses{ netip.MustParseAddr("100.64.0.4"), netip.MustParseAddr("fd7a:115c:a1e0::4"), }, @@ -1046,14 +1046,14 @@ func Test_getFilteredByACLPeers(t *testing.T) { t.Run(tt.name, func(t *testing.T) { aclRulesMap := generateACLPeerCacheMap(tt.args.rules) - got := filterMachinesByACL( - tt.args.machine, - tt.args.machines, + got := filterNodesByACL( + tt.args.node, + tt.args.nodes, &lock, aclRulesMap, ) if !reflect.DeepEqual(got, tt.want) { - t.Errorf("filterMachinesByACL() = %v, want %v", got, tt.want) + t.Errorf("filterNodesByACL() = %v, want %v", got, tt.want) } }) } @@ -1072,7 +1072,7 @@ func TestHeadscale_generateGivenName(t *testing.T) { wantErr bool }{ { - name: "simple machine name generation", + name: "simple node name generation", h: &Headscale{ cfg: &Config{ OIDC: OIDCConfig{ @@ -1081,14 +1081,14 @@ func TestHeadscale_generateGivenName(t *testing.T) { }, }, args: args{ - suppliedName: "testmachine", + suppliedName: "testnode", randomSuffix: false, }, - want: regexp.MustCompile("^testmachine$"), + want: regexp.MustCompile("^testnode$"), wantErr: false, }, { - name: "machine name with 53 chars", + name: "node name with 53 chars", h: &Headscale{ cfg: &Config{ OIDC: OIDCConfig{ @@ -1104,7 +1104,7 @@ func TestHeadscale_generateGivenName(t *testing.T) { wantErr: false, }, { - name: "machine name with 63 chars", + name: "node name with 63 chars", h: &Headscale{ cfg: &Config{ OIDC: OIDCConfig{ @@ -1113,14 +1113,14 @@ func TestHeadscale_generateGivenName(t *testing.T) { }, }, args: args{ - suppliedName: "machineeee12345678901234567890123456789012345678901234567890123", + suppliedName: "nodeeee12345678901234567890123456789012345678901234567890123", randomSuffix: false, }, - want: regexp.MustCompile("^machineeee12345678901234567890123456789012345678901234567890123$"), + want: regexp.MustCompile("^nodeeee12345678901234567890123456789012345678901234567890123$"), wantErr: false, }, { - name: "machine name with 64 chars", + name: "node name with 64 chars", h: &Headscale{ cfg: &Config{ OIDC: OIDCConfig{ @@ -1129,14 +1129,14 @@ func TestHeadscale_generateGivenName(t *testing.T) { }, }, args: args{ - suppliedName: "machineeee123456789012345678901234567890123456789012345678901234", + suppliedName: "nodeeee123456789012345678901234567890123456789012345678901234", randomSuffix: false, }, want: nil, wantErr: true, }, { - name: "machine name with 73 chars", + name: "node name with 73 chars", h: &Headscale{ cfg: &Config{ OIDC: OIDCConfig{ @@ -1145,14 +1145,14 @@ func TestHeadscale_generateGivenName(t *testing.T) { }, }, args: args{ - suppliedName: "machineeee123456789012345678901234567890123456789012345678901234567890123", + suppliedName: "nodeeee123456789012345678901234567890123456789012345678901234567890123", randomSuffix: false, }, want: nil, wantErr: true, }, { - name: "machine name with random suffix", + name: "node name with random suffix", h: &Headscale{ cfg: &Config{ OIDC: OIDCConfig{ @@ -1164,11 +1164,11 @@ func TestHeadscale_generateGivenName(t *testing.T) { suppliedName: "test", randomSuffix: true, }, - want: regexp.MustCompile(fmt.Sprintf("^test-[a-z0-9]{%d}$", MachineGivenNameHashLength)), + want: regexp.MustCompile(fmt.Sprintf("^test-[a-z0-9]{%d}$", NodeGivenNameHashLength)), wantErr: false, }, { - name: "machine name with 63 chars with random suffix", + name: "node name with 63 chars with random suffix", h: &Headscale{ cfg: &Config{ OIDC: OIDCConfig{ @@ -1177,10 +1177,10 @@ func TestHeadscale_generateGivenName(t *testing.T) { }, }, args: args{ - suppliedName: "machineeee12345678901234567890123456789012345678901234567890123", + suppliedName: "nodeeee12345678901234567890123456789012345678901234567890123", randomSuffix: true, }, - want: regexp.MustCompile(fmt.Sprintf("^machineeee1234567890123456789012345678901234567890123-[a-z0-9]{%d}$", MachineGivenNameHashLength)), + want: regexp.MustCompile(fmt.Sprintf("^nodeeee1234567890123456789012345678901234567890123-[a-z0-9]{%d}$", NodeGivenNameHashLength)), wantErr: false, }, } @@ -1233,7 +1233,7 @@ func (s *Suite) TestAutoApproveRoutes(c *check.C) { // Check if a subprefix of an autoapproved route is approved route2 := netip.MustParsePrefix("10.11.0.0/24") - machine := Machine{ + node := Node{ ID: 0, MachineKey: "foo", NodeKey: NodePublicKeyStripPrefix(nodeKey.Public()), @@ -1249,18 +1249,18 @@ func (s *Suite) TestAutoApproveRoutes(c *check.C) { IPAddresses: []netip.Addr{netip.MustParseAddr("100.64.0.1")}, } - app.db.Save(&machine) + app.db.Save(&node) - err = app.processMachineRoutes(&machine) + err = app.processNodeRoutes(&node) c.Assert(err, check.IsNil) - machine0ByID, err := app.GetMachineByID(0) + node0ByID, err := app.GetNodeByID(0) c.Assert(err, check.IsNil) - err = app.EnableAutoApprovedRoutes(machine0ByID) + err = app.EnableAutoApprovedRoutes(node0ByID) c.Assert(err, check.IsNil) - enabledRoutes, err := app.GetEnabledRoutes(machine0ByID) + enabledRoutes, err := app.GetEnabledRoutes(node0ByID) c.Assert(err, check.IsNil) c.Assert(enabledRoutes, check.HasLen, 3) } diff --git a/preauth_keys_test.go b/preauth_keys_test.go index 697144fe..b938b6e9 100644 --- a/preauth_keys_test.go +++ b/preauth_keys_test.go @@ -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) } diff --git a/routes_test.go b/routes_test.go index b67b3ee9..88384ddf 100644 --- a/routes_test.go +++ b/routes_test.go @@ -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)) diff --git a/users_test.go b/users_test.go index 144c3337..3b5288e1 100644 --- a/users_test.go +++ b/users_test.go @@ -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) } diff --git a/utils_test.go b/utils_test.go index fd1d25e7..7a20207d 100644 --- a/utils_test.go +++ b/utils_test.go @@ -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)