From 2c23d4fbbbaece4c162c95efdf1baf088b58f9c0 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 10 Oct 2020 11:46:06 +0300 Subject: test(unix_users): verify setting authorized_keys --- roles/unix_users/subplot.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'roles/unix_users/subplot.py') diff --git a/roles/unix_users/subplot.py b/roles/unix_users/subplot.py index 0735049..7bf921d 100644 --- a/roles/unix_users/subplot.py +++ b/roles/unix_users/subplot.py @@ -31,9 +31,18 @@ def host_user_has_shell(ctx, username=None, shell=None): 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}:"]) + output, exit = qemu.ssh(["sudo", "grep", f"^{username}:", "/etc/shadow"]) assert_eq(exit, 0) for line in output.decode("UTF8").splitlines(): if line.startswith(f"{username}:"): parts = line.split(":") assert_eq(parts[1], password) + + +def host_user_has_authorized_keys_containing(ctx, username=None, substring=None): + assert_eq = globals()["assert_eq"] + qemu = ctx["qemu"] + output, exit = qemu.ssh(["sudo", "cat", f"/home/{username}/.ssh/authorized_keys"]) + assert_eq(exit, 0) + output = output.decode("UTF8") + assert substring in output -- cgit v1.2.1