Skip to content
Open
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
16 changes: 16 additions & 0 deletions collect_coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions container-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ services:
target: smtp
args:
hostname: ${SINGULARITY_HOSTNAME}
coverage: 1
LISTEN_PORT: 1465
volumes:
- type: volume
Expand Down
28 changes: 26 additions & 2 deletions smtp/Containerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions smtp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ curl --url "smtps://$SINGULARITY_HOSTNAME" \
--upload-file - \
--user "user:${REGISTER_PASS}" <<EOF
Subject: Message Subject$CR
To: "other@$SINGULARITY_HOSTNAME" <other@$SINGULARITY_HOSTNAME>$CR
$CR
To whom it may concern,$CR
$CR
Expand All @@ -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}" <<EOF
Subject: Message Subject$CR
To: "other@$SINGULARITY_HOSTNAME" <other@$SINGULARITY_HOSTNAME>$CR
To: "other1@$SINGULARITY_HOSTNAME" <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}" <<EOF
Subject: Message Subject$CR
To: "other@$SINGULARITY_HOSTNAME" <other@$SINGULARITY_HOSTNAME>$CR
Cc: "other1@$SINGULARITY_HOSTNAME" <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" \
Expand Down