diff --git a/collect_coverage.sh b/collect_coverage.sh index d0115af4..bb44ebca 100755 --- a/collect_coverage.sh +++ b/collect_coverage.sh @@ -8,3 +8,19 @@ coverage combine --keep coverage* >/dev/null 2>/dev/null coverage html >/dev/null 2>/dev/null tar -c htmlcov ' | tar -C coverage -x + + + +CONTAINER_NAME="singularity_smtp_1" + +# Ensure the local coverage directory exists +mkdir -p $LOCAL_COVERAGE_DIR + +# Execute commands inside the container to process gcov files +podman exec -i $CONTAINER_NAME sh -exc ' + cd /smtp + rm -rf default.profdata default.profraw htmlcov_smtp + llvm-profdata merge -sparse default.profraw -o default.profdata + llvm-cov show ./smtp -instr-profile=default.profdata -format=html -output-dir=htmlcov_coverage_smtp >/dev/null 2>&1 + tar -c htmlcov_coverage_smtp +' | tar -C coverage_smtp -x \ No newline at end of file diff --git a/container-compose.yml b/container-compose.yml index b7f079d2..19bc3a98 100644 --- a/container-compose.yml +++ b/container-compose.yml @@ -64,6 +64,7 @@ services: target: smtp args: hostname: ${SINGULARITY_HOSTNAME} + coverage: 1 LISTEN_PORT: 1465 volumes: - type: volume diff --git a/smtp/Containerfile b/smtp/Containerfile index 28db12f7..8cc066db 100644 --- a/smtp/Containerfile +++ b/smtp/Containerfile @@ -1,8 +1,13 @@ FROM alpine:3.19 AS build RUN apk add \ clang \ + clang-dev \ + compiler-rt \ + llvm-dev \ + git \ make \ ; + COPY --from=tcp_server_source . /tcp_server ARG LISTEN_PORT=465 @@ -13,19 +18,38 @@ COPY . /smtp ARG hostname RUN test -n "$hostname" || (echo 'hostname is not set' && false) -RUN make -C /smtp CC='clang -static' SRVNAME=$hostname +ARG coverage + +RUN if [ "$coverage" -eq 1 ]; then \ + make -C /smtp CC='clang -static' SRVNAME=$hostname COVERAGE=1; \ + else \ + make -C /smtp CC='clang -static' SRVNAME=$hostname; \ + fi RUN mkdir -p /var/lib/email/mail /var/lib/email/logs && \ chown 100:100 /var/lib/email/mail /var/lib/email/logs && \ : -FROM scratch as smtp +# Set correct permissions for /smtp directory (to copy coverage files later) +RUN chown -R 100:100 /smtp + +FROM alpine:3.19 AS smtp +RUN apk add \ + clang \ + clang-dev \ + compiler-rt \ + make \ + ; COPY --from=build /var/lib/email /var/lib/email VOLUME /var/lib/email/ COPY --from=build /tcp_server/tcp_server /usr/local/bin/tcp_server COPY --from=build /smtp/smtp /usr/local/bin/smtp +# Copy coverage files +COPY --from=build /smtp /smtp +VOLUME /smtp + USER 100:100 ARG LISTEN_PORT=465 diff --git a/smtp/Makefile b/smtp/Makefile index 8ea9e43e..0210cb89 100644 --- a/smtp/Makefile +++ b/smtp/Makefile @@ -3,6 +3,11 @@ CFLAGS = -std=c2x -Weverything -Wno-unsafe-buffer-usage -Wno-c++98-compat -Wno-g -Wno-initializer-overrides -Wno-declaration-after-statement -Wno-four-char-constants \ -Wno-pre-c2x-compat -Wno-disabled-macro-expansion -D_GNU_SOURCE -DHOSTNAME='"$(SRVNAME)"' +# Add flags for gcov support +ifdef COVERAGE + CFLAGS += --coverage +endif + ifdef DEBUG CFLAGS += -DDEBUG -Og -g endif diff --git a/test.sh b/test.sh index c1693ff4..1d09ee0f 100755 --- a/test.sh +++ b/test.sh @@ -308,6 +308,7 @@ curl --url "smtps://$SINGULARITY_HOSTNAME" \ --upload-file - \ --user "user:${REGISTER_PASS}" <$CR $CR To whom it may concern,$CR $CR @@ -316,6 +317,47 @@ EOF ) | tee test/smtp_send_email \ | diff <(printf "") /dev/stdin +# Check that the user can send an email to multiple recipients +( +curl --url "smtps://$SINGULARITY_HOSTNAME" \ + --unix-socket ./socks/smtps.sock \ + "${CURL_OPTS[@]}" \ + --mail-from "user@$SINGULARITY_HOSTNAME" \ + --mail-rcpt "other@$SINGULARITY_HOSTNAME" \ + --mail-rcpt "other1@$SINGULARITY_HOSTNAME" \ + --upload-file - \ + --user "user:${REGISTER_PASS}" <$CR +To: "other1@$SINGULARITY_HOSTNAME" $CR +$CR +To whom it may concern,$CR +$CR +Bottom text$CR +EOF +) | tee test/smtp_send_email_multi_recipients \ + | diff <(printf "") /dev/stdin + +# Check that the user can send an email with Cc (carbon copy) recipients +( +curl --url "smtps://$SINGULARITY_HOSTNAME" \ + --unix-socket ./socks/smtps.sock \ + "${CURL_OPTS[@]}" \ + --mail-from "user@$SINGULARITY_HOSTNAME" \ + --mail-rcpt "other@$SINGULARITY_HOSTNAME" \ + --mail-rcpt "other1@$SINGULARITY_HOSTNAME" \ + --upload-file - \ + --user "user:${REGISTER_PASS}" <$CR +Cc: "other1@$SINGULARITY_HOSTNAME" $CR +$CR +To whom it may concern,$CR +$CR +Bottom text$CR +EOF +) | tee test/smtp_send_email_multi_recipients \ + | diff <(printf "") /dev/stdin # Verify that no email shows up without the journal being updated curl --url "pop3s://$SINGULARITY_HOSTNAME" \