2018-01-24 11:18:46 +01:00
|
|
|
#!/bin/bash
|
|
|
|
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
|
|
|
|
# ex: ts=8 sw=4 sts=4 et filetype=sh
|
|
|
|
set -e
|
|
|
|
TEST_DESCRIPTION="Sysuser-related tests"
|
|
|
|
|
|
|
|
. $TEST_BASE_DIR/test-functions
|
|
|
|
|
|
|
|
test_setup() {
|
|
|
|
mkdir -p $TESTDIR/etc $TESTDIR/usr/lib/sysusers.d $TESTDIR/tmp
|
|
|
|
}
|
|
|
|
|
2018-02-01 05:47:50 +01:00
|
|
|
preprocess() {
|
|
|
|
in="$1"
|
|
|
|
|
|
|
|
# see meson.build how to extract this. gcc -E was used before to
|
|
|
|
# get this value from config.h, however the autopkgtest fails with
|
|
|
|
# it
|
|
|
|
SYSTEM_UID_MAX=$(awk 'BEGIN { uid=999 } /^\s*SYS_UID_MAX\s+/ { uid=$2 } END { print uid }' /etc/login.defs)
|
|
|
|
sed "s/SYSTEM_UID_MAX/${SYSTEM_UID_MAX}/g" "$in"
|
|
|
|
}
|
|
|
|
|
2018-01-24 11:18:46 +01:00
|
|
|
test_run() {
|
2018-01-25 12:50:14 +01:00
|
|
|
# ensure our build of systemd-sysusers is run
|
|
|
|
PATH=${BUILD_DIR}:$PATH
|
|
|
|
|
|
|
|
# happy tests
|
2018-01-24 11:18:46 +01:00
|
|
|
for f in test-*.input; do
|
2018-01-25 12:50:14 +01:00
|
|
|
echo "*** Running $f"
|
2018-01-24 11:18:46 +01:00
|
|
|
rm -f $TESTDIR/etc/*
|
|
|
|
cp $f $TESTDIR/usr/lib/sysusers.d/test.conf
|
2018-01-25 12:50:14 +01:00
|
|
|
systemd-sysusers --root=$TESTDIR
|
|
|
|
|
2018-02-01 05:47:50 +01:00
|
|
|
if ! diff -u $TESTDIR/etc/passwd <(preprocess ${f%.*}.expected-passwd); then
|
2018-01-24 11:18:46 +01:00
|
|
|
echo "**** Unexpected output for $f"
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-02-01 05:47:50 +01:00
|
|
|
if ! diff -u $TESTDIR/etc/group <(preprocess ${f%.*}.expected-group); then
|
2018-01-24 11:18:46 +01:00
|
|
|
echo "**** Unexpected output for $f"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
2018-01-25 12:50:14 +01:00
|
|
|
|
|
|
|
# tests for error conditions
|
|
|
|
for f in unhappy-*.input; do
|
|
|
|
echo "*** Running test $f"
|
|
|
|
rm -f $TESTDIR/etc/*
|
|
|
|
cp $f $TESTDIR/usr/lib/sysusers.d/test.conf
|
|
|
|
systemd-sysusers --root=$TESTDIR 2> /dev/null
|
|
|
|
journalctl -t systemd-sysusers -o cat | tail -n1 > $TESTDIR/tmp/err
|
|
|
|
if ! diff -u $TESTDIR/tmp/err ${f%.*}.expected-err; then
|
|
|
|
echo "**** Unexpected error output for $f"
|
|
|
|
cat $TESTDIR/tmp/err
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
2018-01-24 11:18:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
do_test "$@"
|