From 7377c6375a643c77fb25c8c71da67cc4870fc5da Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Fri, 22 Dec 2023 09:57:35 +0000 Subject: [PATCH] test(ssh): user key storage test: removing --- tests/test_ssh.py | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/tests/test_ssh.py b/tests/test_ssh.py index 5832a2a..e2726d4 100644 --- a/tests/test_ssh.py +++ b/tests/test_ssh.py @@ -373,30 +373,31 @@ def test_adding_user_key_writes_json(generic_userdata, username): assert set(data["users"][user_index]["sshKeys"]) == set([key1, key2]) -# @pytest.mark.parametrize("username", regular_users) -# def test_removing_user_key_writes_json(generic_userdata, username): -# # generic userdata has a a single root key -# admin_name = "tester" +@pytest.mark.parametrize("username", regular_users) +def test_removing_user_key_writes_json(generic_userdata, username): + # generic userdata has a a single root key -# admin_keys = get_user_by_username(admin_name).ssh_keys -# assert len(admin_keys) == 1 -# key1 = admin_keys[0] -# key2 = "ssh-rsa MYSUPERKEY admin@pc" + user_keys = get_user_by_username(username).ssh_keys + assert len(user_keys) == 1 + key1 = user_keys[0] + key2 = "ssh-rsa MYSUPERKEY admin@pc" -# create_ssh_key(admin_name, key2) -# admin_keys = get_user_by_username(admin_name).ssh_keys -# assert len(admin_keys) == 2 + create_ssh_key(username, key2) + user_keys = get_user_by_username(username).ssh_keys + assert len(user_keys) == 2 -# remove_ssh_key(admin_name, key2) + remove_ssh_key(username, key2) -# with ReadUserData() as data: -# assert "sshKeys" in data -# assert data["sshKeys"] == [key1] + with ReadUserData() as data: + user_index = find_user_index_in_json_users(data["users"], username) + assert "sshKeys" in data["users"][user_index] + assert data["users"][user_index]["sshKeys"] == [key1] -# remove_ssh_key(admin_name, key1) -# with ReadUserData() as data: -# assert "sshKeys" in data -# assert data["sshKeys"] == [] + remove_ssh_key(username, key1) + with ReadUserData() as data: + user_index = find_user_index_in_json_users(data["users"], username) + assert "sshKeys" in data["users"][user_index] + assert data["users"][user_index]["sshKeys"] == [] # @pytest.mark.parametrize("username", regular_users)