(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestEngineEnvSecretsCodemod(t *testing.T) { |
| 13 | codemod := getEngineEnvSecretsCodemod() |
| 14 | |
| 15 | t.Run("removes unsafe secret-bearing engine env keys and keeps allowed override", func(t *testing.T) { |
| 16 | content := `--- |
| 17 | on: workflow_dispatch |
| 18 | engine: |
| 19 | id: codex |
| 20 | env: |
| 21 | OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} |
| 22 | OPENAI_BASE_URL: ${{ secrets.AZURE_OPENAI_ENDPOINT }}openai/v1 |
| 23 | --- |
| 24 | ` |
| 25 | frontmatter := map[string]any{ |
| 26 | "on": "workflow_dispatch", |
| 27 | "engine": map[string]any{ |
| 28 | "id": "codex", |
| 29 | "env": map[string]any{ |
| 30 | "OPENAI_API_KEY": "${{ secrets.OPENAI_API_KEY }}", |
| 31 | "OPENAI_BASE_URL": "${{ secrets.AZURE_OPENAI_ENDPOINT }}openai/v1", |
| 32 | }, |
| 33 | }, |
| 34 | } |
| 35 | |
| 36 | result, applied, err := codemod.Apply(content, frontmatter) |
| 37 | require.NoError(t, err, "codemod should apply cleanly") |
| 38 | assert.True(t, applied, "codemod should apply") |
| 39 | assert.Contains(t, result, "OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}", "allowed engine secret override should remain") |
| 40 | assert.NotContains(t, result, "OPENAI_BASE_URL: ${{ secrets.AZURE_OPENAI_ENDPOINT }}openai/v1", "unsafe engine env secret should be removed") |
| 41 | }) |
| 42 | |
| 43 | t.Run("removes empty env block after deleting unsafe entries", func(t *testing.T) { |
| 44 | content := `--- |
| 45 | on: workflow_dispatch |
| 46 | engine: |
| 47 | id: codex |
| 48 | env: |
| 49 | OPENAI_BASE_URL: ${{ secrets.AZURE_OPENAI_ENDPOINT }}openai/v1 |
| 50 | --- |
| 51 | ` |
| 52 | frontmatter := map[string]any{ |
| 53 | "on": "workflow_dispatch", |
| 54 | "engine": map[string]any{ |
| 55 | "id": "codex", |
| 56 | "env": map[string]any{ |
| 57 | "OPENAI_BASE_URL": "${{ secrets.AZURE_OPENAI_ENDPOINT }}openai/v1", |
| 58 | }, |
| 59 | }, |
| 60 | } |
| 61 | |
| 62 | result, applied, err := codemod.Apply(content, frontmatter) |
| 63 | require.NoError(t, err, "codemod should apply cleanly") |
| 64 | assert.True(t, applied, "codemod should apply") |
| 65 | assert.NotContains(t, result, "\n env:\n", "empty env block should be removed") |
| 66 | assert.Contains(t, result, "id: codex", "engine block should remain") |
| 67 | }) |
| 68 | |
| 69 | t.Run("no-op when only allowed engine secret override is used", func(t *testing.T) { |
nothing calls this directly
no test coverage detected