From 144d8b800569264dc0932de11701f3080164f426 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 10 Oct 2020 11:25:50 +0300 Subject: test(unix_users): set encrypted password for users --- roles/unix_users/subplot.md | 2 ++ roles/unix_users/subplot.py | 11 +++++++++++ roles/unix_users/subplot.yaml | 3 +++ 3 files changed, 16 insertions(+) (limited to 'roles') diff --git a/roles/unix_users/subplot.md b/roles/unix_users/subplot.md index c098638..35d53c4 100644 --- a/roles/unix_users/subplot.md +++ b/roles/unix_users/subplot.md @@ -11,6 +11,7 @@ when I use role unix_users and I use variables from foo.yml and I run the playbook then the host has user foo +and the user foo on host has encrypted password foopass and the user foo on host has shell /bin/true ~~~ @@ -19,4 +20,5 @@ unix_users: - username: foo comment: Foo Bar shell: /bin/true + password: foopass ~~~ diff --git a/roles/unix_users/subplot.py b/roles/unix_users/subplot.py index dc4e9f6..0735049 100644 --- a/roles/unix_users/subplot.py +++ b/roles/unix_users/subplot.py @@ -26,3 +26,14 @@ def host_user_has_shell(ctx, username=None, shell=None): if line.startswith(f"{username}:"): logging.debug(f"host_user_has_shell: line={line!r}") assert line.endswith(f":{shell}") + + +def host_user_has_password(ctx, username=None, password=None): + assert_eq = globals()["assert_eq"] + qemu = ctx["qemu"] + output, exit = qemu.ssh(["sudo", "grep", f"^{username}:"]) + assert_eq(exit, 0) + for line in output.decode("UTF8").splitlines(): + if line.startswith(f"{username}:"): + parts = line.split(":") + assert_eq(parts[1], password) diff --git a/roles/unix_users/subplot.yaml b/roles/unix_users/subplot.yaml index a0529b2..c0665aa 100644 --- a/roles/unix_users/subplot.yaml +++ b/roles/unix_users/subplot.yaml @@ -4,5 +4,8 @@ - then: the host has user {username} function: host_has_user +- then: the user {username} on host has encrypted password {password} + function: host_user_has_password + - then: the user {username} on host has shell {shell} function: host_user_has_shell -- cgit v1.2.1