mirror of
https://github.com/juanfont/headscale.git
synced 2025-08-01 13:46:49 +02:00
remove integration test rewrite hack
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
parent
639c5ef150
commit
0cd1e31d61
@ -1085,9 +1085,6 @@ func TestPolicyUpdateWhileRunningWithCLIInDatabase(t *testing.T) {
|
||||
},
|
||||
Hosts: policyv1.Hosts{},
|
||||
}
|
||||
if usePolicyV2ForTest {
|
||||
hsic.RewritePolicyToV2(&p)
|
||||
}
|
||||
|
||||
pBytes, _ := json.Marshal(p)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user