Skip to content

Commit 421350d

Browse files
authored
Merge pull request #1611 from marklogic/feature/ssl-test-renaming
Renamed some things in SSL tests to improve clarity
2 parents 97da46c + 546dd45 commit 421350d

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

marklogic-client-api/src/test/java/com/marklogic/client/test/junit5/RequireSSLExtension.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ public void afterAll(ExtensionContext context) {
6161

6262
/**
6363
* @return a trust manager that accepts the public certificate associated with the certificate template created
64-
* by this class.
64+
* by this class. "secure" is meant to imply that this provides some level of security by only accepting the
65+
* one issuer, as opposed to a "trust everything" approach.
6566
*/
66-
public static X509TrustManager newTrustManager() {
67+
public static X509TrustManager newSecureTrustManager() {
6768
return new X509TrustManager() {
6869
@Override
6970
public void checkClientTrusted(X509Certificate[] chain, String authType) {
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@
1313
import javax.net.ssl.SSLException;
1414
import javax.net.ssl.TrustManager;
1515

16-
import static org.junit.jupiter.api.Assertions.assertEquals;
17-
import static org.junit.jupiter.api.Assertions.assertNull;
18-
import static org.junit.jupiter.api.Assertions.assertThrows;
19-
import static org.junit.jupiter.api.Assertions.assertTrue;
20-
16+
import static org.junit.jupiter.api.Assertions.*;
17+
18+
/**
19+
* Verifies scenarios for "one-way SSL" - i.e. the MarkLogic app server is configured with a certificate template to
20+
* require an SSL connection, but the client only needs to trust the server - the client does not present its own
21+
* certificate. See TwoWaySSLTest for scenarios where the client presents its own certificate which the server must
22+
* trust.
23+
*/
2124
@ExtendWith(RequireSSLExtension.class)
22-
class CheckSSLConnectionTest {
25+
class OneWaySSLTest {
2326

2427
/**
2528
* Simple check for ensuring that an SSL connection can be made when the app server requires SSL to be used. This
@@ -59,14 +62,14 @@ void trustAllManager() throws Exception {
5962
* with the certificate template created via RequireSSLExtension.
6063
*/
6164
@Test
62-
void customTrustManager() {
65+
void trustManagerThatOnlyTrustsTheCertificateFromTheCertificateTemplate() {
6366
if (Common.USE_REVERSE_PROXY_SERVER) {
6467
return;
6568
}
6669

6770
DatabaseClient client = Common.newClientBuilder()
6871
.withSSLProtocol("TLSv1.2")
69-
.withTrustManager(RequireSSLExtension.newTrustManager())
72+
.withTrustManager(RequireSSLExtension.newSecureTrustManager())
7073
.withSSLHostnameVerifier(DatabaseClientFactory.SSLHostnameVerifier.ANY)
7174
.build();
7275

marklogic-client-api/src/test/java/com/marklogic/client/test/ssl/TwoWaySSLTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void digestAuthentication() throws Exception {
105105
DatabaseClient clientWithCert = Common.newClientBuilder()
106106
.withSSLHostnameVerifier(DatabaseClientFactory.SSLHostnameVerifier.ANY)
107107
.withSSLContext(createSSLContextWithClientCertificate(keyStoreFile))
108-
.withTrustManager(RequireSSLExtension.newTrustManager())
108+
.withTrustManager(RequireSSLExtension.newSecureTrustManager())
109109
.build();
110110

111111
verifyTestDocumentCanBeRead(clientWithCert);
@@ -114,7 +114,7 @@ void digestAuthentication() throws Exception {
114114
DatabaseClient clientWithoutCert = Common.newClientBuilder()
115115
.withSSLHostnameVerifier(DatabaseClientFactory.SSLHostnameVerifier.ANY)
116116
.withSSLProtocol("TLSv1.2")
117-
.withTrustManager(RequireSSLExtension.newTrustManager())
117+
.withTrustManager(RequireSSLExtension.newSecureTrustManager())
118118
.build();
119119

120120
// The type of SSL failure varies across Java versions, so not asserting on a particular error message.
@@ -142,7 +142,7 @@ void certificateAuthenticationWithSSLContext() throws Exception {
142142
try {
143143
SSLContext sslContext = createSSLContextWithClientCertificate(keyStoreFile);
144144
DatabaseClient client = Common.newClientBuilder()
145-
.withCertificateAuth(sslContext, RequireSSLExtension.newTrustManager())
145+
.withCertificateAuth(sslContext, RequireSSLExtension.newSecureTrustManager())
146146
.withSSLHostnameVerifier(DatabaseClientFactory.SSLHostnameVerifier.ANY)
147147
.build();
148148

@@ -166,7 +166,7 @@ void certificateAuthenticationWithCertificateFileAndPassword() {
166166
try {
167167
DatabaseClient client = Common.newClientBuilder()
168168
.withCertificateAuth(p12File.getAbsolutePath(), KEYSTORE_PASSWORD)
169-
.withTrustManager(RequireSSLExtension.newTrustManager())
169+
.withTrustManager(RequireSSLExtension.newSecureTrustManager())
170170
.withSSLHostnameVerifier(DatabaseClientFactory.SSLHostnameVerifier.ANY)
171171
.build();
172172

@@ -200,7 +200,7 @@ private SSLContext createSSLContextWithClientCertificate(File keystoreFile) thro
200200
SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
201201
sslContext.init(
202202
keyManagerFactory.getKeyManagers(),
203-
new X509TrustManager[]{RequireSSLExtension.newTrustManager()},
203+
new X509TrustManager[]{RequireSSLExtension.newSecureTrustManager()},
204204
null);
205205
return sslContext;
206206
}

0 commit comments

Comments
 (0)