mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-17 14:37:02 +00:00
When resolving MX records, we need to distinguish between "no such domain" and other kinds of errors. Before Go 1.13, this was not possible, so we had a workaround that assumed any permanent error was a "no such domain", which is not great, but functional. Now that our minimum supported version is Go 1.15, we can remove the workaround. This patch replaces the workaround with proper logic using DNSError.IsNotFound to identify NXDOMAIN results when resolving MX records. This requires to adjust a few tests, that used to work on environments where resolving unknown domains (used for testing) returned a permanent error, and now they no longer do so. Instead of relying on this environmental property, we make the affected tests use our own DNS server, which should make them more hermetic and reproducible.
89 lines
2.7 KiB
Bash
Executable File
89 lines
2.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -e
|
|
. $(dirname ${0})/../util/lib.sh
|
|
|
|
init
|
|
check_hostaliases
|
|
|
|
rm -rf .data-A .data-B .mail
|
|
|
|
# Build with the DNS override, so we can fake DNS records.
|
|
export GOTAGS="dnsoverride"
|
|
|
|
# Launch minidns in the background using our configuration.
|
|
minidns_bg --addr=":9053" -zones=zones >> .minidns.log 2>&1
|
|
|
|
# Two servers:
|
|
# A - listens on :1025, hosts srv-A
|
|
# B - listens on :2015, hosts srv-B
|
|
#
|
|
# We cause the following loop:
|
|
# userA -> aliasB -> aliasA -> aliasB -> ...
|
|
|
|
CONFDIR=A generate_certs_for srv-A
|
|
CONFDIR=A add_user userA@srv-A userA
|
|
|
|
CONFDIR=B generate_certs_for srv-B
|
|
|
|
mkdir -p .logs-A .logs-B
|
|
|
|
chasquid -v=2 --logfile=.logs-A/chasquid.log --config_dir=A \
|
|
--testing__dns_addr=127.0.0.1:9053 \
|
|
--testing__max_received_headers=5 \
|
|
--testing__outgoing_smtp_port=2025 &
|
|
chasquid -v=2 --logfile=.logs-B/chasquid.log --config_dir=B \
|
|
--testing__dns_addr=127.0.0.1:9053 \
|
|
--testing__outgoing_smtp_port=1025 &
|
|
|
|
wait_until_ready 1025
|
|
wait_until_ready 2025
|
|
wait_until_ready 9053
|
|
|
|
run_msmtp aliasB@srv-B < content
|
|
|
|
# Get some of the debugging pages, for troubleshooting, and to make sure they
|
|
# work reasonably well.
|
|
function fexp_gt10() {
|
|
fexp $1 -save $2 && \
|
|
[ $( cat $2 | wc -l ) -gt 10 ]
|
|
}
|
|
|
|
fexp_gt10 http://localhost:1099/ .data-A/dbg-root \
|
|
|| fail "failed to fetch /"
|
|
fexp_gt10 http://localhost:1099/debug/flags .data-A/dbg-flags \
|
|
|| fail "failed to fetch /debug/flags"
|
|
fexp http://localhost:1099/debug/queue -save .data-A/dbg-queue \
|
|
|| fail "failed to fetch /debug/queue"
|
|
fexp_gt10 http://localhost:1099/debug/config .data-A/dbg-config \
|
|
|| fail "failed to fetch /debug/config"
|
|
fexp http://localhost:1099/404 -status 404 \
|
|
|| fail "fetch /404 worked, should have failed"
|
|
fexp_gt10 http://localhost:1099/metrics .data-A/metrics \
|
|
|| fail "failed to fetch /metrics"
|
|
|
|
# Quick sanity-check of the /metrics page, just in case.
|
|
grep -q '^chasquid_queue_itemsWritten [0-9]\+$' .data-A/metrics \
|
|
|| fail "A /metrics is missing the chasquid_queue_itemsWritten counter"
|
|
|
|
# Wait until one of them has noticed and stopped the loop.
|
|
while sleep 0.1; do
|
|
fexp http://localhost:1099/debug/vars -save .data-A/vars
|
|
fexp http://localhost:2099/debug/vars -save .data-B/vars
|
|
# Allow for up to 2 loops to be detected, because if chasquid is fast
|
|
# enough the DSN will also loop before this check notices it.
|
|
if grep -q '"chasquid/smtpIn/loopsDetected": [12],' .data-?/vars; then
|
|
break
|
|
fi
|
|
done
|
|
|
|
# Test that A has outgoing domaininfo for srv-b.
|
|
# This is unrelated to the loop itself, but serves as an end-to-end
|
|
# verification that outgoing domaininfo works.
|
|
if ! grep -q 'outgoing_sec_level:\s*TLS_INSECURE' ".data-A/domaininfo/s:srv-b";
|
|
then
|
|
fail "A is missing the domaininfo for srv-b"
|
|
fi
|
|
|
|
success
|