Skip to content

Commit

Permalink
Rename IP specific function, add missing test case
Browse files Browse the repository at this point in the history
Signed-off-by: Kristoffer Dalby <[email protected]>
  • Loading branch information
kradalby committed Jan 30, 2023
1 parent cffa040 commit 83a538c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
11 changes: 8 additions & 3 deletions acls.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ func (h *Headscale) UpdateACLRules() error {
return nil
}

func generateACLRules(machines []Machine, aclPolicy ACLPolicy, stripEmaildomain bool) ([]tailcfg.FilterRule, error) {
func generateACLRules(
machines []Machine,
aclPolicy ACLPolicy,
stripEmaildomain bool,
) ([]tailcfg.FilterRule, error) {
rules := []tailcfg.FilterRule{}

for index, acl := range aclPolicy.ACLs {
Expand All @@ -160,7 +164,7 @@ func generateACLRules(machines []Machine, aclPolicy ACLPolicy, stripEmaildomain

srcIPs := []string{}
for innerIndex, src := range acl.Sources {
srcs, err := generateACLPolicySrcIP(machines, aclPolicy, src, stripEmaildomain)
srcs, err := generateACLPolicySrc(machines, aclPolicy, src, stripEmaildomain)
if err != nil {
log.Error().
Msgf("Error parsing ACL %d, Source %d", index, innerIndex)
Expand Down Expand Up @@ -311,7 +315,7 @@ func sshCheckAction(duration string) (*tailcfg.SSHAction, error) {
}, nil
}

func generateACLPolicySrcIP(
func generateACLPolicySrc(
machines []Machine,
aclPolicy ACLPolicy,
src string,
Expand Down Expand Up @@ -427,6 +431,7 @@ func parseProtocol(protocol string) ([]int, bool, error) {
// - a user
// - a group
// - a tag
// - a host
// and transform these in IPAddresses.
func expandAlias(
machines []Machine,
Expand Down
17 changes: 16 additions & 1 deletion acls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ func Test_expandAlias(t *testing.T) {
wantErr: false,
},
{
name: "simple host",
name: "simple host by ip",
args: args{
alias: "10.0.0.1",
machines: []Machine{},
Expand All @@ -1051,6 +1051,21 @@ func Test_expandAlias(t *testing.T) {
want: []string{"10.0.0.1"},
wantErr: false,
},
{
name: "simple host by hostname alias",
args: args{
alias: "testy",
machines: []Machine{},
aclPolicy: ACLPolicy{
Hosts: Hosts{
"testy": netip.MustParsePrefix("10.0.0.132/32"),
},
},
stripEmailDomain: true,
},
want: []string{"10.0.0.132/32"},
wantErr: false,
},
{
name: "simple CIDR",
args: args{
Expand Down

0 comments on commit 83a538c

Please sign in to comment.