From d4f5397d2ce5a79fbe126abf8c025a2b369aa78b Mon Sep 17 00:00:00 2001 From: Iker Pedrosa Date: Mon, 10 Mar 2025 09:50:56 +0100 Subject: [PATCH] tests/: extend basic useradd test The test framework PoC only provided basic checks. I've added additional functionality to the framework by checking shadow and gshadow entries and I've extended the basic useradd test to check those too. Signed-off-by: Iker Pedrosa Reviewed-by: Dan Lavu --- tests/system/tests/test_useradd.py | 45 ++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/tests/system/tests/test_useradd.py b/tests/system/tests/test_useradd.py index 7effd61b1..e80f87668 100644 --- a/tests/system/tests/test_useradd.py +++ b/tests/system/tests/test_useradd.py @@ -6,6 +6,7 @@ from __future__ import annotations import pytest +from framework.misc import days_since_epoch from framework.roles.shadow import Shadow from framework.topology import KnownTopology @@ -17,27 +18,53 @@ def test_useradd__add_user(shadow: Shadow): :setup: 1. Create user :steps: - 1. User exists and UID is 1000 - 2. Group exists and GID is 1000 - 3. Home folder exists + 1. Check passwd entry + 2. Check shadow entry + 3. Check group entry + 4. Check gshadow entry + 5. Check home folder :expectedresults: - 1. User is found and UID matches - 2. Group is found and GID matches - 3. Home folder is found + 1. passwd entry for the user exists and the attributes are correct + 2. shadow entry for the user exists and the attributes are correct + 3. group entry for the user exists and the attributes are correct + 4. gshadow entry for the user exists and the attributes are correct + 5. Home folder exists :customerscenario: False """ shadow.useradd("tuser") - result = shadow.tools.id("tuser") + result = shadow.tools.getent.passwd("tuser") assert result is not None, "User should be found" - assert result.user.name == "tuser", "Incorrect username" - assert result.user.id == 1000, "Incorrect UID" + assert result.name == "tuser", "Incorrect username" + assert result.password == "x", "Incorrect password" + assert result.uid == 1000, "Incorrect UID" + assert result.gid == 1000, "Incorrect GID" + assert result.home == "/home/tuser", "Incorrect home" + if "Debian" in shadow.host.distro_name: + assert result.shell == "/bin/sh", "Incorrect shell" + else: + assert result.shell == "/bin/bash", "Incorrect shell" + + result = shadow.tools.getent.shadow("tuser") + assert result is not None, "User should be found" + assert result.name == "tuser", "Incorrect username" + assert result.password == "!", "Incorrect password" + assert result.last_changed == days_since_epoch(), "Incorrect last changed" + assert result.min_days == 0, "Incorrect min days" + assert result.max_days == 99999, "Incorrect max days" + assert result.warn_days == 7, "Incorrect warn days" result = shadow.tools.getent.group("tuser") assert result is not None, "Group should be found" assert result.name == "tuser", "Incorrect groupname" assert result.gid == 1000, "Incorrect GID" + if shadow.host.features["gshadow"]: + result = shadow.tools.getent.gshadow("tuser") + assert result is not None, "User should be found" + assert result.name == "tuser", "Incorrect username" + assert result.password == "!", "Incorrect password" + assert shadow.fs.exists("/home/tuser"), "Home folder should be found" -- 2.47.2