stages(users): add small unit test that passwd is called correctly

This commit is contained in:
Michael Vogt 2024-04-02 09:42:28 +02:00 committed by Brian C. Lane
parent b722bef9cb
commit af7485b406

View file

@ -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"]