TestComputeIntegrityCacheKey_CustomKey verifies that custom keys get the integrity prefix to prevent cross-integrity cache sharing.
(t *testing.T)
| 341 | // TestComputeIntegrityCacheKey_CustomKey verifies that custom keys get the integrity prefix |
| 342 | // to prevent cross-integrity cache sharing. |
| 343 | func TestComputeIntegrityCacheKey_CustomKey(t *testing.T) { |
| 344 | cfg := &GitHubToolConfig{ |
| 345 | MinIntegrity: GitHubIntegrityMerged, |
| 346 | AllowedRepos: "all", |
| 347 | } |
| 348 | policyHash := computePolicyHash(cfg) |
| 349 | |
| 350 | entry := CacheMemoryEntry{ |
| 351 | ID: "default", |
| 352 | Key: "my-custom-key", |
| 353 | } |
| 354 | key := computeIntegrityCacheKey(entry, cfg) |
| 355 | |
| 356 | // Custom keys must be prefixed with integrity/policy to prevent cross-level sharing |
| 357 | expectedPrefix := "memory-merged-" + policyHash + "-" |
| 358 | assert.True(t, strings.HasPrefix(key, expectedPrefix), |
| 359 | "Custom keys must be prefixed with integrity/policy, got: %s", key) |
| 360 | assert.True(t, strings.HasSuffix(key, "-${{ github.run_id }}"), |
| 361 | "Custom keys should end with run_id suffix, got: %s", key) |
| 362 | } |
| 363 | |
| 364 | // TestComputeIntegrityCacheKey_CustomKeyWithRunID verifies that custom keys already containing |
| 365 | // the run_id suffix are not duplicated, but still get the integrity prefix. |
nothing calls this directly
no test coverage detected