TestComputePolicyHash_FieldChanges verifies that changing any single policy field produces a different hash.
(t *testing.T)
| 47 | |
| 48 | // TestComputePolicyHash_FieldChanges verifies that changing any single policy field produces a different hash. |
| 49 | func TestComputePolicyHash_FieldChanges(t *testing.T) { |
| 50 | base := &GitHubToolConfig{ |
| 51 | MinIntegrity: GitHubIntegrityUnapproved, |
| 52 | AllowedRepos: []any{"github/gh-aw"}, |
| 53 | BlockedUsers: []string{}, |
| 54 | } |
| 55 | baseHash := computePolicyHash(base) |
| 56 | |
| 57 | tests := []struct { |
| 58 | name string |
| 59 | cfg *GitHubToolConfig |
| 60 | }{ |
| 61 | { |
| 62 | name: "change min-integrity", |
| 63 | cfg: &GitHubToolConfig{ |
| 64 | MinIntegrity: GitHubIntegrityApproved, |
| 65 | AllowedRepos: []any{"github/gh-aw"}, |
| 66 | BlockedUsers: []string{}, |
| 67 | }, |
| 68 | }, |
| 69 | { |
| 70 | name: "change repos", |
| 71 | cfg: &GitHubToolConfig{ |
| 72 | MinIntegrity: GitHubIntegrityUnapproved, |
| 73 | AllowedRepos: []any{"github/other-repo"}, |
| 74 | BlockedUsers: []string{}, |
| 75 | }, |
| 76 | }, |
| 77 | { |
| 78 | name: "add blocked user", |
| 79 | cfg: &GitHubToolConfig{ |
| 80 | MinIntegrity: GitHubIntegrityUnapproved, |
| 81 | AllowedRepos: []any{"github/gh-aw"}, |
| 82 | BlockedUsers: []string{"attacker1"}, |
| 83 | }, |
| 84 | }, |
| 85 | { |
| 86 | name: "change repos to 'all'", |
| 87 | cfg: &GitHubToolConfig{ |
| 88 | MinIntegrity: GitHubIntegrityUnapproved, |
| 89 | AllowedRepos: "all", |
| 90 | BlockedUsers: []string{}, |
| 91 | }, |
| 92 | }, |
| 93 | } |
| 94 | |
| 95 | for _, tt := range tests { |
| 96 | t.Run(tt.name, func(t *testing.T) { |
| 97 | hash := computePolicyHash(tt.cfg) |
| 98 | assert.NotEqual(t, baseHash, hash, "Changing '%s' must produce a different hash", tt.name) |
| 99 | }) |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | // TestComputePolicyHash_ListOrderIndependent verifies that list order does not affect the hash. |
| 104 | func TestComputePolicyHash_ListOrderIndependent(t *testing.T) { |
nothing calls this directly
no test coverage detected