From af7485b406c5b22dcd595e6ccd18296b3304a4a6 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 2 Apr 2024 09:42:28 +0200 Subject: [PATCH] stages(users): add small unit test that `passwd` is called correctly --- stages/test/test_users.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/stages/test/test_users.py b/stages/test/test_users.py index c74cbe55..53a797a8 100644 --- a/stages/test/test_users.py +++ b/stages/test/test_users.py @@ -82,3 +82,25 @@ def test_users_mock_bin(tmp_path, stage_module, user_opts, expected_args): stage_module.main(tmp_path, options) assert len(mocked_chroot.call_args_list) == 1 assert mocked_chroot.call_args_list[0][2:] == expected_args + ["foo"] + + +# separate test right now as it results in two binaries being called +# (adduser,passwd) which our parameter tests cannot do yet +def test_users_with_expire_date(tmp_path, stage_module): + with mock_command("chroot", "") as mocked_chroot: + make_fake_tree(tmp_path, { + "/etc/passwd": "", + }) + + options = { + "users": { + "foo": { + "force_password_reset": True, + }, + } + } + + stage_module.main(tmp_path, options) + assert len(mocked_chroot.call_args_list) == 2 + assert mocked_chroot.call_args_list[0][1:] == ["useradd", "foo"] + assert mocked_chroot.call_args_list[1][1:] == ["passwd", "--expire", "foo"]