TestCacheMemoryStepsIntegrityAwareKey verifies that the generated cache key includes the integrity level and policy hash.
(t *testing.T)
| 420 | // TestCacheMemoryStepsIntegrityAwareKey verifies that the generated cache key |
| 421 | // includes the integrity level and policy hash. |
| 422 | func TestCacheMemoryStepsIntegrityAwareKey(t *testing.T) { |
| 423 | toolsMap := map[string]any{ |
| 424 | "cache-memory": true, |
| 425 | "github": map[string]any{ |
| 426 | "allowed": []any{"get_repository"}, |
| 427 | "min-integrity": "unapproved", |
| 428 | "allowed-repos": []any{"github/gh-aw"}, |
| 429 | }, |
| 430 | } |
| 431 | |
| 432 | toolsConfig, err := ParseToolsConfig(toolsMap) |
| 433 | require.NoError(t, err, "Should parse tools config") |
| 434 | |
| 435 | compiler := NewCompiler() |
| 436 | cacheMemoryConfig, err := compiler.extractCacheMemoryConfig(toolsConfig) |
| 437 | require.NoError(t, err, "Should extract cache-memory config") |
| 438 | |
| 439 | parsedTools := NewTools(toolsMap) |
| 440 | |
| 441 | data := &WorkflowData{ |
| 442 | CacheMemoryConfig: cacheMemoryConfig, |
| 443 | ParsedTools: parsedTools, |
| 444 | } |
| 445 | |
| 446 | var builder strings.Builder |
| 447 | generateCacheMemorySteps(&builder, data) |
| 448 | output := builder.String() |
| 449 | |
| 450 | // Key should start with "memory-unapproved-" followed by an 8-char hash |
| 451 | assert.Contains(t, output, "key: memory-unapproved-", |
| 452 | "Cache key should include 'unapproved' integrity level") |
| 453 | // Should NOT contain the old format (without integrity prefix) |
| 454 | assert.NotContains(t, output, "key: memory-${{ env.GH_AW_WORKFLOW_ID_SANITIZED }}", |
| 455 | "Cache key should not use the old format without integrity prefix") |
| 456 | } |
| 457 | |
| 458 | // TestCacheMemoryStepsNoPolicy verifies that the generated cache key uses the |
| 459 | // nopolicy sentinel when no guard policy is configured. |
nothing calls this directly
no test coverage detected