mirror of
https://github.com/docker-mailserver/docker-mailserver
synced 2026-11-27 16:14:45 +01:00
* refactor: move image contents into rootfs/ Put everything that ships in the image into rootfs/, laid out like the container's filesystem, so that the repository path of a file is its image path with a `rootfs/` prefix. Moves (git mv, history is kept) - etc/ -> rootfs/etc/ - scripts/bin/ -> rootfs/usr/local/bin/ - scripts/lib/ -> rootfs/usr/local/lib/dms/ - scripts/build.sh -> build.sh (build time only, next to setup.sh) - scripts/ no longer exists. The paths inside the image are unchanged, as are the file modes tracked by Git, so there is no changelog entry. The Dockerfile copies `rootfs/etc/` to `/etc/` and `rootfs/usr/local/` to `/usr/local/`. The two script COPY instructions became one, it still applies `--chmod=755` to everything below `/usr/local/`. All references are updated: the Dockerfile, .dockerignore, .gitattributes, the CI path filters (`rootfs/**` and `build.sh`), ShellCheck source directives, the tests that source repository files, code comments, links to the repository in the docs, and AGENTS.md. * ci: update linter Signed-off-by: Georg Lauterbach <44545919+georglauterbach@users.noreply.github.com> * breaking: remove SHELL and HEALTHCHECK from the Dockerfile and clean it up Neither `SHELL` nor `HEALTHCHECK` is part of the OCI image specification. Builders like Podman and Buildah warn about them and ignore them unless `--format docker` is used. Without them the image builds without warnings with every OCI compliant builder. Breaking: the image no longer ships a `HEALTHCHECK`. Users that rely on the health status (e.g. `depends_on: condition: service_healthy`) must configure `dms-healthcheck` in their runtime. `compose.yaml` now does so. The image filesystem is unchanged. Without `SHELL`, `RUN` uses `/bin/sh`: - every heredoc starts with `set -e` - `echo -e` became `printf` (the written bytes are identical) - the pipe in `echo | crontab -` cannot fail, DL4006 is ignored for it Cleanup - Describe the three stages in the header and use uniform banners with titles that match their content. - Merge the small `RUN` instructions of stage-main into three: ClamAV, package configuration and logs. - Move the removal of locales, man pages and docs, and `update-locale` into `_post_installation_steps` of build.sh, next to the APT cleanup. - Replace the stale permalink in the comment of the ENV defaults. * chore: simplify .gitattributes Replace the 150 lines of per-extension rules with `* text=auto eol=lf` plus the entries for binaries, `-diff` and `export-ignore`. All tracked text files are already LF in the index and the working tree, `git add --renormalize .` is a no-op, and Git detects the six binaries itself. The change closes a gap: `rootfs/etc/`, `test/config/`, the docs and the workflows had no `eol=lf`, so a checkout on Windows could ship CRLF configs into the image or into the test containers. Also drops stale comments (`target/shared/`, `test/linting/`) and entries that had no effect (e.g. `Makefile`). * tests: move bats libraries into test/helper/, retire the legacy helper - Move the submodules bats-support and bats-assert from test/test_helper/ to test/helper/ and rename them in .gitmodules. test/test_helper/ no longer exists. - Update the load paths in test/helper/common.bash and the lint excludes in the Makefile. - Delete the legacy test/test_helper/common.bash and its test serial/test_helper.bats. The test only covered the legacy functions and used a fixture that does not exist. - Port serial/trusted_networks_subnet.bats, the last user of the legacy helper, to the test/helper/ API: unique `dms-test_` container and network names, `_init_with_defaults` and `_common_container_*`, and the `_`-prefixed helpers. The permanently skipped third test targeted a container that no longer exists and is dropped. - Point the comment in change-detection.sh to the existing test/helper/change-detection.bash. Existing checkouts keep working: `git mv` moved the worktrees, the submodule names and gitdirs follow the new paths. * tests: rename test/files to test/fixtures and group transactions by protocol `test/files/` mixed unrelated things under unclear names. The new layout says what each file is and how a test consumes it: - `emails/` mail bodies for `_send_email --data` - `transactions/{smtp,imap,pop3,policy}/` raw protocol transcripts for `_send_raw_transaction*` (replaces `nc/`, `auth/` and `emails/nc_raw/`) - `tls/` certificates (replaces `ssl/`) The Postgrey transcripts live in `transactions/policy/` because they speak Postfix's policy delegation protocol, not SMTP. `TEST_FILES_*` become `TEST_FIXTURES_*`; the in-container mount point `/tmp/docker-mailserver-test` is unchanged. --------- Signed-off-by: Georg Lauterbach <44545919+georglauterbach@users.noreply.github.com>
99 lines
3.7 KiB
Bash
99 lines
3.7 KiB
Bash
load "${REPOSITORY_ROOT}/test/helper/setup"
|
|
load "${REPOSITORY_ROOT}/test/helper/common"
|
|
|
|
BATS_TEST_NAME_PREFIX='[DMS_TRUSTED_NETWORKS] '
|
|
CONTAINER1_NAME='dms-test_trusted_networks_subnet'
|
|
CONTAINER2_NAME='dms-test_trusted_networks_subnet_sender'
|
|
CONTAINER3_NAME='dms-test_trusted_networks_none'
|
|
NETWORK1_NAME='dms-test_trusted_networks_1'
|
|
NETWORK2_NAME='dms-test_trusted_networks_2'
|
|
|
|
function setup_file() {
|
|
docker network create --driver bridge "${NETWORK1_NAME}"
|
|
docker network create --driver bridge "${NETWORK2_NAME}"
|
|
|
|
local COMMON_ARGUMENTS=(
|
|
--env SMTP_ONLY=1
|
|
# The mail log assertions rely on the Amavis hand-off, Rspamd would classify the test mail as spam.
|
|
--env ENABLE_AMAVIS=1
|
|
--env OVERRIDE_HOSTNAME=mail.my-domain.com
|
|
)
|
|
|
|
# Use two networks (the default one of the container and a second one) to recreate the problematic case
|
|
# where trusting only the network of the first interface would not help. `docker create` accepts a single
|
|
# `--network` only, so the container is connected to the second network before it is started.
|
|
export CONTAINER_NAME=${CONTAINER1_NAME}
|
|
_init_with_defaults
|
|
local CONTAINER1_ARGUMENTS=(
|
|
"${COMMON_ARGUMENTS[@]}"
|
|
--env DMS_TRUSTED_NETWORKS=subnet
|
|
--network "${NETWORK1_NAME}"
|
|
)
|
|
_common_container_create 'CONTAINER1_ARGUMENTS'
|
|
docker network connect "${NETWORK2_NAME}" "${CONTAINER_NAME}"
|
|
_common_container_start
|
|
_wait_for_finished_setup_in_container "${CONTAINER_NAME}"
|
|
_wait_for_smtp_port_in_container
|
|
|
|
# Sends mail to the first container from the second network
|
|
export CONTAINER_NAME=${CONTAINER2_NAME}
|
|
_init_with_defaults
|
|
local CONTAINER2_ARGUMENTS=(
|
|
"${COMMON_ARGUMENTS[@]}"
|
|
--env DMS_TRUSTED_NETWORKS=subnet
|
|
--network "${NETWORK2_NAME}"
|
|
)
|
|
_common_container_setup 'CONTAINER2_ARGUMENTS'
|
|
|
|
# Enforces authentication, even for local connections
|
|
export CONTAINER_NAME=${CONTAINER3_NAME}
|
|
_init_with_defaults
|
|
local CONTAINER3_ARGUMENTS=(
|
|
"${COMMON_ARGUMENTS[@]}"
|
|
--env DMS_TRUSTED_NETWORKS=none
|
|
)
|
|
_common_container_setup 'CONTAINER3_ARGUMENTS'
|
|
_wait_for_smtp_port_in_container
|
|
}
|
|
|
|
function teardown_file() {
|
|
docker logs "${CONTAINER1_NAME}"
|
|
docker rm -f "${CONTAINER1_NAME}" "${CONTAINER2_NAME}" "${CONTAINER3_NAME}"
|
|
docker network rm "${NETWORK1_NAME}" "${NETWORK2_NAME}"
|
|
}
|
|
|
|
@test 'subnet: the subnets of all networks of the container are trusted' {
|
|
local IPNET1 IPNET2
|
|
IPNET1=$(docker network inspect --format '{{(index .IPAM.Config 0).Subnet}}' "${NETWORK1_NAME}")
|
|
IPNET2=$(docker network inspect --format '{{(index .IPAM.Config 0).Subnet}}' "${NETWORK2_NAME}")
|
|
|
|
_run_in_container_explicit "${CONTAINER1_NAME}" /bin/sh -c "postconf | grep '^mynetworks ='"
|
|
assert_output --partial "${IPNET1}"
|
|
assert_output --partial "${IPNET2}"
|
|
|
|
_run_in_container_explicit "${CONTAINER1_NAME}" /bin/sh -c 'postconf smtp_host_lookup=no'
|
|
assert_success
|
|
|
|
_reload_postfix "${CONTAINER1_NAME}"
|
|
|
|
# we should be able to send from the other container on the second network!
|
|
local CONTAINER_NAME=${CONTAINER2_NAME}
|
|
_send_raw_transaction_smtp 'transactions/smtp/smtp-only.txt' "${CONTAINER1_NAME} 25"
|
|
assert_output --partial '250 2.0.0 Ok: queued as '
|
|
|
|
_repeat_in_container_until_success_or_timeout 60 "${CONTAINER1_NAME}" \
|
|
/bin/sh -c 'grep -cE "to=<user2\@external.tld>.*status\=sent" /var/log/mail/mail.log'
|
|
}
|
|
|
|
@test 'none: authentication is required' {
|
|
_run_in_container_explicit "${CONTAINER3_NAME}" /bin/sh -c 'postconf smtp_host_lookup=no'
|
|
assert_success
|
|
|
|
_reload_postfix "${CONTAINER3_NAME}"
|
|
|
|
# the mailserver should require authentication and a protocol error should occur when using TLS
|
|
local CONTAINER_NAME=${CONTAINER3_NAME}
|
|
_send_raw_transaction 'transactions/smtp/smtp-only.txt' 'localhost 25'
|
|
assert_output --partial '550 5.5.1 Protocol error'
|
|
}
|