Skip to content

Commit 9466fab

Browse files
authored
Merge pull request #1681 from srinathgit/develop
Making ssl/cert-auth test work
2 parents 2cd2007 + 0fa227d commit 9466fab

File tree

7 files changed

+56
-61
lines changed

7 files changed

+56
-61
lines changed

marklogic-data-hub/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ task setupSSL{
327327
javaexec {
328328
classpath = sourceSets.test.runtimeClasspath
329329
main = 'com.marklogic.bootstrap.SSLsetup'
330-
args = [mlHost, mlSecurityUsername, mlSecurityPassword, certAuth]
330+
args = [mlHost, mlSecurityUsername, mlSecurityPassword, certAuth, sslRun]
331331
}
332332
}
333333
if(sslRun) {
@@ -338,6 +338,8 @@ task setupSSL{
338338
"mlFinalSimpleSsl=true\n" +
339339
"mlAdminScheme=https\n" +
340340
"mlManageScheme=https\n" +
341+
"mlAppServicesSimpleSsl=true\n" +
342+
"mlManageSimpleSsl=true\n" +
341343
"mlStagingSimpleSsl=true")
342344
}
343345
}
@@ -350,6 +352,7 @@ task setupSSL{
350352
"mlAdminScheme=https\n" +
351353
"mlFinalScheme=https\n" +
352354
"mlStagingScheme=https\n" +
355+
"mlManageScheme=https\n" +
353356
"mlJobScheme=https\n" +
354357
"mlJobAuth=certificate")
355358
}

marklogic-data-hub/src/test/java/com/marklogic/bootstrap/Installer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class Installer extends HubTestBase {
1717

1818
private static Logger logger = LoggerFactory.getLogger(Installer.class);
1919

20-
public void setupProject() {
20+
public void setupProject() {
2121
createProjectDir();
2222
}
2323

marklogic-data-hub/src/test/java/com/marklogic/bootstrap/SSLsetup.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import com.marklogic.mgmt.resource.security.CertificateAuthorityManager;
2121
import com.marklogic.mgmt.util.ObjectMapperFactory;
2222
import com.marklogic.rest.util.JsonNodeUtil;
23-
import org.apache.hadoop.conf.Configuration;
24-
import org.springframework.boot.test.context.SpringBootTest;
2523

2624
public class SSLsetup {
2725

@@ -35,7 +33,8 @@ private void convertToSSL(String[] args) {
3533
String mlSecurityUsername = args[1];
3634
String mlSecurityPassword = args[2];
3735
boolean certAuth = Boolean.parseBoolean(args[3]);
38-
if (!certAuth)
36+
boolean sslRun = Boolean.parseBoolean(args[4]);
37+
if (!(certAuth || sslRun))
3938
return;
4039

4140
/*
@@ -74,17 +73,14 @@ private void convertToSSL(String[] args) {
7473

7574
ObjectNode node = ObjectMapperFactory.getObjectMapper().createObjectNode();
7675
if (certAuth) {
77-
node.put("authentication", "certificate");
78-
ArrayNode certnode = node.putArray("ssl-client-certificate-pem");
76+
node.put("authentication", "certificate");
77+
ArrayNode certnode = node.arrayNode();
7978
certnode.add(cacert);
80-
node.put("ssl-certificate-template", "dhf-cert");
81-
node.put("ssl-allow-sslv3", "true");
82-
node.put("ssl-allow-tls", "true");
83-
node.put("ssl-disable-sslv3", "false");
84-
node.put("ssl-disable-tlsv1", "false");
85-
node.put("ssl-disable-tlsv1-1", "false");
86-
node.put("ssl-disable-tlsv1-2", "false");
79+
node.put("ssl-client-certificate-pem", certnode );
80+
8781
}
82+
node.put("ssl-certificate-template", "dhf-cert");
83+
8884
try {
8985
FileUtils.writeStringToFile(new File(System.getProperty("java.io.tmpdir") + "/ssl-server.json"),
9086
node.toString());

marklogic-data-hub/src/test/java/com/marklogic/hub/HubTestBase.java

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,7 @@ protected void init() {
279279
&& stagingAuthMethod.equals(Authentication.CERTIFICATE)) {
280280
setCertAuth(true);
281281
}
282-
283-
if(isSslRun() || isCertAuth()) {
284-
certInit();
285-
}
282+
286283
try {
287284
stagingClient = getClient(host, stagingPort, HubConfig.DEFAULT_STAGING_NAME, user, password, stagingAuthMethod);
288285
flowRunnerClient = getClient(host, stagingPort, HubConfig.DEFAULT_STAGING_NAME, flowRunnerUser, flowRunnerPassword, stagingAuthMethod);
@@ -304,6 +301,9 @@ protected void init() {
304301
modMgr = stagingModulesClient.newDocumentManager();
305302

306303
adminHubConfig.refreshProject();
304+
if(isSslRun() || isCertAuth()) {
305+
certInit();
306+
}
307307
}
308308

309309
protected DatabaseClient getClient(String host, int port, String dbName, String user,String password, Authentication authMethod) throws Exception {
@@ -420,7 +420,27 @@ protected HubConfigImpl getHubFlowRunnerConfig() {
420420
adminHubConfig.setCertFile(DatabaseKind.FINAL, "src/test/resources/ssl/client-data-hub-user.p12");
421421
adminHubConfig.setSslContext(DatabaseKind.JOB,flowRunnercertContext);
422422
manageConfig.setSslContext(flowRunnercertContext);
423-
adminConfig.setSslContext(flowRunnercertContext);
423+
adminConfig.setSslContext(flowRunnercertContext);
424+
425+
appConfig.setAppServicesCertPassword("abcd");
426+
appConfig.setAppServicesTrustManager((X509TrustManager) tmf.getTrustManagers()[0]);
427+
appConfig.setAppServicesSslHostnameVerifier(SSLHostnameVerifier.ANY);
428+
appConfig.setAppServicesSecurityContextType(SecurityContextType.CERTIFICATE);
429+
appConfig.setAppServicesPassword(null);
430+
431+
adminHubConfig.setTrustManager(DatabaseKind.STAGING, (X509TrustManager) tmf.getTrustManagers()[0]);
432+
adminHubConfig.setCertPass(DatabaseKind.STAGING, "abcd");
433+
434+
adminHubConfig.setTrustManager(DatabaseKind.FINAL, (X509TrustManager) tmf.getTrustManagers()[0]);
435+
adminHubConfig.setCertPass(DatabaseKind.FINAL, "abcd");
436+
437+
//manageConfig.setConfigureSimpleSsl(false);
438+
manageConfig.setSecuritySslContext(certContext);
439+
manageConfig.setPassword(null);
440+
manageConfig.setSecurityPassword(null);
441+
442+
//adminConfig.setConfigureSimpleSsl(false);
443+
adminConfig.setPassword(null);
424444
}
425445
adminHubConfig.setAppConfig(appConfig);
426446
((HubConfigImpl)adminHubConfig).setManageConfig(manageConfig);
@@ -477,38 +497,12 @@ private void certInit() {
477497
manageClient = ((HubConfigImpl)adminHubConfig).getManageClient();
478498
adminConfig = ((HubConfigImpl)adminHubConfig).getAdminConfig();
479499

480-
adminHubConfig.setScheme(DatabaseKind.STAGING,"https");
481-
adminHubConfig.setScheme(DatabaseKind.FINAL,"https");
482-
adminHubConfig.setScheme(DatabaseKind.JOB,"https");
483-
484-
adminHubConfig.setSslHostnameVerifier(DatabaseKind.STAGING,SSLHostnameVerifier.ANY);
485-
adminHubConfig.setSslHostnameVerifier(DatabaseKind.FINAL,SSLHostnameVerifier.ANY);
486-
adminHubConfig.setSslHostnameVerifier(DatabaseKind.JOB,SSLHostnameVerifier.ANY);
487-
manageConfig.setScheme("https");
488-
adminConfig.setScheme("https");
489-
manageConfig.setHost(host);
490-
manageConfig.setUsername(user);
491-
manageConfig.setSecurityUsername(secUser);
492-
493-
if(isSslRun()) {
494-
appConfig.setAppServicesSslContext(SimpleX509TrustManager.newSSLContext());
495-
appConfig.setAppServicesSslHostnameVerifier(SSLHostnameVerifier.ANY);
500+
if(isCertAuth()) {
496501

497-
adminHubConfig.setSimpleSsl(DatabaseKind.STAGING,true);
498-
adminHubConfig.setSimpleSsl(DatabaseKind.JOB,true);
499-
adminHubConfig.setSimpleSsl(DatabaseKind.FINAL,true);
502+
adminHubConfig.setSslHostnameVerifier(DatabaseKind.STAGING,SSLHostnameVerifier.ANY);
503+
adminHubConfig.setSslHostnameVerifier(DatabaseKind.FINAL,SSLHostnameVerifier.ANY);
504+
adminHubConfig.setSslHostnameVerifier(DatabaseKind.JOB,SSLHostnameVerifier.ANY);
500505

501-
adminHubConfig.setSslContext(DatabaseKind.STAGING,SimpleX509TrustManager.newSSLContext());
502-
adminHubConfig.setSslContext(DatabaseKind.FINAL,SimpleX509TrustManager.newSSLContext());
503-
adminHubConfig.setSslContext(DatabaseKind.JOB,SimpleX509TrustManager.newSSLContext());
504-
505-
manageConfig.setConfigureSimpleSsl(true);
506-
manageConfig.setSslContext(SimpleX509TrustManager.newSSLContext());
507-
508-
adminConfig.setConfigureSimpleSsl(true);
509-
adminConfig.setSslContext(SimpleX509TrustManager.newSSLContext());
510-
}
511-
if(isCertAuth()) {
512506
appConfig.setAppServicesCertFile("src/test/resources/ssl/client-hub-admin-user.p12");
513507
adminHubConfig.setCertFile(DatabaseKind.STAGING, "src/test/resources/ssl/client-hub-admin-user.p12");
514508
adminHubConfig.setCertFile(DatabaseKind.FINAL, "src/test/resources/ssl/client-hub-admin-user.p12");
@@ -522,22 +516,18 @@ private void certInit() {
522516
appConfig.setAppServicesSecurityContextType(SecurityContextType.CERTIFICATE);
523517
appConfig.setAppServicesPassword(null);
524518

525-
adminHubConfig.setAuthMethod(DatabaseKind.STAGING,"certificate");
526-
adminHubConfig.setAuthMethod(DatabaseKind.JOB,"certificate");
527-
adminHubConfig.setAuthMethod(DatabaseKind.FINAL,"certificate");
528-
529519
adminHubConfig.setTrustManager(DatabaseKind.STAGING, (X509TrustManager) tmf.getTrustManagers()[0]);
530520
adminHubConfig.setCertPass(DatabaseKind.STAGING, "abcd");
531521

532522
adminHubConfig.setTrustManager(DatabaseKind.FINAL, (X509TrustManager) tmf.getTrustManagers()[0]);
533523
adminHubConfig.setCertPass(DatabaseKind.FINAL, "abcd");
534524

535-
manageConfig.setConfigureSimpleSsl(false);
525+
//manageConfig.setConfigureSimpleSsl(false);
536526
manageConfig.setSecuritySslContext(certContext);
537527
manageConfig.setPassword(null);
538528
manageConfig.setSecurityPassword(null);
539529

540-
adminConfig.setConfigureSimpleSsl(false);
530+
//adminConfig.setConfigureSimpleSsl(false);
541531
adminConfig.setPassword(null);
542532

543533
}
@@ -549,6 +539,7 @@ private void certInit() {
549539
((HubConfigImpl)adminHubConfig).setAdminConfig(adminConfig);
550540
wireClients();
551541
}
542+
552543
public void deleteProjectDir() {
553544
if (new File(PROJECT_PATH).exists()) {
554545
try {

marklogic-data-hub/src/test/java/com/marklogic/hub/core/HubConfigTest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,17 @@ public void cleanup() {
4444

4545
@Test
4646
public void applyFinalConnectionPropsToDefaultRestConnection() {
47+
4748
AppConfig config = adminHubConfig.getAppConfig();
4849

4950
assertEquals(new Integer(8011), config.getRestPort(),
5051
"The final port should be used as restPort so that any ml-gradle feature that depends on mlRestPost " +
5152
"ends up talking to the final app server");
52-
assertNull(config.getRestSslContext(), "Should be null because neither mlSimpleSsl nor mlFinalSimpleSsl were set to true");
53-
assertNull(config.getRestSslHostnameVerifier(), "Should be null because neither mlSimpleSsl nor mlFinalSimpleSsl were set to true");
54-
assertNull(config.getRestTrustManager(), "Should be null because neither mlSimpleSsl nor mlFinalSimpleSsl were set to true");
53+
if (!(isCertAuth() || isSslRun())) {
54+
assertNull(config.getRestSslContext(), "Should be null because neither mlSimpleSsl nor mlFinalSimpleSsl were set to true");
55+
assertNull(config.getRestSslHostnameVerifier(), "Should be null because neither mlSimpleSsl nor mlFinalSimpleSsl were set to true");
56+
assertNull(config.getRestTrustManager(), "Should be null because neither mlSimpleSsl nor mlFinalSimpleSsl were set to true");
57+
}
5558
//get the old values
5659
String port = adminHubConfig.getPort(DatabaseKind.FINAL).toString();
5760
String authMethod = adminHubConfig.getAuthMethod(DatabaseKind.FINAL);
@@ -102,6 +105,7 @@ public void applyFinalConnectionPropsToDefaultRestConnection() {
102105
adminHubConfig.setTrustManager(DatabaseKind.FINAL, null);
103106
}
104107

108+
105109
}
106110

107111
@Test

marklogic-data-hub/src/test/java/com/marklogic/hub/core/HubProjectTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import com.marklogic.hub.DatabaseKind;
44
import com.marklogic.hub.HubConfig;
55
import com.marklogic.hub.HubTestBase;
6-
import com.marklogic.hub.impl.HubConfigImpl;
76
import com.marklogic.hub.ApplicationConfig;
87

98
import org.apache.commons.io.FileUtils;
109
import org.apache.commons.io.IOUtils;
1110
import org.junit.jupiter.api.AfterEach;
1211
import org.junit.jupiter.api.Assertions;
12+
import org.junit.jupiter.api.Assumptions;
1313
import org.junit.jupiter.api.BeforeEach;
1414
import org.junit.jupiter.api.Test;
1515
import org.junit.jupiter.api.extension.ExtendWith;
@@ -155,6 +155,7 @@ public void testInit() throws IOException {
155155

156156
@Test
157157
public void upgrade300To403ToCurrentVersion() throws Exception {
158+
Assumptions.assumeFalse((isCertAuth() || isSslRun()));
158159
final String projectPath = "build/tmp/upgrade-projects/dhf403from300";
159160
final File projectDir = Paths.get(projectPath).toFile();
160161

marklogic-data-hub/src/test/java/com/marklogic/hub/deploy/commands/LoadHubModulesCommandTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ public void setup() {
4646
createProjectDir();
4747
loadHubModulesCommand = new LoadHubModulesCommand();
4848
loadHubModulesCommand.setHubConfig(adminHubConfig);
49-
ManageClient manageClient = new ManageClient(new com.marklogic.mgmt.ManageConfig(host, 8002, secUser, secPassword));
50-
commandContext = new CommandContext(adminHubConfig.getAppConfig(), manageClient, null);
49+
//ManageClient manageClient = new ManageClient(new com.marklogic.mgmt.ManageConfig(host, 8002, secUser, secPassword));
50+
commandContext = new CommandContext(adminHubConfig.getAppConfig(), adminHubConfig.getManageClient(), null);
5151
}
5252

5353
@Test

0 commit comments

Comments
 (0)