Fix Certificate.of(…) factory method retaining the private key.

Closes gh-857
This commit is contained in:
Mark Paluch
2024-06-06 14:59:10 +02:00
parent 14626b1ba1
commit 9fd2e6034a
2 changed files with 18 additions and 6 deletions

View File

@@ -95,7 +95,7 @@ public class CertificateBundle extends Certificate {
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);
}
/**

View File

@@ -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;
@@ -27,8 +29,6 @@ import org.junit.jupiter.api.Test;
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}.
*
@@ -97,6 +97,18 @@ class CertificateBundleUnitTests {
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 {
@@ -115,9 +127,9 @@ class CertificateBundleUnitTests {
}
@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);
@@ -132,7 +144,7 @@ class CertificateBundleUnitTests {
}
@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);