Skip to content

Commit

Permalink
Basic integration test now running, but still hitting the wrong server.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ole Friis Østergaard committed May 30, 2011
1 parent 018e76e commit bd80428
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 20 deletions.
Expand Up @@ -52,7 +52,23 @@ public TwoWaySslSecurityHandler() {
public <T> String validAuthorizationTokenFor(Class<T> 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);
Expand All @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions subprojects/integration-test/db/bootstrap.sql
@@ -0,0 +1,2 @@
drop database if exists sdm_warehouse_ig;
create database sdm_warehouse_ig;
42 changes: 39 additions & 3 deletions subprojects/integration-test/integration-test.gradle
Expand Up @@ -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'
Expand All @@ -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")
Expand All @@ -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")
}
Binary file not shown.
Binary file not shown.
@@ -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<String> texts = new HashSet<String>();

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";
}
}
}
10 changes: 0 additions & 10 deletions subprojects/integration-test/src/test/java/DummyTest.java

This file was deleted.

Expand Up @@ -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
Expand Down

0 comments on commit bd80428

Please sign in to comment.