Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set explicit path for regenerated mail test certificates and add debug logging #5729

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading