(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestCompilerNetworkPermissionsExtraction(t *testing.T) { |
| 13 | compiler := NewCompiler() |
| 14 | |
| 15 | // Helper function to create a temporary workflow file for testing |
| 16 | createTempWorkflowFile := func(content string) (string, func()) { |
| 17 | tmpDir, err := os.MkdirTemp("", "test-workflow-") |
| 18 | if err != nil { |
| 19 | t.Fatalf("Failed to create temp dir: %v", err) |
| 20 | } |
| 21 | |
| 22 | filePath := filepath.Join(tmpDir, "test.md") |
| 23 | err = os.WriteFile(filePath, []byte(content), 0644) |
| 24 | if err != nil { |
| 25 | t.Fatalf("Failed to write temp file: %v", err) |
| 26 | } |
| 27 | |
| 28 | cleanup := func() { |
| 29 | os.RemoveAll(tmpDir) |
| 30 | } |
| 31 | |
| 32 | return filePath, cleanup |
| 33 | } |
| 34 | |
| 35 | t.Run("Extract top-level network permissions", func(t *testing.T) { |
| 36 | yamlContent := `--- |
| 37 | on: push |
| 38 | engine: |
| 39 | id: claude |
| 40 | model: claude-3-5-sonnet-20241022 |
| 41 | network: |
| 42 | allowed: |
| 43 | - "github.com" |
| 44 | - "*.example.com" |
| 45 | - "api.trusted.com" |
| 46 | strict: false |
| 47 | --- |
| 48 | |
| 49 | # Test Workflow |
| 50 | This is a test workflow with network permissions.` |
| 51 | |
| 52 | filePath, cleanup := createTempWorkflowFile(yamlContent) |
| 53 | defer cleanup() |
| 54 | |
| 55 | workflowData, err := compiler.ParseWorkflowFile(filePath) |
| 56 | if err != nil { |
| 57 | t.Fatalf("Failed to parse workflow: %v", err) |
| 58 | } |
| 59 | |
| 60 | if workflowData.NetworkPermissions == nil { |
| 61 | t.Fatal("Expected network permissions to be extracted") |
| 62 | } |
| 63 | |
| 64 | expectedDomains := []string{"github.com", "*.example.com", "api.trusted.com"} |
| 65 | if len(workflowData.NetworkPermissions.Allowed) != len(expectedDomains) { |
| 66 | t.Fatalf("Expected %d allowed domains, got %d", len(expectedDomains), len(workflowData.NetworkPermissions.Allowed)) |
| 67 | } |
| 68 | |
| 69 | for i, expected := range expectedDomains { |
nothing calls this directly
no test coverage detected