Skip to content

Commit 3751d8b

Browse files
committed
Used unique port numbers during integration test
1 parent 898b8c7 commit 3751d8b

2 files changed

Lines changed: 53 additions & 55 deletions

File tree

ayza/src/test/java/nl/altindag/ssl/SSLFactoryIT.java

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ void executeHttpsRequestWithMutualAuthentication() throws IOException {
6363
.withProtocols("TLSv1.3")
6464
.build();
6565

66-
Server server = Server.createDefault(sslFactoryForServer);
66+
Server server = Server.createDefault(sslFactoryForServer, 8999);
6767

6868
SSLFactory sslFactoryForClient = SSLFactory.builder()
6969
.withIdentityMaterial("keystore/client-server/client-one/identity.jks", "secret".toCharArray())
7070
.withTrustMaterial("keystore/client-server/client-one/truststore.jks", "secret".toCharArray())
7171
.build();
7272

73-
Response response = executeRequest("https://localhost:8443/api/hello", sslFactoryForClient.getSslSocketFactory());
73+
Response response = executeRequest("https://localhost:8999/api/hello", sslFactoryForClient.getSslSocketFactory());
7474
assertThat(response.getStatusCode()).isEqualTo(200);
7575

7676
server.stop();
@@ -86,14 +86,14 @@ void executeHttpsRequestWithMutualAuthenticationWhileHavingConcealedTrustMateria
8686
.withProtocols("TLSv1.3")
8787
.build();
8888

89-
Server server = Server.createDefault(sslFactoryForServer);
89+
Server server = Server.createDefault(sslFactoryForServer, 8998);
9090

9191
SSLFactory sslFactoryForClient = SSLFactory.builder()
9292
.withIdentityMaterial("keystore/client-server/client-one/identity.jks", "secret".toCharArray())
9393
.withTrustMaterial("keystore/client-server/client-one/truststore.jks", "secret".toCharArray())
9494
.build();
9595

96-
Response response = executeRequest("https://localhost:8443/api/hello", sslFactoryForClient.getSslSocketFactory());
96+
Response response = executeRequest("https://localhost:8998/api/hello", sslFactoryForClient.getSslSocketFactory());
9797
assertThat(response.getStatusCode()).isEqualTo(200);
9898

9999
server.stop();
@@ -116,8 +116,8 @@ void executeRequestToTwoServersWithMutualAuthenticationWithSingleHttpClientAndSi
116116
.withProtocols("TLSv1.2")
117117
.build();
118118

119-
Server serverOne = Server.createDefault(sslFactoryForServerOne, 8443, "Hello from server one");
120-
Server serverTwo = Server.createDefault(sslFactoryForServerTwo, 8444, "Hello from server two");
119+
Server serverOne = Server.createDefault(sslFactoryForServerOne, 8997, "Hello from server one");
120+
Server serverTwo = Server.createDefault(sslFactoryForServerTwo, 8996, "Hello from server two");
121121

122122
SSLFactory sslFactoryForClient = SSLFactory.builder()
123123
.withIdentityMaterial("keystore/client-server/client-one/identity.jks", keyStorePassword)
@@ -127,12 +127,12 @@ void executeRequestToTwoServersWithMutualAuthenticationWithSingleHttpClientAndSi
127127
.withProtocols("TLSv1.2")
128128
.build();
129129

130-
Response response = executeRequest("https://localhost:8443/api/hello", sslFactoryForClient.getSslSocketFactory());
130+
Response response = executeRequest("https://localhost:8997/api/hello", sslFactoryForClient.getSslSocketFactory());
131131

132132
assertThat(response.getStatusCode()).isEqualTo(200);
133133
assertThat(response.getBody()).contains("Hello from server one");
134134

135-
response = executeRequest("https://localhost:8444/api/hello", sslFactoryForClient.getSslSocketFactory());
135+
response = executeRequest("https://localhost:8996/api/hello", sslFactoryForClient.getSslSocketFactory());
136136

137137
assertThat(response.getStatusCode()).isEqualTo(200);
138138
assertThat(response.getBody()).contains("Hello from server two");
@@ -160,12 +160,12 @@ void executeRequestToTwoServersWithMutualAuthenticationWithReroutingClientCertif
160160
.withProtocols("TLSv1.2")
161161
.build();
162162

163-
Server serverOne = Server.createDefault(sslFactoryForServerOne, 8443, "Hello from server one");
164-
Server serverTwo = Server.createDefault(sslFactoryForServerTwo, 8444, "Hello from server two");
163+
Server serverOne = Server.createDefault(sslFactoryForServerOne, 8995, "Hello from server one");
164+
Server serverTwo = Server.createDefault(sslFactoryForServerTwo, 8994, "Hello from server two");
165165

166166
Map<String, List<String>> clientAliasesToHosts = new HashMap<>();
167-
clientAliasesToHosts.put("client-one", Collections.singletonList("https://localhost:8443/api/hello"));
168-
clientAliasesToHosts.put("client-two", Collections.singletonList("https://localhost:8444/api/hello"));
167+
clientAliasesToHosts.put("client-one", Collections.singletonList("https://localhost:8995/api/hello"));
168+
clientAliasesToHosts.put("client-two", Collections.singletonList("https://localhost:8994/api/hello"));
169169

170170
SSLFactory sslFactoryForClient = SSLFactory.builder()
171171
.withIdentityMaterial("keystore/client-server/client-one/identity.jks", keyStorePassword)
@@ -177,12 +177,12 @@ void executeRequestToTwoServersWithMutualAuthenticationWithReroutingClientCertif
177177

178178
SSLSocketFactory sslSocketFactoryWithCorrectClientRoutes = sslFactoryForClient.getSslSocketFactory();
179179

180-
Response response = executeRequest("https://localhost:8443/api/hello", sslSocketFactoryWithCorrectClientRoutes);
180+
Response response = executeRequest("https://localhost:8995/api/hello", sslSocketFactoryWithCorrectClientRoutes);
181181

182182
assertThat(response.getStatusCode()).isEqualTo(200);
183183
assertThat(response.getBody()).contains("Hello from server one");
184184

185-
response = executeRequest("https://localhost:8444/api/hello", sslSocketFactoryWithCorrectClientRoutes);
185+
response = executeRequest("https://localhost:8994/api/hello", sslSocketFactoryWithCorrectClientRoutes);
186186

187187
assertThat(response.getStatusCode()).isEqualTo(200);
188188
assertThat(response.getBody()).contains("Hello from server two");
@@ -192,14 +192,14 @@ void executeRequestToTwoServersWithMutualAuthenticationWithReroutingClientCertif
192192
.withIdentityMaterial("keystore/client-server/client-two/identity.jks", keyStorePassword)
193193
.withTrustMaterial("keystore/client-server/client-one/truststore.jks", keyStorePassword)
194194
.withTrustMaterial("keystore/client-server/client-two/truststore.jks", keyStorePassword)
195-
.withIdentityRoute("client-one", "https://localhost:8444/api/hello")
196-
.withIdentityRoute("client-two", "https://localhost:8443/api/hello")
195+
.withIdentityRoute("client-one", "https://localhost:8994/api/hello")
196+
.withIdentityRoute("client-two", "https://localhost:8995/api/hello")
197197
.build();
198198

199199
SSLSocketFactory sslSocketFactoryWithIncorrectClientRoutes = sslFactoryForClient.getSslSocketFactory();
200-
assertThatThrownBy(() -> executeRequest("https://localhost:8443/api/hello", sslSocketFactoryWithIncorrectClientRoutes))
200+
assertThatThrownBy(() -> executeRequest("https://localhost:8995/api/hello", sslSocketFactoryWithIncorrectClientRoutes))
201201
.isInstanceOfAny(SocketException.class, SSLException.class);
202-
assertThatThrownBy(() -> executeRequest("https://localhost:8444/api/hello", sslSocketFactoryWithIncorrectClientRoutes))
202+
assertThatThrownBy(() -> executeRequest("https://localhost:8994/api/hello", sslSocketFactoryWithIncorrectClientRoutes))
203203
.isInstanceOfAny(SocketException.class, SSLException.class);
204204

205205
serverOne.stop();
@@ -224,8 +224,8 @@ void executeRequestToTwoServersWithMutualAuthenticationWithSwappingClientIdentit
224224
.withProtocols("TLSv1.2")
225225
.build();
226226

227-
Server serverOne = Server.createDefault(sslFactoryForServerOne, 8443, "Hello from server one");
228-
Server serverTwo = Server.createDefault(sslFactoryForServerTwo, 8444, "Hello from server two");
227+
Server serverOne = Server.createDefault(sslFactoryForServerOne, 8993, "Hello from server one");
228+
Server serverTwo = Server.createDefault(sslFactoryForServerTwo, 8992, "Hello from server two");
229229

230230
SSLFactory sslFactoryForClient = SSLFactory.builder()
231231
.withIdentityMaterial("keystore/client-server/client-one/identity.jks", keyStorePassword)
@@ -236,11 +236,11 @@ void executeRequestToTwoServersWithMutualAuthenticationWithSwappingClientIdentit
236236

237237
SSLSocketFactory sslSocketFactory = sslFactoryForClient.getSslSocketFactory();
238238

239-
Response response = executeRequest("https://localhost:8443/api/hello", sslSocketFactory);
239+
Response response = executeRequest("https://localhost:8993/api/hello", sslSocketFactory);
240240
assertThat(response.getStatusCode()).isEqualTo(200);
241241
assertThat(response.getBody()).contains("Hello from server one");
242242

243-
assertThatThrownBy(() -> executeRequest("https://localhost:8444/api/hello", sslSocketFactory))
243+
assertThatThrownBy(() -> executeRequest("https://localhost:8992/api/hello", sslSocketFactory))
244244
.isInstanceOfAny(SocketException.class, SSLException.class);
245245

246246
SSLFactory updatedSslFactoryForClient = SSLFactory.builder()
@@ -250,10 +250,10 @@ void executeRequestToTwoServersWithMutualAuthenticationWithSwappingClientIdentit
250250

251251
SSLFactoryUtils.reload(sslFactoryForClient, updatedSslFactoryForClient);
252252

253-
assertThatThrownBy(() -> executeRequest("https://localhost:8443/api/hello", sslSocketFactory))
253+
assertThatThrownBy(() -> executeRequest("https://localhost:8993/api/hello", sslSocketFactory))
254254
.isInstanceOfAny(SocketException.class, SSLException.class);
255255

256-
response = executeRequest("https://localhost:8444/api/hello", sslFactoryForClient.getSslSocketFactory());
256+
response = executeRequest("https://localhost:8992/api/hello", sslFactoryForClient.getSslSocketFactory());
257257
assertThat(response.getStatusCode()).isEqualTo(200);
258258
assertThat(response.getBody()).contains("Hello from server two");
259259

@@ -279,8 +279,8 @@ void executeRequestToTwoServersWithMutualAuthenticationWithSwappingClientIdentit
279279
.withProtocols("TLSv1.2")
280280
.build();
281281

282-
Server serverOne = Server.createDefault(sslFactoryForServerOne, 8443, "Hello from server one");
283-
Server serverTwo = Server.createDefault(sslFactoryForServerTwo, 8444, "Hello from server two");
282+
Server serverOne = Server.createDefault(sslFactoryForServerOne, 8991, "Hello from server one");
283+
Server serverTwo = Server.createDefault(sslFactoryForServerTwo, 8990, "Hello from server two");
284284

285285
SSLFactory sslFactoryForClient = SSLFactory.builder()
286286
.withIdentityMaterial("keystore/client-server/client-one/identity.jks", keyStorePassword)
@@ -291,11 +291,11 @@ void executeRequestToTwoServersWithMutualAuthenticationWithSwappingClientIdentit
291291

292292
SSLSocketFactory sslSocketFactory = sslFactoryForClient.getSslSocketFactory();
293293

294-
Response response = executeRequest("https://localhost:8443/api/hello", sslSocketFactory);
294+
Response response = executeRequest("https://localhost:8991/api/hello", sslSocketFactory);
295295
assertThat(response.getStatusCode()).isEqualTo(200);
296296
assertThat(response.getBody()).contains("Hello from server one");
297297

298-
assertThatThrownBy(() -> executeRequest("https://localhost:8444/api/hello", sslSocketFactory))
298+
assertThatThrownBy(() -> executeRequest("https://localhost:8990/api/hello", sslSocketFactory))
299299
.isInstanceOfAny(SocketException.class, SSLException.class);
300300

301301
SSLFactory updatedSslFactoryForClient = SSLFactory.builder()
@@ -305,16 +305,16 @@ void executeRequestToTwoServersWithMutualAuthenticationWithSwappingClientIdentit
305305

306306
SSLFactoryUtils.reload(sslFactoryForClient, updatedSslFactoryForClient, false);
307307

308-
response = executeRequest("https://localhost:8443/api/hello", sslSocketFactory);
308+
response = executeRequest("https://localhost:8991/api/hello", sslSocketFactory);
309309
assertThat(response.getStatusCode()).isEqualTo(200);
310310
assertThat(response.getBody()).contains("Hello from server one");
311311

312312
SSLSessionUtils.invalidateCaches(sslFactoryForClient);
313313

314-
assertThatThrownBy(() -> executeRequest("https://localhost:8443/api/hello", sslSocketFactory))
314+
assertThatThrownBy(() -> executeRequest("https://localhost:8991/api/hello", sslSocketFactory))
315315
.isInstanceOfAny(SocketException.class, SSLException.class);
316316

317-
response = executeRequest("https://localhost:8444/api/hello", sslFactoryForClient.getSslSocketFactory());
317+
response = executeRequest("https://localhost:8990/api/hello", sslFactoryForClient.getSslSocketFactory());
318318
assertThat(response.getStatusCode()).isEqualTo(200);
319319
assertThat(response.getBody()).contains("Hello from server two");
320320

@@ -330,7 +330,7 @@ void throwInvalidAlgorithmParameterExceptionWhenUsingSingleTrustManagerWhichIsCo
330330
.withNeedClientAuthentication()
331331
.build();
332332

333-
Server server = Server.createDefault(sslFactoryForServer);
333+
Server server = Server.createDefault(sslFactoryForServer, 8989);
334334

335335
KeyStore emptyKeyStore = KeyStoreUtils.createKeyStore();
336336
X509ExtendedTrustManager emptyTrustManager = TrustManagerUtils.createTrustManager(emptyKeyStore);
@@ -339,7 +339,7 @@ void throwInvalidAlgorithmParameterExceptionWhenUsingSingleTrustManagerWhichIsCo
339339
.withTrustMaterial(emptyTrustManager)
340340
.build();
341341

342-
SSLException sslException = catchThrowableOfType(() -> executeRequest("https://localhost:8443/api/hello", sslFactoryForClient.getSslSocketFactory()), SSLException.class);
342+
SSLException sslException = catchThrowableOfType(() -> executeRequest("https://localhost:8989/api/hello", sslFactoryForClient.getSslSocketFactory()), SSLException.class);
343343

344344
Throwable cause = sslException.getCause();
345345
assertThat(cause).isInstanceOf(RuntimeException.class);
@@ -359,7 +359,7 @@ void throwCertificateExceptionWhenUsingMultipleTrustManagersWhichIsConstructedFr
359359
.withNeedClientAuthentication()
360360
.build();
361361

362-
Server server = Server.createDefault(sslFactoryForServer);
362+
Server server = Server.createDefault(sslFactoryForServer, 8988);
363363

364364
KeyStore emptyKeyStore = KeyStoreUtils.createKeyStore();
365365
X509ExtendedTrustManager emptyTrustManager = TrustManagerUtils.createTrustManager(emptyKeyStore);
@@ -369,7 +369,7 @@ void throwCertificateExceptionWhenUsingMultipleTrustManagersWhichIsConstructedFr
369369
.withTrustMaterial(emptyTrustManager)
370370
.build();
371371

372-
SSLException sslException = catchThrowableOfType(() -> executeRequest("https://localhost:8443/api/hello", sslFactoryForClient.getSslSocketFactory()), SSLException.class);
372+
SSLException sslException = catchThrowableOfType(() -> executeRequest("https://localhost:8988/api/hello", sslFactoryForClient.getSslSocketFactory()), SSLException.class);
373373

374374
Throwable cause = sslException.getCause();
375375
assertThat(cause).isInstanceOf(CertificateException.class);
@@ -397,7 +397,7 @@ void executeRequestToServerWithMutualAuthenticationWithSwappingCiphers() throws
397397
.withProtocols("TLSv1.2")
398398
.build();
399399

400-
Server server = Server.createDefault(sslFactoryForServer, 8443, "Hello from server one");
400+
Server server = Server.createDefault(sslFactoryForServer, 8987, "Hello from server one");
401401

402402
SSLFactory sslFactoryForClient = SSLFactory.builder()
403403
.withIdentityMaterial("keystore/client-server/client-one/identity.jks", keyStorePassword)
@@ -407,13 +407,13 @@ void executeRequestToServerWithMutualAuthenticationWithSwappingCiphers() throws
407407

408408
SSLSocketFactory sslSocketFactory = sslFactoryForClient.getSslSocketFactory();
409409

410-
Response response = executeRequest("https://localhost:8443/api/hello", sslSocketFactory);
410+
Response response = executeRequest("https://localhost:8987/api/hello", sslSocketFactory);
411411
assertThat(response.getStatusCode()).isEqualTo(200);
412412
assertThat(response.getBody()).contains("Hello from server one");
413413

414414
sslFactoryForClient.getSslParameters().setCipherSuites(new String[]{"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384"});
415415

416-
assertThatThrownBy(() -> executeRequest("https://localhost:8443/api/hello", sslSocketFactory))
416+
assertThatThrownBy(() -> executeRequest("https://localhost:8987/api/hello", sslSocketFactory))
417417
.isInstanceOfAny(SocketException.class, SSLException.class);
418418

419419
server.stop();
@@ -437,15 +437,15 @@ void swapCiphersWhileUsingNetty() throws Exception {
437437

438438
Provider provider = ProviderUtils.create(sslFactoryForServer);
439439
Security.insertProviderAt(provider, 1);
440-
Server server = Server.createDefault(sslFactoryForServer);
440+
Server server = Server.createDefault(sslFactoryForServer, 8986);
441441

442-
assertThatThrownBy(() -> executeRequest("https://localhost:8443/api/hello", sslFactoryForClient.getSslSocketFactory()))
442+
assertThatThrownBy(() -> executeRequest("https://localhost:8986/api/hello", sslFactoryForClient.getSslSocketFactory()))
443443
.hasMessageContaining("Received fatal alert: handshake_failure");
444444

445445
SSLParameters sslParameters = sslFactoryForServer.getSslParameters();
446446
sslParameters.setCipherSuites(sslFactoryForClient.getCiphers().toArray(new String[0]));
447447

448-
Response response = executeRequest("https://localhost:8443/api/hello", sslFactoryForClient.getSslSocketFactory());
448+
Response response = executeRequest("https://localhost:8986/api/hello", sslFactoryForClient.getSslSocketFactory());
449449
assertThat(response.getStatusCode()).isEqualTo(200);
450450

451451
server.stop();

0 commit comments

Comments
 (0)