Polishing.

Update since and author tags. Guard tests against older Vault versisons.

Original pull request: gh-677
See gh-676
This commit is contained in:
Mark Paluch
2022-01-05 09:46:00 +01:00
parent 29379d70bc
commit 004fef2a5f
3 changed files with 26 additions and 31 deletions

View File

@@ -27,6 +27,7 @@ import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.Base64Utils;
import org.springframework.vault.VaultException;
@@ -38,6 +39,7 @@ import org.springframework.vault.VaultException;
* {@link X509Certificate}.
*
* @author Mark Paluch
* @author Alex Bremora
* @see #getPrivateKeySpec()
* @see #getX509Certificate()
* @see #getIssuingCaCertificate()
@@ -46,26 +48,11 @@ public class CertificateBundle extends Certificate {
private final String privateKey;
@Nullable
private final String privateKeyType;
private final List<String> caChain;
/**
* Create a new {@link CertificateBundle}.
* @param serialNumber the serial number.
* @param certificate the certificate.
* @param issuingCaCertificate the issuing CA certificate.
* @param caChain the CA chain.
* @param privateKey the private key.
* @deprecated since 2.3.3, use {@link #CertificateBundle(String, String, String, List, String, String)} instead.
*/
@Deprecated
CertificateBundle(String serialNumber, String certificate, String issuingCaCertificate,
List<String> caChain, String privateKey) {
this(serialNumber, certificate, issuingCaCertificate, caChain, privateKey, null);
}
/**
* Create a new {@link CertificateBundle}.
* @param serialNumber the serial number.
@@ -78,7 +65,7 @@ public class CertificateBundle extends Certificate {
CertificateBundle(@JsonProperty("serial_number") String serialNumber,
@JsonProperty("certificate") String certificate, @JsonProperty("issuing_ca") String issuingCaCertificate,
@JsonProperty("ca_chain") List<String> caChain, @JsonProperty("private_key") String privateKey,
@JsonProperty("private_key_type") String privateKeyType) {
@Nullable @JsonProperty("private_key_type") String privateKeyType) {
super(serialNumber, certificate, issuingCaCertificate);
this.privateKey = privateKey;
@@ -93,11 +80,8 @@ public class CertificateBundle extends Certificate {
* @param certificate must not be empty or {@literal null}.
* @param issuingCaCertificate must not be empty or {@literal null}.
* @param privateKey must not be empty or {@literal null}.
* @return the {@link CertificateBundle}
* @deprecated since 2.3.3, use {@link #of(String, String, String, String, String)}
* instead.
* @return the {@link CertificateBundle} instead.
*/
@Deprecated
public static CertificateBundle of(String serialNumber, String certificate, String issuingCaCertificate,
String privateKey) {
@@ -107,7 +91,7 @@ public class CertificateBundle extends Certificate {
Assert.hasText(privateKey, "Private key must not be empty");
return new CertificateBundle(serialNumber, certificate, issuingCaCertificate,
Collections.singletonList(issuingCaCertificate), privateKey);
Collections.singletonList(issuingCaCertificate), privateKey, null);
}
/**
@@ -119,9 +103,10 @@ public class CertificateBundle extends Certificate {
* @param privateKey must not be empty or {@literal null}.
* @param privateKeyType must not be empty or {@literal null}.
* @return the {@link CertificateBundle}
* @since 2.4
*/
public static CertificateBundle of(String serialNumber, String certificate, String issuingCaCertificate,
String privateKey, String privateKeyType) {
String privateKey, @Nullable String privateKeyType) {
Assert.hasText(serialNumber, "Serial number must not be empty");
Assert.hasText(certificate, "Certificate must not be empty");
@@ -141,8 +126,10 @@ public class CertificateBundle extends Certificate {
}
/**
* @return the private key type.
* @return the private key type, can be {@literal null}.
* @since 2.4
*/
@Nullable
public String getPrivateKeyType() {
return this.privateKeyType;
}

View File

@@ -49,21 +49,23 @@ import org.springframework.vault.support.VaultCertificateResponse;
import org.springframework.vault.support.VaultSignCertificateRequestResponse;
import org.springframework.vault.util.IntegrationTestSupport;
import org.springframework.vault.util.RequiresVaultVersion;
import org.springframework.vault.util.Version;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.springframework.vault.util.Settings.findWorkDir;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.vault.util.Settings.*;
/**
* Integration tests for {@link VaultPkiTemplate} through {@link VaultPkiOperations}.
*
* @author Mark Paluch
* @author Alex Bremora
*/
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = VaultIntegrationTestConfiguration.class)
class VaultPkiTemplateIntegrationTests extends IntegrationTestSupport {
static final String NO_TTL_UNIT_REQUIRED_FROM = "0.7.3";
private static final String NO_TTL_UNIT_REQUIRED_FROM = "0.7.3";
private static final Version PRIVATE_KEY_TYPE_FROM = Version.parse("0.7.0");
@Autowired
VaultOperations vaultOperations;
@@ -108,11 +110,16 @@ class VaultPkiTemplateIntegrationTests extends IntegrationTestSupport {
CertificateBundle data = certificateResponse.getRequiredData();
assertThat(data.getPrivateKey()).isNotEmpty();
assertThat(data.getPrivateKeyType()).isEqualTo("rsa");
if (prepare().getVersion().isGreaterThanOrEqualTo(PRIVATE_KEY_TYPE_FROM)) {
assertThat(data.getPrivateKeyType()).isEqualTo("rsa");
}
assertThat(data.getCertificate()).isNotEmpty();
assertThat(data.getIssuingCaCertificate()).isNotEmpty();
assertThat(data.getSerialNumber()).isNotEmpty();
assertThat(data.getX509Certificate().getSubjectX500Principal().getName()).isEqualTo("CN=hello.example.com");
assertThat(data.getX509Certificate().getSubjectX500Principal()
.getName()).isEqualTo("CN=hello.example.com");
assertThat(data.getX509IssuerCertificates()).hasSize(2);
KeyStore keyStore = data.createKeyStore("vault");

View File

@@ -24,12 +24,13 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.*;
/**
* Unit tests for {@link CertificateBundle}.
*
* @author Mark Paluch
* @author Alex Bremora
*/
class CertificateBundleUnitTests {