From 0cd1e31d617aac20a7d4b753c477ee66f28f0a38 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Fri, 21 Mar 2025 14:30:25 +0100 Subject: [PATCH] remove integration test rewrite hack Signed-off-by: Kristoffer Dalby --- integration/acl_test.go | 3 -- integration/cli_test.go | 6 ---- integration/hsic/hsic.go | 64 ---------------------------------------- 3 files changed, 73 deletions(-) diff --git a/integration/acl_test.go b/integration/acl_test.go index d1bf0342..6511f36a 100644 --- a/integration/acl_test.go +++ b/integration/acl_test.go @@ -1085,9 +1085,6 @@ func TestPolicyUpdateWhileRunningWithCLIInDatabase(t *testing.T) { }, Hosts: policyv1.Hosts{}, } - if usePolicyV2ForTest { - hsic.RewritePolicyToV2(&p) - } pBytes, _ := json.Marshal(p) diff --git a/integration/cli_test.go b/integration/cli_test.go index 85b20702..d08ecd5f 100644 --- a/integration/cli_test.go +++ b/integration/cli_test.go @@ -1754,9 +1754,6 @@ func TestPolicyCommand(t *testing.T) { "tag:exists": {"user1"}, }, } - if usePolicyV2ForTest { - hsic.RewritePolicyToV2(&p) - } pBytes, _ := json.Marshal(p) @@ -1843,9 +1840,6 @@ func TestPolicyBrokenConfigCommand(t *testing.T) { "tag:exists": {"user1"}, }, } - if usePolicyV2ForTest { - hsic.RewritePolicyToV2(&p) - } pBytes, _ := json.Marshal(p) diff --git a/integration/hsic/hsic.go b/integration/hsic/hsic.go index 1b976f4a..5a0fa6c5 100644 --- a/integration/hsic/hsic.go +++ b/integration/hsic/hsic.go @@ -12,7 +12,6 @@ import ( "net/netip" "os" "path" - "regexp" "sort" "strconv" "strings" @@ -412,22 +411,6 @@ func New( return nil, fmt.Errorf("failed to write headscale config to container: %w", err) } - if hsic.aclPolicy != nil { - // Rewrite all user entries in the policy to have an @ at the end. - if hsic.policyV2 { - RewritePolicyToV2(hsic.aclPolicy) - } - data, err := json.Marshal(hsic.aclPolicy) - if err != nil { - return nil, fmt.Errorf("failed to marshal ACL Policy to JSON: %w", err) - } - - err = hsic.WriteFile(aclPolicyPath, data) - if err != nil { - return nil, fmt.Errorf("failed to write ACL policy to container: %w", err) - } - } - if hsic.hasTLS() { err = hsic.WriteFile(tlsCertPath, hsic.tlsCert) if err != nil { @@ -878,50 +861,3 @@ func (t *HeadscaleInContainer) SendInterrupt() error { return nil } - -// TODO(kradalby): Remove this function when v1 is deprecated -func rewriteUsersToV2(strs []string) []string { - var result []string - userPattern := regexp.MustCompile(`^user\d+$`) - - for _, username := range strs { - parts := strings.Split(username, ":") - if len(parts) == 0 { - result = append(result, username) - continue - } - firstPart := parts[0] - if userPattern.MatchString(firstPart) { - modifiedFirst := firstPart + "@" - if len(parts) > 1 { - rest := strings.Join(parts[1:], ":") - username = modifiedFirst + ":" + rest - } else { - username = modifiedFirst - } - } - result = append(result, username) - } - - return result -} - -// rewritePolicyToV2 rewrites the policy to v2 format. -// This mostly means adding the @ prefix to user names. -// replaces are done inplace -func RewritePolicyToV2(pol *policyv1.ACLPolicy) { - for idx := range pol.ACLs { - pol.ACLs[idx].Sources = rewriteUsersToV2(pol.ACLs[idx].Sources) - pol.ACLs[idx].Destinations = rewriteUsersToV2(pol.ACLs[idx].Destinations) - } - for idx := range pol.Groups { - pol.Groups[idx] = rewriteUsersToV2(pol.Groups[idx]) - } - for idx := range pol.TagOwners { - pol.TagOwners[idx] = rewriteUsersToV2(pol.TagOwners[idx]) - } - for idx := range pol.SSHs { - pol.SSHs[idx].Sources = rewriteUsersToV2(pol.SSHs[idx].Sources) - pol.SSHs[idx].Destinations = rewriteUsersToV2(pol.SSHs[idx].Destinations) - } -}