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:
@@ -153,7 +153,7 @@ func (s *Server) InitDomainInfo(dir string) *domaininfo.DB {
|
||||
func (s *Server) InitQueue(path string, localC, remoteC courier.Courier) {
|
||||
q, err := queue.New(path, s.localDomains, s.aliasesR, localC, remoteC)
|
||||
if err != nil {
|
||||
log.Fatalf("Error initializing queue: %v:", err)
|
||||
log.Fatalf("Error initializing queue: %v", err)
|
||||
}
|
||||
|
||||
err = q.Load()
|
||||
|
||||
@@ -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
1
test/t-20-bad_configs/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!.expected-error
|
||||
1
test/t-20-bad_configs/c-01-empty/.expected-error
Normal file
1
test/t-20-bad_configs/c-01-empty/.expected-error
Normal file
@@ -0,0 +1 @@
|
||||
open c-01-empty/chasquid.conf: no such file or directory
|
||||
@@ -0,0 +1 @@
|
||||
open certs/: no such file or directory
|
||||
@@ -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"
|
||||
1
test/t-20-bad_configs/c-03-no_certs/.expected-error
Normal file
1
test/t-20-bad_configs/c-03-no_certs/.expected-error
Normal file
@@ -0,0 +1 @@
|
||||
At least one valid certificate is needed
|
||||
9
test/t-20-bad_configs/c-03-no_certs/chasquid.conf
Normal file
9
test/t-20-bad_configs/c-03-no_certs/chasquid.conf
Normal 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"
|
||||
26
test/t-20-bad_configs/c-03-no_certs/domains/testserver/users
Normal file
26
test/t-20-bad_configs/c-03-no_certs/domains/testserver/users
Normal 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
1
test/t-20-bad_configs/c-04-no_cert_dirs/.expected-error
Normal file
1
test/t-20-bad_configs/c-04-no_cert_dirs/.expected-error
Normal file
@@ -0,0 +1 @@
|
||||
No entries found in "certs/"
|
||||
9
test/t-20-bad_configs/c-04-no_cert_dirs/chasquid.conf
Normal file
9
test/t-20-bad_configs/c-04-no_cert_dirs/chasquid.conf
Normal 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"
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
1
test/t-20-bad_configs/c-05-no_addrs/.expected-error
Normal file
1
test/t-20-bad_configs/c-05-no_addrs/.expected-error
Normal file
@@ -0,0 +1 @@
|
||||
No address to listen on
|
||||
5
test/t-20-bad_configs/c-05-no_addrs/chasquid.conf
Normal file
5
test/t-20-bad_configs/c-05-no_addrs/chasquid.conf
Normal 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"
|
||||
26
test/t-20-bad_configs/c-05-no_addrs/domains/testserver/users
Normal file
26
test/t-20-bad_configs/c-05-no_addrs/domains/testserver/users
Normal 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
1
test/t-20-bad_configs/c-06-bad_maillog/.expected-error
Normal file
1
test/t-20-bad_configs/c-06-bad_maillog/.expected-error
Normal file
@@ -0,0 +1 @@
|
||||
Error opening mail log: open /sys/bad-dir/mail_log: no such file or directory
|
||||
11
test/t-20-bad_configs/c-06-bad_maillog/chasquid.conf
Normal file
11
test/t-20-bad_configs/c-06-bad_maillog/chasquid.conf
Normal 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"
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Error opening domain info database: mkdir ../data-c-07-bad_domain_info/domaininfo: not a directory
|
||||
9
test/t-20-bad_configs/c-07-bad_domain_info/chasquid.conf
Normal file
9
test/t-20-bad_configs/c-07-bad_domain_info/chasquid.conf
Normal 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"
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
1
test/t-20-bad_configs/c-08-bad_sts_cache/.expected-error
Normal file
1
test/t-20-bad_configs/c-08-bad_sts_cache/.expected-error
Normal file
@@ -0,0 +1 @@
|
||||
Failed to initialize STS cache: mkdir ../data-c-08-bad_sts_cache/sts-cache: not a directory
|
||||
9
test/t-20-bad_configs/c-08-bad_sts_cache/chasquid.conf
Normal file
9
test/t-20-bad_configs/c-08-bad_sts_cache/chasquid.conf
Normal 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"
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
1
test/t-20-bad_configs/c-09-bad_queue_dir/.expected-error
Normal file
1
test/t-20-bad_configs/c-09-bad_queue_dir/.expected-error
Normal file
@@ -0,0 +1 @@
|
||||
Error initializing queue: mkdir ../data-c-09-bad_queue_dir/queue: not a directory
|
||||
9
test/t-20-bad_configs/c-09-bad_queue_dir/chasquid.conf
Normal file
9
test/t-20-bad_configs/c-09-bad_queue_dir/chasquid.conf
Normal 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"
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
This is a file, not a directory as expected
|
||||
1
test/t-20-bad_configs/data-c-08-bad_sts_cache/sts-cache
Normal file
1
test/t-20-bad_configs/data-c-08-bad_sts_cache/sts-cache
Normal file
@@ -0,0 +1 @@
|
||||
This is a file, not a directory as expected
|
||||
1
test/t-20-bad_configs/data-c-09-bad_queue_dir/queue
Normal file
1
test/t-20-bad_configs/data-c-09-bad_queue_dir/queue
Normal file
@@ -0,0 +1 @@
|
||||
This is a file, not a directory as expected
|
||||
48
test/t-20-bad_configs/run.sh
Executable file
48
test/t-20-bad_configs/run.sh
Executable 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
|
||||
Reference in New Issue
Block a user