diff --git a/subprojects/client/src/main/java/com/trifork/stamdata/client/security/TwoWaySslSecurityHandler.java b/subprojects/client/src/main/java/com/trifork/stamdata/client/security/TwoWaySslSecurityHandler.java index 712b3e95..1d6b8492 100644 --- a/subprojects/client/src/main/java/com/trifork/stamdata/client/security/TwoWaySslSecurityHandler.java +++ b/subprojects/client/src/main/java/com/trifork/stamdata/client/security/TwoWaySslSecurityHandler.java @@ -52,7 +52,23 @@ public TwoWaySslSecurityHandler() { public String validAuthorizationTokenFor(Class entityType) throws Exception { return ""; } - + + protected String getTrustStorePassword() { + return Main.getParameter("stamdata.client.truststore.password"); + } + + protected String getTrustStorePath() { + return Main.getParameter("stamdata.client.truststore"); + } + + protected String getKeyStorePassword() { + return Main.getParameter("stamdata.client.keystore.password"); + } + + protected String getKeyStorePath() { + return Main.getParameter("stamdata.client.keystore"); + } + private KeyStore createKeyStoreFromParams(String storePath, String password) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException { if(storePath.startsWith("classpath:")) { return createKeyStore(storePath.substring("classpath:".length()), password); @@ -62,18 +78,17 @@ private KeyStore createKeyStoreFromParams(String storePath, String password) thr private TrustManager[] createTrustManagers() throws NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException { TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); - String trustStorePath = Main.getParameter("stamdata.client.truststore"); - String trustStorePassword = Main.getParameter("stamdata.client.truststore.password"); + String trustStorePath = getTrustStorePath(); + String trustStorePassword = getTrustStorePassword(); KeyStore truststore = createKeyStoreFromParams(trustStorePath, trustStorePassword ); trustManagerFactory.init(truststore); return trustManagerFactory.getTrustManagers(); - } private KeyManager[] createKeyManagers() throws NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException, UnrecoverableKeyException { KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); - String keyStorePath = Main.getParameter("stamdata.client.keystore"); - String keyStorePassword = Main.getParameter("stamdata.client.keystore.password"); + String keyStorePath = getKeyStorePath(); + String keyStorePassword = getKeyStorePassword(); KeyStore keyStore = createKeyStoreFromParams(keyStorePath, keyStorePassword ); keyManagerFactory.init(keyStore, keyStorePassword.toCharArray()); return keyManagerFactory.getKeyManagers(); diff --git a/subprojects/integration-test/db/bootstrap.sql b/subprojects/integration-test/db/bootstrap.sql new file mode 100644 index 00000000..ca5f9849 --- /dev/null +++ b/subprojects/integration-test/db/bootstrap.sql @@ -0,0 +1,2 @@ +drop database if exists sdm_warehouse_ig; +create database sdm_warehouse_ig; \ No newline at end of file diff --git a/subprojects/integration-test/integration-test.gradle b/subprojects/integration-test/integration-test.gradle index fa08cdf1..fde5d36a 100644 --- a/subprojects/integration-test/integration-test.gradle +++ b/subprojects/integration-test/integration-test.gradle @@ -22,14 +22,18 @@ // National Board of e-Health (NSI). All Rights Reserved. configurations { + db cargo } dependencies { compile project(':shared') + compile project(':client') testCompile libs.junit testCompile libs.hamcrest testCompile libs.mockito + + db libs.mysql_driver cargo('org.codehaus.cargo:cargo-ant:1.1.0') { exclude module: 'cargo-core-container-resin' @@ -47,11 +51,26 @@ dependencies { ant.taskdef(resource: 'cargo.tasks', classpath: configurations.cargo.asPath) -task startServer { - ant.cargo(containerId: "tomcat7x", output: "subprojects/integration-test/logs/output.log", log: "logs/cargo.log", action: "start", wait: "false") { +def runSql(sqlFile, database) { + driver = 'com.mysql.jdbc.Driver' + userid = 'root' + password: '' + ant.sql(src: sqlFile, print: true, driver: driver, + url: "jdbc:mysql://localhost:3306/$database", userid: userid, password: password, + onerror: 'abort', classpath: configurations.db.asPath) +} + +task dbtest << { + runSql 'db/bootstrap.sql', 'sdm_warehouse' + runSql "$rootDir/db/schema.sql", 'sdm_warehouse_ig' +} + +task startServer << { + ant.echo(message: 'Starting server') + ant.cargo(id: 'ig-server', containerId: "tomcat7x", output: "subprojects/integration-test/logs/output.log", log: "logs/cargo.log", action: "start", wait: "false") { zipUrlInstaller(installUrl: 'http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.12/bin/apache-tomcat-7.0.12.zip') configuration { - property(name: "cargo.servlet.port", value: "8080") + property(name: "cargo.servlet.port", value: "8081") property(name: "cargo.logging", value: "high") deployable(type: "war", file: "subprojects/importer/build/libs/importer-3.0.0-SNAPSHOT.war") { property(name: "context", value: "importer") @@ -62,3 +81,20 @@ task startServer { } } } + +task integrationTest(type: Test) { + include '**/*IntegrationTest.*' + } + +test { + exclude '**/*IntegrationTest.*' +} + +task hello << { + ant.echo(message: 'hello from Ant') +} + +task stopServer << { + ant.echo(message: 'Stopping server') + ant.cargo(refId: "ig-server", action: "stop") +} \ No newline at end of file diff --git a/subprojects/integration-test/src/main/resources/keystore.jks b/subprojects/integration-test/src/main/resources/keystore.jks new file mode 100644 index 00000000..eae45e1d Binary files /dev/null and b/subprojects/integration-test/src/main/resources/keystore.jks differ diff --git a/subprojects/integration-test/src/main/resources/truststore.jks b/subprojects/integration-test/src/main/resources/truststore.jks new file mode 100644 index 00000000..cb4c5bf7 Binary files /dev/null and b/subprojects/integration-test/src/main/resources/truststore.jks differ diff --git a/subprojects/integration-test/src/test/java/DummyIntegrationTest.java b/subprojects/integration-test/src/test/java/DummyIntegrationTest.java new file mode 100644 index 00000000..f3e6368c --- /dev/null +++ b/subprojects/integration-test/src/test/java/DummyIntegrationTest.java @@ -0,0 +1,61 @@ +import static org.junit.Assert.*; + +import java.net.URL; +import java.net.URLConnection; +import java.util.HashSet; +import java.util.Set; + +import javax.xml.stream.XMLEventReader; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.events.XMLEvent; + +import org.junit.Test; + +import com.trifork.stamdata.client.security.TwoWaySslSecurityHandler; + +public class DummyIntegrationTest { + @Test + public void dummy() throws Exception { + Set texts = new HashSet(); + + new DummyTwoWaySslSecurityHandler(); + URLConnection connection = new URL("https://localhost:8443/lookup/person/0708610089").openConnection(); + XMLInputFactory readerFactory = XMLInputFactory.newInstance(); + XMLEventReader reader = readerFactory.createXMLEventReader(connection.getInputStream(), "UTF-8"); + try { + while (reader.hasNext()) { + XMLEvent event = reader.nextEvent(); + if (event.isCharacters()) { + texts.add(event.asCharacters().getData()); + } + } + } finally { + reader.close(); + } + + assertTrue("No CPR number in output: " + texts, texts.contains("0708610089")); + } + + + static class DummyTwoWaySslSecurityHandler extends TwoWaySslSecurityHandler { + @Override + protected String getTrustStorePassword() { + return "Test1234"; + } + + @Override + protected String getTrustStorePath() { + return "classpath:/truststore.jks"; + } + + @Override + protected String getKeyStorePassword() { + return "Test1234"; + } + + @Override + protected String getKeyStorePath() { + return "classpath:/keystore.jks"; + } + } +} diff --git a/subprojects/integration-test/src/test/java/DummyTest.java b/subprojects/integration-test/src/test/java/DummyTest.java deleted file mode 100644 index abe530b4..00000000 --- a/subprojects/integration-test/src/test/java/DummyTest.java +++ /dev/null @@ -1,10 +0,0 @@ -import static org.junit.Assert.*; - -import org.junit.Test; - -public class DummyTest { - @Test - public void dummy() { - assertTrue(true); - } -} diff --git a/subprojects/lookup/src/main/resources/lookup.default.properties b/subprojects/lookup/src/main/resources/lookup.default.properties index 0abdda08..7e86a81f 100644 --- a/subprojects/lookup/src/main/resources/lookup.default.properties +++ b/subprojects/lookup/src/main/resources/lookup.default.properties @@ -6,7 +6,7 @@ db.connection.username=root db.connection.password= # List of OCES certificates (SubjectSerialNumbers) allowed to access the CPR lookup client -security.authorized.clients=CVR:20921897-FID:1305269840643,CVR:31569648-RID:1249470221794 +security.authorized.clients=CVR:20921897-FID:1305269840643,CVR:31569648-RID:1249470221794,CVR:20921897-FID:1303973231424 # Use the OCES test environment. MUST be false in production security.ssl.test=true