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

chasquid-util: Use server for aliases-resolve and domaininfo-remove

This patch makes chasquid-util's aliases-resolve and domaininfo-remove
commands talk to the chasquid server (via the new localrpc server).

For aliases-resolve, currently has fairly hacky logic which reimplements
a bunch of the servers', and is also incomplete because it does not
support hooks.

In this patch we fix that by having it talk to the server, where we get
authoritative responses and have no issues with aliases hooks. This
resolves https://github.com/albertito/chasquid/issues/18.

For domaininfo-remove, currently its implementation is also very hacky
since it manipulates files behind the servers' back and without even
using the internal library.

In this patch we fix that by doing the operation through the server,
avoiding the need for those hacks, and also remove the need to manually
reload the server afterwards.
This commit is contained in:
Alberto Bertogli
2023-07-29 22:49:50 +01:00
parent ddd1b6d96e
commit e6c6df457d
13 changed files with 147 additions and 72 deletions

View File

@@ -0,0 +1,6 @@
#!/bin/bash
# Wrapper so chamuyero scripts can invoke chasquid-util for testing.
# Run from the config directory because data_dir is relative.
cd config
go run ../../../cmd/chasquid-util/chasquid-util.go -C=. "$@"

View File

@@ -66,6 +66,16 @@ if run_msmtp nono@testserver < content 2> .logs/msmtp.out; then
echo "expected delivery to nono@ to fail, but succeeded"
fi
# Test chasquid-util's ability to do alias resolution talking to chasquid.
# We use chamuyero for convenience, so we can match the output exactly.
for i in *.cmy; do
if ! chamuyero "$i" > "$i.log" 2>&1 ; then
echo "$i failed, log follows"
cat "$i.log"
exit 1
fi
done
# Remove the hooks, leave a clean state.
rm -f config/hooks/alias-resolve

View File

@@ -0,0 +1,27 @@
# Resolve an unknown user.
c = ./chasquid-util.sh aliases-resolve anunknownuser@blah
c <- (email) anunknownuser@blah
c wait 0
# Resolve a known alias.
c = ./chasquid-util.sh aliases-resolve a.ñi_l-blah@testserver
c <- (email) azul@testserver
c <- (email) índigo@testserver
c wait 0
# Resolve a pipe alias.
c = ./chasquid-util.sh aliases-resolve tubo@testserver
c <- (pipe) writemailto ../.data/pipe_alias_worked
c wait 0
# Resolve aliases that are exposed via the hook.
c = ./chasquid-util.sh aliases-resolve vicuña@testserver
c <- (email) jose@testserver
c <- (email) juan@testserver
c wait 0
# The hook for this alias exits with error.
c = ./chasquid-util.sh aliases-resolve roto@testserver
c <- Error resolving: exit status 1
c wait 1

View File

@@ -62,5 +62,19 @@ then
fail "B is missing the domaininfo for srv-a"
fi
# In A, remove domaininfo data about srv-B.
# Check that it was cleared successfully.
CONFDIR=A chasquid-util domaininfo-remove srv-b
if grep -q 'outgoing_sec_level:' ".data-A/domaininfo/s:srv-b";
then
fail "Error clearing A's domaininfo about srv-b"
fi
# While at it, check that a domaininfo-remove for an unknown domain results in
# an error.
if CONFDIR=A chasquid-util domaininfo-remove srv-X > .cdu-di-r-x.log 2>&1; then
fail "Expected error on chasquid-util domaininfo-remove srv-X"
fi
success

View File

@@ -43,6 +43,17 @@ function chasquid() {
"${TBASE}/../../chasquid" "$@"
}
function chasquid-util() {
# Run chasquid-util from inside the config dir, since in our tests
# data_dir is relative to the config.
CONFDIR="${CONFDIR:-config}"
( cd "$CONFDIR" && \
go run "${TBASE}/../../cmd/chasquid-util/chasquid-util.go" \
-C=. \
"$@" \
)
}
# Add a user with chasquid-util. Because this is somewhat cryptographically
# intensive, it can slow down the tests significantly, so most of the time we
# use the simpler add_user (below) for testing purposes.
@@ -50,8 +61,7 @@ function chasquid-util-user-add() {
CONFDIR="${CONFDIR:-config}"
DOMAIN=$(echo "$1" | cut -d @ -f 2)
mkdir -p "${CONFDIR}/domains/$DOMAIN/"
go run "${TBASE}/../../cmd/chasquid-util/chasquid-util.go" \
-C="${CONFDIR}" \
chasquid-util \
user-add "$1" \
--password="$2" \
>> .add_user_logs