74 lines
2.3 KiB
Bash
Executable File
74 lines
2.3 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
PASSWORD=${BONGO_TEST_PASSWORD:-}
|
|
USERS=${BONGO_TEST_USERS:-"stq01a stq01b stqqueue stqquota protocoltest"}
|
|
LAYOUT_USERS=${BONGO_TEST_LAYOUT_USERS:-"stq01a stq01b"}
|
|
ADMIN=${BONGO_TEST_ADMIN:-/usr/bin/bongo-admin}
|
|
STORETOOL=${BONGO_TEST_STORETOOL:-/usr/bin/bongo-storetool}
|
|
STATE_DIR=${BONGO_TEST_USER_STATE_DIR:-/var/lib/bongo/users}
|
|
|
|
if [ "${BONGO_ALLOW_LIVE_USER_TEST:-}" != 1 ]; then
|
|
echo "set BONGO_ALLOW_LIVE_USER_TEST=1 for the disposable host" >&2
|
|
exit 2
|
|
fi
|
|
if [ -z "$PASSWORD" ]; then
|
|
echo "set BONGO_TEST_PASSWORD to a disposable password" >&2
|
|
exit 2
|
|
fi
|
|
|
|
for user in $USERS; do
|
|
if sudo -n "$ADMIN" user info "$user" >/dev/null 2>&1; then
|
|
echo "KEEP existing test user $user"
|
|
else
|
|
sudo -n "$ADMIN" user add "$user"
|
|
fi
|
|
printf '%s\n%s\n' "$PASSWORD" "$PASSWORD" |
|
|
sudo -n "$ADMIN" __user-password-stdin "$user" >/dev/null
|
|
echo "PASS test password set for $user"
|
|
done
|
|
|
|
expected_mail='/mail/INBOX /mail/drafts /mail/archives /mail/sent /mail/trash /mail/junk'
|
|
expected_addressbook='/addressbook/personal /addressbook/collected'
|
|
expected_calendars='/calendars/personal'
|
|
store_inodes=
|
|
|
|
check_collection()
|
|
{
|
|
user=$1
|
|
collection=$2
|
|
expected=$3
|
|
output=$(sudo -n -u bongo "$STORETOOL" -u "$user" -p "$PASSWORD" \
|
|
document-list "$collection")
|
|
for path in $expected; do
|
|
if ! printf '%s\n' "$output" | awk '{ print $3 }' | grep -Fqx "$path"; then
|
|
echo "$user is missing standard collection $path" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
}
|
|
|
|
for user in $LAYOUT_USERS; do
|
|
check_collection "$user" /mail "$expected_mail"
|
|
check_collection "$user" /addressbook "$expected_addressbook"
|
|
check_collection "$user" /calendars "$expected_calendars"
|
|
|
|
state=$(sudo -n /usr/bin/stat -c '%a %U:%G %s %i' \
|
|
"$STATE_DIR/$user/store.db")
|
|
set -- $state
|
|
if [ "$1" != 600 ] || [ "$2" != bongo:bongo ] || [ "$3" -le 0 ]; then
|
|
echo "unsafe or empty Store database for $user: $state" >&2
|
|
exit 1
|
|
fi
|
|
case " $store_inodes " in
|
|
*" $4 "*)
|
|
echo "Store database inode $4 is shared by multiple users" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
store_inodes="$store_inodes $4"
|
|
echo "PASS $user has an independent Store and complete standard layout"
|
|
done
|
|
|
|
echo "PASS disposable test users are provisioned: $USERS"
|