git » chasquid » commit 06aea2f

chasquid-util: Move tests to chamuyero scripts

author Alberto Bertogli
2024-03-06 23:04:21 UTC
committer Alberto Bertogli
2024-03-07 23:07:37 UTC
parent ac2b037f332f867a165f2c8017e1a5d234910061

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.

cmd/chasquid-util/chasquid-util.go +0 -5
cmd/chasquid-util/test.sh +5 -47
cmd/chasquid-util/test_bad_args.cmy +21 -0
cmd/chasquid-util/test_general.cmy +24 -0
cmd/chasquid-util/test_users.cmy +51 -0

diff --git a/cmd/chasquid-util/chasquid-util.go b/cmd/chasquid-util/chasquid-util.go
index 36614d7..6f6ad64 100644
--- a/cmd/chasquid-util/chasquid-util.go
+++ b/cmd/chasquid-util/chasquid-util.go
@@ -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
diff --git a/cmd/chasquid-util/test.sh b/cmd/chasquid-util/test.sh
index fccca8a..30bb2f6 100755
--- a/cmd/chasquid-util/test.sh
+++ b/cmd/chasquid-util/test.sh
@@ -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
-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
+	fail print-config
 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
diff --git a/cmd/chasquid-util/test_bad_args.cmy b/cmd/chasquid-util/test_bad_args.cmy
new file mode 100644
index 0000000..1f9c81e
--- /dev/null
+++ b/cmd/chasquid-util/test_bad_args.cmy
@@ -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
+
diff --git a/cmd/chasquid-util/test_general.cmy b/cmd/chasquid-util/test_general.cmy
new file mode 100644
index 0000000..53d7414
--- /dev/null
+++ b/cmd/chasquid-util/test_general.cmy
@@ -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
+
diff --git a/cmd/chasquid-util/test_users.cmy b/cmd/chasquid-util/test_users.cmy
new file mode 100644
index 0000000..0786d0a
--- /dev/null
+++ b/cmd/chasquid-util/test_users.cmy
@@ -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