Skip to content

Commit

Permalink
fix: move certificates in kubernetes-client-api to avoid collisions w…
Browse files Browse the repository at this point in the history
…ith those from mockwebserver

Signed-off-by: Marc Nuri <marc@marcnuri.com>
  • Loading branch information
manusa committed Oct 26, 2023
1 parent 0c0f0e4 commit 20de83f
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#### Bugs
* Fix #5501: (crd-generator) Fix fallback value of `Default` annotation in presence of multiple accessors
* Fix #5522: type inference fixed by bumping Sundrio to 0.101.2 (see https://github.com/sundrio/sundrio/pull/431)
* Fix #5554: move certificates in kubernetes-client-api to avoid collisions with those from mockwebserver

#### Improvements

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

class CertUtilsTest {

private static final String FABRIC8_STORE_PATH = Utils.filePath(CertUtilsTest.class.getResource("/ssl/fabric8-store"));
private static final String FABRIC8_STORE_PATH = Utils.filePath(CertUtilsTest.class.getResource("/ssl-test/fabric8-store"));
private static final String FABRIC8_STORE_PASSPHRASE = "fabric8";
private Properties systemProperties;

Expand Down Expand Up @@ -76,7 +76,7 @@ void handleReadOnlyJavaTrustStore() throws Exception {
KeyStore trustStore = Mockito.spy(system);
Mockito.doThrow(KeyStoreException.class).when(trustStore).setCertificateEntry(Mockito.anyString(), Mockito.any());
KeyStore result = CertUtils.mergePemCertsIntoTrustStore(
CertUtils.getInputStreamFromDataOrFile(null, "src/test/resources/ssl/multiple-certs.pem"), trustStore, true);
CertUtils.getInputStreamFromDataOrFile(null, "src/test/resources/ssl-test/multiple-certs.pem"), trustStore, true);

assertNotSame(trustStore, result);
assertThat(Collections.list(result.aliases()))
Expand All @@ -88,7 +88,7 @@ void handleReadOnlyJavaTrustStore() throws Exception {
@Test
void loadingMultipleCertsFromSameFile() throws Exception {
KeyStore ts = CertUtils.createTrustStore(
null, "src/test/resources/ssl/multiple-certs.pem", null, "changeit");
null, "src/test/resources/ssl-test/multiple-certs.pem", null, "changeit");

assertThat(Collections.list(ts.aliases()))
.hasSizeGreaterThanOrEqualTo(2)
Expand All @@ -99,15 +99,15 @@ void loadingMultipleCertsFromSameFile() throws Exception {
@Test
void loadingMultipleCertsWithSameSubjectFromSameFile() throws Exception {
KeyStore ts = CertUtils.createTrustStore(
null, "src/test/resources/ssl/nonunique-subject.pem", null, "changeit");
null, "src/test/resources/ssl-test/nonunique-subject.pem", null, "changeit");

assertTrue(ts.size() >= 2);
}

@Test
void loadTrustStoreFromFileUsingConfigProperties() throws Exception {
KeyStore trustStore = CertUtils.createTrustStore(
null, "src/test/resources/ssl/multiple-certs.pem", FABRIC8_STORE_PATH, FABRIC8_STORE_PASSPHRASE);
null, "src/test/resources/ssl-test/multiple-certs.pem", FABRIC8_STORE_PATH, FABRIC8_STORE_PASSPHRASE);

assertThat(Collections.list(trustStore.aliases()))
.hasSizeGreaterThanOrEqualTo(3)
Expand All @@ -123,7 +123,7 @@ void loadTrustStoreFromFileUsingSystemProperties() throws Exception {
System.setProperty("javax.net.ssl.trustStorePassword", FABRIC8_STORE_PASSPHRASE);

KeyStore trustStore = CertUtils.createTrustStore(
null, "src/test/resources/ssl/multiple-certs.pem", null, null);
null, "src/test/resources/ssl-test/multiple-certs.pem", null, null);

assertEquals(3, trustStore.size());
verifyFabric8InStore(trustStore);
Expand All @@ -132,8 +132,8 @@ void loadTrustStoreFromFileUsingSystemProperties() throws Exception {
@Test
void loadKeyStoreFromFileUsingConfigProperties() throws Exception {
KeyStore trustStore = CertUtils.createKeyStore(
null, "src/test/resources/ssl/multiple-certs.pem",
null, "src/test/resources/ssl/fabric8", "RSA", "changeit",
null, "src/test/resources/ssl-test/multiple-certs.pem",
null, "src/test/resources/ssl-test/fabric8", "RSA", "changeit",
FABRIC8_STORE_PATH, FABRIC8_STORE_PASSPHRASE);

assertEquals(2, trustStore.size());
Expand All @@ -145,8 +145,8 @@ void loadKeyStoreFromFileUsingSystemProperties() throws Exception {
System.setProperty("javax.net.ssl.keyStore", FABRIC8_STORE_PATH);
System.setProperty("javax.net.ssl.keyStorePassword", String.valueOf(FABRIC8_STORE_PASSPHRASE));

String privateKeyPath = Utils.filePath(getClass().getResource("/ssl/fabric8"));
String multipleCertsPath = Utils.filePath(getClass().getResource("/ssl/multiple-certs.pem"));
String privateKeyPath = Utils.filePath(getClass().getResource("/ssl-test/fabric8"));
String multipleCertsPath = Utils.filePath(getClass().getResource("/ssl-test/multiple-certs.pem"));

KeyStore trustStore = CertUtils.createKeyStore(null, multipleCertsPath, null, privateKeyPath, "RSA", "changeit", null,
null);
Expand All @@ -159,7 +159,7 @@ void loadKeyStoreFromFileUsingSystemProperties() throws Exception {
void getInputStreamFromDataOrFileShouldNotDecodedPEMAgain() throws IOException {
// Given
File certFile = new File(
Objects.requireNonNull(getClass().getResource("/ssl/valid-non-base64-encoded-cert.pem")).getFile());
Objects.requireNonNull(getClass().getResource("/ssl-test/valid-non-base64-encoded-cert.pem")).getFile());
String certData = new String(Files.readAllBytes(certFile.toPath()));

// When
Expand Down Expand Up @@ -188,7 +188,7 @@ void getInputStreamFromDataOrFileShouldDecodeBase64EncodedString() throws IOExce
void storeKeyFallbacksToDefault() throws Exception {
// When
final KeyStore result = CertUtils.createTrustStore(
null, "src/test/resources/ssl/multiple-certs.pem", null, "");
null, "src/test/resources/ssl-test/multiple-certs.pem", null, "");
// Then
assertThat(Collections.list(result.aliases()))
.hasSizeGreaterThanOrEqualTo(2)
Expand All @@ -203,7 +203,7 @@ private void verifyFabric8InStore(KeyStore trustStore)
assertNotNull(certificate);

KeyStore storeWithCert = CertUtils.createTrustStore(
null, "src/test/resources/ssl/fabric8.crt", null, "");
null, "src/test/resources/ssl-test/fabric8.crt", null, "");
String certificateAlias = storeWithCert.getCertificateAlias(certificate);
assertNotNull(certificateAlias);
}
Expand Down

0 comments on commit 20de83f

Please sign in to comment.