chore: Make TestOpenSSLCertificateCreator a spring boot test
This commit is contained in:
parent
344e80e5ac
commit
c24adcbcd6
2 changed files with 19 additions and 10 deletions
|
@ -88,28 +88,28 @@ public class OpenSSLCertificateCreator {
|
|||
throw new CommandLineOperationException("Could not create temporary directory for certificate creation", e);
|
||||
}
|
||||
|
||||
String certPassword = passwordProvider.generateNewPassword();
|
||||
Path keyFile = createKeyfile(request, tmpDir.resolve("certificate.key"), certPassword);
|
||||
String keypassphrase = passwordProvider.generateNewPassword();
|
||||
Path keyFile = createKeyfile(request, tmpDir.resolve("certificate.key"), keypassphrase);
|
||||
if (
|
||||
request.getType() == RequestType.ROOT_AUTHORITY || request.getType() == RequestType.STANDALONE_CERTIFICATE
|
||||
) {
|
||||
Path certificate = createCertificate(request, keyFile, tmpDir.resolve("certificate.crt"), certPassword);
|
||||
Path certificate = createCertificate(request, keyFile, tmpDir.resolve("certificate.crt"), keypassphrase);
|
||||
String fingerprint = getCertificateFingerprint(certificate);
|
||||
passwordProvider.setPasswordFor(fingerprint, certPassword);
|
||||
passwordProvider.setPasswordFor(fingerprint, keypassphrase);
|
||||
return new OpenSSLCertificateResult(tmpDir, certificate, keyFile, certificate, fingerprint);
|
||||
}
|
||||
|
||||
try (var certAuthority = certificateProvider.requestCertificateUsage(request.getTrustingAuthority())) {
|
||||
Path unsignedCert = createSigningRequest(request, keyFile, tmpDir.resolve("child.csr"), certPassword);
|
||||
Path unsignedCert = createSigningRequest(request, keyFile, tmpDir.resolve("child.csr"), keypassphrase);
|
||||
Path signedCert = signCertificate(
|
||||
request,
|
||||
certAuthority.certificatePath(),
|
||||
certAuthority.certificateKeyPath(),
|
||||
unsignedCert,
|
||||
certPassword
|
||||
keypassphrase
|
||||
);
|
||||
String fingerprint = getCertificateFingerprint(signedCert);
|
||||
passwordProvider.setPasswordFor(fingerprint, certPassword);
|
||||
passwordProvider.setPasswordFor(fingerprint, keypassphrase);
|
||||
|
||||
Path fullchain = tmpDir.resolve("fullchain.pem");
|
||||
try {
|
||||
|
@ -129,7 +129,7 @@ public class OpenSSLCertificateCreator {
|
|||
private Path createKeyfile(CertificateRequest request, Path outFile, String filePassword)
|
||||
throws CommandLineOperationException, InterruptedException {
|
||||
Path keyFile = outFile.toAbsolutePath();
|
||||
log.atDebug().log("Writing new certificate key to {}", keyFile);
|
||||
log.debug("Writing new certificate key to {}", keyFile);
|
||||
|
||||
try {
|
||||
StartedProcess keygenProc = new ProcessExecutor()
|
||||
|
@ -158,7 +158,7 @@ public class OpenSSLCertificateCreator {
|
|||
|
||||
private Path createCertificate(CertificateRequest request, Path keyFile, Path outFile, String certPassword)
|
||||
throws CommandLineOperationException, InterruptedException {
|
||||
log.atDebug().log("Writing new certificate file {}", outFile);
|
||||
log.debug("Writing new certificate file {}", outFile);
|
||||
|
||||
String certSubject = buildSubjectArg(request);
|
||||
try {
|
||||
|
|
|
@ -9,14 +9,23 @@ import java.nio.file.Path;
|
|||
import java.util.Objects;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
@SpringBootTest
|
||||
class TestOpenSSLCertificateCreator {
|
||||
|
||||
public static final String TEST_CERT_PASSPHRASE = "ABC-123";
|
||||
public static final Path TEST_CERT_PATH = Path.of("src/test/resources/openssl");
|
||||
public static final String ERR_NOT_ENCRYPTED = "Private key not encrypted";
|
||||
public static final String ERR_VERIFY_FAILED = "Certificate verification failed";
|
||||
private CertificatePasswordProvider passwordProvider;
|
||||
|
||||
@Autowired
|
||||
OpenSSLCertificateCreator openSSLCertificateCreator;
|
||||
|
||||
@MockBean
|
||||
CertificatePasswordProvider passwordProvider;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
|
Loading…
Add table
Reference in a new issue