Skip to content

Commit 9fd2e60

Browse files
committed
Fix Certificate.of(…) factory method retaining the private key.
Closes gh-857
1 parent 14626b1 commit 9fd2e60

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

spring-vault-core/src/main/java/org/springframework/vault/support/CertificateBundle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static CertificateBundle of(String serialNumber, String certificate, Stri
9595
Assert.hasText(privateKey, "Private key must not be empty");
9696

9797
return new CertificateBundle(serialNumber, certificate, issuingCaCertificate,
98-
Collections.singletonList(issuingCaCertificate), null, privateKey, null);
98+
Collections.singletonList(issuingCaCertificate), privateKey, privateKey, null);
9999
}
100100

101101
/**

spring-vault-core/src/test/java/org/springframework/vault/support/CertificateBundleUnitTests.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package org.springframework.vault.support;
1717

18+
import static org.assertj.core.api.Assertions.*;
19+
1820
import java.io.IOException;
1921
import java.net.URL;
2022
import java.security.KeyFactory;
@@ -27,8 +29,6 @@
2729
import org.junit.jupiter.params.ParameterizedTest;
2830
import org.junit.jupiter.params.provider.ValueSource;
2931

30-
import static org.assertj.core.api.Assertions.*;
31-
3232
/**
3333
* Unit tests for {@link CertificateBundle}.
3434
*
@@ -97,6 +97,18 @@ void invalidEcKeySpecShouldThrowException() {
9797
assertThat(bundle.getPrivateKeySpec()).isNotNull();
9898
}
9999

100+
@Test
101+
void shouldReturnPrivateKey() {
102+
103+
String serialNumber = "aserialnumber";
104+
String certificate = "certificate";
105+
String caCertificate = "caCertificate";
106+
String privateKey = "aprivatekey";
107+
108+
CertificateBundle bundle = CertificateBundle.of(serialNumber, certificate, caCertificate, privateKey);
109+
assertThat(bundle.getPrivateKey()).isNotNull();
110+
}
111+
100112
@Test
101113
void getAsKeystore() throws Exception {
102114

@@ -115,9 +127,9 @@ void getAsKeystore() throws Exception {
115127
}
116128

117129
@ParameterizedTest
118-
@ValueSource(strings = { "certificate-response-rsa-pem.json", "certificate-response-rsa-der.json",
130+
@ValueSource(strings = {"certificate-response-rsa-pem.json", "certificate-response-rsa-der.json",
119131
"certificate-response-rsa-pembundle.json", "certificate-response-ec-pem.json",
120-
"certificate-response-ec-der.json", "certificate-response-ec-pembundle.json" })
132+
"certificate-response-ec-der.json", "certificate-response-ec-pembundle.json"})
121133
void createKeystore(String path) {
122134

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

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

138150
CertificateBundle bundle = loadCertificateBundle(path);

0 commit comments

Comments
 (0)