-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test to make sure that trustStore work in native mode
- Loading branch information
Showing
6 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
integration-tests/rest-client/generate-trust-store-for-self-signed.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
45 changes: 45 additions & 0 deletions
45
...client/src/main/java/io/quarkus/it/rest/client/selfsigned/ExternalSelfSignedResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...t-client/src/test/java/io/quarkus/it/rest/client/selfsigned/ExternalSelfSignedITCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...client/src/test/java/io/quarkus/it/rest/client/selfsigned/ExternalSelfSignedTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()))); | ||
} | ||
} |