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
)
26 SYSTEM_GID_MAX
=$
(awk 'BEGIN { gid=999 } /^\s*SYS_GID_MAX\s+/ { gid=$2 } END { print gid }' /etc
/login.defs
)
28 # we can't rely on config.h to get the nologin path, as autopkgtest
29 # uses pre-compiled binaries, so extract it from the systemd-sysusers
30 # binary which we are about to execute
31 NOLOGIN
=$
(strings $
(type -p systemd-sysusers
) |
grep nologin
)
33 sed -e "s/SYSTEM_UID_MAX/${SYSTEM_UID_MAX}/g" \
34 -e "s/SYSTEM_GID_MAX/${SYSTEM_GID_MAX}/g" \
35 -e "s#NOLOGIN#${NOLOGIN}#g" "$in"
39 if ! diff -u $TESTDIR/etc
/passwd
<(preprocess
${1%.*}.expected-passwd
); then
40 echo "**** Unexpected output for $f"
44 if ! diff -u $TESTDIR/etc
/group
<(preprocess
${1%.*}.expected-group
); then
45 echo "**** Unexpected output for $f $2"
51 # ensure our build of systemd-sysusers is run
52 PATH
=${BUILD_DIR}:$PATH
54 rm -f $TESTDIR/etc
/sysusers.d
/* $TESTDIR/usr
/lib
/sysusers.d
/*
57 for f
in test-
*.input
; do
59 prepare_testdir
${f%.input}
60 cp $f $TESTDIR/usr
/lib
/sysusers.d
/test.conf
61 systemd-sysusers
--root=$TESTDIR
66 for f
in test-
*.input
; do
67 echo "*** Running $f on stdin"
68 prepare_testdir
${f%.input}
69 touch $TESTDIR/etc
/sysusers.d
/test.conf
70 cat $f | systemd-sysusers
--root=$TESTDIR -
75 for f
in test-
*.input
; do
76 echo "*** Running $f on stdin with --replace"
77 prepare_testdir
${f%.input}
78 touch $TESTDIR/etc
/sysusers.d
/test.conf
79 # this overrides test.conf which is masked on disk
80 cat $f | systemd-sysusers
--root=$TESTDIR --replace=/etc
/sysusers.d
/test.conf
-
81 # this should be ignored
82 cat test-1.input | systemd-sysusers
--root=$TESTDIR --replace=/usr
/lib
/sysusers.d
/test.conf
-
84 compare
$f "on stdin with --replace"
88 echo "*** Testing --inline"
90 # copy a random file to make sure it is ignored
91 cp $f $TESTDIR/etc
/sysusers.d
/confuse.conf
92 systemd-sysusers
--root=$TESTDIR --inline \
93 "u u1 222 - - /bin/zsh" \
96 compare inline
"(--inline)"
99 echo "*** Testing --inline with --replace"
101 # copy a random file to make sure it is ignored
102 cp $f $TESTDIR/etc
/sysusers.d
/confuse.conf
103 systemd-sysusers
--root=$TESTDIR \
105 --replace=/etc
/sysusers.d
/confuse.conf \
106 "u u1 222 - - /bin/zsh" \
109 compare inline
"(--inline --replace=…)"
111 rm -f $TESTDIR/etc
/sysusers.d
/* $TESTDIR/usr
/lib
/sysusers.d
/*
113 # tests for error conditions
114 for f
in unhappy-
*.input
; do
115 echo "*** Running test $f"
116 prepare_testdir
${f%.input}
117 cp $f $TESTDIR/usr
/lib
/sysusers.d
/test.conf
118 systemd-sysusers
--root=$TESTDIR 2> /dev
/null
120 journalctl
-t systemd-sysusers
-o cat |
tail -n1 > $TESTDIR/tmp
/err
121 if ! diff -u $TESTDIR/tmp
/err
${f%.*}.expected-err
; then
122 echo "**** Unexpected error output for $f"