test(ssh): user key storage test: adding

This commit is contained in:
Houkime 2023-12-22 09:49:27 +00:00
parent bc45a48af3
commit 0669dc117b

View file

@ -349,30 +349,32 @@ def test_read_user_keys_from_json(generic_userdata, username):
# deeper deletions are for user getter tests, not here # deeper deletions are for user getter tests, not here
# @pytest.mark.parametrize("username", regular_users) @pytest.mark.parametrize("username", regular_users)
# def test_adding_user_key_writes_json(generic_userdata, regular_users): def test_adding_user_key_writes_json(generic_userdata, username):
# admin_name = "tester"
# with WriteUserData() as data: with WriteUserData() as data:
# del data["sshKeys"] user_index = find_user_index_in_json_users(data["users"], username)
# key1 = "ssh-ed25519 KEY test@pc" del data["users"][user_index]["sshKeys"]
# key2 = "ssh-ed25519 KEY2 test@pc" key1 = "ssh-ed25519 KEY test@pc"
# create_ssh_key(admin_name, key1) key2 = "ssh-ed25519 KEY2 test@pc"
create_ssh_key(username, key1)
# with ReadUserData() as data: with ReadUserData() as data:
# assert "sshKeys" in data user_index = find_user_index_in_json_users(data["users"], username)
# assert data["sshKeys"] == [key1] assert "sshKeys" in data["users"][user_index]
assert data["users"][user_index]["sshKeys"] == [key1]
# create_ssh_key(admin_name, key2) create_ssh_key(username, key2)
# with ReadUserData() as data: with ReadUserData() as data:
# assert "sshKeys" in data user_index = find_user_index_in_json_users(data["users"], username)
# # order is irrelevant assert "sshKeys" in data["users"][user_index]
# assert set(data["sshKeys"]) == set([key1, key2]) # order is irrelevant
assert set(data["users"][user_index]["sshKeys"]) == set([key1, key2])
# @pytest.mark.parametrize("username", regular_users) # @pytest.mark.parametrize("username", regular_users)
# def test_removing_user_key_writes_json(generic_userdata, regular_users): # def test_removing_user_key_writes_json(generic_userdata, username):
# # generic userdata has a a single root key # # generic userdata has a a single root key
# admin_name = "tester" # admin_name = "tester"
@ -398,7 +400,7 @@ def test_read_user_keys_from_json(generic_userdata, username):
# @pytest.mark.parametrize("username", regular_users) # @pytest.mark.parametrize("username", regular_users)
# def test_remove_user_key_on_undefined(generic_userdata, regular_users): # def test_remove_user_key_on_undefined(generic_userdata, username):
# # generic userdata has a a single root key # # generic userdata has a a single root key
# admin_name = "tester" # admin_name = "tester"