-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fix broken trustStore usage in RestClient in native mode
- Loading branch information
Showing
9 changed files
with
124 additions
and
4 deletions.
There are no files selected for viewing
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
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
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
14 changes: 14 additions & 0 deletions
14
...-tests/rest-client/src/main/java/io/quarkus/it/rest/client/wronghost/WrongHostClient.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,14 @@ | ||
package io.quarkus.it.rest.client.wronghost; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
@Path("/") | ||
public interface WrongHostClient { | ||
|
||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
String root(); | ||
} |
33 changes: 33 additions & 0 deletions
33
...ests/rest-client/src/main/java/io/quarkus/it/rest/client/wronghost/WrongHostResource.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,33 @@ | ||
package io.quarkus.it.rest.client.wronghost; | ||
|
||
import java.io.FileInputStream; | ||
import java.net.URL; | ||
import java.security.KeyStore; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.apache.http.conn.ssl.NoopHostnameVerifier; | ||
import org.eclipse.microprofile.rest.client.RestClientBuilder; | ||
|
||
@Path("/wrong-host") | ||
public class WrongHostResource { | ||
|
||
@GET | ||
@Path("/rest-client") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String restClient() throws Exception { | ||
KeyStore ks = KeyStore.getInstance("JKS"); | ||
|
||
// the system props are set in pom.xml and made available for native tests via RestClientTestResource | ||
ks.load(new FileInputStream(System.getProperty("rest-client.trustStore")), | ||
System.getProperty("rest-client.trustStorePassword").toCharArray()); | ||
|
||
return RestClientBuilder.newBuilder().baseUrl(new URL("https://wrong.host.badssl.com/")).trustStore(ks) | ||
.hostnameVerifier(NoopHostnameVerifier.INSTANCE) | ||
.build(WrongHostClient.class) | ||
.root(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ion-tests/rest-client/src/test/java/io/quarkus/it/rest/client/RestClientTestResource.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,25 @@ | ||
package io.quarkus.it.rest.client; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; | ||
|
||
/** | ||
* The only point of this class is to propagate the properties when running the native tests | ||
*/ | ||
public class RestClientTestResource implements QuarkusTestResourceLifecycleManager { | ||
|
||
@Override | ||
public Map<String, String> start() { | ||
Map<String, String> result = new HashMap<>(); | ||
result.put("rest-client.trustStore", System.getProperty("rest-client.trustStore")); | ||
result.put("rest-client.trustStorePassword", System.getProperty("rest-client.trustStorePassword")); | ||
return result; | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
|
||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...ts/rest-client/src/test/java/io/quarkus/it/rest/client/wronghost/ExternalWrongHostIT.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,7 @@ | ||
package io.quarkus.it.rest.client.wronghost; | ||
|
||
import io.quarkus.test.junit.NativeImageTest; | ||
|
||
@NativeImageTest | ||
public class ExternalWrongHostIT extends ExternalWrongHostTestCase { | ||
} |
26 changes: 26 additions & 0 deletions
26
...t-client/src/test/java/io/quarkus/it/rest/client/wronghost/ExternalWrongHostTestCase.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,26 @@ | ||
package io.quarkus.it.rest.client.wronghost; | ||
|
||
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.it.rest.client.RestClientTestResource; | ||
import io.quarkus.test.common.QuarkusTestResource; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.restassured.RestAssured; | ||
|
||
@QuarkusTest | ||
@QuarkusTestResource(RestClientTestResource.class) | ||
public class ExternalWrongHostTestCase { | ||
|
||
@Test | ||
public void restClient() { | ||
RestAssured.when() | ||
.get("/wrong-host/rest-client") | ||
.then() | ||
.statusCode(200) | ||
.body(is(not(empty()))); | ||
} | ||
} |
Binary file not shown.