TestComputePolicyHash_BlockedUsersExpr verifies that BlockedUsersExpr is included in the policy hash so that expression-based policies are correctly isolated.
(t *testing.T)
| 137 | // TestComputePolicyHash_BlockedUsersExpr verifies that BlockedUsersExpr is included |
| 138 | // in the policy hash so that expression-based policies are correctly isolated. |
| 139 | func TestComputePolicyHash_BlockedUsersExpr(t *testing.T) { |
| 140 | base := &GitHubToolConfig{ |
| 141 | MinIntegrity: GitHubIntegrityUnapproved, |
| 142 | AllowedRepos: []any{"github/gh-aw"}, |
| 143 | BlockedUsers: []string{}, |
| 144 | } |
| 145 | baseHash := computePolicyHash(base) |
| 146 | |
| 147 | // Switching to an expression-based blocked-users should produce a different hash |
| 148 | cfgWithExpr := &GitHubToolConfig{ |
| 149 | MinIntegrity: GitHubIntegrityUnapproved, |
| 150 | AllowedRepos: []any{"github/gh-aw"}, |
| 151 | BlockedUsersExpr: "${{ vars.BLOCKED_USERS }}", |
| 152 | } |
| 153 | assert.NotEqual(t, baseHash, computePolicyHash(cfgWithExpr), |
| 154 | "Expression-based blocked-users must produce a different hash than an empty list") |
| 155 | |
| 156 | // Different expressions must produce different hashes |
| 157 | cfgWithExpr2 := &GitHubToolConfig{ |
| 158 | MinIntegrity: GitHubIntegrityUnapproved, |
| 159 | AllowedRepos: []any{"github/gh-aw"}, |
| 160 | BlockedUsersExpr: "${{ vars.OTHER_BLOCKED_USERS }}", |
| 161 | } |
| 162 | assert.NotEqual(t, computePolicyHash(cfgWithExpr), computePolicyHash(cfgWithExpr2), |
| 163 | "Different expressions must produce different hashes") |
| 164 | |
| 165 | // Same expression must produce the same hash (deterministic) |
| 166 | cfgWithExprCopy := &GitHubToolConfig{ |
| 167 | MinIntegrity: GitHubIntegrityUnapproved, |
| 168 | AllowedRepos: []any{"github/gh-aw"}, |
| 169 | BlockedUsersExpr: "${{ vars.BLOCKED_USERS }}", |
| 170 | } |
| 171 | assert.Equal(t, computePolicyHash(cfgWithExpr), computePolicyHash(cfgWithExprCopy), |
| 172 | "Same expression must produce the same hash") |
| 173 | } |
| 174 | |
| 175 | // TestComputePolicyHash_CaseInsensitive verifies that user/repo names are lowercased before hashing. |
| 176 | func TestComputePolicyHash_CaseInsensitive(t *testing.T) { |
nothing calls this directly
no test coverage detected