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
16 # see meson.build how to extract this. gcc -E was used before to
17 # get this value from config.h, however the autopkgtest fails with
19 SYSTEM_UID_MAX
=$
(awk 'BEGIN { uid=999 } /^\s*SYS_UID_MAX\s+/ { uid=$2 } END { print uid }' /etc
/login.defs
)
20 sed "s/SYSTEM_UID_MAX/${SYSTEM_UID_MAX}/g" "$in"
24 if ! diff -u $TESTDIR/etc
/passwd
<(preprocess
${1%.*}.expected-passwd
); then
25 echo "**** Unexpected output for $f"
29 if ! diff -u $TESTDIR/etc
/group
<(preprocess
${1%.*}.expected-group
); then
30 echo "**** Unexpected output for $f $2"
36 # ensure our build of systemd-sysusers is run
37 PATH
=${BUILD_DIR}:$PATH
39 rm -f $TESTDIR/etc
/sysusers.d
/* $TESTDIR/usr
/lib
/sysusers.d
/*
42 for f
in test-
*.input
; do
44 rm -f $TESTDIR/etc
/*{passwd
,group
,shadow
}
45 cp $f $TESTDIR/usr
/lib
/sysusers.d
/test.conf
46 systemd-sysusers
--root=$TESTDIR
51 for f
in test-
*.input
; do
52 echo "*** Running $f on stdin"
53 rm -f $TESTDIR/etc
/*{passwd
,group
,shadow
}
54 touch $TESTDIR/etc
/sysusers.d
/test.conf
55 cat $f | systemd-sysusers
--root=$TESTDIR -
60 for f
in test-
*.input
; do
61 echo "*** Running $f on stdin with --replace"
62 rm -f $TESTDIR/etc
/*{passwd
,group
,shadow
}
63 touch $TESTDIR/etc
/sysusers.d
/test.conf
64 # this overrides test.conf which is masked on disk
65 cat $f | systemd-sysusers
--root=$TESTDIR --replace=/etc
/sysusers.d
/test.conf
-
66 # this should be ignored
67 cat test-1.input | systemd-sysusers
--root=$TESTDIR --replace=/usr
/lib
/sysusers.d
/test.conf
-
69 compare
$f "on stdin with --replace"
73 echo "*** Testing --inline"
74 rm -f $TESTDIR/etc
/*{passwd
,group
,shadow
}
75 # copy a random file to make sure it is ignored
76 cp $f $TESTDIR/etc
/sysusers.d
/confuse.conf
77 systemd-sysusers
--root=$TESTDIR --inline \
78 "u u1 222 - - /bin/zsh" \
81 compare inline
"(--inline)"
84 echo "*** Testing --inline with --replace"
85 rm -f $TESTDIR/etc
/*{passwd
,group
,shadow
}
86 # copy a random file to make sure it is ignored
87 cp $f $TESTDIR/etc
/sysusers.d
/confuse.conf
88 systemd-sysusers
--root=$TESTDIR \
90 --replace=/etc
/sysusers.d
/confuse.conf \
91 "u u1 222 - - /bin/zsh" \
94 compare inline
"(--inline --replace=…)"
96 rm -f $TESTDIR/etc
/sysusers.d
/* $TESTDIR/usr
/lib
/sysusers.d
/*
98 # tests for error conditions
99 for f
in unhappy-
*.input
; do
100 echo "*** Running test $f"
101 rm -f $TESTDIR/etc
/*{passwd
,group
,shadow
}
102 cp $f $TESTDIR/usr
/lib
/sysusers.d
/test.conf
103 systemd-sysusers
--root=$TESTDIR 2> /dev
/null
104 journalctl
-t systemd-sysusers
-o cat |
tail -n1 > $TESTDIR/tmp
/err
105 if ! diff -u $TESTDIR/tmp
/err
${f%.*}.expected-err
; then
106 echo "**** Unexpected error output for $f"