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

chasquid-util: Move tests to chamuyero scripts

We already use chamuyero scripts for some of chasquid-util's tests, this
patch moves most of the rest too, for consistency.
This commit is contained in:
Alberto Bertogli
2024-03-06 23:04:21 +00:00
parent ac2b037f33
commit 06aea2f786
5 changed files with 101 additions and 52 deletions

View File

@@ -16,7 +16,6 @@ import (
"blitiri.com.ar/go/chasquid/internal/envelope"
"blitiri.com.ar/go/chasquid/internal/localrpc"
"blitiri.com.ar/go/chasquid/internal/normalize"
"blitiri.com.ar/go/chasquid/internal/trace"
"blitiri.com.ar/go/chasquid/internal/userdb"
"golang.org/x/term"
"google.golang.org/protobuf/encoding/prototext"
@@ -284,10 +283,6 @@ func domaininfoRemove() {
}
}
func allUsersExist(tr *trace.Trace, user, domain string) (bool, error) {
return true, nil
}
// parseArgs parses the command line arguments, and returns a map.
//
// Arguments starting with "-" will be parsed as key-value pairs, and

View File

@@ -29,40 +29,11 @@ rm -f .config/chasquid.conf
echo 'data_dir: ".data"' >> .config/chasquid.conf
if ! r print-config > /dev/null; then
echo print-config failed
exit 1
fail print-config
fi
if ! r user-add user@domain --password=passwd > /dev/null; then
echo user-add failed
exit 1
fi
check_userdb
if ! r user-add denied@domain --receive_only > /dev/null; then
echo user-add --receive_only failed
exit 1
fi
check_userdb
if r user-add xxx@domain --password=passwd --receive_only > /dev/null 2>&1; then
echo user-add --password --receive_only worked
exit 1
fi
if ! r authenticate user@domain --password=passwd > /dev/null; then
echo authenticate failed
exit 1
fi
if r authenticate user@domain --password=abcd > /dev/null 2>&1; then
echo authenticate with bad password worked
exit 1
fi
if r authenticate denied@domain --password=abcd > /dev/null 2>&1; then
echo authenticate on a no-submission user worked
exit 1
if ! r user-add interactive@domain --password=passwd > /dev/null; then
fail user-add
fi
# Interactive authentication.
@@ -71,27 +42,14 @@ fi
if hash script 2>/dev/null; then
if ! (echo passwd; echo passwd ) \
| script \
-qfec "./chasquid-util -C=.config authenticate user@domain" \
-qfec "./chasquid-util -C=.config authenticate interactive@domain" \
".script-out" \
| grep -q "Authentication succeeded";
then
echo interactive authenticate failed
exit 1
fail interactive authentication
fi
fi
if ! r user-remove user@domain > /dev/null; then
echo user-remove failed
exit 1
fi
check_userdb
if r authenticate user@domain --password=passwd > /dev/null 2>&1; then
echo authenticate for removed user worked
exit 1
fi
C=$(r print-config | grep hostname)
if ! ( echo "$C" | grep -E -q "hostname:.*\"$HOSTNAME\"" ); then
echo print-config failed

View File

@@ -0,0 +1,21 @@
# Unknown argument.
c = ./chasquid-util --configdir=.config blahrarghar
c <- Unknown argument "blahrarghar"
c wait 1
c = ./chasquid-util --configdir=.nonono check-userdb
c <- Error loading database: open .nonono/domains//users: no such file or directory
c wait 1
c = ./chasquid-util --configdir=.nonono print-config
c <- Error loading config: failed to read config at ".nonono/chasquid.conf": open .nonono/chasquid.conf: no such file or directory
c wait 1
c = ./chasquid-util --configdir=.nonono aliases-resolve email@addr
c <- Error loading config: failed to read config at ".nonono/chasquid.conf": open .nonono/chasquid.conf: no such file or directory
c wait 1
c = ./chasquid-util --configdir=.nonono domaininfo-remove domain
c <- Error loading config: failed to read config at ".nonono/chasquid.conf": open .nonono/chasquid.conf: no such file or directory
c wait 1

View File

@@ -0,0 +1,24 @@
# --help
c = ./chasquid-util --configdir=.config --help
c <-
c <- Usage:
c wait 0
# print-config
c = ./chasquid-util -C=.config print-config
c <~ hostname: +".*"
c <~ max_data_size_mb: +50
c <~ smtp_address: +"systemd"
c <~ submission_address: +"systemd"
c <~ submission_over_tls_address: +"systemd"
c <~ mail_delivery_agent_bin: +"maildrop"
c <~ mail_delivery_agent_args: +"-f"
c <~ mail_delivery_agent_args: +"%from%"
c <~ mail_delivery_agent_args: +"-d"
c <~ mail_delivery_agent_args: +"%to_user%"
c <~ data_dir: +".data"
c <~ suffix_separators: +"\+"
c <~ drop_characters: +"\."
c <~ mail_log_path: +"<syslog>"
c wait 0

View File

@@ -0,0 +1,51 @@
# Tests for user management commands.
c = ./chasquid-util -C=.config user-add user@domain --password=passwd
c <- Added user
c wait 0
c = ./chasquid-util -C=.config check-userdb domain
c <- Database loaded
c wait 0
c = ./chasquid-util -C=.config user-add receive@domain --receive_only
c <- Added user
c wait 0
c = ./chasquid-util -C=.config user-add xxx@domain \
--password=passwd --receive_only
c <- Cannot specify both --receive_only and --password
c wait 1
c = ./chasquid-util -C=.config authenticate user@domain --password=passwd
c <- Authentication succeeded
c wait 0
c = ./chasquid-util -C=.config authenticate user@domain --password=abcd
c <- Authentication failed
c wait 1
# Try to authenticate on the receive-only user
c = ./chasquid-util -C=.config authenticate receive@domain --password=passwd
c <- Authentication failed
c wait 1
# Remove a user, then check authentication fails.
c = ./chasquid-util -C=.config user-remove user@domain
c <- Removed user
c wait 0
c = ./chasquid-util -C=.config authenticate user@domain --password=passwd
c <- Authentication failed
c wait 1
c = ./chasquid-util -C=.config user-remove unknown@domain
c <- Unknown user
c wait 1
c = ./chasquid-util -C=.config user-add badarg
c <- Domain missing, username should be of the form 'user@domain'
c wait 1
c = ./chasquid-util -C=.config user-add "bad user@domain"
c <- Error normalizing user: precis: disallowed rune encountered
c wait 1