Skip to content

Commit 004fef2

Browse files
committed
Polishing.
Update since and author tags. Guard tests against older Vault versisons. Original pull request: gh-677 See gh-676
1 parent 29379d7 commit 004fef2

File tree

3 files changed

+26
-31
lines changed

3 files changed

+26
-31
lines changed

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

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import com.fasterxml.jackson.annotation.JsonProperty;
2929

30+
import org.springframework.lang.Nullable;
3031
import org.springframework.util.Assert;
3132
import org.springframework.util.Base64Utils;
3233
import org.springframework.vault.VaultException;
@@ -38,6 +39,7 @@
3839
* {@link X509Certificate}.
3940
*
4041
* @author Mark Paluch
42+
* @author Alex Bremora
4143
* @see #getPrivateKeySpec()
4244
* @see #getX509Certificate()
4345
* @see #getIssuingCaCertificate()
@@ -46,26 +48,11 @@ public class CertificateBundle extends Certificate {
4648

4749
private final String privateKey;
4850

51+
@Nullable
4952
private final String privateKeyType;
5053

5154
private final List<String> caChain;
5255

53-
/**
54-
* Create a new {@link CertificateBundle}.
55-
* @param serialNumber the serial number.
56-
* @param certificate the certificate.
57-
* @param issuingCaCertificate the issuing CA certificate.
58-
* @param caChain the CA chain.
59-
* @param privateKey the private key.
60-
* @deprecated since 2.3.3, use {@link #CertificateBundle(String, String, String, List, String, String)} instead.
61-
*/
62-
@Deprecated
63-
CertificateBundle(String serialNumber, String certificate, String issuingCaCertificate,
64-
List<String> caChain, String privateKey) {
65-
66-
this(serialNumber, certificate, issuingCaCertificate, caChain, privateKey, null);
67-
}
68-
6956
/**
7057
* Create a new {@link CertificateBundle}.
7158
* @param serialNumber the serial number.
@@ -78,7 +65,7 @@ public class CertificateBundle extends Certificate {
7865
CertificateBundle(@JsonProperty("serial_number") String serialNumber,
7966
@JsonProperty("certificate") String certificate, @JsonProperty("issuing_ca") String issuingCaCertificate,
8067
@JsonProperty("ca_chain") List<String> caChain, @JsonProperty("private_key") String privateKey,
81-
@JsonProperty("private_key_type") String privateKeyType) {
68+
@Nullable @JsonProperty("private_key_type") String privateKeyType) {
8269

8370
super(serialNumber, certificate, issuingCaCertificate);
8471
this.privateKey = privateKey;
@@ -93,11 +80,8 @@ public class CertificateBundle extends Certificate {
9380
* @param certificate must not be empty or {@literal null}.
9481
* @param issuingCaCertificate must not be empty or {@literal null}.
9582
* @param privateKey must not be empty or {@literal null}.
96-
* @return the {@link CertificateBundle}
97-
* @deprecated since 2.3.3, use {@link #of(String, String, String, String, String)}
98-
* instead.
83+
* @return the {@link CertificateBundle} instead.
9984
*/
100-
@Deprecated
10185
public static CertificateBundle of(String serialNumber, String certificate, String issuingCaCertificate,
10286
String privateKey) {
10387

@@ -107,7 +91,7 @@ public static CertificateBundle of(String serialNumber, String certificate, Stri
10791
Assert.hasText(privateKey, "Private key must not be empty");
10892

10993
return new CertificateBundle(serialNumber, certificate, issuingCaCertificate,
110-
Collections.singletonList(issuingCaCertificate), privateKey);
94+
Collections.singletonList(issuingCaCertificate), privateKey, null);
11195
}
11296

11397
/**
@@ -119,9 +103,10 @@ public static CertificateBundle of(String serialNumber, String certificate, Stri
119103
* @param privateKey must not be empty or {@literal null}.
120104
* @param privateKeyType must not be empty or {@literal null}.
121105
* @return the {@link CertificateBundle}
106+
* @since 2.4
122107
*/
123108
public static CertificateBundle of(String serialNumber, String certificate, String issuingCaCertificate,
124-
String privateKey, String privateKeyType) {
109+
String privateKey, @Nullable String privateKeyType) {
125110

126111
Assert.hasText(serialNumber, "Serial number must not be empty");
127112
Assert.hasText(certificate, "Certificate must not be empty");
@@ -141,8 +126,10 @@ public String getPrivateKey() {
141126
}
142127

143128
/**
144-
* @return the private key type.
129+
* @return the private key type, can be {@literal null}.
130+
* @since 2.4
145131
*/
132+
@Nullable
146133
public String getPrivateKeyType() {
147134
return this.privateKeyType;
148135
}

spring-vault-core/src/test/java/org/springframework/vault/core/VaultPkiTemplateIntegrationTests.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,23 @@
4949
import org.springframework.vault.support.VaultSignCertificateRequestResponse;
5050
import org.springframework.vault.util.IntegrationTestSupport;
5151
import org.springframework.vault.util.RequiresVaultVersion;
52+
import org.springframework.vault.util.Version;
5253

53-
import static org.assertj.core.api.Assertions.assertThat;
54-
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
55-
import static org.springframework.vault.util.Settings.findWorkDir;
54+
import static org.assertj.core.api.Assertions.*;
55+
import static org.springframework.vault.util.Settings.*;
5656

5757
/**
5858
* Integration tests for {@link VaultPkiTemplate} through {@link VaultPkiOperations}.
5959
*
6060
* @author Mark Paluch
61+
* @author Alex Bremora
6162
*/
6263
@ExtendWith(SpringExtension.class)
6364
@ContextConfiguration(classes = VaultIntegrationTestConfiguration.class)
6465
class VaultPkiTemplateIntegrationTests extends IntegrationTestSupport {
6566

66-
static final String NO_TTL_UNIT_REQUIRED_FROM = "0.7.3";
67+
private static final String NO_TTL_UNIT_REQUIRED_FROM = "0.7.3";
68+
private static final Version PRIVATE_KEY_TYPE_FROM = Version.parse("0.7.0");
6769

6870
@Autowired
6971
VaultOperations vaultOperations;
@@ -108,11 +110,16 @@ void issueCertificateShouldCreateCertificate() throws KeyStoreException {
108110
CertificateBundle data = certificateResponse.getRequiredData();
109111

110112
assertThat(data.getPrivateKey()).isNotEmpty();
111-
assertThat(data.getPrivateKeyType()).isEqualTo("rsa");
113+
114+
if (prepare().getVersion().isGreaterThanOrEqualTo(PRIVATE_KEY_TYPE_FROM)) {
115+
assertThat(data.getPrivateKeyType()).isEqualTo("rsa");
116+
}
117+
112118
assertThat(data.getCertificate()).isNotEmpty();
113119
assertThat(data.getIssuingCaCertificate()).isNotEmpty();
114120
assertThat(data.getSerialNumber()).isNotEmpty();
115-
assertThat(data.getX509Certificate().getSubjectX500Principal().getName()).isEqualTo("CN=hello.example.com");
121+
assertThat(data.getX509Certificate().getSubjectX500Principal()
122+
.getName()).isEqualTo("CN=hello.example.com");
116123
assertThat(data.getX509IssuerCertificates()).hasSize(2);
117124

118125
KeyStore keyStore = data.createKeyStore("vault");

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@
2424
import org.junit.jupiter.api.BeforeEach;
2525
import org.junit.jupiter.api.Test;
2626

27-
import static org.assertj.core.api.Assertions.assertThat;
27+
import static org.assertj.core.api.Assertions.*;
2828

2929
/**
3030
* Unit tests for {@link CertificateBundle}.
3131
*
3232
* @author Mark Paluch
33+
* @author Alex Bremora
3334
*/
3435
class CertificateBundleUnitTests {
3536

0 commit comments

Comments
 (0)