]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: regression tests for chsh(1)
authorChristian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Mon, 20 Apr 2026 21:44:30 +0000 (17:44 -0400)
committerChristian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Wed, 29 Apr 2026 10:13:58 +0000 (06:13 -0400)
Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
tests/commands.sh
tests/expected/chsh/options-shell [new file with mode: 0644]
tests/ts/chfn/gecos
tests/ts/chsh/options [new file with mode: 0755]

index e68d0b3e363d2d1bdc46fc621537509f5e7ff7a6..f1cdf52a6b58a558f7a82421c52f87de7b91c9cc 100644 (file)
@@ -78,6 +78,7 @@ TS_CMD_BLKDISCARD=${TS_CMD_BLKID-"${ts_commandsdir}blkdiscard"}
 TS_CMD_BLKID=${TS_CMD_BLKID-"${ts_commandsdir}blkid"}
 TS_CMD_CAL=${TS_CMD_CAL-"${ts_commandsdir}cal"}
 TS_CMD_CHOOM=${TS_CMD_CHOOM:-"${ts_commandsdir}choom"}
+TS_CMD_CHSH=${TS_CMD_CHSH:-"${ts_commandsdir}chsh"}
 TS_CMD_COLCRT=${TS_CMD_COLCRT:-"${ts_commandsdir}colcrt"}
 TS_CMD_COLRM=${TS_CMD_COLRM:-"${ts_commandsdir}colrm"}
 TS_CMD_COL=${TS_CMD_COL:-"${ts_commandsdir}col"}
diff --git a/tests/expected/chsh/options-shell b/tests/expected/chsh/options-shell
new file mode 100644 (file)
index 0000000..3c73add
--- /dev/null
@@ -0,0 +1,3 @@
+Changing shell for chsh_test_user.
+Shell changed.
+/bin/sh
index b95a920a9314c5f7a53216f60fdef36c9d8ef57c..d44d930926c4ec0a6866283905d826261563ef79 100755 (executable)
@@ -30,7 +30,10 @@ ts_check_prog "useradd"
 ts_check_prog "userdel"
 
 ts_log "Initialize user"
-useradd -u 9899 --shell /bin/bash testuser_chfn_test
+useradd -u 9899 --shell /bin/bash testuser_chfn_test \
+    || ts_skip "coul not create test user (testuser)"
+
+
 grep testuser /etc/passwd >> $TS_OUTPUT
 $TS_CMD_CHFN --full-name test_gecos --office none --office-phone 111 \
                                                 testuser_chfn_test >>$TS_OUTPUT
diff --git a/tests/ts/chsh/options b/tests/ts/chsh/options
new file mode 100755 (executable)
index 0000000..78852be
--- /dev/null
@@ -0,0 +1,56 @@
+#!/usr/bin/env bash
+
+# This file is part of util-linux.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# Copyright (C) 2026 Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="options"
+
+. "$TS_TOPDIR"/functions.sh
+ts_init "$*"
+
+ts_skip_nonroot
+
+ts_check_test_command "$TS_CMD_CHSH"
+ts_check_prog "useradd"
+ts_check_prog "userdel"
+ts_check_prog "diff"
+ts_check_prog "awk"
+
+export LIBUSER_CONF=/dev/null
+TEST_USERNAME="chsh_test_user"
+
+useradd --uid 10000 -m --shell /bin/bash "$TEST_USERNAME" \
+    || ts_skip "unable to create test user ($TEST_USERNAME)"
+
+
+ts_init_subtest "list-shells"
+
+diff <(grep '^/' /etc/shells) <("$TS_CMD_CHSH" --list-shells) >>"$TS_OUTPUT" 2>>"$TS_ERRLOG"
+
+ts_finalize_subtest
+
+
+ts_init_subtest "shell"
+
+{
+    "$TS_CMD_CHSH" --shell /bin/sh "$TEST_USERNAME"
+     awk -F: -v u="^$TEST_USERNAME"  '$1 ~ u {print $7}' /etc/passwd
+} >>"$TS_OUTPUT" 2>>"$TS_ERRLOG"
+
+ts_finalize_subtest
+
+userdel --remove "$TEST_USERNAME"
+
+ts_finalize