Skip to content

Commit 234aa92

Browse files
committedDec 14, 2017
Fully working Integrationtest included after every component has been build with the help of docker-compose-rule - this is so freaking cool!
1 parent b72c443 commit 234aa92

File tree

4 files changed

+129
-13
lines changed

4 files changed

+129
-13
lines changed
 

‎README.md

+29-13
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,44 @@ In contrast the present project focusses on the configuration of more than one c
99
Therefore we use several Spring Boot based microservices that provide different client certificate secured REST endpoint and a separate microservice that accesses these services:
1010

1111
```
12-
================
13-
= =
14-
= server-alice =
15-
============== = =
16-
= = ------------------> ================
17-
= client-bob =
18-
= = ------------------> ================
19-
============== = =
20-
= server-tom =
21-
= =
22-
================
12+
-------------------------------------------
13+
| Docker Network scope |
14+
| ================ |
15+
| = = |
16+
| = server-alice = |
17+
============ | ============== = = |
18+
= docker- = | = = -----> ================ |
19+
= network- = -----> = client-bob = |
20+
= client = | = = -----> ================ |
21+
============ | ============== = = |
22+
| = server-tom = |
23+
| = = |
24+
| ================ |
25+
-------------------------------------------
26+
2327
```
2428

2529

2630
For a general approach on how to generate private keys and certificates and create Java Keystores, have a look into https://github.com/jonashackt/spring-boot-rest-clientcertificate#generate-the-usual-key-and-crt---and-import-them-into-needed-keystore-jks-files
2731

2832
# HowTo Use
2933

34+
Everything you need to run a full build and __complete__ test (incl. Integrationtest of docker-network-client firing up all three microservices that´ll call each other with client certificate support) is this:
35+
3036
```
3137
mvn clean install
32-
docker-compose up
3338
```
3439

35-
Open your Browser with [http:localhost:8080/swagger-ui.html] and fire up a GET-Request to /secretservers with Swagger :)
40+
Only, if you want to check manually, you can do a `docker-compose up -d` and open your Browser with [http:localhost:8080/swagger-ui.html] and fire up a GET-Request to /secretservers with Swagger :)
41+
42+
43+
# Integrationtesting
44+
45+
As client-bob only has access to the DNS aliases `server-alice` and `server-tom`, if it itself is part of the Docker (Compose) network and these aliases are used to access both client certificate secured endpoints, we need another way to run an Integration test inside the Docker network scope.
46+
47+
Therefore we use the [docker-compose-rule](https://github.com/palantir/docker-compose-rule) and the __docker-network-client__ that just calls client-bob inside the Docker network.
48+
49+
docker-compose-rule needs a special Maven repository to be added, because it is only served on Bintray.
3650

3751

3852
# TlDR: How to create multiple keys & certificates for multiple servers - and add these into one truststore / keystore
@@ -285,3 +299,5 @@ https://serverfault.com/questions/779475/openssl-add-subject-alternate-name-san-
285299
Look into the documentation of Tomcat in section `keyAlias`: http://tomcat.apache.org/tomcat-6.0-doc/config/http.html#SSL_Support
286300

287301
https://stackoverflow.com/questions/5292074/how-to-specify-outbound-certificate-alias-for-https-calls
302+
303+
https://stackoverflow.com/questions/6370745/can-we-load-multiple-certificates-keys-in-a-key-store

‎docker-network-client/pom.xml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>de.jonashackt</groupId>
7+
<artifactId>docker-network-client</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<parent>
12+
<groupId>de.jonashackt</groupId>
13+
<artifactId>spring-boot-rest-clientcertificates-docker-compose</artifactId>
14+
<version>0.0.1-SNAPSHOT</version>
15+
</parent>
16+
17+
<properties>
18+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19+
<java.version>1.8</java.version>
20+
<rest-assured.version>3.0.3</rest-assured.version>
21+
<docker-compose-rule-junit4.version>0.33.0</docker-compose-rule-junit4.version>
22+
</properties>
23+
24+
<dependencies>
25+
<dependency>
26+
<groupId>org.springframework.boot</groupId>
27+
<artifactId>spring-boot-starter-web</artifactId>
28+
</dependency>
29+
30+
<!-- Testing -->
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-test</artifactId>
34+
<scope>test</scope>
35+
</dependency>
36+
37+
<dependency>
38+
<groupId>io.rest-assured</groupId>
39+
<artifactId>rest-assured</artifactId>
40+
<version>${rest-assured.version}</version>
41+
<scope>test</scope>
42+
</dependency>
43+
44+
<dependency>
45+
<groupId>com.palantir.docker.compose</groupId>
46+
<artifactId>docker-compose-rule-junit4</artifactId>
47+
<version>${docker-compose-rule-junit4.version}</version>
48+
<scope>test</scope>
49+
</dependency>
50+
51+
</dependencies>
52+
53+
<repositories>
54+
<repository>
55+
<id>bintray</id>
56+
<name>Bintray Maven Repository - as docker-compose-rule-junit4 is only available there</name>
57+
<url>https://dl.bintray.com/palantir/releases</url>
58+
<layout>default</layout>
59+
</repository>
60+
</repositories>
61+
62+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package de.jonashackt;
2+
3+
import com.palantir.docker.compose.DockerComposeRule;
4+
import com.palantir.docker.compose.connection.waiting.HealthChecks;
5+
import org.apache.http.HttpStatus;
6+
import org.junit.ClassRule;
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
import org.springframework.test.context.ContextConfiguration;
10+
import org.springframework.test.context.junit4.SpringRunner;
11+
12+
import static io.restassured.RestAssured.when;
13+
import static org.hamcrest.Matchers.containsString;
14+
15+
@RunWith(SpringRunner.class)
16+
@ContextConfiguration()
17+
public class ClientTest {
18+
19+
@ClassRule
20+
public static DockerComposeRule docker = DockerComposeRule.builder()
21+
.file("../docker-compose.yml")
22+
.waitingForService("server-alice", HealthChecks.toHaveAllPortsOpen())
23+
.waitingForService("server-tom", HealthChecks.toHaveAllPortsOpen())
24+
.waitingForService("client-bob", HealthChecks.toRespondOverHttp(8080, (port) -> port.inFormat("http://localhost:8080/swagger-ui.html")))
25+
.build();
26+
27+
@Test
28+
public void is_client_bob_able_to_call_all_servers_with_client_certs() {
29+
30+
when()
31+
.get("http://localhost:8080/secretservers")
32+
.then()
33+
.statusCode(HttpStatus.SC_OK)
34+
.assertThat()
35+
.body(containsString("Both Servers called - Alice said 'Alice answering!' & Tom replied 'Tom answering!'."));
36+
}
37+
}

‎pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<module>server-alice</module>
2626
<module>server-tom</module>
2727
<module>client-bob</module>
28+
<module>docker-network-client</module>
2829
</modules>
2930

3031
</project>

0 commit comments

Comments
 (0)
Please sign in to comment.