mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-22 04:01:27 +00:00
test(ssh): add rootkey json tests
This commit is contained in:
parent
0b90e3d20f
commit
a5ab0df161
|
@ -1,6 +1,12 @@
|
|||
import pytest
|
||||
|
||||
from selfprivacy_api.actions.ssh import set_ssh_settings, get_ssh_settings
|
||||
from selfprivacy_api.actions.ssh import (
|
||||
set_ssh_settings,
|
||||
get_ssh_settings,
|
||||
create_ssh_key,
|
||||
remove_ssh_key,
|
||||
)
|
||||
from selfprivacy_api.actions.users import get_users
|
||||
from selfprivacy_api.utils import WriteUserData, ReadUserData
|
||||
|
||||
|
||||
|
@ -107,3 +113,77 @@ def test_enabling_disabling_writes_json(
|
|||
get_raw_json_ssh_setting("passwordAuthentication")
|
||||
== password_auth_spectrum
|
||||
)
|
||||
|
||||
|
||||
def test_read_root_keys_from_json(generic_userdata):
|
||||
assert get_ssh_settings().rootKeys == ["ssh-ed25519 KEY test@pc"]
|
||||
new_keys = ["ssh-ed25519 KEY test@pc", "ssh-ed25519 KEY2 test@pc"]
|
||||
|
||||
with WriteUserData() as data:
|
||||
data["ssh"]["rootKeys"] = new_keys
|
||||
|
||||
assert get_ssh_settings().rootKeys == new_keys
|
||||
|
||||
with WriteUserData() as data:
|
||||
del data["ssh"]["rootKeys"]
|
||||
|
||||
assert get_ssh_settings().rootKeys == []
|
||||
|
||||
with WriteUserData() as data:
|
||||
del data["ssh"]
|
||||
|
||||
assert get_ssh_settings().rootKeys == []
|
||||
|
||||
|
||||
def test_removing_root_key_writes_json(generic_userdata):
|
||||
# generic userdata has a a single root key
|
||||
rootkeys = get_ssh_settings().rootKeys
|
||||
assert len(rootkeys) == 1
|
||||
key1 = rootkeys[0]
|
||||
key2 = "ssh-rsa MYSUPERKEY root@pc"
|
||||
|
||||
create_ssh_key("root", key2)
|
||||
rootkeys = get_ssh_settings().rootKeys
|
||||
assert len(rootkeys) == 2
|
||||
|
||||
remove_ssh_key("root", key2)
|
||||
with ReadUserData() as data:
|
||||
assert "ssh" in data
|
||||
assert "rootKeys" in data["ssh"]
|
||||
assert data["ssh"]["rootKeys"] == [key1]
|
||||
|
||||
remove_ssh_key("root", key1)
|
||||
with ReadUserData() as data:
|
||||
assert "ssh" in data
|
||||
assert "rootKeys" in data["ssh"]
|
||||
assert data["ssh"]["rootKeys"] == []
|
||||
|
||||
|
||||
def test_adding_root_key_writes_json(generic_userdata):
|
||||
with WriteUserData() as data:
|
||||
del data["ssh"]
|
||||
key1 = "ssh-ed25519 KEY test@pc"
|
||||
key2 = "ssh-ed25519 KEY2 test@pc"
|
||||
create_ssh_key("root", key1)
|
||||
|
||||
with ReadUserData() as data:
|
||||
assert "ssh" in data
|
||||
assert "rootKeys" in data["ssh"]
|
||||
assert data["ssh"]["rootKeys"] == [key1]
|
||||
|
||||
with WriteUserData() as data:
|
||||
del data["ssh"]["rootKeys"]
|
||||
create_ssh_key("root", key1)
|
||||
|
||||
with ReadUserData() as data:
|
||||
assert "ssh" in data
|
||||
assert "rootKeys" in data["ssh"]
|
||||
assert data["ssh"]["rootKeys"] == [key1]
|
||||
|
||||
create_ssh_key("root", key2)
|
||||
|
||||
with ReadUserData() as data:
|
||||
assert "ssh" in data
|
||||
assert "rootKeys" in data["ssh"]
|
||||
# order is irrelevant
|
||||
assert set(data["ssh"]["rootKeys"]) == set([key1, key2])
|
||||
|
|
Loading…
Reference in a new issue