From 1e589ed2649ad6ed31406c281fd4178fb396288a Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 24 Jan 2018 11:18:46 +0100 Subject: [PATCH] test: add TEST-21-SYSUSERS test This test tests the systemd-sysuser binary via the --root=$TESTDIR option and ensures that for the given inputs the expected passwd and group files will be generated. --- test/TEST-21-SYSUSERS/Makefile | 4 ++++ test/TEST-21-SYSUSERS/test-1.expected-group | 2 ++ test/TEST-21-SYSUSERS/test-1.expected-passwd | 1 + test/TEST-21-SYSUSERS/test-1.input | 3 +++ test/TEST-21-SYSUSERS/test-2.expected-group | 1 + test/TEST-21-SYSUSERS/test-2.expected-passwd | 1 + test/TEST-21-SYSUSERS/test-2.input | 2 ++ test/TEST-21-SYSUSERS/test-3.expected-group | 4 ++++ test/TEST-21-SYSUSERS/test-3.expected-passwd | 4 ++++ test/TEST-21-SYSUSERS/test-3.input | 7 +++++++ test/TEST-21-SYSUSERS/test.sh | 30 ++++++++++++++++++++++++++++ 11 files changed, 59 insertions(+) create mode 100644 test/TEST-21-SYSUSERS/Makefile create mode 100644 test/TEST-21-SYSUSERS/test-1.expected-group create mode 100644 test/TEST-21-SYSUSERS/test-1.expected-passwd create mode 100644 test/TEST-21-SYSUSERS/test-1.input create mode 100644 test/TEST-21-SYSUSERS/test-2.expected-group create mode 100644 test/TEST-21-SYSUSERS/test-2.expected-passwd create mode 100644 test/TEST-21-SYSUSERS/test-2.input create mode 100644 test/TEST-21-SYSUSERS/test-3.expected-group create mode 100644 test/TEST-21-SYSUSERS/test-3.expected-passwd create mode 100644 test/TEST-21-SYSUSERS/test-3.input create mode 100755 test/TEST-21-SYSUSERS/test.sh diff --git a/test/TEST-21-SYSUSERS/Makefile b/test/TEST-21-SYSUSERS/Makefile new file mode 100644 index 0000000..34d7cc6 --- /dev/null +++ b/test/TEST-21-SYSUSERS/Makefile @@ -0,0 +1,4 @@ +BUILD_DIR=$(shell ../../tools/find-build-dir.sh) + +all setup clean run: + @basedir=../.. TEST_BASE_DIR=../ BUILD_DIR=$(BUILD_DIR) ./test.sh --$@ diff --git a/test/TEST-21-SYSUSERS/test-1.expected-group b/test/TEST-21-SYSUSERS/test-1.expected-group new file mode 100644 index 0000000..cc9093f --- /dev/null +++ b/test/TEST-21-SYSUSERS/test-1.expected-group @@ -0,0 +1,2 @@ +g1:x:111: +u1:x:222: diff --git a/test/TEST-21-SYSUSERS/test-1.expected-passwd b/test/TEST-21-SYSUSERS/test-1.expected-passwd new file mode 100644 index 0000000..8d0bfff --- /dev/null +++ b/test/TEST-21-SYSUSERS/test-1.expected-passwd @@ -0,0 +1 @@ +u1:x:222:222::/:/sbin/nologin diff --git a/test/TEST-21-SYSUSERS/test-1.input b/test/TEST-21-SYSUSERS/test-1.input new file mode 100644 index 0000000..bffc2cd --- /dev/null +++ b/test/TEST-21-SYSUSERS/test-1.input @@ -0,0 +1,3 @@ +#Type Name ID GECOS HOMEDIR +u u1 222 - - +g g1 111 - - diff --git a/test/TEST-21-SYSUSERS/test-2.expected-group b/test/TEST-21-SYSUSERS/test-2.expected-group new file mode 100644 index 0000000..f98e85f --- /dev/null +++ b/test/TEST-21-SYSUSERS/test-2.expected-group @@ -0,0 +1 @@ +u1:x:999: diff --git a/test/TEST-21-SYSUSERS/test-2.expected-passwd b/test/TEST-21-SYSUSERS/test-2.expected-passwd new file mode 100644 index 0000000..d907e48 --- /dev/null +++ b/test/TEST-21-SYSUSERS/test-2.expected-passwd @@ -0,0 +1 @@ +u1:x:999:999:some gecos:/random/dir:/sbin/nologin diff --git a/test/TEST-21-SYSUSERS/test-2.input b/test/TEST-21-SYSUSERS/test-2.input new file mode 100644 index 0000000..d8f3134 --- /dev/null +++ b/test/TEST-21-SYSUSERS/test-2.input @@ -0,0 +1,2 @@ +#Type Name ID GECOS HOMEDIR +u u1 - "some gecos" /random/dir diff --git a/test/TEST-21-SYSUSERS/test-3.expected-group b/test/TEST-21-SYSUSERS/test-3.expected-group new file mode 100644 index 0000000..6ea8bce --- /dev/null +++ b/test/TEST-21-SYSUSERS/test-3.expected-group @@ -0,0 +1,4 @@ +hoge:x:300: +baz:x:302: +foo:x:301: +ccc:x:306: diff --git a/test/TEST-21-SYSUSERS/test-3.expected-passwd b/test/TEST-21-SYSUSERS/test-3.expected-passwd new file mode 100644 index 0000000..c35e9ab --- /dev/null +++ b/test/TEST-21-SYSUSERS/test-3.expected-passwd @@ -0,0 +1,4 @@ +foo:x:301:301::/:/sbin/nologin +aaa:x:303:302::/:/sbin/nologin +bbb:x:304:302::/:/sbin/nologin +ccc:x:305:306::/:/sbin/nologin diff --git a/test/TEST-21-SYSUSERS/test-3.input b/test/TEST-21-SYSUSERS/test-3.input new file mode 100644 index 0000000..672c57b --- /dev/null +++ b/test/TEST-21-SYSUSERS/test-3.input @@ -0,0 +1,7 @@ +g hoge 300 - - +u foo 301 - - + +g baz 302 - - +u aaa 303:302 - - +u bbb 304:302 - - +u ccc 305:306 - - diff --git a/test/TEST-21-SYSUSERS/test.sh b/test/TEST-21-SYSUSERS/test.sh new file mode 100755 index 0000000..a206fb7 --- /dev/null +++ b/test/TEST-21-SYSUSERS/test.sh @@ -0,0 +1,30 @@ +#!/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 +} + +test_run() { + for f in test-*.input; do + echo "***** Running $f" + rm -f $TESTDIR/etc/* + cp $f $TESTDIR/usr/lib/sysusers.d/test.conf + ${BUILD_DIR}/systemd-sysusers --root=$TESTDIR + if ! diff -u $TESTDIR/etc/passwd ${f%.*}.expected-passwd; then + echo "**** Unexpected output for $f" + exit 1 + fi + if ! diff -u $TESTDIR/etc/group ${f%.*}.expected-group; then + echo "**** Unexpected output for $f" + exit 1 + fi + done +} + +do_test "$@" -- 2.7.4