Skip to content

Commit cfdfdf2

Browse files
cristimclaude
andauthored
test(cli): clear service-specific AWS endpoint overrides in every test stub (#2227)
Shared clearAWSEndpointOverrides helper blanks AWS_ENDPOINT_URL_* and AWS_IGNORE_CONFIGURED_ENDPOINT_URLS; used by isolateAWSEnv, rdsAPIStub.serveEnv and the GCP signal child launcher. Closes #2222 Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 52ad82f commit cfdfdf2

4 files changed

Lines changed: 19 additions & 9 deletions

‎cmd/configure_gcp_signal_test.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ func childState(child *exec.Cmd) string {
146146

147147
func startGCPInterruptChild(t *testing.T, phase string) (*exec.Cmd, string, io.ReadCloser, *syncBuffer) {
148148
t.Helper()
149+
// The child inherits this env; it sets its own secretsmanager endpoint.
150+
clearAWSEndpointOverrides(t)
149151
dir := t.TempDir()
150152
adc := filepath.Join(dir, "adc.json")
151153
require.NoError(t, os.WriteFile(adc, []byte(`{"type":"authorized_user","client_id":"fixture","client_secret":"fixture","refresh_token":"fixture"}`), 0600))

‎cmd/multi_service_extended_support_unavailable_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func (s *rdsAPIStub) serveEnv(t *testing.T) {
161161
t.Setenv("AWS_SHARED_CREDENTIALS_FILE", empty)
162162
t.Setenv("AWS_EC2_METADATA_DISABLED", "true")
163163
t.Setenv("AWS_PROFILE", "")
164-
t.Setenv("AWS_IGNORE_CONFIGURED_ENDPOINT_URLS", "")
164+
clearAWSEndpointOverrides(t)
165165
t.Setenv("AWS_ACCESS_KEY_ID", "AKIDEXAMPLE")
166166
t.Setenv("AWS_SECRET_ACCESS_KEY", "secret")
167167
t.Setenv("AWS_SESSION_TOKEN", "")

‎cmd/multi_service_test.go‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,20 @@ func TestFilterAndAdjustRecommendations(t *testing.T) {
16481648
}
16491649
}
16501650

1651+
// clearAWSEndpointOverrides blanks every service-specific AWS_ENDPOINT_URL_*
1652+
// variable and AWS_IGNORE_CONFIGURED_ENDPOINT_URLS for the test, so a
1653+
// developer's global overrides can neither bypass nor disable a test's local
1654+
// endpoint. Set the test's own endpoint variables after calling it.
1655+
func clearAWSEndpointOverrides(t *testing.T) {
1656+
t.Helper()
1657+
for _, kv := range os.Environ() {
1658+
if name, _, _ := strings.Cut(kv, "="); strings.HasPrefix(name, "AWS_ENDPOINT_URL_") {
1659+
t.Setenv(name, "")
1660+
}
1661+
}
1662+
t.Setenv("AWS_IGNORE_CONFIGURED_ENDPOINT_URLS", "")
1663+
}
1664+
16511665
// isolateAWSEnv pins the AWS environment to deterministic invalid static
16521666
// credentials and points every SDK client at a local server that answers 403
16531667
// AccessDenied, so the runToolFromCSV tests behave identically on credentialed
@@ -1674,13 +1688,7 @@ func isolateAWSEnv(t *testing.T) *atomic.Int64 {
16741688
}))
16751689
t.Cleanup(srv.Close)
16761690

1677-
// A developer's global endpoint overrides must not bypass the local server.
1678-
for _, kv := range os.Environ() {
1679-
if name, _, _ := strings.Cut(kv, "="); strings.HasPrefix(name, "AWS_ENDPOINT_URL_") {
1680-
t.Setenv(name, "")
1681-
}
1682-
}
1683-
t.Setenv("AWS_IGNORE_CONFIGURED_ENDPOINT_URLS", "")
1691+
clearAWSEndpointOverrides(t)
16841692
t.Setenv("AWS_ENDPOINT_URL", srv.URL)
16851693
return hits
16861694
}

‎cmd/purchase_confirmation_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ func TestRunToolFromCSVRequiresTerminal(t *testing.T) {
150150
t.Setenv("HTTP_PROXY", server.URL)
151151
t.Setenv("HTTPS_PROXY", server.URL)
152152
t.Setenv("NO_PROXY", "")
153+
clearAWSEndpointOverrides(t)
153154
for _, key := range []string{"AWS_ENDPOINT_URL", "AWS_ENDPOINT_URL_RDS", "AWS_ENDPOINT_URL_EC2"} {
154155
t.Setenv(key, server.URL)
155156
}
156-
t.Setenv("AWS_IGNORE_CONFIGURED_ENDPOINT_URLS", "false")
157157
cfg := toolCfg
158158
cfg.ActualPurchase = actualPurchase
159159
cfg.Coverage = 100

0 commit comments

Comments
 (0)