-
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.
Use CertificateGenerator in OIDC Wiremock tests
- Loading branch information
1 parent
d1c1e91
commit ebb2c0c
Showing
13 changed files
with
120 additions
and
180 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
Binary file removed
BIN
-1.82 KB
integration-tests/oidc-wiremock/src/main/resources/truststore-rootcert.p12
Binary file not shown.
Binary file not shown.
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
59 changes: 59 additions & 0 deletions
59
...ts/oidc-wiremock/src/test/java/io/quarkus/it/keycloak/CustomOidcWiremockTestResource.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,59 @@ | ||
package io.quarkus.it.keycloak; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.security.KeyStore; | ||
import java.security.cert.X509Certificate; | ||
import java.util.Map; | ||
|
||
import io.quarkus.test.oidc.server.OidcWiremockTestResource; | ||
import io.smallrye.certs.chain.CertificateChainGenerator; | ||
import io.smallrye.jwt.util.KeyUtils; | ||
|
||
public class CustomOidcWiremockTestResource extends OidcWiremockTestResource { | ||
@Override | ||
public Map<String, String> start() { | ||
try { | ||
generateCertificates(); | ||
} catch (Exception ex) { | ||
throw new RuntimeException(ex); | ||
} | ||
|
||
return super.start(); | ||
} | ||
|
||
private void generateCertificates() throws Exception { | ||
File chainDir = new File("target/chain"); | ||
CertificateChainGenerator chainGenerator = new CertificateChainGenerator(chainDir) | ||
.withCN("www.quarkustest.com"); | ||
chainGenerator.generate(); | ||
|
||
Path rootCertPath = Paths.get("target/chain/root.crt"); | ||
X509Certificate rootCert = KeyUtils.getCertificate(Files.readString(rootCertPath)); | ||
|
||
Path leafCertPath = Paths.get("target/chain/www.quarkustest.com.crt"); | ||
X509Certificate leafCert = KeyUtils.getCertificate(Files.readString(leafCertPath)); | ||
|
||
File trustStore = new File(chainDir, "truststore.p12"); | ||
KeyStore keyStore = KeyStore.getInstance("PKCS12"); | ||
keyStore.load(null, null); | ||
keyStore.setCertificateEntry("root", rootCert); | ||
keyStore.setCertificateEntry("leaf", leafCert); | ||
var fos = new FileOutputStream(trustStore); | ||
keyStore.store(fos, "storepassword".toCharArray()); | ||
fos.close(); | ||
|
||
File trustStoreRoot = new File(chainDir, "truststore-rootcert.p12"); | ||
KeyStore keyStoreRootCert = KeyStore.getInstance("PKCS12"); | ||
keyStoreRootCert.load(null, null); | ||
keyStoreRootCert.setCertificateEntry("root", rootCert); | ||
var fosRootCert = new FileOutputStream(trustStoreRoot); | ||
keyStoreRootCert.store(fosRootCert, "storepassword".toCharArray()); | ||
fosRootCert.close(); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.