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

test: Add a set of tests for handling bad/invalid configs

This patch adds a set of tests to validate chasquid's handling of bad
and invalid configurations, to make sure we fail as expected.
This commit is contained in:
Alberto Bertogli
2023-05-16 11:47:31 +01:00
parent 0c9d1536db
commit 01a6d088e2
32 changed files with 314 additions and 7 deletions

View File

@@ -12,12 +12,6 @@ if ! chasquid --version > /dev/null; then
fail "chasquid --version failed"
fi
# This should fail, as it has no certificates.
rm -f config/certs/testserver/*.pem
if chasquid -v=2 --logfile=.logs/chasquid.log --config_dir=config; then
fail "chasquid should not start without certificates"
fi
generate_certs_for testserver
chasquid-util-user-add user@testserver secretpassword
chasquid-util-user-add someone@testserver secretpassword

1
test/t-20-bad_configs/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
!.expected-error

View File

@@ -0,0 +1 @@
open c-01-empty/chasquid.conf: no such file or directory

View File

@@ -0,0 +1 @@
open certs/: no such file or directory

View File

@@ -0,0 +1,9 @@
smtp_address: ":1025"
submission_address: ":1587"
submission_over_tls_address: ":1465"
mail_delivery_agent_bin: "test-mda"
mail_delivery_agent_args: "%to%"
data_dir: "../.data"
mail_log_path: "../.logs/mail_log"

View File

@@ -0,0 +1 @@
At least one valid certificate is needed

View File

@@ -0,0 +1,9 @@
smtp_address: ":1025"
submission_address: ":1587"
submission_over_tls_address: ":1465"
mail_delivery_agent_bin: "test-mda"
mail_delivery_agent_args: "%to%"
data_dir: "../.data"
mail_log_path: "../.logs/mail_log"

View File

@@ -0,0 +1,26 @@
users: {
key: "someone"
value: {
scrypt: {
logN: 14
r: 8
p: 1
keyLen: 32
salt: "J\x01\xed7]\x02\n\xe9;z[\x8d˱\x10\xc1"
encrypted: "\xa50宴\xcbb\xc1!r]K\xd1yI\xa2\x99\x8d\xdaQx\x8e69\xac\xf4$\x01\x11\x03\x8d\x10"
}
}
}
users: {
key: "user"
value: {
scrypt: {
logN: 14
r: 8
p: 1
keyLen: 32
salt: "\n\xc6\x1c\x8f\xb2\x0c\x15p\x8d\xa1\xc3\x05U6\xdb\xc4"
encrypted: "\xc3\xe6B2\x84W\x1a\nq{\x07\xe0\x9c\x854\n\xac\xbc\xb7\x9c\x86Kyk\x8dj\x16\x1a\x8c$*N"
}
}
}

View File

@@ -0,0 +1 @@
No entries found in "certs/"

View File

@@ -0,0 +1,9 @@
smtp_address: ":1025"
submission_address: ":1587"
submission_over_tls_address: ":1465"
mail_delivery_agent_bin: "test-mda"
mail_delivery_agent_args: "%to%"
data_dir: "../.data"
mail_log_path: "../.logs/mail_log"

View File

@@ -0,0 +1,26 @@
users: {
key: "someone"
value: {
scrypt: {
logN: 14
r: 8
p: 1
keyLen: 32
salt: "J\x01\xed7]\x02\n\xe9;z[\x8d˱\x10\xc1"
encrypted: "\xa50宴\xcbb\xc1!r]K\xd1yI\xa2\x99\x8d\xdaQx\x8e69\xac\xf4$\x01\x11\x03\x8d\x10"
}
}
}
users: {
key: "user"
value: {
scrypt: {
logN: 14
r: 8
p: 1
keyLen: 32
salt: "\n\xc6\x1c\x8f\xb2\x0c\x15p\x8d\xa1\xc3\x05U6\xdb\xc4"
encrypted: "\xc3\xe6B2\x84W\x1a\nq{\x07\xe0\x9c\x854\n\xac\xbc\xb7\x9c\x86Kyk\x8dj\x16\x1a\x8c$*N"
}
}
}

View File

@@ -0,0 +1 @@
No address to listen on

View File

@@ -0,0 +1,5 @@
mail_delivery_agent_bin: "test-mda"
mail_delivery_agent_args: "%to%"
data_dir: "../.data"
mail_log_path: "../.logs/mail_log"

View File

@@ -0,0 +1,26 @@
users: {
key: "someone"
value: {
scrypt: {
logN: 14
r: 8
p: 1
keyLen: 32
salt: "J\x01\xed7]\x02\n\xe9;z[\x8d˱\x10\xc1"
encrypted: "\xa50宴\xcbb\xc1!r]K\xd1yI\xa2\x99\x8d\xdaQx\x8e69\xac\xf4$\x01\x11\x03\x8d\x10"
}
}
}
users: {
key: "user"
value: {
scrypt: {
logN: 14
r: 8
p: 1
keyLen: 32
salt: "\n\xc6\x1c\x8f\xb2\x0c\x15p\x8d\xa1\xc3\x05U6\xdb\xc4"
encrypted: "\xc3\xe6B2\x84W\x1a\nq{\x07\xe0\x9c\x854\n\xac\xbc\xb7\x9c\x86Kyk\x8dj\x16\x1a\x8c$*N"
}
}
}

View File

@@ -0,0 +1 @@
Error opening mail log: open /sys/bad-dir/mail_log: no such file or directory

View File

@@ -0,0 +1,11 @@
smtp_address: ":1025"
submission_address: ":1587"
submission_over_tls_address: ":1465"
mail_delivery_agent_bin: "test-mda"
mail_delivery_agent_args: "%to%"
data_dir: "../.data"
# This is expected to be invalid, and impossible to mkdir.
mail_log_path: "/sys/bad-dir/mail_log"

View File

@@ -0,0 +1,26 @@
users: {
key: "someone"
value: {
scrypt: {
logN: 14
r: 8
p: 1
keyLen: 32
salt: "J\x01\xed7]\x02\n\xe9;z[\x8d˱\x10\xc1"
encrypted: "\xa50宴\xcbb\xc1!r]K\xd1yI\xa2\x99\x8d\xdaQx\x8e69\xac\xf4$\x01\x11\x03\x8d\x10"
}
}
}
users: {
key: "user"
value: {
scrypt: {
logN: 14
r: 8
p: 1
keyLen: 32
salt: "\n\xc6\x1c\x8f\xb2\x0c\x15p\x8d\xa1\xc3\x05U6\xdb\xc4"
encrypted: "\xc3\xe6B2\x84W\x1a\nq{\x07\xe0\x9c\x854\n\xac\xbc\xb7\x9c\x86Kyk\x8dj\x16\x1a\x8c$*N"
}
}
}

View File

@@ -0,0 +1 @@
Error opening domain info database: mkdir ../data-c-07-bad_domain_info/domaininfo: not a directory

View File

@@ -0,0 +1,9 @@
smtp_address: ":1025"
submission_address: ":1587"
submission_over_tls_address: ":1465"
mail_delivery_agent_bin: "test-mda"
mail_delivery_agent_args: "%to%"
data_dir: "../data-c-07-bad_domain_info"
mail_log_path: "../.logs/mail_log"

View File

@@ -0,0 +1,26 @@
users: {
key: "someone"
value: {
scrypt: {
logN: 14
r: 8
p: 1
keyLen: 32
salt: "J\x01\xed7]\x02\n\xe9;z[\x8d˱\x10\xc1"
encrypted: "\xa50宴\xcbb\xc1!r]K\xd1yI\xa2\x99\x8d\xdaQx\x8e69\xac\xf4$\x01\x11\x03\x8d\x10"
}
}
}
users: {
key: "user"
value: {
scrypt: {
logN: 14
r: 8
p: 1
keyLen: 32
salt: "\n\xc6\x1c\x8f\xb2\x0c\x15p\x8d\xa1\xc3\x05U6\xdb\xc4"
encrypted: "\xc3\xe6B2\x84W\x1a\nq{\x07\xe0\x9c\x854\n\xac\xbc\xb7\x9c\x86Kyk\x8dj\x16\x1a\x8c$*N"
}
}
}

View File

@@ -0,0 +1 @@
Failed to initialize STS cache: mkdir ../data-c-08-bad_sts_cache/sts-cache: not a directory

View File

@@ -0,0 +1,9 @@
smtp_address: ":1025"
submission_address: ":1587"
submission_over_tls_address: ":1465"
mail_delivery_agent_bin: "test-mda"
mail_delivery_agent_args: "%to%"
data_dir: "../data-c-08-bad_sts_cache"
mail_log_path: "../.logs/mail_log"

View File

@@ -0,0 +1,26 @@
users: {
key: "someone"
value: {
scrypt: {
logN: 14
r: 8
p: 1
keyLen: 32
salt: "J\x01\xed7]\x02\n\xe9;z[\x8d˱\x10\xc1"
encrypted: "\xa50宴\xcbb\xc1!r]K\xd1yI\xa2\x99\x8d\xdaQx\x8e69\xac\xf4$\x01\x11\x03\x8d\x10"
}
}
}
users: {
key: "user"
value: {
scrypt: {
logN: 14
r: 8
p: 1
keyLen: 32
salt: "\n\xc6\x1c\x8f\xb2\x0c\x15p\x8d\xa1\xc3\x05U6\xdb\xc4"
encrypted: "\xc3\xe6B2\x84W\x1a\nq{\x07\xe0\x9c\x854\n\xac\xbc\xb7\x9c\x86Kyk\x8dj\x16\x1a\x8c$*N"
}
}
}

View File

@@ -0,0 +1 @@
Error initializing queue: mkdir ../data-c-09-bad_queue_dir/queue: not a directory

View File

@@ -0,0 +1,9 @@
smtp_address: ":1025"
submission_address: ":1587"
submission_over_tls_address: ":1465"
mail_delivery_agent_bin: "test-mda"
mail_delivery_agent_args: "%to%"
data_dir: "../data-c-09-bad_queue_dir"
mail_log_path: "../.logs/mail_log"

View File

@@ -0,0 +1,26 @@
users: {
key: "someone"
value: {
scrypt: {
logN: 14
r: 8
p: 1
keyLen: 32
salt: "J\x01\xed7]\x02\n\xe9;z[\x8d˱\x10\xc1"
encrypted: "\xa50宴\xcbb\xc1!r]K\xd1yI\xa2\x99\x8d\xdaQx\x8e69\xac\xf4$\x01\x11\x03\x8d\x10"
}
}
}
users: {
key: "user"
value: {
scrypt: {
logN: 14
r: 8
p: 1
keyLen: 32
salt: "\n\xc6\x1c\x8f\xb2\x0c\x15p\x8d\xa1\xc3\x05U6\xdb\xc4"
encrypted: "\xc3\xe6B2\x84W\x1a\nq{\x07\xe0\x9c\x854\n\xac\xbc\xb7\x9c\x86Kyk\x8dj\x16\x1a\x8c$*N"
}
}
}

View File

@@ -0,0 +1 @@
This is a file, not a directory as expected

View File

@@ -0,0 +1 @@
This is a file, not a directory as expected

View File

@@ -0,0 +1 @@
This is a file, not a directory as expected

48
test/t-20-bad_configs/run.sh Executable file
View File

@@ -0,0 +1,48 @@
#!/bin/bash
set -e
. "$(dirname "$0")/../util/lib.sh"
init
check_hostaliases
mkdir -p .logs
if chasquid --config_dir=doesnotexist > .chasquid-doesnotexist.out 2>&1; then
fail "chasquid should not start without a config"
fi
# Create this empty directory. We can't use a .keep file because that defeats
# the purpose of the test.
mkdir -p c-04-no_cert_dirs/certs/
# Generate certs for the tests that need them.
for i in c-05-no_addrs c-06-bad_maillog c-07-bad_domain_info \
c-08-bad_sts_cache c-09-bad_queue_dir ;
do
CONFDIR=$i/ generate_certs_for testserver
done
for i in c-*; do
if chasquid --config_dir="$i" > ".chasquid-$i.out" 2>&1; then
echo "$i failed; output:"
echo
cat ".chasquid-$i.out"
echo
fail "$i: chasquid should not start with this invalid config"
fi
# Test that they failed as expected, and not by chance/unrelated error.
if ! tail -n 1 ".chasquid-$i.out" \
| grep -q -E "$(cat "$i/.expected-error")"; then
echo "$i failed"
echo "expected last line to match:"
echo " '$(cat "$i/.expected-error")'"
echo "got last line:"
echo " '$(tail -n 1 ".chasquid-$i.out")'"
echo
fail "$i: chasquid did not fail as expected"
fi
done
success