This is a small Hello World server with SSL/TLS enabled which can be used during integration test to validate your ssl configuration with Keystores, PEM files or other configurations related to ssl.
Initially I used BadSSL.com for one of my projects, SSLContext-Kickstart, however the certificates would not get updated shortly after expiring which resulted into false-positive failing tests. I always needed to temporally disable those tests till the certificates got updated. I wanted to have something as easy as possible to just only test my ssl configuration and that is how this project came into life.
Install with Maven
<dependency>
<groupId>io.github.hakky54</groupId>
<artifactId>ssl-server</artifactId>
<version>1.0.6</version>
<scope>test</scope>
</dependency>
testImplementation 'io.github.hakky54:ssl-server:1.0.6'
testImplementation("io.github.hakky54:ssl-server:1.0.6")
libraryDependencies += "io.github.hakky54" % "ssl-server" % "1.0.6" % Test
Example integration test:
import nl.altindag.ssl.SSLFactory;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import static org.assertj.core.api.Assertions.assertThat;
public class ServerShould {
@Test
public void startWithSslEnabledAndRequireMutualAuthentication() throws IOException, InterruptedException {
SSLFactory sslFactoryForServer = SSLFactory.builder()
.withIdentityMaterial("keystore/server/identity.jks", "secret".toCharArray())
.withTrustMaterial("keystore/server/truststore.jks", "secret".toCharArray())
.withNeedClientAuthentication()
.build();
Server server = Server.createDefault(sslFactoryForServer);
SSLFactory sslFactoryForClient = SSLFactory.builder()
.withIdentityMaterial("keystore/client/identity.jks", "secret".toCharArray())
.withTrustMaterial("keystore/client/truststore.jks", "secret".toCharArray())
.build();
HttpClient client = HttpClient.newBuilder()
.sslContext(sslFactoryForClient.getSslContext())
.sslParameters(sslFactoryForClient.getSslParameters())
.build();
HttpRequest request = HttpRequest.newBuilder()
.GET()
.uri(URI.create("https://localhost:8443/api/hello"))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
assertThat(response.statusCode()).isEqualTo(200);
assertThat(response.body()).isEqualTo("Hello World!");
server.stop();
}
}