2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
5 TEST_DESCRIPTION
="Sysuser-related tests"
7 .
$TEST_BASE_DIR/test-functions
10 mkdir
-p $TESTDIR/etc
/sysusers.d
$TESTDIR/usr
/lib
/sysusers.d
$TESTDIR/tmp
14 rm -f $TESTDIR/etc
/*{passwd
,group
,shadow
}
15 for i
in $1.initial-
{passwd
,group
,shadow
}; do
16 test -f $i && cp $i $TESTDIR/etc
/${i#*.initial-}
23 # see meson.build how to extract this. gcc -E was used before to
24 # get this value from config.h, however the autopkgtest fails with
26 SYSTEM_UID_MAX
=$
(awk 'BEGIN { uid=999 } /^\s*SYS_UID_MAX\s+/ { uid=$2 } END { print uid }' /etc
/login.defs
)
27 sed "s/SYSTEM_UID_MAX/${SYSTEM_UID_MAX}/g" "$in"
31 if ! diff -u $TESTDIR/etc
/passwd
<(preprocess
${1%.*}.expected-passwd
); then
32 echo "**** Unexpected output for $f"
36 if ! diff -u $TESTDIR/etc
/group
<(preprocess
${1%.*}.expected-group
); then
37 echo "**** Unexpected output for $f $2"
43 # ensure our build of systemd-sysusers is run
44 PATH
=${BUILD_DIR}:$PATH
46 rm -f $TESTDIR/etc
/sysusers.d
/* $TESTDIR/usr
/lib
/sysusers.d
/*
49 for f
in test-
*.input
; do
51 prepare_testdir
${f%.input}
52 cp $f $TESTDIR/usr
/lib
/sysusers.d
/test.conf
53 systemd-sysusers
--root=$TESTDIR
58 for f
in test-
*.input
; do
59 echo "*** Running $f on stdin"
60 prepare_testdir
${f%.input}
61 touch $TESTDIR/etc
/sysusers.d
/test.conf
62 cat $f | systemd-sysusers
--root=$TESTDIR -
67 for f
in test-
*.input
; do
68 echo "*** Running $f on stdin with --replace"
69 prepare_testdir
${f%.input}
70 touch $TESTDIR/etc
/sysusers.d
/test.conf
71 # this overrides test.conf which is masked on disk
72 cat $f | systemd-sysusers
--root=$TESTDIR --replace=/etc
/sysusers.d
/test.conf
-
73 # this should be ignored
74 cat test-1.input | systemd-sysusers
--root=$TESTDIR --replace=/usr
/lib
/sysusers.d
/test.conf
-
76 compare
$f "on stdin with --replace"
80 echo "*** Testing --inline"
82 # copy a random file to make sure it is ignored
83 cp $f $TESTDIR/etc
/sysusers.d
/confuse.conf
84 systemd-sysusers
--root=$TESTDIR --inline \
85 "u u1 222 - - /bin/zsh" \
88 compare inline
"(--inline)"
91 echo "*** Testing --inline with --replace"
93 # copy a random file to make sure it is ignored
94 cp $f $TESTDIR/etc
/sysusers.d
/confuse.conf
95 systemd-sysusers
--root=$TESTDIR \
97 --replace=/etc
/sysusers.d
/confuse.conf \
98 "u u1 222 - - /bin/zsh" \
101 compare inline
"(--inline --replace=…)"
103 rm -f $TESTDIR/etc
/sysusers.d
/* $TESTDIR/usr
/lib
/sysusers.d
/*
105 # tests for error conditions
106 for f
in unhappy-
*.input
; do
107 echo "*** Running test $f"
108 prepare_testdir
${f%.input}
109 cp $f $TESTDIR/usr
/lib
/sysusers.d
/test.conf
110 systemd-sysusers
--root=$TESTDIR 2> /dev
/null
111 journalctl
-t systemd-sysusers
-o cat |
tail -n1 > $TESTDIR/tmp
/err
112 if ! diff -u $TESTDIR/tmp
/err
${f%.*}.expected-err
; then
113 echo "**** Unexpected error output for $f"