mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-18 14:47:03 +00:00
test: Readability cleanup
This patch makes a few small changes to the tests for readability, such as changing the arguments to the add_user function.
This commit is contained in:
@@ -6,7 +6,7 @@ They're not expected to be portable, as that gets impractical very quickly.
|
|||||||
They also have some dependencies, listed below.
|
They also have some dependencies, listed below.
|
||||||
|
|
||||||
|
|
||||||
=== Dependencies
|
## Dependencies
|
||||||
|
|
||||||
The tests depend on the following things being installed on the system (listed
|
The tests depend on the following things being installed on the system (listed
|
||||||
as Debian package, for consistency):
|
as Debian package, for consistency):
|
||||||
@@ -15,9 +15,11 @@ as Debian package, for consistency):
|
|||||||
- msmtp
|
- msmtp
|
||||||
- util-linux (for /usr/bin/setsid)
|
- util-linux (for /usr/bin/setsid)
|
||||||
|
|
||||||
For t-exim (Exim interaction tests):
|
For t-02-exim (Exim interaction tests):
|
||||||
- gettext-base (for /usr/bin/envsubst)
|
- gettext-base (for /usr/bin/envsubst)
|
||||||
- The exim binary available somewhere, but it doesn't have to be installed.
|
- The exim binary available somewhere, but it doesn't have to be installed.
|
||||||
There's a script "get-exim4-debian.sh" to get it from the archives.
|
There's a script "get-exim4-debian.sh" to get it from the archives.
|
||||||
|
|
||||||
|
For some tests, python >= 3.5 is required; they will be skipped if it's not
|
||||||
|
available.
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ set -e
|
|||||||
init
|
init
|
||||||
|
|
||||||
generate_certs_for testserver
|
generate_certs_for testserver
|
||||||
add_user testserver user secretpassword
|
add_user user@testserver secretpassword
|
||||||
add_user testserver someone secretpassword
|
add_user someone@testserver secretpassword
|
||||||
|
|
||||||
mkdir -p .logs
|
mkdir -p .logs
|
||||||
chasquid -v=2 --log_dir=.logs --config_dir=config &
|
chasquid -v=2 --log_dir=.logs --config_dir=config &
|
||||||
@@ -22,23 +22,19 @@ mail_diff content .mail/someone@testserver
|
|||||||
# At least for now, we allow AUTH over the SMTP port to avoid unnecessary
|
# At least for now, we allow AUTH over the SMTP port to avoid unnecessary
|
||||||
# complexity, so we expect it to work.
|
# complexity, so we expect it to work.
|
||||||
if ! run_msmtp -a smtpport someone@testserver < content 2> /dev/null; then
|
if ! run_msmtp -a smtpport someone@testserver < content 2> /dev/null; then
|
||||||
echo "ERROR: failed auth on the SMTP port"
|
fail "failed auth on the SMTP port"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if run_msmtp nobody@testserver < content 2> /dev/null; then
|
if run_msmtp nobody@testserver < content 2> /dev/null; then
|
||||||
echo "ERROR: successfuly sent an email to a non-existent user"
|
fail "successfuly sent an email to a non-existent user"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if run_msmtp -a baduser someone@testserver < content 2> /dev/null; then
|
if run_msmtp -a baduser someone@testserver < content 2> /dev/null; then
|
||||||
echo "ERROR: successfully sent an email with a bad password"
|
fail "successfully sent an email with a bad password"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if run_msmtp -a badpasswd someone@testserver < content 2> /dev/null; then
|
if run_msmtp -a badpasswd someone@testserver < content 2> /dev/null; then
|
||||||
echo "ERROR: successfully sent an email with a bad password"
|
fail "successfully sent an email with a bad password"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
success
|
success
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ set -e
|
|||||||
init
|
init
|
||||||
|
|
||||||
if ! .exim4/exim4 --version > /dev/null; then
|
if ! .exim4/exim4 --version > /dev/null; then
|
||||||
skip "(exim4 binary at .exim4/exim4 is not functional)"
|
skip "exim4 binary at .exim4/exim4 is not functional"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -38,8 +38,8 @@ mkdir -p .exim4
|
|||||||
EXIMDIR="$PWD/.exim4" envsubst < config/exim4.in > .exim4/config
|
EXIMDIR="$PWD/.exim4" envsubst < config/exim4.in > .exim4/config
|
||||||
|
|
||||||
generate_certs_for srv-chasquid
|
generate_certs_for srv-chasquid
|
||||||
add_user srv-chasquid user secretpassword
|
add_user user@srv-chasquid secretpassword
|
||||||
add_user srv-chasquid someone secretpassword
|
add_user someone@srv-chasquid secretpassword
|
||||||
|
|
||||||
# Launch chasquid at port 1025 (in config).
|
# Launch chasquid at port 1025 (in config).
|
||||||
# Use outgoing port 2025 which is where exim will be at.
|
# Use outgoing port 2025 which is where exim will be at.
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ set -e
|
|||||||
init
|
init
|
||||||
|
|
||||||
generate_certs_for testserver
|
generate_certs_for testserver
|
||||||
add_user testserver user secretpassword
|
add_user user@testserver secretpassword
|
||||||
|
|
||||||
mkdir -p .logs
|
mkdir -p .logs
|
||||||
chasquid -v=2 --log_dir=.logs --config_dir=config &
|
chasquid -v=2 --log_dir=.logs --config_dir=config &
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ set -e
|
|||||||
init
|
init
|
||||||
|
|
||||||
generate_certs_for testserver
|
generate_certs_for testserver
|
||||||
add_user testserver user secretpassword
|
add_user user@testserver secretpassword
|
||||||
|
|
||||||
mkdir -p .logs
|
mkdir -p .logs
|
||||||
chasquid -v=2 --log_dir=.logs --config_dir=config &
|
chasquid -v=2 --log_dir=.logs --config_dir=config &
|
||||||
|
|||||||
@@ -14,12 +14,12 @@ skip_if_python_is_too_old
|
|||||||
# B - listens on :2015, hosts srv-ü
|
# B - listens on :2015, hosts srv-ü
|
||||||
|
|
||||||
CONFDIR=A generate_certs_for srv-ñ
|
CONFDIR=A generate_certs_for srv-ñ
|
||||||
CONFDIR=A add_user srv-ñ ñangapirí antaño
|
CONFDIR=A add_user ñangapirí@srv-ñ antaño
|
||||||
CONFDIR=A add_user nadaA nadaA nadaA
|
CONFDIR=A add_user nadaA@nadaA nadaA
|
||||||
|
|
||||||
CONFDIR=B generate_certs_for srv-ü
|
CONFDIR=B generate_certs_for srv-ü
|
||||||
CONFDIR=B add_user srv-ü pingüino velóz
|
CONFDIR=B add_user pingüino@srv-ü velóz
|
||||||
CONFDIR=B add_user nadaB nadaB nadaB
|
CONFDIR=B add_user nadaB@nadaB nadaB
|
||||||
|
|
||||||
mkdir -p .logs-A .logs-B
|
mkdir -p .logs-A .logs-B
|
||||||
|
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ generate_certs_for ñoños
|
|||||||
|
|
||||||
# Intentionally have a config directory for upper case; this should be
|
# Intentionally have a config directory for upper case; this should be
|
||||||
# normalized to lowercase internally (and match the cert accordingly).
|
# normalized to lowercase internally (and match the cert accordingly).
|
||||||
add_user ñoñOS ñangapirí antaño
|
add_user ñangapirí@ñoñOS antaño
|
||||||
|
|
||||||
# Python doesn't support UTF8 for auth, use an ascii user and domain.
|
# Python doesn't support UTF8 for auth, use an ascii user and domain.
|
||||||
add_user nada nada nada
|
add_user nada@nada nada
|
||||||
|
|
||||||
mkdir -p .logs
|
mkdir -p .logs
|
||||||
chasquid -v=2 --log_dir=.logs --config_dir=config &
|
chasquid -v=2 --log_dir=.logs --config_dir=config &
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ rm -rf .data-A .data-B .mail
|
|||||||
# userA -> aliasB -> aliasA -> aliasB -> ...
|
# userA -> aliasB -> aliasA -> aliasB -> ...
|
||||||
|
|
||||||
CONFDIR=A generate_certs_for srv-A
|
CONFDIR=A generate_certs_for srv-A
|
||||||
CONFDIR=A add_user srv-A userA userA
|
CONFDIR=A add_user userA@srv-A userA
|
||||||
|
|
||||||
CONFDIR=B generate_certs_for srv-B
|
CONFDIR=B generate_certs_for srv-B
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ set -e
|
|||||||
init
|
init
|
||||||
|
|
||||||
generate_certs_for testserver
|
generate_certs_for testserver
|
||||||
add_user testserver user secretpassword
|
add_user user@testserver secretpassword
|
||||||
add_user testserver someone secretpassword
|
add_user someone@testserver secretpassword
|
||||||
add_user testserver blockme secretpassword
|
add_user blockme@testserver secretpassword
|
||||||
|
|
||||||
mkdir -p .logs
|
mkdir -p .logs
|
||||||
chasquid -v=2 --log_dir=.logs --config_dir=config &
|
chasquid -v=2 --log_dir=.logs --config_dir=config &
|
||||||
@@ -23,14 +23,12 @@ wait_for_file .mail/someone@testserver
|
|||||||
mail_diff content .mail/someone@testserver
|
mail_diff content .mail/someone@testserver
|
||||||
|
|
||||||
if ! grep -q "X-Post-Data: success" .mail/someone@testserver; then
|
if ! grep -q "X-Post-Data: success" .mail/someone@testserver; then
|
||||||
echo "missing X-Post-Data header"
|
fail "missing X-Post-Data header"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
function check() {
|
function check() {
|
||||||
if ! grep -q "$1" .data/post-data.out; then
|
if ! grep -q "$1" .data/post-data.out; then
|
||||||
echo missing: $1
|
fail "missing: $1"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,8 +46,7 @@ check "REMOTE_ADDR="
|
|||||||
|
|
||||||
# Check that a failure in the script results in failing delivery.
|
# Check that a failure in the script results in failing delivery.
|
||||||
if run_msmtp blockme@testserver < content 2>/dev/null; then
|
if run_msmtp blockme@testserver < content 2>/dev/null; then
|
||||||
echo "ERROR: hook did not block email as expected"
|
fail "ERROR: hook did not block email as expected"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check that the bad hooks don't prevent delivery.
|
# Check that the bad hooks don't prevent delivery.
|
||||||
|
|||||||
@@ -40,11 +40,12 @@ function chasquid() {
|
|||||||
|
|
||||||
function add_user() {
|
function add_user() {
|
||||||
CONFDIR="${CONFDIR:-config}"
|
CONFDIR="${CONFDIR:-config}"
|
||||||
mkdir -p "${CONFDIR}/domains/${1}/"
|
DOMAIN=$(echo $1 | cut -d @ -f 2)
|
||||||
|
mkdir -p "${CONFDIR}/domains/$DOMAIN/"
|
||||||
go run ${TBASE}/../../cmd/chasquid-util/chasquid-util.go \
|
go run ${TBASE}/../../cmd/chasquid-util/chasquid-util.go \
|
||||||
-C "${CONFDIR}" \
|
-C "${CONFDIR}" \
|
||||||
user-add "$2@$1" \
|
user-add "$1" \
|
||||||
--password "${3}" \
|
--password "$2" \
|
||||||
>> .add_user_logs
|
>> .add_user_logs
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,11 +66,17 @@ function mail_diff() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function success() {
|
function success() {
|
||||||
echo "SUCCESS"
|
echo success
|
||||||
}
|
}
|
||||||
|
|
||||||
function skip() {
|
function skip() {
|
||||||
echo "SKIPPED" $*
|
echo skipped: $*
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
function fail() {
|
||||||
|
echo FAILED: $*
|
||||||
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Wait until there's something listening on the given port.
|
# Wait until there's something listening on the given port.
|
||||||
@@ -103,8 +110,7 @@ function generate_certs_for() {
|
|||||||
function skip_if_python_is_too_old() {
|
function skip_if_python_is_too_old() {
|
||||||
# We need Python >= 3.5 to be able to use SMTPUTF8.
|
# We need Python >= 3.5 to be able to use SMTPUTF8.
|
||||||
check='import sys; sys.exit(0 if sys.version_info >= (3, 5) else 1)'
|
check='import sys; sys.exit(0 if sys.version_info >= (3, 5) else 1)'
|
||||||
if ! python3 -c "${check}"; then
|
if ! python3 -c "${check}" > /dev/null 2>&1; then
|
||||||
skip "python3 >= 3.5 not available"
|
skip "python3 >= 3.5 not available"
|
||||||
exit 0
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user