23
23
import static com .github .tomakehurst .wiremock .client .WireMock .putRequestedFor ;
24
24
import static com .github .tomakehurst .wiremock .client .WireMock .urlEqualTo ;
25
25
import static com .github .tomakehurst .wiremock .client .WireMock .verify ;
26
+ import static com .github .tomakehurst .wiremock .core .WireMockConfiguration .wireMockConfig ;
26
27
import static org .assertj .core .api .Assertions .assertThat ;
27
28
28
29
import com .github .tomakehurst .wiremock .junit .WireMockRule ;
@@ -47,12 +48,18 @@ public class AutoDefaultsModeDiscoveryEc2MetadataClientTest {
47
48
private static final EnvironmentVariableHelper ENVIRONMENT_VARIABLE_HELPER = new EnvironmentVariableHelper ();
48
49
49
50
@ Rule
50
- public WireMockRule wireMock = new WireMockRule (0 );
51
+ public WireMockRule wireMock = new WireMockRule (wireMockConfig ()
52
+ .port (0 )
53
+ .httpsPort (-1 ));
51
54
52
55
@ Before
53
56
public void setup () {
54
57
System .setProperty (SdkSystemSetting .AWS_EC2_METADATA_SERVICE_ENDPOINT .property (),
55
58
"http://localhost:" + wireMock .port ());
59
+
60
+ clearEnvironmentVariable ("AWS_EXECUTION_ENV" );
61
+ clearEnvironmentVariable ("AWS_REGION" );
62
+ clearEnvironmentVariable ("AWS_DEFAULT_REGION" );
56
63
}
57
64
58
65
@ After
@@ -62,6 +69,15 @@ public void cleanup() {
62
69
System .clearProperty (SdkSystemSetting .AWS_EC2_METADATA_SERVICE_ENDPOINT .property ());
63
70
}
64
71
72
+ // Clear an environment variable by setting it to null.
73
+ private void clearEnvironmentVariable (String name ) {
74
+ try {
75
+ ENVIRONMENT_VARIABLE_HELPER .set (name , null );
76
+ } catch (Exception e ) {
77
+ // Ignore
78
+ }
79
+ }
80
+
65
81
@ Test
66
82
public void autoDefaultsModeDiscovery_shouldUseSharedHttpClient () throws Exception {
67
83
// Stub successful IMDS responses
@@ -132,8 +148,8 @@ public void awsEc2MetadataDisabled_shouldSkipImdsAndUseStandardMode() {
132
148
assertThat (result ).isEqualTo (DefaultsMode .STANDARD );
133
149
134
150
// Verify no IMDS requests were made
135
- wireMock . verify (0 , putRequestedFor (urlEqualTo ("/latest/api/token" )));
136
- wireMock . verify (0 , getRequestedFor (urlEqualTo ("/latest/meta-data/placement/region" )));
151
+ verify (0 , putRequestedFor (urlEqualTo ("/latest/api/token" )));
152
+ verify (0 , getRequestedFor (urlEqualTo ("/latest/meta-data/placement/region" )));
137
153
}
138
154
139
155
@ Test
0 commit comments