1717
1818package com.marklogic.gradle.fullcycle
1919
20+ import com.fasterxml.jackson.databind.node.ObjectNode
2021import com.marklogic.client.DatabaseClientFactory
2122import com.marklogic.client.ext.modulesloader.ssl.SimpleX509TrustManager
2223import com.marklogic.client.io.DOMHandle
2324import com.marklogic.client.io.DocumentMetadataHandle
2425import com.marklogic.gradle.task.BaseTest
26+ import com.marklogic.hub.DatabaseKind
2527import com.marklogic.hub.HubConfig
28+ import com.marklogic.rest.util.JsonNodeUtil
29+
30+ import org.apache.commons.io.FileUtils
2631import org.gradle.testkit.runner.UnexpectedBuildFailure
2732import spock.lang.Ignore
2833
@@ -32,32 +37,20 @@ import javax.net.ssl.TrustManager
3237import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual
3338import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
3439
40+ import java.nio.file.Files
41+ import java.nio.file.Path
3542
36- /* this particular test requires bootstrap to run on a clean
37- and ssl-enabled database.
38- Note this test is diabled until we fix the blocking bug in ml-app-deployer
39- that inststalls amps via CMA
40- */
4143class SslTest extends BaseTest {
4244
43- @Ignore
44- def setupSpecSKIPTHIS () {
45+
46+ def setupSpec () {
4547 createFullPropertiesFile()
4648 BaseTest . buildFile = BaseTest . testProjectDir. newFile(' build.gradle' )
4749 BaseTest . buildFile << '''
4850 plugins {
4951 id 'com.marklogic.ml-data-hub'
5052 }
5153
52- ext {
53- def command = new com.marklogic.appdeployer.command.security.GenerateTemporaryCertificateCommand()
54- command.setTemplateIdOrName("dhf-cert")
55- command.setCommonName("localhost")
56- command.setValidFor(365)
57- mlAppDeployer.commands.add(command)
58- }
59-
60-
6154 task enableSSL(type: com.marklogic.gradle.task.MarkLogicTask) {
6255 doFirst {
6356 def manageConfig = getProject().property("mlManageConfig")
@@ -73,12 +66,19 @@ class SslTest extends BaseTest {
7366
7467 def certManager = new com.marklogic.mgmt.resource.security.CertificateTemplateManager(manageClient)
7568 certManager.save(adminCert())
69+ certManager.save(dhfCert())
7670
7771 def gtcc = new com.marklogic.appdeployer.command.security.GenerateTemporaryCertificateCommand();
7872 gtcc.setTemplateIdOrName("admin-cert");
7973 gtcc.setCommonName("localhost");
80- gtcc.execute(new com.marklogic.appdeployer.command.CommandContext(getStagingAppConfig(), manageClient, adminManager));
81-
74+ gtcc.execute(new com.marklogic.appdeployer.command.CommandContext(getAppConfig(), manageClient, adminManager));
75+
76+ def command = new com.marklogic.appdeployer.command.security.GenerateTemporaryCertificateCommand()
77+ command.setTemplateIdOrName("dhf-cert")
78+ command.setCommonName("localhost")
79+ command.setValidFor(365)
80+ command.execute(new com.marklogic.appdeployer.command.CommandContext(getAppConfig(), manageClient, adminManager));
81+
8282 adminConfig = getProject().property("mlAdminConfig")
8383 adminConfig.setScheme("https")
8484 adminConfig.setConfigureSimpleSsl(true)
@@ -113,6 +113,7 @@ class SslTest extends BaseTest {
113113
114114 def certManager = new com.marklogic.mgmt.resource.security.CertificateTemplateManager(mgClient)
115115 certManager.delete(adminCert())
116+ certManager.delete(dhfCert())
116117 }
117118 }
118119
@@ -133,14 +134,43 @@ class SslTest extends BaseTest {
133134 """
134135 }
135136
137+ def dhfCert() {
138+ return """
139+ <certificate-template-properties xmlns="http://marklogic.com/manage">
140+ <template-name>dhf-cert</template-name>
141+ <template-description>Sample description</template-description>
142+ <key-type>rsa</key-type>
143+ <key-options />
144+ <req>
145+ <version>0</version>
146+ <subject>
147+ <countryName>US</countryName>
148+ <stateOrProvinceName>VA</stateOrProvinceName>
149+ <localityName>McLean</localityName>
150+ <organizationName>MarkLogic</organizationName>
151+ <organizationalUnitName>Consulting</organizationalUnitName>
152+ <emailAddress>[email protected] </emailAddress> 153+ </subject>
154+ </req>
155+ </certificate-template-properties>
156+ """
157+ }
158+
136159 '''
137160
138161 runTask(" hubInit" )
139162 runTask(" mlDeploySecurity" )
140- copyResourceToFile(" ssl-test/my-template.xml" , new File (BaseTest . testProjectDir. root, " user-config/security/certificate-templates/my-template.xml" ))
141- copyResourceToFile(" ssl-test/ssl-server.json" , new File (BaseTest . testProjectDir. root, " user-config/servers/final-server.json" ))
142- copyResourceToFile(" ssl-test/ssl-server.json" , new File (BaseTest . testProjectDir. root, " user-config/servers/job-server.json" ))
143- copyResourceToFile(" ssl-test/ssl-server.json" , new File (BaseTest . testProjectDir. root, " user-config/servers/staging-server.json" ))
163+
164+ writeSSLFiles(new File (BaseTest . testProjectDir. root, " src/main/ml-config/servers/final-server.json" ),
165+ new File (" src/test/resources/ssl-test/ssl-server.json" ))
166+ writeSSLFiles(new File (BaseTest . testProjectDir. root, " src/main/hub-internal-config/servers/job-server.json" ),
167+ new File (" src/test/resources/ssl-test/ssl-server.json" ))
168+ writeSSLFiles(new File (BaseTest . testProjectDir. root, " src/main/hub-internal-config/servers/staging-server.json" ),
169+ new File (" src/test/resources/ssl-test/ssl-server.json" ))
170+ /* copyResourceToFile("ssl-test/my-template.xml", new File(BaseTest.testProjectDir.root, "src/main/ml-config/security/certificate-templates/my-template.xml"))
171+ copyResourceToFile("ssl-test/ssl-server.json", new File(BaseTest.testProjectDir.root, "src/main/ml-config/servers/final-server.json"))
172+ copyResourceToFile("ssl-test/ssl-server.json", new File(BaseTest.testProjectDir.root, "src/main/hub-internal-config/servers/job-server.json"))
173+ copyResourceToFile("ssl-test/ssl-server.json", new File(BaseTest.testProjectDir.root, "src/main/hub-internal-config/servers/staging-server.json"))*/
144174 createProperties()
145175 try {
146176 clearDatabases(hubConfig(). DEFAULT_MODULES_DB_NAME )
@@ -150,8 +180,7 @@ class SslTest extends BaseTest {
150180 runTask(" enableSSL" )
151181 }
152182
153- @Ignore
154- def cleanupSpecSKIPTHIS () {
183+ def cleanupSpec () {
155184 runTask(" mlUndeploy" , " -Pconfirm=true" )
156185 runTask(" mlDeploySecurity" )
157186 runTask(" disableSSL" , " --stacktrace" )
@@ -174,7 +203,7 @@ class SslTest extends BaseTest {
174203 """
175204 }
176205
177- @Ignore
206+
178207 def " bootstrap a project with ssl out the wazoo" () {
179208 when :
180209 def result = runTask(' mlDeploy' )
@@ -191,7 +220,7 @@ class SslTest extends BaseTest {
191220 result. task(" :mlDeploy" ). outcome == SUCCESS
192221 }
193222
194- @Ignore
223+
195224 def " runHarmonizeFlow with default src and dest" () {
196225 given :
197226 println (runTask(' hubCreateHarmonizeFlow' , ' -PentityName=my-new-entity' , ' -PflowName=my-new-harmonize-flow' , ' -PdataFormat=xml' , ' -PpluginFormat=xqy' , ' -PuseES=false' ). getOutput())
@@ -227,7 +256,7 @@ class SslTest extends BaseTest {
227256 assertXMLEqual(getXmlFromResource(" run-flow-test/harmonized2.xml" ), hubConfig(). newFinalClient(). newDocumentManager(). read(" /employee2.xml" ). next(). getContent(new DOMHandle ()). get())
228257 }
229258
230- @Ignore
259+
231260 def " runHarmonizeFlow with swapped src and dest" () {
232261 given :
233262 println (runTask(' hubCreateHarmonizeFlow' , ' -PentityName=my-new-entity' , ' -PflowName=my-new-harmonize-flow' , ' -PdataFormat=xml' , ' -PpluginFormat=xqy' , ' -PuseES=false' ). getOutput())
@@ -253,13 +282,13 @@ class SslTest extends BaseTest {
253282
254283 when :
255284 println (runTask(
256- ' hubRunFlow' ,
257- ' -PentityName=my-new-entity' ,
258- ' -PflowName=my-new-harmonize-flow' ,
259- ' -PsourceDB=data-hub-FINAL' ,
260- ' -PdestDB=data-hub-STAGING' ,
261- ' -i'
262- ). getOutput())
285+ ' hubRunFlow' ,
286+ ' -PentityName=my-new-entity' ,
287+ ' -PflowName=my-new-harmonize-flow' ,
288+ ' -PsourceDB=data-hub-FINAL' ,
289+ ' -PdestDB=data-hub-STAGING' ,
290+ ' -i'
291+ ). getOutput())
263292
264293 then :
265294 notThrown(UnexpectedBuildFailure )
0 commit comments