1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-17 14:37:02 +00:00

test: Use minidns in the Docker tests

The integration tests depend on having a DNS server that resolves
"localhost", which is unfortunate but currently unavoidable given
glibc's limitations ($HOSTALIASES only works on DNS-level aliases, and
does not do lookups in /etc/hosts).

Even under docker, this makes the tests depend on the DNS server, and
whether it resolves localhost or not.

In order to make the docker tests more hermetic and isolated from the
environment, this patch introduces a docker entrypoint that, within the
container, will launch minidns and override /etc/resolv.conf to use it.

This guarantees that the tests will be able to resolve localhost, and
also avoid accidental reliance on external DNS zones.
This commit is contained in:
Alberto Bertogli
2018-11-29 00:31:48 +00:00
parent 57f5a09901
commit dd7cfaebf2
2 changed files with 54 additions and 2 deletions

46
test/util/docker_entrypoint.sh Executable file
View File

@@ -0,0 +1,46 @@
#!/bin/bash
#
# Script that is used as a Docker entrypoint.
#
# It starts minidns with a zone resolving "localhost", and overrides
# /etc/resolv.conf to use it. Then launches docker CMD.
#
# This is used for more hermetic Docker test environments.
set -e
. $(dirname ${0})/../util/lib.sh
init
# Go to the root of the repository.
cd ../..
# Undo the EXIT trap, so minidns continues to run in the background.
trap - EXIT
set -v
go build -o /tmp/minidns "${UTILDIR}/minidns.go"
# The DNS server resolves only "localhost"; tests will rely on this, as we
# $HOSTALIASES to point our test hostnames to localhost, so it needs to
# resolve.
echo "
localhost A 127.0.0.1
localhost AAAA ::1
" > /tmp/zones
start-stop-daemon --start --background \
--exec /tmp/minidns \
-- --zones=/tmp/zones
echo "nameserver 127.0.0.1" > /etc/resolv.conf
echo "nameserver ::1" >> /etc/resolv.conf
# Launch arguments, which come from docker CMD, as "chasquid" user.
# Running tests as root makes some integration tests more difficult, as for
# example Exim has hard-coded protections against running as root.
sudo -u chasquid -g chasquid \
--set-home \
--preserve-env PATH=${PATH} \
-- "$@"