3 TEST_DESCRIPTION
="Sysuser-related tests"
5 .
$TEST_BASE_DIR/test-functions
8 mkdir
-p $TESTDIR/etc
/sysusers.d
$TESTDIR/usr
/lib
/sysusers.d
$TESTDIR/tmp
12 rm -f $TESTDIR/etc
/*{passwd
,group
,shadow
}
13 for i
in $1.initial-
{passwd
,group
,shadow
}; do
14 test -f $i && cp $i $TESTDIR/etc
/${i#*.initial-}
22 # see meson.build how to extract this. gcc -E was used before to
23 # get this value from config.h, however the autopkgtest fails with
25 SYSTEM_UID_MAX
=$
(awk 'BEGIN { uid=999 } /^\s*SYS_UID_MAX\s+/ { uid=$2 } END { print uid }' /etc
/login.defs
)
27 # we can't rely on config.h to get the nologin path, as autopkgtest
28 # uses pre-compiled binaries, so extract it from the systemd-sysusers
29 # binary which we are about to execute
30 NOLOGIN
=$
(strings $
(type -p systemd-sysusers
) |
grep nologin
)
32 sed -e "s/SYSTEM_UID_MAX/${SYSTEM_UID_MAX}/g" \
33 -e "s#NOLOGIN#${NOLOGIN}#g" "$in"
37 if ! diff -u $TESTDIR/etc
/passwd
<(preprocess
${1%.*}.expected-passwd
); then
38 echo "**** Unexpected output for $f"
42 if ! diff -u $TESTDIR/etc
/group
<(preprocess
${1%.*}.expected-group
); then
43 echo "**** Unexpected output for $f $2"
49 # ensure our build of systemd-sysusers is run
50 PATH
=${BUILD_DIR}:$PATH
52 rm -f $TESTDIR/etc
/sysusers.d
/* $TESTDIR/usr
/lib
/sysusers.d
/*
55 for f
in test-
*.input
; do
57 prepare_testdir
${f%.input}
58 cp $f $TESTDIR/usr
/lib
/sysusers.d
/test.conf
59 systemd-sysusers
--root=$TESTDIR
64 for f
in test-
*.input
; do
65 echo "*** Running $f on stdin"
66 prepare_testdir
${f%.input}
67 touch $TESTDIR/etc
/sysusers.d
/test.conf
68 cat $f | systemd-sysusers
--root=$TESTDIR -
73 for f
in test-
*.input
; do
74 echo "*** Running $f on stdin with --replace"
75 prepare_testdir
${f%.input}
76 touch $TESTDIR/etc
/sysusers.d
/test.conf
77 # this overrides test.conf which is masked on disk
78 cat $f | systemd-sysusers
--root=$TESTDIR --replace=/etc
/sysusers.d
/test.conf
-
79 # this should be ignored
80 cat test-1.input | systemd-sysusers
--root=$TESTDIR --replace=/usr
/lib
/sysusers.d
/test.conf
-
82 compare
$f "on stdin with --replace"
86 echo "*** Testing --inline"
88 # copy a random file to make sure it is ignored
89 cp $f $TESTDIR/etc
/sysusers.d
/confuse.conf
90 systemd-sysusers
--root=$TESTDIR --inline \
91 "u u1 222 - - /bin/zsh" \
94 compare inline
"(--inline)"
97 echo "*** Testing --inline with --replace"
99 # copy a random file to make sure it is ignored
100 cp $f $TESTDIR/etc
/sysusers.d
/confuse.conf
101 systemd-sysusers
--root=$TESTDIR \
103 --replace=/etc
/sysusers.d
/confuse.conf \
104 "u u1 222 - - /bin/zsh" \
107 compare inline
"(--inline --replace=…)"
109 rm -f $TESTDIR/etc
/sysusers.d
/* $TESTDIR/usr
/lib
/sysusers.d
/*
111 # tests for error conditions
112 for f
in unhappy-
*.input
; do
113 echo "*** Running test $f"
114 prepare_testdir
${f%.input}
115 cp $f $TESTDIR/usr
/lib
/sysusers.d
/test.conf
116 systemd-sysusers
--root=$TESTDIR 2> /dev
/null
117 journalctl
-t systemd-sysusers
-o cat |
tail -n1 > $TESTDIR/tmp
/err
118 if ! diff -u $TESTDIR/tmp
/err
${f%.*}.expected-err
; then
119 echo "**** Unexpected error output for $f"