mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-18 14:47:03 +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:
@@ -16,7 +16,6 @@ import (
|
|||||||
"blitiri.com.ar/go/chasquid/internal/envelope"
|
"blitiri.com.ar/go/chasquid/internal/envelope"
|
||||||
"blitiri.com.ar/go/chasquid/internal/localrpc"
|
"blitiri.com.ar/go/chasquid/internal/localrpc"
|
||||||
"blitiri.com.ar/go/chasquid/internal/normalize"
|
"blitiri.com.ar/go/chasquid/internal/normalize"
|
||||||
"blitiri.com.ar/go/chasquid/internal/trace"
|
|
||||||
"blitiri.com.ar/go/chasquid/internal/userdb"
|
"blitiri.com.ar/go/chasquid/internal/userdb"
|
||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
"google.golang.org/protobuf/encoding/prototext"
|
"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.
|
// parseArgs parses the command line arguments, and returns a map.
|
||||||
//
|
//
|
||||||
// Arguments starting with "-" will be parsed as key-value pairs, and
|
// Arguments starting with "-" will be parsed as key-value pairs, and
|
||||||
|
|||||||
@@ -29,40 +29,11 @@ rm -f .config/chasquid.conf
|
|||||||
echo 'data_dir: ".data"' >> .config/chasquid.conf
|
echo 'data_dir: ".data"' >> .config/chasquid.conf
|
||||||
|
|
||||||
if ! r print-config > /dev/null; then
|
if ! r print-config > /dev/null; then
|
||||||
echo print-config failed
|
fail print-config
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! r user-add user@domain --password=passwd > /dev/null; then
|
if ! r user-add interactive@domain --password=passwd > /dev/null; then
|
||||||
echo user-add failed
|
fail user-add
|
||||||
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
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Interactive authentication.
|
# Interactive authentication.
|
||||||
@@ -71,27 +42,14 @@ fi
|
|||||||
if hash script 2>/dev/null; then
|
if hash script 2>/dev/null; then
|
||||||
if ! (echo passwd; echo passwd ) \
|
if ! (echo passwd; echo passwd ) \
|
||||||
| script \
|
| script \
|
||||||
-qfec "./chasquid-util -C=.config authenticate user@domain" \
|
-qfec "./chasquid-util -C=.config authenticate interactive@domain" \
|
||||||
".script-out" \
|
".script-out" \
|
||||||
| grep -q "Authentication succeeded";
|
| grep -q "Authentication succeeded";
|
||||||
then
|
then
|
||||||
echo interactive authenticate failed
|
fail interactive authentication
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
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)
|
C=$(r print-config | grep hostname)
|
||||||
if ! ( echo "$C" | grep -E -q "hostname:.*\"$HOSTNAME\"" ); then
|
if ! ( echo "$C" | grep -E -q "hostname:.*\"$HOSTNAME\"" ); then
|
||||||
echo print-config failed
|
echo print-config failed
|
||||||
|
|||||||
21
cmd/chasquid-util/test_bad_args.cmy
Normal file
21
cmd/chasquid-util/test_bad_args.cmy
Normal 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
|
||||||
|
|
||||||
24
cmd/chasquid-util/test_general.cmy
Normal file
24
cmd/chasquid-util/test_general.cmy
Normal 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
|
||||||
|
|
||||||
51
cmd/chasquid-util/test_users.cmy
Normal file
51
cmd/chasquid-util/test_users.cmy
Normal 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
|
||||||
Reference in New Issue
Block a user