forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce support for the TLS Registry in the REST Client
Closes: quarkusio#41005
- Loading branch information
1 parent
1f6317c
commit 91b2e65
Showing
17 changed files
with
593 additions
and
39 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
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
74 changes: 74 additions & 0 deletions
74
...ment/src/test/java/io/quarkus/rest/client/reactive/tls/MtlsConfigFromRegistryCdiTest.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,74 @@ | ||
package io.quarkus.rest.client.reactive.tls; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.io.File; | ||
|
||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.core.Context; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.vertx.ext.web.RoutingContext; | ||
import me.escoffier.certs.Format; | ||
import me.escoffier.certs.junit5.Certificate; | ||
import me.escoffier.certs.junit5.Certificates; | ||
|
||
@Certificates(baseDir = "target/certs", certificates = @Certificate(name = "mtls-test", password = "secret", formats = { | ||
Format.JKS, Format.PKCS12, Format.PEM }, client = true)) | ||
public class MtlsConfigFromRegistryCdiTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(Client.class, Resource.class) | ||
.addAsResource(new File("target/certs/mtls-test-keystore.p12"), "server-keystore.p12") | ||
.addAsResource(new File("target/certs/mtls-test-server-truststore.p12"), "server-truststore.p12") | ||
.addAsResource(new File("target/certs/mtls-test-client-keystore.p12"), "client-keystore.p12") | ||
.addAsResource(new File("target/certs/mtls-test-client-truststore.p12"), "client-truststore.p12")) | ||
|
||
.overrideConfigKey("quarkus.tls.server.key-store.p12.path", "server-keystore.p12") | ||
.overrideConfigKey("quarkus.tls.server.key-store.p12.password", "secret") | ||
.overrideConfigKey("quarkus.tls.server.trust-store.p12.path", "server-truststore.p12") | ||
.overrideConfigKey("quarkus.tls.server.trust-store.p12.password", "secret") | ||
.overrideConfigKey("quarkus.http.tls-configuration-name", "server") | ||
|
||
.overrideConfigKey("quarkus.tls.rest-client.key-store.p12.path", "client-keystore.p12") | ||
.overrideConfigKey("quarkus.tls.rest-client.key-store.p12.password", "secret") | ||
.overrideConfigKey("quarkus.tls.rest-client.trust-store.p12.path", "client-truststore.p12") | ||
.overrideConfigKey("quarkus.tls.rest-client.trust-store.p12.password", "secret") | ||
.overrideConfigKey("quarkus.rest-client.rc.url", "https://localhost:${quarkus.http.test-ssl-port:8444}") | ||
.overrideConfigKey("quarkus.rest-client.rc.tls-configuration-name", "rest-client"); | ||
|
||
@RestClient | ||
Client client; | ||
|
||
@Test | ||
void shouldHello() { | ||
assertThat(client.echo("w0rld")).isEqualTo("hello, w0rld"); | ||
} | ||
|
||
@Path("/hello") | ||
@RegisterRestClient(configKey = "rc") | ||
public interface Client { | ||
@POST | ||
String echo(String name); | ||
} | ||
|
||
@Path("/hello") | ||
public static class Resource { | ||
@POST | ||
public String echo(String name, @Context RoutingContext rc) { | ||
Assertions.assertThat(rc.request().connection().isSsl()).isTrue(); | ||
Assertions.assertThat(rc.request().isSSL()).isTrue(); | ||
Assertions.assertThat(rc.request().connection().sslSession()).isNotNull(); | ||
return "hello, " + name; | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...ent/src/test/java/io/quarkus/rest/client/reactive/tls/TlsConfigFromPropertiesCdiTest.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,65 @@ | ||
package io.quarkus.rest.client.reactive.tls; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.io.File; | ||
|
||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.core.Context; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.vertx.ext.web.RoutingContext; | ||
import me.escoffier.certs.Format; | ||
import me.escoffier.certs.junit5.Certificate; | ||
import me.escoffier.certs.junit5.Certificates; | ||
|
||
@Certificates(baseDir = "target/certs", certificates = @Certificate(name = "tls-test", password = "secret", formats = { | ||
Format.JKS, Format.PKCS12, Format.PEM })) | ||
public class TlsConfigFromPropertiesCdiTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(Client.class, Resource.class) | ||
.addAsResource(new File("target/certs/tls-test-keystore.jks"), "keystore.jks") | ||
.addAsResource(new File("target/certs/tls-test-truststore.jks"), "truststore.jks")) | ||
.overrideConfigKey("quarkus.tls.key-store.jks.path", "keystore.jks") | ||
.overrideConfigKey("quarkus.tls.key-store.jks.password", "secret") | ||
|
||
.overrideConfigKey("quarkus.rest-client.rc.url", "https://localhost:${quarkus.http.test-ssl-port:8444}") | ||
.overrideConfigKey("quarkus.rest-client.rc.trust-store", "classpath:truststore.jks") | ||
.overrideConfigKey("quarkus.rest-client.rc.trust-store-password", "secret"); | ||
|
||
@RestClient | ||
Client client; | ||
|
||
@Test | ||
void shouldHello() { | ||
assertThat(client.echo("w0rld")).isEqualTo("hello, w0rld"); | ||
} | ||
|
||
@Path("/hello") | ||
@RegisterRestClient(configKey = "rc") | ||
public interface Client { | ||
@POST | ||
String echo(String name); | ||
} | ||
|
||
@Path("/hello") | ||
public static class Resource { | ||
@POST | ||
public String echo(String name, @Context RoutingContext rc) { | ||
Assertions.assertThat(rc.request().connection().isSsl()).isTrue(); | ||
Assertions.assertThat(rc.request().isSSL()).isTrue(); | ||
Assertions.assertThat(rc.request().connection().sslSession()).isNotNull(); | ||
return "hello, " + name; | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...yment/src/test/java/io/quarkus/rest/client/reactive/tls/TlsConfigFromRegistryCdiTest.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,66 @@ | ||
package io.quarkus.rest.client.reactive.tls; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.io.File; | ||
|
||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.core.Context; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.vertx.ext.web.RoutingContext; | ||
import me.escoffier.certs.Format; | ||
import me.escoffier.certs.junit5.Certificate; | ||
import me.escoffier.certs.junit5.Certificates; | ||
|
||
@Certificates(baseDir = "target/certs", certificates = @Certificate(name = "tls-test", password = "secret", formats = { | ||
Format.JKS, Format.PKCS12, Format.PEM })) | ||
public class TlsConfigFromRegistryCdiTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(Client.class, Resource.class) | ||
.addAsResource(new File("target/certs/tls-test-keystore.jks"), "keystore.jks") | ||
.addAsResource(new File("target/certs/tls-test-truststore.jks"), "truststore.jks")) | ||
.overrideConfigKey("quarkus.tls.key-store.jks.path", "keystore.jks") | ||
.overrideConfigKey("quarkus.tls.key-store.jks.password", "secret") | ||
.overrideConfigKey("quarkus.tls.rest-client.trust-store.jks.path", "truststore.jks") | ||
.overrideConfigKey("quarkus.tls.rest-client.trust-store.jks.password", "secret") | ||
|
||
.overrideConfigKey("quarkus.rest-client.rc.url", "https://localhost:${quarkus.http.test-ssl-port:8444}") | ||
.overrideConfigKey("quarkus.rest-client.rc.tls-configuration-name", "rest-client"); | ||
|
||
@RestClient | ||
Client client; | ||
|
||
@Test | ||
void shouldHello() { | ||
assertThat(client.echo("w0rld")).isEqualTo("hello, w0rld"); | ||
} | ||
|
||
@Path("/hello") | ||
@RegisterRestClient(configKey = "rc") | ||
public interface Client { | ||
@POST | ||
String echo(String name); | ||
} | ||
|
||
@Path("/hello") | ||
public static class Resource { | ||
@POST | ||
public String echo(String name, @Context RoutingContext rc) { | ||
Assertions.assertThat(rc.request().connection().isSsl()).isTrue(); | ||
Assertions.assertThat(rc.request().isSSL()).isTrue(); | ||
Assertions.assertThat(rc.request().connection().sslSession()).isNotNull(); | ||
return "hello, " + name; | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...nt/src/test/java/io/quarkus/rest/client/reactive/tls/TlsConfigFromRegistryManualTest.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,73 @@ | ||
package io.quarkus.rest.client.reactive.tls; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.io.File; | ||
import java.net.URL; | ||
import java.util.Optional; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.core.Context; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.rest.client.reactive.QuarkusRestClientBuilder; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.common.http.TestHTTPResource; | ||
import io.quarkus.tls.TlsConfiguration; | ||
import io.quarkus.tls.TlsConfigurationRegistry; | ||
import io.vertx.ext.web.RoutingContext; | ||
import me.escoffier.certs.Format; | ||
import me.escoffier.certs.junit5.Certificate; | ||
import me.escoffier.certs.junit5.Certificates; | ||
|
||
@Certificates(baseDir = "target/certs", certificates = @Certificate(name = "tls-test", password = "secret", formats = { | ||
Format.JKS, Format.PKCS12, Format.PEM })) | ||
public class TlsConfigFromRegistryManualTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(Client.class, Resource.class) | ||
.addAsResource(new File("target/certs/tls-test-keystore.jks"), "keystore.jks") | ||
.addAsResource(new File("target/certs/tls-test-truststore.jks"), "truststore.jks")) | ||
.overrideConfigKey("quarkus.tls.key-store.jks.path", "keystore.jks") | ||
.overrideConfigKey("quarkus.tls.key-store.jks.password", "secret") | ||
.overrideConfigKey("quarkus.tls.rest-client.trust-store.jks.path", "truststore.jks") | ||
.overrideConfigKey("quarkus.tls.rest-client.trust-store.jks.password", "secret"); | ||
|
||
@TestHTTPResource(tls = true) | ||
URL url; | ||
|
||
@Inject | ||
TlsConfigurationRegistry registry; | ||
|
||
@Test | ||
void shouldHello() { | ||
Optional<TlsConfiguration> maybeTlsConfiguration = TlsConfiguration.from(registry, Optional.of("rest-client")); | ||
assertThat(maybeTlsConfiguration).isPresent(); | ||
Client client = QuarkusRestClientBuilder.newBuilder().baseUrl(url).tlsConfiguration(maybeTlsConfiguration.get()) | ||
.build(Client.class); | ||
assertThat(client.echo("w0rld")).isEqualTo("hello, w0rld"); | ||
} | ||
|
||
@Path("/hello") | ||
public interface Client { | ||
@POST | ||
String echo(String name); | ||
} | ||
|
||
@Path("/hello") | ||
public static class Resource { | ||
@POST | ||
public String echo(String name, @Context RoutingContext rc) { | ||
assertThat(rc.request().connection().isSsl()).isTrue(); | ||
assertThat(rc.request().isSSL()).isTrue(); | ||
assertThat(rc.request().connection().sslSession()).isNotNull(); | ||
return "hello, " + name; | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...est/client/reactive/ssl/TrustAllTest.java → ...est/client/reactive/tls/TrustAllTest.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
Oops, something went wrong.