From: Christian Goeschel Ndjomouo Date: Mon, 20 Apr 2026 21:44:30 +0000 (-0400) Subject: tests: regression tests for chsh(1) X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=bc56132da072d372d8ccc1095038b0eb64c6e0ec;p=thirdparty%2Futil-linux.git tests: regression tests for chsh(1) Signed-off-by: Christian Goeschel Ndjomouo --- diff --git a/tests/commands.sh b/tests/commands.sh index e68d0b3e3..f1cdf52a6 100644 --- a/tests/commands.sh +++ b/tests/commands.sh @@ -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 index 000000000..3c73add52 --- /dev/null +++ b/tests/expected/chsh/options-shell @@ -0,0 +1,3 @@ +Changing shell for chsh_test_user. +Shell changed. +/bin/sh diff --git a/tests/ts/chfn/gecos b/tests/ts/chfn/gecos index b95a920a9..d44d93092 100755 --- a/tests/ts/chfn/gecos +++ b/tests/ts/chfn/gecos @@ -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 index 000000000..78852be5c --- /dev/null +++ b/tests/ts/chsh/options @@ -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 + +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