@@ -116,7 +116,7 @@ public void methodTeardown() {
116
116
}
117
117
118
118
@ Test
119
- public void canMakeHttpsRequestWhenKeyProviderConfigured () throws IOException {
119
+ public void prepareRequest_whenKeyProviderConfigured_successfullyMakesHttpsRequest () throws IOException {
120
120
client = Apache5HttpClient .builder ()
121
121
.tlsKeyManagersProvider (keyManagersProvider )
122
122
.build ();
@@ -125,13 +125,13 @@ public void canMakeHttpsRequestWhenKeyProviderConfigured() throws IOException {
125
125
}
126
126
127
127
@ Test
128
- public void requestFailsWhenKeyProviderNotConfigured () throws IOException {
128
+ public void prepareRequest_whenKeyProviderNotConfigured_throwsSslException () throws IOException {
129
129
client = Apache5HttpClient .builder ().tlsKeyManagersProvider (NoneTlsKeyManagersProvider .getInstance ()).build ();
130
130
assertThatThrownBy (() -> makeRequestWithHttpClient (client )).isInstanceOfAny (SSLException .class , SocketException .class );
131
131
}
132
132
133
133
@ Test
134
- public void authenticatesWithTlsProxy () throws IOException {
134
+ public void prepareRequest_whenTlsProxyConfigured_authenticatesSuccessfully () throws IOException {
135
135
ProxyConfiguration proxyConfig = ProxyConfiguration .builder ()
136
136
.endpoint (URI .create ("https://localhost:" + wireMockServer .httpsPort ()))
137
137
.build ();
@@ -148,7 +148,7 @@ public void authenticatesWithTlsProxy() throws IOException {
148
148
}
149
149
150
150
@ Test
151
- public void defaultTlsKeyManagersProviderIsSystemPropertyProvider () throws IOException {
151
+ public void build_whenNoTlsKeyManagersProviderSet_usesSystemPropertyProvider () throws IOException {
152
152
System .setProperty (SSL_KEY_STORE .property (), clientKeyStore .toAbsolutePath ().toString ());
153
153
System .setProperty (SSL_KEY_STORE_TYPE .property (), CLIENT_STORE_TYPE );
154
154
System .setProperty (SSL_KEY_STORE_PASSWORD .property (), STORE_PASSWORD );
@@ -164,7 +164,7 @@ public void defaultTlsKeyManagersProviderIsSystemPropertyProvider() throws IOExc
164
164
}
165
165
166
166
@ Test
167
- public void defaultTlsKeyManagersProviderIsSystemPropertyProvider_explicitlySetToNull () throws IOException {
167
+ public void build_whenTlsKeyManagersProviderExplicitlySetToNull_usesSystemPropertyProvider () throws IOException {
168
168
System .setProperty (SSL_KEY_STORE .property (), clientKeyStore .toAbsolutePath ().toString ());
169
169
System .setProperty (SSL_KEY_STORE_TYPE .property (), CLIENT_STORE_TYPE );
170
170
System .setProperty (SSL_KEY_STORE_PASSWORD .property (), STORE_PASSWORD );
@@ -180,7 +180,7 @@ public void defaultTlsKeyManagersProviderIsSystemPropertyProvider_explicitlySetT
180
180
}
181
181
182
182
@ Test
183
- public void build_notSettingSocketFactory_configuresClientWithDefaultSocketFactory () throws Exception {
183
+ public void build_whenSocketFactoryNotSet_configuresDefaultSocketFactory () throws Exception {
184
184
System .setProperty (SSL_KEY_STORE .property (), clientKeyStore .toAbsolutePath ().toString ());
185
185
System .setProperty (SSL_KEY_STORE_TYPE .property (), CLIENT_STORE_TYPE );
186
186
System .setProperty (SSL_KEY_STORE_PASSWORD .property (), STORE_PASSWORD );
@@ -212,7 +212,7 @@ public void build_notSettingSocketFactory_configuresClientWithDefaultSocketFacto
212
212
}
213
213
214
214
@ Test
215
- public void build_settingCustomSocketFactory_configuresClientWithGivenSocketFactory () throws IOException ,
215
+ public void build_whenCustomSocketFactorySet_usesProvidedSocketFactory () throws IOException ,
216
216
NoSuchAlgorithmException ,
217
217
KeyManagementException {
218
218
TlsKeyManagersProvider provider = FileStoreTlsKeyManagersProvider .create (clientKeyStore ,
@@ -259,7 +259,7 @@ private HttpExecuteResponse makeRequestWithHttpClient(SdkHttpClient httpClient)
259
259
}
260
260
261
261
@ Test
262
- public void tls_strategy_configuration () throws Exception {
262
+ public void build_whenTlsSocketStrategyConfigured_usesProvidedStrategy () throws Exception {
263
263
// Setup TLS context
264
264
KeyManager [] keyManagers = keyManagersProvider .keyManagers ();
265
265
SSLContext sslContext = SSLContext .getInstance ("TLS" );
@@ -289,45 +289,32 @@ public void tls_strategy_configuration() throws Exception {
289
289
}
290
290
291
291
@ Test
292
- public void tls_strategy_overrides_legacy_factory () throws Exception {
292
+ public void build_whenBothTlsStrategyAndLegacyFactorySet_throwsIllegalArgumentException () throws Exception {
293
293
// Setup TLS context
294
294
KeyManager [] keyManagers = keyManagersProvider .keyManagers ();
295
295
SSLContext sslContext = SSLContext .getInstance ("TLS" );
296
296
sslContext .init (keyManagers , null , null );
297
297
298
- // Create spies for both approaches
298
+ // Create both socket factory and TLS strategy
299
299
SSLConnectionSocketFactory legacyFactory = new SSLConnectionSocketFactory (
300
300
sslContext ,
301
301
NoopHostnameVerifier .INSTANCE
302
302
);
303
- SSLConnectionSocketFactory legacyFactorySpy = Mockito .spy (legacyFactory );
304
303
305
304
TlsSocketStrategy tlsStrategy = new SdkTlsSocketFactory (
306
305
sslContext ,
307
306
NoopHostnameVerifier .INSTANCE
308
307
);
309
- TlsSocketStrategy tlsStrategySpy = Mockito .spy (tlsStrategy );
310
-
311
- // Build client with both - TLS strategy should take precedence
312
- client = Apache5HttpClient .builder ()
313
- .socketFactory (legacyFactorySpy )
314
- .tlsSocketStrategy (tlsStrategySpy ) // This should override
315
- .build ();
316
-
317
- // Make request
318
- HttpExecuteResponse response = makeRequestWithHttpClient (client );
319
- assertThat (response .httpResponse ().isSuccessful ()).isTrue ();
320
-
321
- // Verify only TLS strategy was used, not legacy
322
- Mockito .verify (tlsStrategySpy ).upgrade (
323
- Mockito .any (Socket .class ),
324
- Mockito .anyString (),
325
- Mockito .anyInt (),
326
- Mockito .any (),
327
- Mockito .any (HttpContext .class )
328
- );
329
308
330
- Mockito .verifyNoInteractions (legacyFactorySpy );
309
+ // Attempt to build client with both - should throw exception
310
+ assertThatThrownBy (() -> Apache5HttpClient .builder ()
311
+ .socketFactory (legacyFactory )
312
+ .tlsSocketStrategy (tlsStrategy )
313
+ .build ())
314
+ .isInstanceOf (IllegalArgumentException .class )
315
+ .hasMessageContaining ("Cannot configure both tlsSocketStrategy and socketFactory" )
316
+ .hasMessageContaining ("deprecated" )
317
+ .hasMessageContaining ("use tlsSocketStrategy" );
331
318
}
332
319
333
320
}
0 commit comments