mirror of
https://github.com/juanfont/headscale.git
synced 2025-12-08 08:42:39 -05:00
Merge branch 'main' into registration-simplification
This commit is contained in:
115
acls_test.go
115
acls_test.go
@@ -423,8 +423,9 @@ func (s *Suite) TestPortGroup(c *check.C) {
|
||||
|
||||
func Test_expandGroup(t *testing.T) {
|
||||
type args struct {
|
||||
aclPolicy ACLPolicy
|
||||
group string
|
||||
aclPolicy ACLPolicy
|
||||
group string
|
||||
stripEmailDomain bool
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -441,7 +442,8 @@ func Test_expandGroup(t *testing.T) {
|
||||
"group:foo": []string{"user2", "user3"},
|
||||
},
|
||||
},
|
||||
group: "group:test",
|
||||
group: "group:test",
|
||||
stripEmailDomain: true,
|
||||
},
|
||||
want: []string{"user1", "user2", "user3"},
|
||||
wantErr: false,
|
||||
@@ -455,15 +457,54 @@ func Test_expandGroup(t *testing.T) {
|
||||
"group:foo": []string{"user2", "user3"},
|
||||
},
|
||||
},
|
||||
group: "group:undefined",
|
||||
group: "group:undefined",
|
||||
stripEmailDomain: true,
|
||||
},
|
||||
want: []string{},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "Expand emails in group",
|
||||
args: args{
|
||||
aclPolicy: ACLPolicy{
|
||||
Groups: Groups{
|
||||
"group:admin": []string{
|
||||
"joe.bar@gmail.com",
|
||||
"john.doe@yahoo.fr",
|
||||
},
|
||||
},
|
||||
},
|
||||
group: "group:admin",
|
||||
stripEmailDomain: true,
|
||||
},
|
||||
want: []string{"joe.bar", "john.doe"},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Expand emails in group",
|
||||
args: args{
|
||||
aclPolicy: ACLPolicy{
|
||||
Groups: Groups{
|
||||
"group:admin": []string{
|
||||
"joe.bar@gmail.com",
|
||||
"john.doe@yahoo.fr",
|
||||
},
|
||||
},
|
||||
},
|
||||
group: "group:admin",
|
||||
stripEmailDomain: false,
|
||||
},
|
||||
want: []string{"joe.bar.gmail.com", "john.doe.yahoo.fr"},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
got, err := expandGroup(test.args.aclPolicy, test.args.group)
|
||||
got, err := expandGroup(
|
||||
test.args.aclPolicy,
|
||||
test.args.group,
|
||||
test.args.stripEmailDomain,
|
||||
)
|
||||
if (err != nil) != test.wantErr {
|
||||
t.Errorf("expandGroup() error = %v, wantErr %v", err, test.wantErr)
|
||||
|
||||
@@ -478,8 +519,9 @@ func Test_expandGroup(t *testing.T) {
|
||||
|
||||
func Test_expandTagOwners(t *testing.T) {
|
||||
type args struct {
|
||||
aclPolicy ACLPolicy
|
||||
tag string
|
||||
aclPolicy ACLPolicy
|
||||
tag string
|
||||
stripEmailDomain bool
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -493,7 +535,8 @@ func Test_expandTagOwners(t *testing.T) {
|
||||
aclPolicy: ACLPolicy{
|
||||
TagOwners: TagOwners{"tag:test": []string{"user1"}},
|
||||
},
|
||||
tag: "tag:test",
|
||||
tag: "tag:test",
|
||||
stripEmailDomain: true,
|
||||
},
|
||||
want: []string{"user1"},
|
||||
wantErr: false,
|
||||
@@ -505,7 +548,8 @@ func Test_expandTagOwners(t *testing.T) {
|
||||
Groups: Groups{"group:foo": []string{"user1", "user2"}},
|
||||
TagOwners: TagOwners{"tag:test": []string{"group:foo"}},
|
||||
},
|
||||
tag: "tag:test",
|
||||
tag: "tag:test",
|
||||
stripEmailDomain: true,
|
||||
},
|
||||
want: []string{"user1", "user2"},
|
||||
wantErr: false,
|
||||
@@ -517,7 +561,8 @@ func Test_expandTagOwners(t *testing.T) {
|
||||
Groups: Groups{"group:foo": []string{"user1", "user2"}},
|
||||
TagOwners: TagOwners{"tag:test": []string{"group:foo", "user3"}},
|
||||
},
|
||||
tag: "tag:test",
|
||||
tag: "tag:test",
|
||||
stripEmailDomain: true,
|
||||
},
|
||||
want: []string{"user1", "user2", "user3"},
|
||||
wantErr: false,
|
||||
@@ -528,7 +573,8 @@ func Test_expandTagOwners(t *testing.T) {
|
||||
aclPolicy: ACLPolicy{
|
||||
TagOwners: TagOwners{"tag:foo": []string{"group:foo", "user1"}},
|
||||
},
|
||||
tag: "tag:test",
|
||||
tag: "tag:test",
|
||||
stripEmailDomain: true,
|
||||
},
|
||||
want: []string{},
|
||||
wantErr: true,
|
||||
@@ -540,7 +586,8 @@ func Test_expandTagOwners(t *testing.T) {
|
||||
Groups: Groups{"group:bar": []string{"user1", "user2"}},
|
||||
TagOwners: TagOwners{"tag:test": []string{"group:foo", "user2"}},
|
||||
},
|
||||
tag: "tag:test",
|
||||
tag: "tag:test",
|
||||
stripEmailDomain: true,
|
||||
},
|
||||
want: []string{},
|
||||
wantErr: true,
|
||||
@@ -548,7 +595,11 @@ func Test_expandTagOwners(t *testing.T) {
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
got, err := expandTagOwners(test.args.aclPolicy, test.args.tag)
|
||||
got, err := expandTagOwners(
|
||||
test.args.aclPolicy,
|
||||
test.args.tag,
|
||||
test.args.stripEmailDomain,
|
||||
)
|
||||
if (err != nil) != test.wantErr {
|
||||
t.Errorf("expandTagOwners() error = %v, wantErr %v", err, test.wantErr)
|
||||
|
||||
@@ -710,9 +761,10 @@ func Test_listMachinesInNamespace(t *testing.T) {
|
||||
// nolint
|
||||
func Test_expandAlias(t *testing.T) {
|
||||
type args struct {
|
||||
machines []Machine
|
||||
aclPolicy ACLPolicy
|
||||
alias string
|
||||
machines []Machine
|
||||
aclPolicy ACLPolicy
|
||||
alias string
|
||||
stripEmailDomain bool
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -732,7 +784,8 @@ func Test_expandAlias(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
aclPolicy: ACLPolicy{},
|
||||
aclPolicy: ACLPolicy{},
|
||||
stripEmailDomain: true,
|
||||
},
|
||||
want: []string{"*"},
|
||||
wantErr: false,
|
||||
@@ -770,6 +823,7 @@ func Test_expandAlias(t *testing.T) {
|
||||
aclPolicy: ACLPolicy{
|
||||
Groups: Groups{"group:accountant": []string{"joe", "marc"}},
|
||||
},
|
||||
stripEmailDomain: true,
|
||||
},
|
||||
want: []string{"100.64.0.1", "100.64.0.2", "100.64.0.3"},
|
||||
wantErr: false,
|
||||
@@ -807,6 +861,7 @@ func Test_expandAlias(t *testing.T) {
|
||||
aclPolicy: ACLPolicy{
|
||||
Groups: Groups{"group:accountant": []string{"joe", "marc"}},
|
||||
},
|
||||
stripEmailDomain: true,
|
||||
},
|
||||
want: []string{},
|
||||
wantErr: true,
|
||||
@@ -814,9 +869,10 @@ func Test_expandAlias(t *testing.T) {
|
||||
{
|
||||
name: "simple ipaddress",
|
||||
args: args{
|
||||
alias: "10.0.0.3",
|
||||
machines: []Machine{},
|
||||
aclPolicy: ACLPolicy{},
|
||||
alias: "10.0.0.3",
|
||||
machines: []Machine{},
|
||||
aclPolicy: ACLPolicy{},
|
||||
stripEmailDomain: true,
|
||||
},
|
||||
want: []string{"10.0.0.3"},
|
||||
wantErr: false,
|
||||
@@ -831,6 +887,7 @@ func Test_expandAlias(t *testing.T) {
|
||||
"homeNetwork": netaddr.MustParseIPPrefix("192.168.1.0/24"),
|
||||
},
|
||||
},
|
||||
stripEmailDomain: true,
|
||||
},
|
||||
want: []string{"192.168.1.0/24"},
|
||||
wantErr: false,
|
||||
@@ -838,9 +895,10 @@ func Test_expandAlias(t *testing.T) {
|
||||
{
|
||||
name: "simple host",
|
||||
args: args{
|
||||
alias: "10.0.0.1",
|
||||
machines: []Machine{},
|
||||
aclPolicy: ACLPolicy{},
|
||||
alias: "10.0.0.1",
|
||||
machines: []Machine{},
|
||||
aclPolicy: ACLPolicy{},
|
||||
stripEmailDomain: true,
|
||||
},
|
||||
want: []string{"10.0.0.1"},
|
||||
wantErr: false,
|
||||
@@ -848,9 +906,10 @@ func Test_expandAlias(t *testing.T) {
|
||||
{
|
||||
name: "simple CIDR",
|
||||
args: args{
|
||||
alias: "10.0.0.0/16",
|
||||
machines: []Machine{},
|
||||
aclPolicy: ACLPolicy{},
|
||||
alias: "10.0.0.0/16",
|
||||
machines: []Machine{},
|
||||
aclPolicy: ACLPolicy{},
|
||||
stripEmailDomain: true,
|
||||
},
|
||||
want: []string{"10.0.0.0/16"},
|
||||
wantErr: false,
|
||||
@@ -894,6 +953,7 @@ func Test_expandAlias(t *testing.T) {
|
||||
aclPolicy: ACLPolicy{
|
||||
TagOwners: TagOwners{"tag:hr-webserver": []string{"joe"}},
|
||||
},
|
||||
stripEmailDomain: true,
|
||||
},
|
||||
want: []string{"100.64.0.1", "100.64.0.2"},
|
||||
wantErr: false,
|
||||
@@ -934,6 +994,7 @@ func Test_expandAlias(t *testing.T) {
|
||||
"tag:accountant-webserver": []string{"group:accountant"},
|
||||
},
|
||||
},
|
||||
stripEmailDomain: true,
|
||||
},
|
||||
want: []string{},
|
||||
wantErr: true,
|
||||
@@ -977,6 +1038,7 @@ func Test_expandAlias(t *testing.T) {
|
||||
aclPolicy: ACLPolicy{
|
||||
TagOwners: TagOwners{"tag:accountant-webserver": []string{"joe"}},
|
||||
},
|
||||
stripEmailDomain: true,
|
||||
},
|
||||
want: []string{"100.64.0.4"},
|
||||
wantErr: false,
|
||||
@@ -988,6 +1050,7 @@ func Test_expandAlias(t *testing.T) {
|
||||
test.args.machines,
|
||||
test.args.aclPolicy,
|
||||
test.args.alias,
|
||||
test.args.stripEmailDomain,
|
||||
)
|
||||
if (err != nil) != test.wantErr {
|
||||
t.Errorf("expandAlias() error = %v, wantErr %v", err, test.wantErr)
|
||||
|
||||
Reference in New Issue
Block a user