Skip to content

Commit

Permalink
Set explicit path for regenerated mail test certificates and add debu…
Browse files Browse the repository at this point in the history
…g logging
  • Loading branch information
jamesnetherton committed Feb 7, 2024
1 parent bf89a77 commit 8b53153
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
import org.apache.commons.io.FileUtils;
import org.eclipse.microprofile.config.ConfigProvider;
import org.jboss.logging.Logger;
import org.testcontainers.DockerClientFactory;
import org.testcontainers.containers.Container.ExecResult;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.HttpWaitStrategy;
import org.testcontainers.images.builder.Transferable;
import org.testcontainers.utility.MountableFile;

public class MailTestResource implements QuarkusTestResourceLifecycleManager {
private static final Logger LOG = Logger.getLogger(MailTestResource.class);
private static final String GREENMAIL_IMAGE_NAME = ConfigProvider.getConfig().getValue("greenmail.container.image",
String.class);
private static final String GREENMAIL_CERTIFICATE_STORE_FILE = "greenmail.p12";
Expand Down Expand Up @@ -109,8 +112,14 @@ private void regenerateCertificatesForDockerHost() {
container.copyFileToContainer(
MountableFile.forClasspathResource(GENERATE_CERTIFICATE_SCRIPT),
"/" + GENERATE_CERTIFICATE_SCRIPT);
container.execInContainer("/bin/bash", "/" + GENERATE_CERTIFICATE_SCRIPT, host,
"DNS:%s,IP:%s".formatted(host, host));
ExecResult result = container.execInContainer("/bin/bash", "/" + GENERATE_CERTIFICATE_SCRIPT, host,
"DNS:%s,IP:%s".formatted(host, host), "/" + GREENMAIL_CERTIFICATE_STORE_FILE);

LOG.info(GENERATE_CERTIFICATE_SCRIPT + " - STDOUT:");
LOG.info(result.getStdout());
LOG.info(GENERATE_CERTIFICATE_SCRIPT + " - STDERR:");
LOG.info(result.getStderr());

container.copyFileFromContainer("/" + GREENMAIL_CERTIFICATE_STORE_FILE,
certificateStoreLocation.resolve(GREENMAIL_CERTIFICATE_STORE_FILE).toString());
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@

export CN=${1:-localhost}
export SUBJECT_ALT_NAMES=${2:-"DNS:localhost,IP:127.0.0.1"}
export CERT_OUTPUT_FILE=${3:-greenmail.p12}

echo "====> PWD = ${PWD}"
echo "====> CN = ${CN}"
echo "====> SUBJECT_ALT_NAMES = ${SUBJECT_ALT_NAMES}"
echo "====> CERT_OUTPUT_FILE = ${CERT_OUTPUT_FILE}"

openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes -keyout greenmail.key -out greenmail.crt -subj "/CN=${CN}" -addext "subjectAltName=${SUBJECT_ALT_NAMES}"
openssl pkcs12 -export -out greenmail.p12 -inkey greenmail.key -in greenmail.crt -password pass:changeit
openssl pkcs12 -export -out ${CERT_OUTPUT_FILE} -inkey greenmail.key -in greenmail.crt -password pass:changeit

rm -f *.crt *.key

0 comments on commit 8b53153

Please sign in to comment.