-
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.
Introduced io.quarkus.restclient.NoopHostnameVerifier
This should be used in the rest-client when hostname verification needs to be disabled for a specific client endpoint Also tests were improved to use what's provided in the rest-client extension
- Loading branch information
Showing
13 changed files
with
147 additions
and
66 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
20 changes: 20 additions & 0 deletions
20
extensions/rest-client/runtime/src/main/java/io/quarkus/restclient/NoopHostnameVerifier.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,20 @@ | ||
package io.quarkus.restclient; | ||
|
||
import javax.net.ssl.HostnameVerifier; | ||
import javax.net.ssl.SSLSession; | ||
|
||
/** | ||
* The {@link NoopHostnameVerifier} essentially turns hostname verification off. | ||
*/ | ||
public class NoopHostnameVerifier implements HostnameVerifier { | ||
|
||
@Override | ||
public boolean verify(String hostname, SSLSession session) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public final String toString() { | ||
return "NO_OP"; | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
...t-client/src/main/java/io/quarkus/it/rest/client/selfsigned/ExternalSelfSignedClient.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,15 @@ | ||
package io.quarkus.it.rest.client.selfsigned; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.eclipse.microprofile.faulttolerance.Retry; | ||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
|
||
@RegisterRestClient(baseUri = "https://self-signed.badssl.com/", configKey = "self-signed") | ||
public interface ExternalSelfSignedClient { | ||
|
||
@GET | ||
@Retry(delay = 1000) | ||
Response invoke(); | ||
} |
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
10 changes: 7 additions & 3 deletions
10
...-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 |
---|---|---|
@@ -1,14 +1,18 @@ | ||
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; | ||
import javax.ws.rs.core.Response; | ||
|
||
@Path("/") | ||
import org.eclipse.microprofile.faulttolerance.Retry; | ||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
|
||
@RegisterRestClient(baseUri = "https://wrong.host.badssl.com/", configKey = "wrong-host") | ||
public interface WrongHostClient { | ||
|
||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
String root(); | ||
@Retry(delay = 1000) | ||
Response invoke(); | ||
} |
26 changes: 9 additions & 17 deletions
26
...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 |
---|---|---|
@@ -1,33 +1,25 @@ | ||
package io.quarkus.it.rest.client.wronghost; | ||
|
||
import java.io.FileInputStream; | ||
import java.net.URL; | ||
import java.security.KeyStore; | ||
import java.io.IOException; | ||
|
||
import javax.inject.Inject; | ||
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; | ||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
|
||
@Path("/wrong-host") | ||
public class WrongHostResource { | ||
|
||
@Inject | ||
@RestClient | ||
WrongHostClient client; | ||
|
||
@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(); | ||
public String perform() throws IOException { | ||
return String.valueOf(client.invoke().getStatus()); | ||
} | ||
} |
25 changes: 0 additions & 25 deletions
25
...ion-tests/rest-client/src/test/java/io/quarkus/it/rest/client/RestClientTestResource.java
This file was deleted.
Oops, something went wrong.
15 changes: 12 additions & 3 deletions
15
...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 |
---|---|---|
@@ -1,23 +1,32 @@ | ||
package io.quarkus.it.rest.client.selfsigned; | ||
|
||
import static io.restassured.RestAssured.when; | ||
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() | ||
public void should_accept_self_signed_certs() { | ||
when() | ||
.get("/self-signed") | ||
.then() | ||
.statusCode(200) | ||
.body(is("200")); | ||
} | ||
|
||
@Test | ||
public void should_accept_self_signed_certs_java_url() { | ||
when() | ||
.get("/self-signed/java") | ||
.then() | ||
.statusCode(200) | ||
.body(is(not(empty()))); | ||
} | ||
} |
13 changes: 5 additions & 8 deletions
13
...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 |
---|---|---|
@@ -1,26 +1,23 @@ | ||
package io.quarkus.it.rest.client.wronghost; | ||
|
||
import static org.hamcrest.Matchers.empty; | ||
import static io.restassured.RestAssured.when; | ||
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) | ||
@QuarkusTestResource(ExternalWrongHostTestResource.class) | ||
public class ExternalWrongHostTestCase { | ||
|
||
@Test | ||
public void restClient() { | ||
RestAssured.when() | ||
.get("/wrong-host/rest-client") | ||
when() | ||
.get("/wrong-host") | ||
.then() | ||
.statusCode(200) | ||
.body(is(not(empty()))); | ||
.body(is("200")); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ient/src/test/java/io/quarkus/it/rest/client/wronghost/ExternalWrongHostTestResource.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,27 @@ | ||
package io.quarkus.it.rest.client.wronghost; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import io.quarkus.restclient.NoopHostnameVerifier; | ||
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; | ||
|
||
/** | ||
* The only point of this class is to propagate the properties when running the native tests | ||
*/ | ||
public class ExternalWrongHostTestResource implements QuarkusTestResourceLifecycleManager { | ||
|
||
@Override | ||
public Map<String, String> start() { | ||
Map<String, String> result = new HashMap<>(); | ||
result.put("wrong-host/mp-rest/trustStore", System.getProperty("rest-client.trustStore")); | ||
result.put("wrong-host/mp-rest/trustStorePassword", System.getProperty("rest-client.trustStorePassword")); | ||
result.put("wrong-host/mp-rest/hostnameVerifier", NoopHostnameVerifier.class.getName()); | ||
return result; | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
|
||
} | ||
} |