-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preserve keystore_password when merging env properties (#829)
- Loading branch information
1 parent
d9cff1b
commit 9d0f17c
Showing
4 changed files
with
222 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/test/groovy/io/openliberty/tools/gradle/TestServerEnvKeystorePasswordPreserve.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package io.openliberty.tools.gradle | ||
|
||
import org.junit.AfterClass | ||
import org.junit.BeforeClass | ||
import org.junit.Test | ||
|
||
import javax.xml.parsers.DocumentBuilder; | ||
import javax.xml.parsers.DocumentBuilderFactory; | ||
import javax.xml.xpath.XPath; | ||
import javax.xml.xpath.XPathConstants; | ||
import javax.xml.xpath.XPathFactory; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.FileReader; | ||
|
||
|
||
import org.junit.BeforeClass | ||
import org.junit.FixMethodOrder | ||
import org.junit.Test | ||
import org.junit.runners.MethodSorters | ||
import org.junit.Assert; | ||
import org.w3c.dom.Document; | ||
import org.w3c.dom.NodeList; | ||
import org.w3c.dom.Node; | ||
import org.w3c.dom.Element; | ||
|
||
@FixMethodOrder(MethodSorters.NAME_ASCENDING) | ||
class TestServerEnvKeystorePasswordPreserve extends AbstractIntegrationTest { | ||
static File resourceDir = new File("build/resources/test/sample.servlet") | ||
static File buildDir = new File(integTestDir, "/test-server-env-keystore-password-preserve") | ||
static String buildFilename = "testServerEnvKeystorePasswordPreserve.gradle" | ||
|
||
@BeforeClass | ||
public static void setup() { | ||
createDir(buildDir) | ||
createTestProject(buildDir, resourceDir, buildFilename) | ||
runTasks(buildDir, 'libertyCreate') | ||
} | ||
|
||
@Test | ||
public void check_for_server_env() { | ||
assert new File('build/testBuilds/test-server-env-keystore-password-preserve/build/wlp/usr/servers/LibertyProjectServer/server.env').exists() : 'server.env not found!' | ||
} | ||
|
||
/* | ||
# envProps in build.gradle | ||
env = ['TEST_PROP_2':'white', 'CONFIG_SERVER_ENV_PROPS':'TEST'] | ||
# default server.env | ||
keystore_password=sfKRrA1ioLdtIFQC9bEfkua | ||
# Final server.env | ||
# Generated by liberty-gradle-plugin | ||
keystore_password=sfKRrA1ioLdtIFQC9bEfkua | ||
CONFIG_SERVER_ENV_PROPS=TEST | ||
TEST_PROP_2=white | ||
*/ | ||
@Test | ||
public void check_server_env_contents() { | ||
File serverEnv = new File("build/testBuilds/test-server-env-keystore-password-preserve/build/wlp/usr/servers/LibertyProjectServer/server.env") | ||
FileInputStream input = new FileInputStream(serverEnv) | ||
|
||
Map<String,String> serverEnvContents = new HashMap<String,String>(); | ||
|
||
BufferedReader bf = new BufferedReader(new FileReader(serverEnv)) | ||
String line = bf.readLine(); | ||
boolean commentFound = false | ||
while(line != null) { | ||
//ignore comment lines | ||
if(!line.startsWith("#")) { | ||
String[] keyValuePair = line.split("="); | ||
String key = keyValuePair[0]; | ||
String value = keyValuePair[1]; | ||
|
||
serverEnvContents.put(key,value); | ||
} else { | ||
commentFound = true | ||
Assert.assertTrue("File should have been generated by liberty-gradle-plugin", line.contains("liberty-gradle-plugin")); | ||
} | ||
line = bf.readLine(); | ||
} | ||
Assert.assertTrue("Expected generated by liberty-gradle-plugin comment not found", commentFound); | ||
|
||
// The contents of the default server.env can change over time. | ||
// Only the keystore_password should be preserved at this time. Ensure that no additional lines are in the "merged" server.env file. | ||
Assert.assertEquals("Number of env properties should be 3, but is "+serverEnvContents.size(), serverEnvContents.size(), 3) | ||
Assert.assertTrue("keystore_password mapping found", serverEnvContents.containsKey("keystore_password")) | ||
Assert.assertTrue("CONFIG_SERVER_ENV_PROPS=TEST", serverEnvContents.get("CONFIG_SERVER_ENV_PROPS").equals("TEST")) | ||
Assert.assertTrue("TEST_PROP_2=white", serverEnvContents.get("TEST_PROP_2").equals("white")) | ||
|
||
} | ||
|
||
} |
92 changes: 92 additions & 0 deletions
92
src/test/resources/sample.servlet/testServerEnvKeystorePasswordPreserve.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
This test checks whether the application was successfully installed without the version number in the package | ||
when deploy is called and stripVersion is set to true. | ||
*/ | ||
group = 'liberty.gradle' | ||
version = '1' | ||
|
||
buildscript { | ||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
maven { | ||
name = 'Sonatype Nexus Snapshots' | ||
url = 'https://oss.sonatype.org/content/repositories/snapshots/' | ||
} | ||
} | ||
dependencies { | ||
classpath "io.openliberty.tools:liberty-gradle-plugin:$lgpVersion" | ||
} | ||
} | ||
|
||
apply plugin: 'war' | ||
apply plugin: 'liberty' | ||
|
||
sourceCompatibility = 1.7 | ||
targetCompatibility = 1.7 | ||
|
||
compileJava.options.encoding = 'UTF-8' | ||
|
||
ext { | ||
// Liberty server properties | ||
wlpServerName = 'LibertyProjectServer' | ||
serverDirectory = "${project.buildDir}/wlp/usr/servers/${wlpServerName}" | ||
testServerHttpPort = 9080 | ||
testServerHttpsPort = 9443 | ||
|
||
// This is set in the ibm-web-ext.xml file | ||
warContext = 'myLibertyApp' | ||
|
||
} | ||
|
||
liberty { | ||
server{ | ||
serverXmlFile = file("src/main/liberty/config/server-apps-test.xml") | ||
name = wlpServerName | ||
deploy { | ||
apps = [war] | ||
copyLibsDirectory = file("${project.buildDir}/libs") | ||
} | ||
mergeServerEnv = true | ||
env = ['TEST_PROP_2':'white', 'CONFIG_SERVER_ENV_PROPS':'TEST'] | ||
} | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
testImplementation 'junit:junit:4.13.1' | ||
providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version:'3.1.0' | ||
implementation 'org.apache.commons:commons-text:1.1' | ||
libertyRuntime group: runtimeGroup, name: kernelArtifactId, version: runtimeVersion | ||
} | ||
|
||
test { | ||
println 'inside the test block' | ||
reports.html.outputLocation = file("$buildDir/reports/unit") | ||
reports.junitXml.outputLocation = file("$buildDir/test-results/unit") | ||
exclude '**/it/**' | ||
} | ||
|
||
task integrationTest(type: Test) { | ||
group 'Verification' | ||
description 'Runs the integration tests.' | ||
reports.html.outputLocation = file("$buildDir/reports/it") | ||
reports.junitXml.outputLocation = file("$buildDir/test-results/it") | ||
include '**/it/**' | ||
exclude '**/unit/**' | ||
|
||
systemProperties = ['liberty.test.port': testServerHttpPort, 'war.name': warContext] | ||
} | ||
|
||
task printMessageAboutRunningServer { | ||
doLast { | ||
println "The server is now running at http://localhost:${testServerHttpPort}/${warContext}" | ||
println "To stop the server run 'gradle libertyStop'" | ||
} | ||
} | ||
|
||
deploy.dependsOn 'war' | ||
libertyStart.finalizedBy 'printMessageAboutRunningServer' |