Skip to content

Commit

Permalink
Fix Certificate.of(…) factory method retaining the private key.
Browse files Browse the repository at this point in the history
Closes gh-857
  • Loading branch information
mp911de committed Jun 6, 2024
1 parent 14626b1 commit 9fd2e60
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static CertificateBundle of(String serialNumber, String certificate, Stri
Assert.hasText(privateKey, "Private key must not be empty");

return new CertificateBundle(serialNumber, certificate, issuingCaCertificate,
Collections.singletonList(issuingCaCertificate), null, privateKey, null);
Collections.singletonList(issuingCaCertificate), privateKey, privateKey, null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.springframework.vault.support;

import static org.assertj.core.api.Assertions.*;

import java.io.IOException;
import java.net.URL;
import java.security.KeyFactory;
Expand All @@ -27,8 +29,6 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import static org.assertj.core.api.Assertions.*;

/**
* Unit tests for {@link CertificateBundle}.
*
Expand Down Expand Up @@ -97,6 +97,18 @@ void invalidEcKeySpecShouldThrowException() {
assertThat(bundle.getPrivateKeySpec()).isNotNull();
}

@Test
void shouldReturnPrivateKey() {

String serialNumber = "aserialnumber";
String certificate = "certificate";
String caCertificate = "caCertificate";
String privateKey = "aprivatekey";

CertificateBundle bundle = CertificateBundle.of(serialNumber, certificate, caCertificate, privateKey);
assertThat(bundle.getPrivateKey()).isNotNull();
}

@Test
void getAsKeystore() throws Exception {

Expand All @@ -115,9 +127,9 @@ void getAsKeystore() throws Exception {
}

@ParameterizedTest
@ValueSource(strings = { "certificate-response-rsa-pem.json", "certificate-response-rsa-der.json",
@ValueSource(strings = {"certificate-response-rsa-pem.json", "certificate-response-rsa-der.json",
"certificate-response-rsa-pembundle.json", "certificate-response-ec-pem.json",
"certificate-response-ec-der.json", "certificate-response-ec-pembundle.json" })
"certificate-response-ec-der.json", "certificate-response-ec-pembundle.json"})
void createKeystore(String path) {

CertificateBundle bundle = loadCertificateBundle(path);
Expand All @@ -132,7 +144,7 @@ void createKeystore(String path) {
}

@ParameterizedTest
@ValueSource(strings = { "certificate-response-rsa-pem-pkcs8.json", "certificate-response-ec-pem-pkcs8.json" })
@ValueSource(strings = {"certificate-response-rsa-pem-pkcs8.json", "certificate-response-ec-pem-pkcs8.json"})
void shouldCreateKeystore(String path) {

CertificateBundle bundle = loadCertificateBundle(path);
Expand Down

0 comments on commit 9fd2e60

Please sign in to comment.