TestGetDIFCProxyPolicyJSON verifies that the proxy policy JSON contains only the static fields (min-integrity and repos) without dynamic expressions.
(t *testing.T)
| 234 | // TestGetDIFCProxyPolicyJSON verifies that the proxy policy JSON contains |
| 235 | // only the static fields (min-integrity and repos) without dynamic expressions. |
| 236 | func TestGetDIFCProxyPolicyJSON(t *testing.T) { |
| 237 | tests := []struct { |
| 238 | name string |
| 239 | githubTool map[string]any |
| 240 | expectedContains []string |
| 241 | expectedAbsent []string |
| 242 | expectEmpty bool |
| 243 | }{ |
| 244 | { |
| 245 | name: "nil tool", |
| 246 | githubTool: nil, |
| 247 | expectEmpty: true, |
| 248 | }, |
| 249 | { |
| 250 | name: "empty map tool", |
| 251 | githubTool: map[string]any{}, |
| 252 | expectEmpty: true, |
| 253 | }, |
| 254 | { |
| 255 | name: "min-integrity only", |
| 256 | githubTool: map[string]any{ |
| 257 | "min-integrity": "approved", |
| 258 | }, |
| 259 | expectedContains: []string{`"allow-only"`, `"min-integrity":"approved"`, `"repos":"all"`}, |
| 260 | expectedAbsent: []string{"blocked-users", "approval-labels", "steps.parse-guard-vars", "__GH_AW_GUARD_EXPR"}, |
| 261 | }, |
| 262 | { |
| 263 | name: "min-integrity and repos", |
| 264 | githubTool: map[string]any{ |
| 265 | "min-integrity": "merged", |
| 266 | "repos": "all", |
| 267 | }, |
| 268 | expectedContains: []string{`"allow-only"`, `"min-integrity":"merged"`, `"repos":"all"`}, |
| 269 | expectedAbsent: []string{"blocked-users", "approval-labels"}, |
| 270 | }, |
| 271 | { |
| 272 | name: "allowed-repos (preferred field name)", |
| 273 | githubTool: map[string]any{ |
| 274 | "min-integrity": "unapproved", |
| 275 | "allowed-repos": "owner/*", |
| 276 | }, |
| 277 | expectedContains: []string{`"min-integrity":"unapproved"`, `"repos":"owner/*"`}, |
| 278 | expectedAbsent: []string{"blocked-users", "approval-labels"}, |
| 279 | }, |
| 280 | { |
| 281 | name: "allowed-repos github.repository expression", |
| 282 | githubTool: map[string]any{ |
| 283 | "min-integrity": "approved", |
| 284 | "allowed-repos": "${{ github.repository }}", |
| 285 | }, |
| 286 | expectedContains: []string{`"min-integrity":"approved"`, `"repos":"${{ github.repository }}"`}, |
| 287 | expectedAbsent: []string{"blocked-users", "approval-labels"}, |
| 288 | }, |
| 289 | { |
| 290 | name: "tool without guard policy fields", |
| 291 | githubTool: map[string]any{ |
| 292 | "toolsets": []string{"default"}, |
| 293 | }, |
nothing calls this directly
no test coverage detected