-
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.
Rewrite TLS test for the rest-client and reactive-rest-client
- Remove the trust store maven plugin which has not be super reliable recently on CI - Use the cert generator instead - Make sure the tests are not tainted with a quarkus.tls.trust-all=true
- Loading branch information
1 parent
1748f93
commit 9641f25
Showing
23 changed files
with
298 additions
and
167 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
58 changes: 58 additions & 0 deletions
58
...ive/src/test/java/io/quarkus/it/rest/client/selfsigned/SelfSignedServiceTestResource.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,58 @@ | ||
package io.quarkus.it.rest.client.selfsigned; | ||
|
||
import java.io.File; | ||
import java.time.Duration; | ||
import java.util.Map; | ||
|
||
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; | ||
import io.smallrye.certs.CertificateGenerator; | ||
import io.smallrye.certs.CertificateRequest; | ||
import io.smallrye.certs.Format; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.core.http.HttpServerOptions; | ||
import io.vertx.core.net.PfxOptions; | ||
|
||
public class SelfSignedServiceTestResource implements QuarkusTestResourceLifecycleManager { | ||
|
||
Vertx vertx = Vertx.vertx(); | ||
|
||
@Override | ||
public Map<String, String> start() { | ||
File file = new File("target/certs"); | ||
file.mkdirs(); | ||
// Generate self-signed certificate | ||
// We do not use the junit 5 plugin to avoid having to annotate all the tests to make sure the certs are | ||
// generated before the tests are run | ||
CertificateGenerator generator = new CertificateGenerator(file.toPath(), false); | ||
CertificateRequest cr = new CertificateRequest() | ||
.withName("self-signed") | ||
.withFormat(Format.PKCS12) | ||
.withPassword("changeit") | ||
.withDuration(Duration.ofDays(2)) | ||
.withCN("localhost"); | ||
try { | ||
generator.generate(cr); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
HttpServerOptions options = new HttpServerOptions() | ||
.setSsl(true) | ||
.setKeyCertOptions(new PfxOptions() | ||
.setPath("target/certs/self-signed-keystore.p12") | ||
.setPassword("changeit")); | ||
var server = vertx.createHttpServer(options) | ||
.requestHandler(req -> req.response().end("OK")) | ||
.listen(-2).toCompletionStage().toCompletableFuture().join(); | ||
|
||
return Map.of( | ||
"quarkus.rest-client.self-signed.url", "https://localhost:" + server.actualPort() + "/", | ||
"quarkus.rest-client.self-signed.trust-store", "target/certs/self-signed-truststore.p12", | ||
"quarkus.rest-client.self-signed.trust-store-password", "changeit"); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
vertx.close().toCompletionStage().toCompletableFuture().join(); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...eactive/src/test/java/io/quarkus/it/rest/client/wronghost/BadHostServiceTestResource.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,75 @@ | ||
package io.quarkus.it.rest.client.wronghost; | ||
|
||
import java.io.File; | ||
import java.time.Duration; | ||
import java.util.Map; | ||
|
||
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; | ||
import io.smallrye.certs.CertificateGenerator; | ||
import io.smallrye.certs.CertificateRequest; | ||
import io.smallrye.certs.Format; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.core.http.HttpServerOptions; | ||
import io.vertx.core.net.PfxOptions; | ||
|
||
public class BadHostServiceTestResource implements QuarkusTestResourceLifecycleManager { | ||
|
||
Vertx vertx = Vertx.vertx(); | ||
|
||
@Override | ||
public Map<String, String> start() { | ||
File file = new File("target/certs"); | ||
file.mkdirs(); | ||
// Generate self-signed certificate | ||
// We do not use the junit 5 plugin to avoid having to annotate all the tests to make sure the certs are | ||
// generated before the tests are run | ||
CertificateGenerator generator = new CertificateGenerator(file.toPath(), false); | ||
CertificateRequest cr = new CertificateRequest() | ||
.withName("bad-host") | ||
.withFormat(Format.PKCS12) | ||
.withPassword("changeit") | ||
.withDuration(Duration.ofDays(2)) | ||
.withCN("bad-host.com") | ||
.withSubjectAlternativeName("DNS:bad-host.com"); | ||
try { | ||
generator.generate(cr); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
File f = new File("target/certs/bad-host-keystore.p12"); | ||
System.out.println(f.getAbsolutePath() + " / " + f.exists()); | ||
HttpServerOptions options = new HttpServerOptions() | ||
.setSsl(true) | ||
.setKeyCertOptions(new PfxOptions() | ||
.setPath("target/certs/bad-host-keystore.p12") | ||
.setPassword("changeit")); | ||
var server = vertx.createHttpServer(options) | ||
.requestHandler(req -> req.response().end("OK")) | ||
.listen(-1).toCompletionStage().toCompletableFuture().join(); | ||
|
||
// Wrong Host client (connection accepted, as host verification is turned off) | ||
// quarkus.rest-client.wrong-host.trust-store=${wrong-host.trust-store} | ||
// quarkus.rest-client.wrong-host.trust-store-password=${wrong-host.trust-store-password} | ||
// quarkus.rest-client.wrong-host.verify-host=false | ||
|
||
// Wrong Host client verified (connection rejected, as host verification is turned on by default) | ||
// quarkus.rest-client.wrong-host-rejected.trust-store=${wrong-host.trust-store} | ||
// quarkus.rest-client.wrong-host-rejected.trust-store-password=${wrong-host.trust-store-password} | ||
|
||
return Map.of( | ||
"quarkus.rest-client.wrong-host.url", "https://localhost:" + server.actualPort() + "/", | ||
"quarkus.rest-client.wrong-host.trust-store", "target/certs/bad-host-truststore.p12", | ||
"quarkus.rest-client.wrong-host.trust-store-password", "changeit", | ||
"quarkus.rest-client.wrong-host.verify-host", "false", | ||
|
||
"quarkus.rest-client.wrong-host-rejected.url", "https://localhost:" + server.actualPort() + "/", | ||
"quarkus.rest-client.wrong-host-rejected.trust-store", "target/certs/bad-host-truststore.p12", | ||
"quarkus.rest-client.wrong-host-rejected.trust-store-password", "changeit"); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
vertx.close().toCompletionStage().toCompletableFuture().join(); | ||
} | ||
} |
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
Oops, something went wrong.