mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-25 13:31:27 +00:00
test(ssh): user key storage test: removing user keys on undefined
This commit is contained in:
parent
7377c6375a
commit
03feab76b0
|
@ -12,6 +12,7 @@ from selfprivacy_api.actions.ssh import (
|
|||
create_ssh_key,
|
||||
remove_ssh_key,
|
||||
KeyNotFound,
|
||||
UserNotFound,
|
||||
)
|
||||
from selfprivacy_api.actions.users import (
|
||||
get_users,
|
||||
|
@ -275,7 +276,7 @@ def test_adding_admin_key_writes_json(generic_userdata):
|
|||
|
||||
|
||||
def test_removing_admin_key_writes_json(generic_userdata):
|
||||
# generic userdata has a a single root key
|
||||
# generic userdata has a a single admin key
|
||||
admin_name = "tester"
|
||||
|
||||
admin_keys = get_user_by_username(admin_name).ssh_keys
|
||||
|
@ -300,7 +301,7 @@ def test_removing_admin_key_writes_json(generic_userdata):
|
|||
|
||||
|
||||
def test_remove_admin_key_on_undefined(generic_userdata):
|
||||
# generic userdata has a a single root key
|
||||
# generic userdata has a a single admin key
|
||||
admin_name = "tester"
|
||||
|
||||
admin_keys = get_user_by_username(admin_name).ssh_keys
|
||||
|
@ -375,7 +376,7 @@ def test_adding_user_key_writes_json(generic_userdata, username):
|
|||
|
||||
@pytest.mark.parametrize("username", 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 user key
|
||||
|
||||
user_keys = get_user_by_username(username).ssh_keys
|
||||
assert len(user_keys) == 1
|
||||
|
@ -400,19 +401,32 @@ def test_removing_user_key_writes_json(generic_userdata, username):
|
|||
assert data["users"][user_index]["sshKeys"] == []
|
||||
|
||||
|
||||
# @pytest.mark.parametrize("username", regular_users)
|
||||
# def test_remove_user_key_on_undefined(generic_userdata, username):
|
||||
# # generic userdata has a a single root key
|
||||
# admin_name = "tester"
|
||||
@pytest.mark.parametrize("username", regular_users)
|
||||
def test_remove_user_key_on_undefined(generic_userdata, username):
|
||||
# generic userdata has a a single user key
|
||||
user_keys = get_user_by_username(username).ssh_keys
|
||||
assert len(user_keys) == 1
|
||||
key1 = user_keys[0]
|
||||
|
||||
# admin_keys = get_user_by_username(admin_name).ssh_keys
|
||||
# assert len(admin_keys) == 1
|
||||
# key1 = admin_keys[0]
|
||||
with WriteUserData() as data:
|
||||
user_index = find_user_index_in_json_users(data["users"], username)
|
||||
del data["users"][user_index]["sshKeys"]
|
||||
|
||||
# with WriteUserData() as data:
|
||||
# del data["sshKeys"]
|
||||
with pytest.raises(KeyNotFound):
|
||||
remove_ssh_key(username, key1)
|
||||
|
||||
# with pytest.raises(KeyNotFound):
|
||||
# remove_ssh_key(admin_name, key1)
|
||||
# admin_keys = get_user_by_username(admin_name).ssh_keys
|
||||
# assert len(admin_keys) == 0
|
||||
user_keys = get_user_by_username(username).ssh_keys
|
||||
assert len(user_keys) == 0
|
||||
|
||||
with WriteUserData() as data:
|
||||
user_index = find_user_index_in_json_users(data["users"], username)
|
||||
del data["users"][user_index]
|
||||
|
||||
with pytest.raises(UserNotFound):
|
||||
remove_ssh_key(username, key1)
|
||||
|
||||
with WriteUserData() as data:
|
||||
del data["users"]
|
||||
|
||||
with pytest.raises(UserNotFound):
|
||||
remove_ssh_key(username, key1)
|
||||
|
|
Loading…
Reference in a new issue