Skip to content

Commit 0dc2ea4

Browse files
committed
Used unique port numbers during integration test
1 parent e26f895 commit 0dc2ea4

1 file changed

Lines changed: 16 additions & 19 deletions

File tree

ayza/src/test/java/nl/altindag/ssl/trustmanager/HotSwappableX509ExtendedTrustManagerIT.java

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
import nl.altindag.ssl.util.KeyStoreUtils;
2121
import nl.altindag.ssl.util.SSLSessionUtils;
2222
import nl.altindag.ssl.util.TrustManagerUtils;
23+
import org.junit.jupiter.api.AfterAll;
24+
import org.junit.jupiter.api.AfterEach;
2325
import org.junit.jupiter.api.BeforeAll;
26+
import org.junit.jupiter.api.BeforeEach;
2427
import org.junit.jupiter.api.MethodOrderer;
2528
import org.junit.jupiter.api.Order;
2629
import org.junit.jupiter.api.Test;
@@ -46,6 +49,7 @@ class HotSwappableX509ExtendedTrustManagerIT {
4649
private static SSLSocketFactory sslSocketFactory;
4750
private static SSLSessionContext sslSessionContext;
4851
private static X509ExtendedTrustManager trustManager;
52+
private static Server server;
4953

5054
@BeforeAll
5155
static void setUpSSLSocketFactory() {
@@ -60,54 +64,47 @@ static void setUpSSLSocketFactory() {
6064

6165
sslSocketFactory = sslFactory.getSslSocketFactory();
6266
sslSessionContext = sslFactory.getSslContext().getClientSessionContext();
63-
}
6467

65-
@Test
66-
@Order(1)
67-
void executeHttpsRequestWithSslSocketFactoryContainingTrustManager() throws IOException {
6868
SSLFactory sslFactoryForServer = SSLFactory.builder()
6969
.withIdentityMaterial("keystore/client-server/server-one/identity.jks", "secret".toCharArray())
7070
.withTrustMaterial("keystore/client-server/server-one/truststore.jks", "secret".toCharArray())
7171
.withNeedClientAuthentication()
7272
.build();
7373

74-
Server server = Server.createDefault(sslFactoryForServer, 7985);
74+
server = Server.createDefault(sslFactoryForServer, 7000);
75+
}
7576

76-
HttpsURLConnection connection = (HttpsURLConnection) new URL("https://localhost:7985/api/hello").openConnection();
77+
@AfterAll
78+
static void stopServer() {
79+
server.stop();
80+
}
81+
82+
@Test
83+
@Order(1)
84+
void executeHttpsRequestWithSslSocketFactoryContainingTrustManager() throws IOException {
85+
HttpsURLConnection connection = (HttpsURLConnection) new URL("https://localhost:7000/api/hello").openConnection();
7786
connection.setSSLSocketFactory(sslSocketFactory);
7887
connection.setRequestMethod("GET");
7988

8089
int statusCode = connection.getResponseCode();
8190
connection.disconnect();
8291

8392
assertThat(statusCode).isEqualTo(200);
84-
85-
server.stop();
8693
}
8794

8895
@Test
8996
@Order(2)
9097
void executeHttpsRequestWithExistingSslSocketFactoryContainingASwappedUnsafeTrustManager() throws IOException {
91-
SSLFactory sslFactoryForServer = SSLFactory.builder()
92-
.withIdentityMaterial("keystore/client-server/server-one/identity.jks", "secret".toCharArray())
93-
.withTrustMaterial("keystore/client-server/server-one/truststore.jks", "secret".toCharArray())
94-
.withNeedClientAuthentication()
95-
.build();
96-
97-
Server server = Server.createDefault(sslFactoryForServer, 7985);
98-
9998
KeyStore trustStoreWithClientTwo = KeyStoreUtils.loadKeyStore("keystore/client-server/client-two/truststore.jks", "secret".toCharArray());
10099
X509ExtendedTrustManager trustManagerWithClientTwo = TrustManagerUtils.createTrustManager(trustStoreWithClientTwo);
101100
TrustManagerUtils.swapTrustManager(trustManager, trustManagerWithClientTwo);
102101
SSLSessionUtils.invalidateCaches(sslSessionContext);
103102

104-
HttpsURLConnection connection = (HttpsURLConnection) new URL("https://localhost:7985/api/hello").openConnection();
103+
HttpsURLConnection connection = (HttpsURLConnection) new URL("https://localhost:7000/api/hello").openConnection();
105104
connection.setSSLSocketFactory(sslSocketFactory);
106105
connection.setRequestMethod("GET");
107106

108107
assertThatThrownBy(connection::getResponseCode);
109-
110-
server.stop();
111108
}
112109

113110
}

0 commit comments

Comments
 (0)