Skip to content

Commit

Permalink
Add test to make sure that trustStore work in native mode
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Jun 10, 2020
1 parent dc06ee3 commit cf4eee1
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

##########################################################################################################################################
# Script that generates the trustStore containing the self signed certificate used in 'io.quarkus.it.rest.client.selfsigned.ExternalSelfSignedResource' #
##########################################################################################################################################


echo -n | openssl s_client -connect self-signed.badssl.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > self-signed.cert
keytool -importcert -file self-signed.cert -alias self-signed -keystore self-signed -storepass changeit -noprompt
rm self-signed.cert
6 changes: 5 additions & 1 deletion integration-tests/rest-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
<systemPropertyVariables>
<!-- force the locale as we want to explicitly test message interpolation -->
<user.language>en</user.language>
<javax.net.ssl.trustStore>${project.basedir}/self-signed</javax.net.ssl.trustStore>
<javax.net.ssl.trustStorePassword>changeit</javax.net.ssl.trustStorePassword>
</systemPropertyVariables>
</configuration>
</plugin>
Expand Down Expand Up @@ -119,9 +121,11 @@
<reportErrorsAtRuntime>false</reportErrorsAtRuntime>
<cleanupServer>true</cleanupServer>
<enableHttpUrlHandler>true</enableHttpUrlHandler>
<enableHttpsUrlHandler>true</enableHttpsUrlHandler>
<enableServer>false</enableServer>
<dumpProxies>false</dumpProxies>
<graalvmHome>${graalvmHome}</graalvmHome>
<additionalBuildArgs>-J-Djavax.net.ssl.trustStore=${project.basedir}/self-signed, -J-Djavax.net.ssl.trustStorePassword=changeit</additionalBuildArgs>
</configuration>
</execution>
</executions>
Expand All @@ -131,4 +135,4 @@
</profile>
</profiles>

</project>
</project>
Binary file added integration-tests/rest-client/self-signed
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.quarkus.it.rest.client.selfsigned;

import java.io.IOException;
import java.net.URL;

import javax.net.ssl.HttpsURLConnection;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

/**
* This has nothing to do with rest-client, but we add it here in order to avoid creating
* a new integration test that would slow down our CI
*/
@Path("/self-signed")
public class ExternalSelfSignedResource {

@GET
@Produces(MediaType.TEXT_PLAIN)
public String perform() throws IOException {
try {
return doGetCipher();
} catch (IOException e) {

// if it fails it might be because the remote service is down, so sleep and try again
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {

}

return doGetCipher();
}
}

private String doGetCipher() throws IOException {
// this URL provides an always on example of an HTTPS URL utilizing self-signed certificate
URL url = new URL("https://self-signed.badssl.com/");
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.getResponseCode();
return con.getCipherSuite();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.quarkus.it.rest.client.selfsigned;

import io.quarkus.test.junit.NativeImageTest;

@NativeImageTest
public class ExternalSelfSignedITCase extends ExternalSelfSignedTestCase {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.quarkus.it.rest.client.selfsigned;

import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;

@QuarkusTest
public class ExternalSelfSignedTestCase {

@Test
public void included() {
RestAssured.when()
.get("/self-signed")
.then()
.statusCode(200)
.body(is(not(empty())));
}
}

0 comments on commit cf4eee1

Please sign in to comment.