Skip to content

Commit b472e37

Browse files
authored
Merge pull request #1699 from marklogic/feature/java-17-test-fix
Better way of disabling some tests when using reverse proxy server
2 parents 0cf9546 + 578aad4 commit b472e37

File tree

5 files changed

+40
-38
lines changed

5 files changed

+40
-38
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright © 2024 MarkLogic Corporation. All Rights Reserved.
3+
*/
4+
package com.marklogic.client.test.junit5;
5+
6+
import com.marklogic.client.test.Common;
7+
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
8+
import org.junit.jupiter.api.extension.ExecutionCondition;
9+
import org.junit.jupiter.api.extension.ExtensionContext;
10+
11+
/**
12+
* Some tests can't run when using the reverse proxy server; for example, TLS/SSL messages don't yet work with our
13+
* reverse proxy server.
14+
*/
15+
public class DisabledWhenUsingReverseProxyServer implements ExecutionCondition {
16+
17+
@Override
18+
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext extensionContext) {
19+
return Common.USE_REVERSE_PROXY_SERVER ?
20+
ConditionEvaluationResult.disabled("This test is disabled when the tests are run against a reverse proxy server.") :
21+
ConditionEvaluationResult.enabled("This test is enabled since the reverse proxy server is not being used.");
22+
}
23+
}

marklogic-client-api/src/test/java/com/marklogic/client/test/rows/RowManagerTest.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.marklogic.client.row.RowManager.RowStructure;
2020
import com.marklogic.client.row.RowRecord.ColumnKind;
2121
import com.marklogic.client.test.Common;
22+
import com.marklogic.client.test.junit5.DisabledWhenUsingReverseProxyServer;
2223
import com.marklogic.client.test.junit5.RequiresML11;
2324
import com.marklogic.client.type.*;
2425
import com.marklogic.client.util.EditableNamespaceContext;
@@ -511,13 +512,9 @@ public void testSQLNoResults() {
511512
}
512513

513514
@Test
514-
@ExtendWith(RequiresML11.class)
515+
// A different kind of error is thrown when using the reverse proxy.
516+
@ExtendWith({DisabledWhenUsingReverseProxyServer.class, RequiresML11.class})
515517
public void testErrorWhileStreamingRows() {
516-
if (Common.USE_REVERSE_PROXY_SERVER) {
517-
// Different kind of error is thrown when using reverse proxy.
518-
return;
519-
}
520-
521518
final String validQueryThatEventuallyThrowsAnError = "select case " +
522519
"when lastName = 'Byron' then fn_error(fn_qname('', 'SQL-TABLENOTFOUND'), 'Internal Server Error') end, " +
523520
"opticUnitTest.musician.* from (select * from opticUnitTest.musician order by lastName)";

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

+5-13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.marklogic.client.ForbiddenUserException;
66
import com.marklogic.client.MarkLogicIOException;
77
import com.marklogic.client.test.Common;
8+
import com.marklogic.client.test.junit5.DisabledWhenUsingReverseProxyServer;
89
import com.marklogic.client.test.junit5.RequireSSLExtension;
910
import org.junit.jupiter.api.Test;
1011
import org.junit.jupiter.api.extension.ExtendWith;
@@ -21,7 +22,10 @@
2122
* certificate. See TwoWaySSLTest for scenarios where the client presents its own certificate which the server must
2223
* trust.
2324
*/
24-
@ExtendWith(RequireSSLExtension.class)
25+
@ExtendWith({
26+
DisabledWhenUsingReverseProxyServer.class,
27+
RequireSSLExtension.class
28+
})
2529
class OneWaySSLTest {
2630

2731
/**
@@ -34,14 +38,6 @@ class OneWaySSLTest {
3438
*/
3539
@Test
3640
void trustAllManager() throws Exception {
37-
if (Common.USE_REVERSE_PROXY_SERVER) {
38-
/**
39-
* Have not been able to get this to work yet, see the ReverseProxyServer class in test-app for more info.
40-
* We know SSL works fine when hitting MarkLogic Cloud though, which is the important part.
41-
*/
42-
return;
43-
}
44-
4541
SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
4642
sslContext.init(null, new TrustManager[]{Common.TRUST_ALL_MANAGER}, null);
4743

@@ -63,10 +59,6 @@ void trustAllManager() throws Exception {
6359
*/
6460
@Test
6561
void trustManagerThatOnlyTrustsTheCertificateFromTheCertificateTemplate() {
66-
if (Common.USE_REVERSE_PROXY_SERVER) {
67-
return;
68-
}
69-
7062
DatabaseClient client = Common.newClientBuilder()
7163
.withSSLProtocol("TLSv1.2")
7264
.withTrustManager(RequireSSLExtension.newSecureTrustManager())

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

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import com.marklogic.client.io.StringHandle;
1111
import com.marklogic.client.test.Common;
1212
import org.junit.jupiter.api.Test;
13+
import org.junit.jupiter.api.condition.EnabledOnJre;
14+
import org.junit.jupiter.api.condition.JRE;
1315

1416
import javax.net.ssl.*;
1517
import javax.security.auth.x500.X500Principal;
@@ -78,6 +80,8 @@ public void testSSLAuth() throws NoSuchAlgorithmException, KeyManagementExceptio
7880
}
7981

8082
@Test
83+
// Not able to mock the X509Certificate class on Java 21.
84+
@EnabledOnJre({JRE.JAVA_8, JRE.JAVA_11, JRE.JAVA_17})
8185
public void testHostnameVerifier() throws SSLException, CertificateParsingException {
8286
// three things our SSLHostnameVerifier will capture
8387
AtomicReference<String> capturedHost = new AtomicReference<>();

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

+5-19
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.marklogic.client.eval.EvalResultIterator;
1010
import com.marklogic.client.io.StringHandle;
1111
import com.marklogic.client.test.Common;
12+
import com.marklogic.client.test.junit5.DisabledWhenUsingReverseProxyServer;
1213
import com.marklogic.client.test.junit5.RequireSSLExtension;
1314
import com.marklogic.mgmt.ManageClient;
1415
import com.marklogic.mgmt.resource.appservers.ServerManager;
@@ -35,7 +36,10 @@
3536

3637
import static org.junit.jupiter.api.Assertions.*;
3738

38-
@ExtendWith(RequireSSLExtension.class)
39+
@ExtendWith({
40+
DisabledWhenUsingReverseProxyServer.class,
41+
RequireSSLExtension.class
42+
})
3943
public class TwoWaySSLTest {
4044

4145
private final static String TEST_DOCUMENT_URI = "/optic/test/musician1.json";
@@ -54,9 +58,6 @@ public class TwoWaySSLTest {
5458

5559
@BeforeAll
5660
public static void setup() throws Exception {
57-
if (Common.USE_REVERSE_PROXY_SERVER) {
58-
return;
59-
}
6061
// Create a client using the java-unittest app server - which requires SSL via RequiresSSLExtension - and that
6162
// talks to the Security database.
6263
securityClient = Common.newClientBuilder()
@@ -82,9 +83,6 @@ public static void setup() throws Exception {
8283

8384
@AfterAll
8485
public static void teardown() {
85-
if (Common.USE_REVERSE_PROXY_SERVER) {
86-
return;
87-
}
8886
removeTwoWaySSLConfig();
8987
deleteCertificateAuthority();
9088
}
@@ -101,10 +99,6 @@ public static void teardown() {
10199
*/
102100
@Test
103101
void digestAuthentication() {
104-
if (Common.USE_REVERSE_PROXY_SERVER) {
105-
return;
106-
}
107-
108102
// This client uses our Java KeyStore file with a client certificate in it, so it should work.
109103
DatabaseClient clientWithCert = Common.newClientBuilder()
110104
.withKeyStorePath(keyStoreFile.getAbsolutePath())
@@ -199,10 +193,6 @@ void invalidKeyStoreAlgorithm() {
199193
*/
200194
@Test
201195
void certificateAuthenticationWithSSLContext() throws Exception {
202-
if (Common.USE_REVERSE_PROXY_SERVER) {
203-
return;
204-
}
205-
206196
setAuthenticationToCertificate();
207197
try {
208198
SSLContext sslContext = createSSLContextWithClientCertificate(keyStoreFile);
@@ -223,10 +213,6 @@ void certificateAuthenticationWithSSLContext() throws Exception {
223213
*/
224214
@Test
225215
void certificateAuthenticationWithCertificateFileAndPassword() {
226-
if (Common.USE_REVERSE_PROXY_SERVER) {
227-
return;
228-
}
229-
230216
setAuthenticationToCertificate();
231217
try {
232218
DatabaseClient client = Common.newClientBuilder()

0 commit comments

Comments
 (0)