TestFirewallArgsInCopilotEngine tests that custom firewall args are included in AWF command
(t *testing.T)
| 11 | |
| 12 | // TestFirewallArgsInCopilotEngine tests that custom firewall args are included in AWF command |
| 13 | func TestFirewallArgsInCopilotEngine(t *testing.T) { |
| 14 | t.Run("no custom args uses only default flags", func(t *testing.T) { |
| 15 | workflowData := &WorkflowData{ |
| 16 | Name: "test-workflow", |
| 17 | EngineConfig: &EngineConfig{ |
| 18 | ID: "copilot", |
| 19 | }, |
| 20 | NetworkPermissions: &NetworkPermissions{ |
| 21 | Firewall: &FirewallConfig{ |
| 22 | Enabled: true, |
| 23 | }, |
| 24 | }, |
| 25 | } |
| 26 | |
| 27 | engine := NewCopilotEngine() |
| 28 | steps := engine.GetExecutionSteps(workflowData, "test.log") |
| 29 | |
| 30 | stepContent := requireCopilotExecutionStep(t, steps) |
| 31 | |
| 32 | // Check that the command contains awf (AWF v0.15.0+ uses chroot mode by default) |
| 33 | if !strings.Contains(stepContent, "sudo -E awf") { |
| 34 | t.Error("Expected command to contain 'sudo -E awf'") |
| 35 | } |
| 36 | |
| 37 | // With config file support (default AWF version), domains appear in the JSON config |
| 38 | // rather than as a --allow-domains CLI flag. Verify the config JSON is written. |
| 39 | if !strings.Contains(stepContent, "allowDomains") { |
| 40 | t.Error("Expected command to contain 'allowDomains' in the AWF config JSON") |
| 41 | } |
| 42 | |
| 43 | if !strings.Contains(stepContent, "--log-level") { |
| 44 | t.Error("Expected command to contain '--log-level'") |
| 45 | } |
| 46 | |
| 47 | initSnippet := `GH_AW_DOCKER_HOST_PATH_PREFIX_ARGS=""` |
| 48 | dockerHostInitSnippet := `GH_AW_DOCKER_HOST=""` |
| 49 | dockerHostConditionSnippet := `if [[ "${DOCKER_HOST:-}" =~ ^tcp:// ]]; then` |
| 50 | dockerHostAssignmentSnippet := `GH_AW_DOCKER_HOST="${DOCKER_HOST}"` |
| 51 | dockerHostArgsRefSnippet := `${GH_AW_DOCKER_HOST:+--docker-host "$GH_AW_DOCKER_HOST"}` |
| 52 | conditionSnippet := `if [[ "${DOCKER_HOST:-}" =~ ^tcp:// ]]; then` |
| 53 | flagAssignmentSnippet := `GH_AW_DOCKER_HOST_PATH_PREFIX_ARGS="--docker-host-path-prefix ${RUNNER_TEMP}/gh-aw"` |
| 54 | argsRefSnippet := `${GH_AW_DOCKER_HOST_PATH_PREFIX_ARGS}` |
| 55 | |
| 56 | dockerHostInitIdx := strings.Index(stepContent, dockerHostInitSnippet) |
| 57 | dockerHostConditionIdx := strings.Index(stepContent, dockerHostConditionSnippet) |
| 58 | dockerHostAssignmentIdx := strings.Index(stepContent, dockerHostAssignmentSnippet) |
| 59 | dockerHostArgsRefIdx := strings.Index(stepContent, dockerHostArgsRefSnippet) |
| 60 | initIdx := strings.Index(stepContent, initSnippet) |
| 61 | conditionIdx := -1 |
| 62 | if initIdx != -1 { |
| 63 | conditionOffset := strings.Index(stepContent[initIdx:], conditionSnippet) |
| 64 | if conditionOffset != -1 { |
| 65 | conditionIdx = initIdx + conditionOffset |
| 66 | } |
| 67 | } |
| 68 | flagIdx := strings.Index(stepContent, flagAssignmentSnippet) |
| 69 | argsRefIdx := strings.Index(stepContent, argsRefSnippet) |
| 70 | if dockerHostInitIdx == -1 || dockerHostConditionIdx == -1 || dockerHostAssignmentIdx == -1 || dockerHostArgsRefIdx == -1 || dockerHostInitIdx >= dockerHostConditionIdx || dockerHostConditionIdx >= dockerHostAssignmentIdx || dockerHostAssignmentIdx >= dockerHostArgsRefIdx { |
nothing calls this directly
no test coverage detected