@@ -605,8 +605,15 @@ Test workflow with non-api prefix api-target.
605605 // Check allowDomains in AWF JSON config contains expected domains.
606606 // Network settings are now expressed via --config JSON file instead of
607607 // --allow-domains CLI flag (see BuildAWFConfigJSON).
608+ // The JSON is shell-escaped in the lock file, so try both the unescaped
609+ // ("allowDomains":[) and escaped (\"allowDomains\":[) forms.
608610 allowDomainsPrefix := `"allowDomains":[`
611+ allowDomainsPrefixEscaped := `\"allowDomains\":[`
609612 allowDomainsIdx := strings .Index (lockStr , allowDomainsPrefix )
613+ if allowDomainsIdx < 0 {
614+ allowDomainsPrefix = allowDomainsPrefixEscaped
615+ allowDomainsIdx = strings .Index (lockStr , allowDomainsPrefixEscaped )
616+ }
610617 if allowDomainsIdx < 0 {
611618 t .Fatal ("allowDomains key not found in compiled lock file" )
612619 }
@@ -618,15 +625,22 @@ Test workflow with non-api prefix api-target.
618625 }
619626 allowDomainsSection := lockStr [arrayStart : arrayStart + allowDomainsEnd ]
620627
628+ // containsJSONDomain checks for a domain as a JSON string value, handling both
629+ // escaped (\"domain\") and unescaped ("domain") forms in the lock file.
630+ containsJSONDomain := func (section , domain string ) bool {
631+ return strings .Contains (section , `"` + domain + `"` ) ||
632+ strings .Contains (section , `\"` + domain + `\"` )
633+ }
634+
621635 for _ , domain := range tt .expectedDomains {
622- if ! strings . Contains (allowDomainsSection , `"` + domain + `"` ) {
636+ if ! containsJSONDomain (allowDomainsSection , domain ) {
623637 t .Errorf ("Expected domain %q not found in allowDomains.\n Section: %s" , domain , allowDomainsSection )
624638 }
625639 }
626640 // Use exact JSON string matching for "not present" checks to avoid false positives
627641 // (e.g. "corp.example.com" would substring-match "copilot.corp.example.com").
628642 for _ , domain := range tt .unexpectedDomains {
629- if strings . Contains (allowDomainsSection , `"` + domain + `"` ) {
643+ if containsJSONDomain (allowDomainsSection , domain ) {
630644 t .Errorf ("Unexpected domain %q found in allowDomains.\n Section: %s" , domain , allowDomainsSection )
631645 }
632646 }
@@ -801,16 +815,28 @@ Test workflow with GHE data residency api-target and threat detection.
801815 // once for the main agent AWF run and once for the threat detection AWF run.
802816 // API proxy settings are now expressed via --config JSON file instead of
803817 // --copilot-api-target CLI flag (see BuildAWFConfigJSON).
804- apiTargetCount := strings .Count (lockStr , `"copilot":{"host":"api.contoso-aw.ghe.com"}` )
818+ // The JSON is shell-escaped in the lock file, so try both unescaped and escaped forms.
819+ apiTargetUnescaped := `"copilot":{"host":"api.contoso-aw.ghe.com"}`
820+ apiTargetEscaped := `\"copilot\":{\"host\":\"api.contoso-aw.ghe.com\"}`
821+ apiTargetCount := strings .Count (lockStr , apiTargetUnescaped )
822+ if apiTargetCount == 0 {
823+ apiTargetCount = strings .Count (lockStr , apiTargetEscaped )
824+ }
805825 if apiTargetCount < 2 {
806826 t .Errorf ("Expected copilot api-target to appear in both the main agent and threat detection AWF JSON configs (at least 2 times), but found %d occurrence(s)." , apiTargetCount )
807827 }
808828
809829 // Find all allowDomains occurrences in AWF JSON config and verify each contains the GHE domains.
810830 // api.contoso-aw.ghe.com triggers base-domain derivation, so both the API domain
811831 // and the base domain (contoso-aw.ghe.com) must appear in each AWF invocation.
832+ // The JSON is shell-escaped in the lock file, so try both unescaped and escaped key forms.
812833 requiredDomains := []string {"api.contoso-aw.ghe.com" , "contoso-aw.ghe.com" }
813834 allowDomainsPrefix := `"allowDomains":[`
835+ allowDomainsPrefixEscaped := `\"allowDomains\":[`
836+ // Use whichever prefix form is present in the lock file.
837+ if strings .Index (lockStr , allowDomainsPrefix ) < 0 {
838+ allowDomainsPrefix = allowDomainsPrefixEscaped
839+ }
814840 remaining := lockStr
815841 occurrenceIdx := 0
816842 for {
@@ -826,7 +852,8 @@ Test workflow with GHE data residency api-target and threat detection.
826852 }
827853 section := remaining [arrayStart : arrayStart + arrayEnd ]
828854 for _ , domain := range requiredDomains {
829- if ! strings .Contains (section , `"` + domain + `"` ) {
855+ // Handle both escaped (\"domain\") and unescaped ("domain") forms.
856+ if ! strings .Contains (section , `"` + domain + `"` ) && ! strings .Contains (section , `\"` + domain + `\"` ) {
830857 t .Errorf ("allowDomains occurrence #%d is missing GHE domain %q.\n Section: %s" , occurrenceIdx , domain , section )
831858 }
832859 }
0 commit comments