From 02ff631527f2e1a7b166c786e1900928a393d983 Mon Sep 17 00:00:00 2001 From: Christian Goeschel Ndjomouo Date: Thu, 15 Jan 2026 00:06:41 -0500 Subject: [PATCH] tests: (chfn) ensure that invalid input is detected correctly Signed-off-by: Christian Goeschel Ndjomouo --- .../expected/chfn/input-illegal-passwd-chars | 1 + tests/expected/chfn/input-too-long | 1 + tests/ts/chfn/input | 39 +++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 tests/expected/chfn/input-illegal-passwd-chars create mode 100644 tests/expected/chfn/input-too-long create mode 100755 tests/ts/chfn/input diff --git a/tests/expected/chfn/input-illegal-passwd-chars b/tests/expected/chfn/input-illegal-passwd-chars new file mode 100644 index 0000000000..9766475a41 --- /dev/null +++ b/tests/expected/chfn/input-illegal-passwd-chars @@ -0,0 +1 @@ +ok diff --git a/tests/expected/chfn/input-too-long b/tests/expected/chfn/input-too-long new file mode 100644 index 0000000000..9766475a41 --- /dev/null +++ b/tests/expected/chfn/input-too-long @@ -0,0 +1 @@ +ok diff --git a/tests/ts/chfn/input b/tests/ts/chfn/input new file mode 100755 index 0000000000..a39b680bd9 --- /dev/null +++ b/tests/ts/chfn/input @@ -0,0 +1,39 @@ +#!/bin/bash +# +# Copyright (C) 2025 Christian Goeschel Ndjomouo +# +# 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. +# +TS_TOPDIR="${0%/*}/../.." +TS_DESC="input" + +. "$TS_TOPDIR"/functions.sh +ts_init "$*" + +ts_check_test_command "$TS_CMD_CHFN" + +# invalid passwd characters are [,:="\n] +ts_init_subtest "illegal-passwd-chars" +if ! "$TS_CMD_CHFN" --full-name "foo=bar:," &>/dev/null; then + echo "ok" > "$TS_OUTPUT" +fi +ts_finalize_subtest + +# currently we limit a valid GECOS field to 256 characters +ts_init_subtest "too-long" +if ! "$TS_CMD_CHFN" --full-name "$(head -c 257 /dev/zero | tr '\0' 'a')" &>/dev/null; then + echo "ok" > "$TS_OUTPUT" +fi +ts_finalize_subtest + +ts_finalize -- 2.47.3