test: Fix test db setup and add lombok annotations (#6)
* Fix test db setup and add lombok annotations * Formatting
This commit is contained in:
parent
c3da0eff5c
commit
a2aea580f2
6 changed files with 26 additions and 41 deletions
|
|
@ -1,7 +1,5 @@
|
|||
package de.mlessmann.certassist.openssl;
|
||||
|
||||
import static org.slf4j.LoggerFactory.getLogger;
|
||||
|
||||
import de.mlessmann.certassist.ExecutableResolver;
|
||||
import de.mlessmann.certassist.except.CommandLineOperationException;
|
||||
import de.mlessmann.certassist.except.UnresolvableCLIDependency;
|
||||
|
|
@ -13,9 +11,9 @@ import java.nio.file.StandardOpenOption;
|
|||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.zeroturnaround.exec.ProcessExecutor;
|
||||
|
|
@ -23,11 +21,12 @@ import org.zeroturnaround.exec.StartedProcess;
|
|||
import org.zeroturnaround.exec.stream.slf4j.Slf4jStream;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class OpenSSLCertificateCreator {
|
||||
|
||||
public static final String OPENSSL_CERT_SUBJECT_TEMPLATE =
|
||||
"/C=ISO-COUNTRY/ST=STATE/L=LOCALITY/O=ORGANIZATION/CN=COMMON-NAME";
|
||||
private static final Logger LOGGER = getLogger(OpenSSLCertificateCreator.class);
|
||||
private static final String CSR_EXT_TEMPLATE =
|
||||
"""
|
||||
authorityKeyIdentifier=keyid,issuer
|
||||
|
|
@ -40,11 +39,6 @@ public class OpenSSLCertificateCreator {
|
|||
|
||||
private final ExecutableResolver executableResolver;
|
||||
|
||||
@Autowired
|
||||
public OpenSSLCertificateCreator(ExecutableResolver executableResolver) {
|
||||
this.executableResolver = executableResolver;
|
||||
}
|
||||
|
||||
private static String buildSubjectArg(CertificateRequest request) {
|
||||
String certSubject = OPENSSL_CERT_SUBJECT_TEMPLATE
|
||||
.replace("ISO-COUNTRY", request.getSubject().getCountry())
|
||||
|
|
@ -85,7 +79,7 @@ public class OpenSSLCertificateCreator {
|
|||
private Path createKeyfile(CertificateRequest request, Path outFile)
|
||||
throws CommandLineOperationException, InterruptedException {
|
||||
Path keyFile = outFile.toAbsolutePath();
|
||||
LOGGER.atDebug().log("Writing new certificate key to {}", keyFile);
|
||||
log.atDebug().log("Writing new certificate key to {}", keyFile);
|
||||
|
||||
try {
|
||||
StartedProcess keygenProc = new ProcessExecutor()
|
||||
|
|
@ -113,7 +107,7 @@ public class OpenSSLCertificateCreator {
|
|||
|
||||
private Path createCertificate(CertificateRequest request, Path keyFile, Path outFile)
|
||||
throws CommandLineOperationException, InterruptedException {
|
||||
LOGGER.atDebug().log("Writing new certificate file {}", outFile);
|
||||
log.atDebug().log("Writing new certificate file {}", outFile);
|
||||
|
||||
String certSubject = buildSubjectArg(request);
|
||||
try {
|
||||
|
|
@ -153,7 +147,7 @@ public class OpenSSLCertificateCreator {
|
|||
private Path signCertificate(CertificateRequest request, Path caCert, Path caKey, Path csrFile)
|
||||
throws CommandLineOperationException, InterruptedException {
|
||||
Path outFile = csrFile.resolveSibling(csrFile.getFileName().toString().replace(".csr", ".crt"));
|
||||
LOGGER.atDebug().log("Writing new signed certificate file {}", outFile);
|
||||
log.atDebug().log("Writing new signed certificate file {}", outFile);
|
||||
Path extFile = csrFile.resolveSibling(csrFile.getFileName().toString().replace(".csr", ".ext"));
|
||||
|
||||
try {
|
||||
|
|
@ -170,7 +164,7 @@ public class OpenSSLCertificateCreator {
|
|||
extContent = extContent.replaceAll("\\[alt_names]\n?, ", "");
|
||||
}
|
||||
|
||||
LOGGER.debug("Writing extension file content: \n {}", extContent);
|
||||
log.debug("Writing extension file content: \n {}", extContent);
|
||||
Files.writeString(
|
||||
extFile,
|
||||
extContent,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue