diff --git a/selfprivacy_api/dependencies.py b/selfprivacy_api/dependencies.py index 1955601..98ed526 100644 --- a/selfprivacy_api/dependencies.py +++ b/selfprivacy_api/dependencies.py @@ -27,4 +27,4 @@ async def get_token_header( def get_api_version() -> str: """Get API version""" - return "2.4.2" + return "2.4.2-flakes" diff --git a/selfprivacy_api/services/bitwarden/__init__.py b/selfprivacy_api/services/bitwarden/__init__.py index 2f695fd..f095ef8 100644 --- a/selfprivacy_api/services/bitwarden/__init__.py +++ b/selfprivacy_api/services/bitwarden/__init__.py @@ -61,7 +61,9 @@ class Bitwarden(Service): @staticmethod def is_enabled() -> bool: with ReadUserData() as user_data: - return user_data.get("bitwarden", {}).get("enable", False) + return ( + user_data.get("modules", {}).get("bitwarden", {}).get("enable", False) + ) @staticmethod def get_status() -> ServiceStatus: @@ -80,17 +82,21 @@ class Bitwarden(Service): def enable(): """Enable Bitwarden service.""" with WriteUserData() as user_data: - if "bitwarden" not in user_data: - user_data["bitwarden"] = {} - user_data["bitwarden"]["enable"] = True + if "modules" not in user_data: + user_data["modules"] = {} + if "bitwarden" not in user_data["modules"]: + user_data["modules"]["bitwarden"] = {} + user_data["modules"]["bitwarden"]["enable"] = True @staticmethod def disable(): """Disable Bitwarden service.""" with WriteUserData() as user_data: - if "bitwarden" not in user_data: - user_data["bitwarden"] = {} - user_data["bitwarden"]["enable"] = False + if "modules" not in user_data: + user_data["modules"] = {} + if "bitwarden" not in user_data["modules"]: + user_data["modules"]["bitwarden"] = {} + user_data["modules"]["bitwarden"]["enable"] = False @staticmethod def stop(): diff --git a/selfprivacy_api/services/gitea/__init__.py b/selfprivacy_api/services/gitea/__init__.py index fcb9ca7..ed4c9d5 100644 --- a/selfprivacy_api/services/gitea/__init__.py +++ b/selfprivacy_api/services/gitea/__init__.py @@ -57,7 +57,7 @@ class Gitea(Service): @staticmethod def is_enabled() -> bool: with ReadUserData() as user_data: - return user_data.get("gitea", {}).get("enable", False) + return user_data.get("modules", {}).get("gitea", {}).get("enable", False) @staticmethod def get_status() -> ServiceStatus: @@ -75,17 +75,21 @@ class Gitea(Service): def enable(): """Enable Gitea service.""" with WriteUserData() as user_data: - if "gitea" not in user_data: - user_data["gitea"] = {} - user_data["gitea"]["enable"] = True + if "modules" not in user_data: + user_data["modules"] = {} + if "gitea" not in user_data["modules"]: + user_data["modules"]["gitea"] = {} + user_data["modules"]["gitea"]["enable"] = True @staticmethod def disable(): """Disable Gitea service.""" with WriteUserData() as user_data: - if "gitea" not in user_data: - user_data["gitea"] = {} - user_data["gitea"]["enable"] = False + if "modules" not in user_data: + user_data["modules"] = {} + if "gitea" not in user_data["modules"]: + user_data["modules"]["gitea"] = {} + user_data["modules"]["gitea"]["enable"] = False @staticmethod def stop(): diff --git a/selfprivacy_api/services/jitsi/__init__.py b/selfprivacy_api/services/jitsi/__init__.py index 2684fc3..e2b644d 100644 --- a/selfprivacy_api/services/jitsi/__init__.py +++ b/selfprivacy_api/services/jitsi/__init__.py @@ -58,7 +58,7 @@ class Jitsi(Service): @staticmethod def is_enabled() -> bool: with ReadUserData() as user_data: - return user_data.get("jitsi", {}).get("enable", False) + return user_data.get("modules", {}).get("jitsi", {}).get("enable", False) @staticmethod def get_status() -> ServiceStatus: @@ -70,17 +70,21 @@ class Jitsi(Service): def enable(): """Enable Jitsi service.""" with WriteUserData() as user_data: - if "jitsi" not in user_data: - user_data["jitsi"] = {} - user_data["jitsi"]["enable"] = True + if "modules" not in user_data: + user_data["modules"] = {} + if "jitsi" not in user_data["modules"]: + user_data["modules"]["jitsi"] = {} + user_data["modules"]["jitsi"]["enable"] = True @staticmethod def disable(): """Disable Gitea service.""" with WriteUserData() as user_data: - if "jitsi" not in user_data: - user_data["jitsi"] = {} - user_data["jitsi"]["enable"] = False + if "modules" not in user_data: + user_data["modules"] = {} + if "jitsi" not in user_data["modules"]: + user_data["modules"]["jitsi"] = {} + user_data["modules"]["jitsi"]["enable"] = False @staticmethod def stop(): diff --git a/selfprivacy_api/services/nextcloud/__init__.py b/selfprivacy_api/services/nextcloud/__init__.py index 27b72f2..cb108d6 100644 --- a/selfprivacy_api/services/nextcloud/__init__.py +++ b/selfprivacy_api/services/nextcloud/__init__.py @@ -79,9 +79,9 @@ class Nextcloud(Service): with WriteUserData() as user_data: if "modules" not in user_data: user_data["modules"] = {} - if "nextcloud" not in user_data: - user_data["nextcloud"] = {} - user_data["nextcloud"]["enable"] = True + if "nextcloud" not in user_data["modules"]: + user_data["modules"]["nextcloud"] = {} + user_data["modules"]["nextcloud"]["enable"] = True @staticmethod def disable(): @@ -89,9 +89,9 @@ class Nextcloud(Service): with WriteUserData() as user_data: if "modules" not in user_data: user_data["modules"] = {} - if "nextcloud" not in user_data: - user_data["nextcloud"] = {} - user_data["nextcloud"]["enable"] = False + if "nextcloud" not in user_data["modules"]: + user_data["modules"]["nextcloud"] = {} + user_data["modules"]["nextcloud"]["enable"] = False @staticmethod def stop(): diff --git a/selfprivacy_api/services/ocserv/__init__.py b/selfprivacy_api/services/ocserv/__init__.py index 98c6e97..120fd9d 100644 --- a/selfprivacy_api/services/ocserv/__init__.py +++ b/selfprivacy_api/services/ocserv/__init__.py @@ -54,7 +54,7 @@ class Ocserv(Service): @staticmethod def is_enabled() -> bool: with ReadUserData() as user_data: - return user_data.get("ocserv", {}).get("enable", False) + return user_data.get("modules", {}).get("ocserv", {}).get("enable", False) @staticmethod def get_status() -> ServiceStatus: @@ -63,16 +63,20 @@ class Ocserv(Service): @staticmethod def enable(): with WriteUserData() as user_data: - if "ocserv" not in user_data: - user_data["ocserv"] = {} - user_data["ocserv"]["enable"] = True + if "modules" not in user_data: + user_data["modules"] = {} + if "ocserv" not in user_data["modules"]: + user_data["modules"]["ocserv"] = {} + user_data["modules"]["ocserv"]["enable"] = True @staticmethod def disable(): with WriteUserData() as user_data: - if "ocserv" not in user_data: - user_data["ocserv"] = {} - user_data["ocserv"]["enable"] = False + if "modules" not in user_data: + user_data["modules"] = {} + if "ocserv" not in user_data["modules"]: + user_data["modules"]["ocserv"] = {} + user_data["modules"]["ocserv"]["enable"] = False @staticmethod def stop(): diff --git a/selfprivacy_api/services/pleroma/__init__.py b/selfprivacy_api/services/pleroma/__init__.py index d98b13f..c367532 100644 --- a/selfprivacy_api/services/pleroma/__init__.py +++ b/selfprivacy_api/services/pleroma/__init__.py @@ -53,7 +53,7 @@ class Pleroma(Service): @staticmethod def is_enabled() -> bool: with ReadUserData() as user_data: - return user_data.get("pleroma", {}).get("enable", False) + return user_data.get("modules", {}).get("pleroma", {}).get("enable", False) @staticmethod def get_status() -> ServiceStatus: @@ -62,16 +62,20 @@ class Pleroma(Service): @staticmethod def enable(): with WriteUserData() as user_data: - if "pleroma" not in user_data: - user_data["pleroma"] = {} - user_data["pleroma"]["enable"] = True + if "modules" not in user_data: + user_data["modules"] = {} + if "pleroma" not in user_data["modules"]: + user_data["modules"]["pleroma"] = {} + user_data["modules"]["pleroma"]["enable"] = True @staticmethod def disable(): with WriteUserData() as user_data: - if "pleroma" not in user_data: - user_data["pleroma"] = {} - user_data["pleroma"]["enable"] = False + if "modules" not in user_data: + user_data["modules"] = {} + if "pleroma" not in user_data["modules"]: + user_data["modules"]["pleroma"] = {} + user_data["modules"]["pleroma"]["enable"] = False @staticmethod def stop(): diff --git a/setup.py b/setup.py index 399b157..49aa0c6 100755 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( name="selfprivacy_api", - version="2.4.2", + version="2.4.2-flakes", packages=find_packages(), scripts=[ "selfprivacy_api/app.py", diff --git a/tests/test_graphql/test_system/turned_on.json b/tests/test_graphql/test_system/turned_on.json index caf2658..68cd37e 100644 --- a/tests/test_graphql/test_system/turned_on.json +++ b/tests/test_graphql/test_system/turned_on.json @@ -3,9 +3,6 @@ "token": "TEST_TOKEN", "enableSwagger": false }, - "bitwarden": { - "enable": true - }, "databasePassword": "PASSWORD", "domain": "test.tld", "hashedMasterPassword": "HASHED_PASSWORD", @@ -19,18 +16,6 @@ ] }, "username": "tester", - "gitea": { - "enable": true - }, - "ocserv": { - "enable": true - }, - "pleroma": { - "enable": true - }, - "jitsi": { - "enable": true - }, "autoUpgrade": { "enable": true, "allowReboot": true @@ -50,6 +35,21 @@ "nextcloud": { "enable": true }, + "bitwarden": { + "enable": true + }, + "gitea": { + "enable": true + }, + "ocserv": { + "enable": true + }, + "pleroma": { + "enable": true + }, + "jitsi": { + "enable": true + }, "simple-nixos-mailserver": { "enable": true } diff --git a/tests/test_rest_endpoints/services/data/gitkeep b/tests/test_rest_endpoints/services/data/gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/tests/test_rest_endpoints/services/test_bitwarden.py b/tests/test_rest_endpoints/services/test_bitwarden.py deleted file mode 100644 index 3977253..0000000 --- a/tests/test_rest_endpoints/services/test_bitwarden.py +++ /dev/null @@ -1,125 +0,0 @@ -import json -import pytest - - -def read_json(file_path): - with open(file_path, "r") as f: - return json.load(f) - - -############################################################################### - - -@pytest.fixture -def bitwarden_off(mocker, datadir): - mocker.patch("selfprivacy_api.utils.USERDATA_FILE", new=datadir / "turned_off.json") - assert read_json(datadir / "turned_off.json")["bitwarden"]["enable"] == False - return datadir - - -@pytest.fixture -def bitwarden_on(mocker, datadir): - mocker.patch("selfprivacy_api.utils.USERDATA_FILE", new=datadir / "turned_on.json") - assert read_json(datadir / "turned_on.json")["bitwarden"]["enable"] == True - return datadir - - -@pytest.fixture -def bitwarden_enable_undefined(mocker, datadir): - mocker.patch( - "selfprivacy_api.utils.USERDATA_FILE", new=datadir / "enable_undefined.json" - ) - assert "enable" not in read_json(datadir / "enable_undefined.json")["bitwarden"] - return datadir - - -@pytest.fixture -def bitwarden_undefined(mocker, datadir): - mocker.patch("selfprivacy_api.utils.USERDATA_FILE", new=datadir / "undefined.json") - assert "bitwarden" not in read_json(datadir / "undefined.json") - return datadir - - -############################################################################### - - -@pytest.mark.parametrize("endpoint", ["enable", "disable"]) -def test_unauthorized(client, bitwarden_off, endpoint): - response = client.post(f"/services/bitwarden/{endpoint}") - assert response.status_code == 401 - - -@pytest.mark.parametrize("endpoint", ["enable", "disable"]) -def test_illegal_methods(authorized_client, bitwarden_off, endpoint): - response = authorized_client.get(f"/services/bitwarden/{endpoint}") - assert response.status_code == 405 - response = authorized_client.put(f"/services/bitwarden/{endpoint}") - assert response.status_code == 405 - response = authorized_client.delete(f"/services/bitwarden/{endpoint}") - assert response.status_code == 405 - - -@pytest.mark.parametrize( - "endpoint,target_file", - [("enable", "turned_on.json"), ("disable", "turned_off.json")], -) -def test_switch_from_off(authorized_client, bitwarden_off, endpoint, target_file): - response = authorized_client.post(f"/services/bitwarden/{endpoint}") - assert response.status_code == 200 - assert read_json(bitwarden_off / "turned_off.json") == read_json( - bitwarden_off / target_file - ) - - -@pytest.mark.parametrize( - "endpoint,target_file", - [("enable", "turned_on.json"), ("disable", "turned_off.json")], -) -def test_switch_from_on(authorized_client, bitwarden_on, endpoint, target_file): - response = authorized_client.post(f"/services/bitwarden/{endpoint}") - assert response.status_code == 200 - assert read_json(bitwarden_on / "turned_on.json") == read_json( - bitwarden_on / target_file - ) - - -@pytest.mark.parametrize( - "endpoint,target_file", - [("enable", "turned_on.json"), ("disable", "turned_off.json")], -) -def test_switch_twice(authorized_client, bitwarden_off, endpoint, target_file): - response = authorized_client.post(f"/services/bitwarden/{endpoint}") - assert response.status_code == 200 - response = authorized_client.post(f"/services/bitwarden/{endpoint}") - assert response.status_code == 200 - assert read_json(bitwarden_off / "turned_off.json") == read_json( - bitwarden_off / target_file - ) - - -@pytest.mark.parametrize( - "endpoint,target_file", - [("enable", "turned_on.json"), ("disable", "turned_off.json")], -) -def test_on_attribute_deleted( - authorized_client, bitwarden_enable_undefined, endpoint, target_file -): - response = authorized_client.post(f"/services/bitwarden/{endpoint}") - assert response.status_code == 200 - assert read_json(bitwarden_enable_undefined / "enable_undefined.json") == read_json( - bitwarden_enable_undefined / target_file - ) - - -@pytest.mark.parametrize( - "endpoint,target_file", - [("enable", "turned_on.json"), ("disable", "turned_off.json")], -) -def test_on_bitwarden_undefined( - authorized_client, bitwarden_undefined, endpoint, target_file -): - response = authorized_client.post(f"/services/bitwarden/{endpoint}") - assert response.status_code == 200 - assert read_json(bitwarden_undefined / "undefined.json") == read_json( - bitwarden_undefined / target_file - ) diff --git a/tests/test_rest_endpoints/services/test_bitwarden/enable_undefined.json b/tests/test_rest_endpoints/services/test_bitwarden/enable_undefined.json deleted file mode 100644 index 1a95e85..0000000 --- a/tests/test_rest_endpoints/services/test_bitwarden/enable_undefined.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "bitwarden": { - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "nextcloud": { - "adminPassword": "ADMIN", - "databasePassword": "ADMIN", - "enable": true - }, - "resticPassword": "PASS", - "ssh": { - "enable": true, - "passwordAuthentication": true, - "rootKeys": [ - "ssh-ed25519 KEY test@pc" - ] - }, - "username": "tester", - "gitea": { - "enable": false - }, - "ocserv": { - "enable": true - }, - "pleroma": { - "enable": true - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "sshKeys": [ - "ssh-rsa KEY test@pc" - ], - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - }, - "backup": { - "provider": "BACKBLAZE", - "accountId": "ID", - "accountKey": "KEY", - "bucket": "selfprivacy" - } -} \ No newline at end of file diff --git a/tests/test_rest_endpoints/services/test_bitwarden/turned_off.json b/tests/test_rest_endpoints/services/test_bitwarden/turned_off.json deleted file mode 100644 index c1691ea..0000000 --- a/tests/test_rest_endpoints/services/test_bitwarden/turned_off.json +++ /dev/null @@ -1,57 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "bitwarden": { - "enable": false - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "nextcloud": { - "adminPassword": "ADMIN", - "databasePassword": "ADMIN", - "enable": true - }, - "resticPassword": "PASS", - "ssh": { - "enable": true, - "passwordAuthentication": true, - "rootKeys": [ - "ssh-ed25519 KEY test@pc" - ] - }, - "username": "tester", - "gitea": { - "enable": false - }, - "ocserv": { - "enable": true - }, - "pleroma": { - "enable": true - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "sshKeys": [ - "ssh-rsa KEY test@pc" - ], - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - }, - "backup": { - "provider": "BACKBLAZE", - "accountId": "ID", - "accountKey": "KEY", - "bucket": "selfprivacy" - } -} \ No newline at end of file diff --git a/tests/test_rest_endpoints/services/test_bitwarden/turned_on.json b/tests/test_rest_endpoints/services/test_bitwarden/turned_on.json deleted file mode 100644 index 42999d8..0000000 --- a/tests/test_rest_endpoints/services/test_bitwarden/turned_on.json +++ /dev/null @@ -1,57 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "bitwarden": { - "enable": true - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "nextcloud": { - "adminPassword": "ADMIN", - "databasePassword": "ADMIN", - "enable": true - }, - "resticPassword": "PASS", - "ssh": { - "enable": true, - "passwordAuthentication": true, - "rootKeys": [ - "ssh-ed25519 KEY test@pc" - ] - }, - "username": "tester", - "gitea": { - "enable": false - }, - "ocserv": { - "enable": true - }, - "pleroma": { - "enable": true - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "sshKeys": [ - "ssh-rsa KEY test@pc" - ], - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - }, - "backup": { - "provider": "BACKBLAZE", - "accountId": "ID", - "accountKey": "KEY", - "bucket": "selfprivacy" - } -} \ No newline at end of file diff --git a/tests/test_rest_endpoints/services/test_bitwarden/undefined.json b/tests/test_rest_endpoints/services/test_bitwarden/undefined.json deleted file mode 100644 index ee288c2..0000000 --- a/tests/test_rest_endpoints/services/test_bitwarden/undefined.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "nextcloud": { - "adminPassword": "ADMIN", - "databasePassword": "ADMIN", - "enable": true - }, - "resticPassword": "PASS", - "ssh": { - "enable": true, - "passwordAuthentication": true, - "rootKeys": [ - "ssh-ed25519 KEY test@pc" - ] - }, - "username": "tester", - "gitea": { - "enable": false - }, - "ocserv": { - "enable": true - }, - "pleroma": { - "enable": true - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "sshKeys": [ - "ssh-rsa KEY test@pc" - ], - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - }, - "backup": { - "provider": "BACKBLAZE", - "accountId": "ID", - "accountKey": "KEY", - "bucket": "selfprivacy" - } -} \ No newline at end of file diff --git a/tests/test_rest_endpoints/services/test_gitea.py b/tests/test_rest_endpoints/services/test_gitea.py deleted file mode 100644 index 0a50c19..0000000 --- a/tests/test_rest_endpoints/services/test_gitea.py +++ /dev/null @@ -1,121 +0,0 @@ -import json -import pytest - - -def read_json(file_path): - with open(file_path, "r") as f: - return json.load(f) - - -############################################################################### - - -@pytest.fixture -def gitea_off(mocker, datadir): - mocker.patch("selfprivacy_api.utils.USERDATA_FILE", new=datadir / "turned_off.json") - assert read_json(datadir / "turned_off.json")["gitea"]["enable"] == False - return datadir - - -@pytest.fixture -def gitea_on(mocker, datadir): - mocker.patch("selfprivacy_api.utils.USERDATA_FILE", new=datadir / "turned_on.json") - assert read_json(datadir / "turned_on.json")["gitea"]["enable"] == True - return datadir - - -@pytest.fixture -def gitea_enable_undefined(mocker, datadir): - mocker.patch( - "selfprivacy_api.utils.USERDATA_FILE", new=datadir / "enable_undefined.json" - ) - assert "enable" not in read_json(datadir / "enable_undefined.json")["gitea"] - return datadir - - -@pytest.fixture -def gitea_undefined(mocker, datadir): - mocker.patch("selfprivacy_api.utils.USERDATA_FILE", new=datadir / "undefined.json") - assert "gitea" not in read_json(datadir / "undefined.json") - return datadir - - -############################################################################### - - -@pytest.mark.parametrize("endpoint", ["enable", "disable"]) -def test_unauthorized(client, gitea_off, endpoint): - response = client.post(f"/services/gitea/{endpoint}") - assert response.status_code == 401 - - -@pytest.mark.parametrize("endpoint", ["enable", "disable"]) -def test_illegal_methods(authorized_client, gitea_off, endpoint): - response = authorized_client.get(f"/services/gitea/{endpoint}") - assert response.status_code == 405 - response = authorized_client.put(f"/services/gitea/{endpoint}") - assert response.status_code == 405 - response = authorized_client.delete(f"/services/gitea/{endpoint}") - assert response.status_code == 405 - - -@pytest.mark.parametrize( - "endpoint,target_file", - [("enable", "turned_on.json"), ("disable", "turned_off.json")], -) -def test_switch_from_off(authorized_client, gitea_off, endpoint, target_file): - response = authorized_client.post(f"/services/gitea/{endpoint}") - assert response.status_code == 200 - assert read_json(gitea_off / "turned_off.json") == read_json( - gitea_off / target_file - ) - - -@pytest.mark.parametrize( - "endpoint,target_file", - [("enable", "turned_on.json"), ("disable", "turned_off.json")], -) -def test_switch_from_on(authorized_client, gitea_on, endpoint, target_file): - response = authorized_client.post(f"/services/gitea/{endpoint}") - assert response.status_code == 200 - assert read_json(gitea_on / "turned_on.json") == read_json(gitea_on / target_file) - - -@pytest.mark.parametrize( - "endpoint,target_file", - [("enable", "turned_on.json"), ("disable", "turned_off.json")], -) -def test_switch_twice(authorized_client, gitea_off, endpoint, target_file): - response = authorized_client.post(f"/services/gitea/{endpoint}") - assert response.status_code == 200 - response = authorized_client.post(f"/services/gitea/{endpoint}") - assert response.status_code == 200 - assert read_json(gitea_off / "turned_off.json") == read_json( - gitea_off / target_file - ) - - -@pytest.mark.parametrize( - "endpoint,target_file", - [("enable", "turned_on.json"), ("disable", "turned_off.json")], -) -def test_on_attribute_deleted( - authorized_client, gitea_enable_undefined, endpoint, target_file -): - response = authorized_client.post(f"/services/gitea/{endpoint}") - assert response.status_code == 200 - assert read_json(gitea_enable_undefined / "enable_undefined.json") == read_json( - gitea_enable_undefined / target_file - ) - - -@pytest.mark.parametrize( - "endpoint,target_file", - [("enable", "turned_on.json"), ("disable", "turned_off.json")], -) -def test_on_gitea_undefined(authorized_client, gitea_undefined, endpoint, target_file): - response = authorized_client.post(f"/services/gitea/{endpoint}") - assert response.status_code == 200 - assert read_json(gitea_undefined / "undefined.json") == read_json( - gitea_undefined / target_file - ) diff --git a/tests/test_rest_endpoints/services/test_gitea/enable_undefined.json b/tests/test_rest_endpoints/services/test_gitea/enable_undefined.json deleted file mode 100644 index f9fb878..0000000 --- a/tests/test_rest_endpoints/services/test_gitea/enable_undefined.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "bitwarden": { - "enable": false - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "nextcloud": { - "adminPassword": "ADMIN", - "databasePassword": "ADMIN", - "enable": true - }, - "resticPassword": "PASS", - "ssh": { - "enable": true, - "passwordAuthentication": true, - "rootKeys": [ - "ssh-ed25519 KEY test@pc" - ] - }, - "username": "tester", - "gitea": { - }, - "ocserv": { - "enable": true - }, - "pleroma": { - "enable": true - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "sshKeys": [ - "ssh-rsa KEY test@pc" - ], - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - }, - "backup": { - "provider": "BACKBLAZE", - "accountId": "ID", - "accountKey": "KEY", - "bucket": "selfprivacy" - } -} \ No newline at end of file diff --git a/tests/test_rest_endpoints/services/test_gitea/turned_off.json b/tests/test_rest_endpoints/services/test_gitea/turned_off.json deleted file mode 100644 index c1691ea..0000000 --- a/tests/test_rest_endpoints/services/test_gitea/turned_off.json +++ /dev/null @@ -1,57 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "bitwarden": { - "enable": false - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "nextcloud": { - "adminPassword": "ADMIN", - "databasePassword": "ADMIN", - "enable": true - }, - "resticPassword": "PASS", - "ssh": { - "enable": true, - "passwordAuthentication": true, - "rootKeys": [ - "ssh-ed25519 KEY test@pc" - ] - }, - "username": "tester", - "gitea": { - "enable": false - }, - "ocserv": { - "enable": true - }, - "pleroma": { - "enable": true - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "sshKeys": [ - "ssh-rsa KEY test@pc" - ], - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - }, - "backup": { - "provider": "BACKBLAZE", - "accountId": "ID", - "accountKey": "KEY", - "bucket": "selfprivacy" - } -} \ No newline at end of file diff --git a/tests/test_rest_endpoints/services/test_gitea/turned_on.json b/tests/test_rest_endpoints/services/test_gitea/turned_on.json deleted file mode 100644 index f9a1eaf..0000000 --- a/tests/test_rest_endpoints/services/test_gitea/turned_on.json +++ /dev/null @@ -1,57 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "bitwarden": { - "enable": false - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "nextcloud": { - "adminPassword": "ADMIN", - "databasePassword": "ADMIN", - "enable": true - }, - "resticPassword": "PASS", - "ssh": { - "enable": true, - "passwordAuthentication": true, - "rootKeys": [ - "ssh-ed25519 KEY test@pc" - ] - }, - "username": "tester", - "gitea": { - "enable": true - }, - "ocserv": { - "enable": true - }, - "pleroma": { - "enable": true - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "sshKeys": [ - "ssh-rsa KEY test@pc" - ], - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - }, - "backup": { - "provider": "BACKBLAZE", - "accountId": "ID", - "accountKey": "KEY", - "bucket": "selfprivacy" - } -} \ No newline at end of file diff --git a/tests/test_rest_endpoints/services/test_gitea/undefined.json b/tests/test_rest_endpoints/services/test_gitea/undefined.json deleted file mode 100644 index a50a070..0000000 --- a/tests/test_rest_endpoints/services/test_gitea/undefined.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "bitwarden": { - "enable": false - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "nextcloud": { - "adminPassword": "ADMIN", - "databasePassword": "ADMIN", - "enable": true - }, - "resticPassword": "PASS", - "ssh": { - "enable": true, - "passwordAuthentication": true, - "rootKeys": [ - "ssh-ed25519 KEY test@pc" - ] - }, - "username": "tester", - "ocserv": { - "enable": true - }, - "pleroma": { - "enable": true - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "sshKeys": [ - "ssh-rsa KEY test@pc" - ], - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - }, - "backup": { - "provider": "BACKBLAZE", - "accountId": "ID", - "accountKey": "KEY", - "bucket": "selfprivacy" - } -} \ No newline at end of file diff --git a/tests/test_rest_endpoints/services/test_nextcloud/enable_undefined.json b/tests/test_rest_endpoints/services/test_nextcloud/enable_undefined.json deleted file mode 100644 index 19f1f2d..0000000 --- a/tests/test_rest_endpoints/services/test_nextcloud/enable_undefined.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "bitwarden": { - "enable": false - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "nextcloud": { - "adminPassword": "ADMIN", - "databasePassword": "ADMIN" - }, - "resticPassword": "PASS", - "ssh": { - "enable": true, - "passwordAuthentication": true, - "rootKeys": [ - "ssh-ed25519 KEY test@pc" - ] - }, - "username": "tester", - "gitea": { - "enable": false - }, - "ocserv": { - "enable": true - }, - "pleroma": { - "enable": true - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "sshKeys": [ - "ssh-rsa KEY test@pc" - ], - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - }, - "backup": { - "provider": "BACKBLAZE", - "accountId": "ID", - "accountKey": "KEY", - "bucket": "selfprivacy" - } -} \ No newline at end of file diff --git a/tests/test_rest_endpoints/services/test_nextcloud/turned_off.json b/tests/test_rest_endpoints/services/test_nextcloud/turned_off.json deleted file mode 100644 index b80ad9e..0000000 --- a/tests/test_rest_endpoints/services/test_nextcloud/turned_off.json +++ /dev/null @@ -1,57 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "bitwarden": { - "enable": false - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "nextcloud": { - "adminPassword": "ADMIN", - "databasePassword": "ADMIN", - "enable": false - }, - "resticPassword": "PASS", - "ssh": { - "enable": true, - "passwordAuthentication": true, - "rootKeys": [ - "ssh-ed25519 KEY test@pc" - ] - }, - "username": "tester", - "gitea": { - "enable": false - }, - "ocserv": { - "enable": true - }, - "pleroma": { - "enable": true - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "sshKeys": [ - "ssh-rsa KEY test@pc" - ], - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - }, - "backup": { - "provider": "BACKBLAZE", - "accountId": "ID", - "accountKey": "KEY", - "bucket": "selfprivacy" - } -} \ No newline at end of file diff --git a/tests/test_rest_endpoints/services/test_nextcloud/turned_on.json b/tests/test_rest_endpoints/services/test_nextcloud/turned_on.json deleted file mode 100644 index c1691ea..0000000 --- a/tests/test_rest_endpoints/services/test_nextcloud/turned_on.json +++ /dev/null @@ -1,57 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "bitwarden": { - "enable": false - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "nextcloud": { - "adminPassword": "ADMIN", - "databasePassword": "ADMIN", - "enable": true - }, - "resticPassword": "PASS", - "ssh": { - "enable": true, - "passwordAuthentication": true, - "rootKeys": [ - "ssh-ed25519 KEY test@pc" - ] - }, - "username": "tester", - "gitea": { - "enable": false - }, - "ocserv": { - "enable": true - }, - "pleroma": { - "enable": true - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "sshKeys": [ - "ssh-rsa KEY test@pc" - ], - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - }, - "backup": { - "provider": "BACKBLAZE", - "accountId": "ID", - "accountKey": "KEY", - "bucket": "selfprivacy" - } -} \ No newline at end of file diff --git a/tests/test_rest_endpoints/services/test_nextcloud/undefined.json b/tests/test_rest_endpoints/services/test_nextcloud/undefined.json deleted file mode 100644 index 46c09f3..0000000 --- a/tests/test_rest_endpoints/services/test_nextcloud/undefined.json +++ /dev/null @@ -1,49 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "resticPassword": "PASS", - "ssh": { - "enable": true, - "passwordAuthentication": true, - "rootKeys": [ - "ssh-ed25519 KEY test@pc" - ] - }, - "username": "tester", - "gitea": { - "enable": false - }, - "ocserv": { - "enable": true - }, - "pleroma": { - "enable": true - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "sshKeys": [ - "ssh-rsa KEY test@pc" - ], - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - }, - "backup": { - "provider": "BACKBLAZE", - "accountId": "ID", - "accountKey": "KEY", - "bucket": "selfprivacy" - } -} \ No newline at end of file diff --git a/tests/test_rest_endpoints/services/test_ocserv.py b/tests/test_rest_endpoints/services/test_ocserv.py deleted file mode 100644 index 8f43e70..0000000 --- a/tests/test_rest_endpoints/services/test_ocserv.py +++ /dev/null @@ -1,123 +0,0 @@ -import json -import pytest - - -def read_json(file_path): - with open(file_path, "r") as f: - return json.load(f) - - -############################################################################### - - -@pytest.fixture -def ocserv_off(mocker, datadir): - mocker.patch("selfprivacy_api.utils.USERDATA_FILE", new=datadir / "turned_off.json") - assert read_json(datadir / "turned_off.json")["ocserv"]["enable"] == False - return datadir - - -@pytest.fixture -def ocserv_on(mocker, datadir): - mocker.patch("selfprivacy_api.utils.USERDATA_FILE", new=datadir / "turned_on.json") - assert read_json(datadir / "turned_on.json")["ocserv"]["enable"] == True - return datadir - - -@pytest.fixture -def ocserv_enable_undefined(mocker, datadir): - mocker.patch( - "selfprivacy_api.utils.USERDATA_FILE", new=datadir / "enable_undefined.json" - ) - assert "enable" not in read_json(datadir / "enable_undefined.json")["ocserv"] - return datadir - - -@pytest.fixture -def ocserv_undefined(mocker, datadir): - mocker.patch("selfprivacy_api.utils.USERDATA_FILE", new=datadir / "undefined.json") - assert "ocserv" not in read_json(datadir / "undefined.json") - return datadir - - -############################################################################### - - -@pytest.mark.parametrize("endpoint", ["enable", "disable"]) -def test_unauthorized(client, ocserv_off, endpoint): - response = client.post(f"/services/ocserv/{endpoint}") - assert response.status_code == 401 - - -@pytest.mark.parametrize("endpoint", ["enable", "disable"]) -def test_illegal_methods(authorized_client, ocserv_off, endpoint): - response = authorized_client.get(f"/services/ocserv/{endpoint}") - assert response.status_code == 405 - response = authorized_client.put(f"/services/ocserv/{endpoint}") - assert response.status_code == 405 - response = authorized_client.delete(f"/services/ocserv/{endpoint}") - assert response.status_code == 405 - - -@pytest.mark.parametrize( - "endpoint,target_file", - [("enable", "turned_on.json"), ("disable", "turned_off.json")], -) -def test_switch_from_off(authorized_client, ocserv_off, endpoint, target_file): - response = authorized_client.post(f"/services/ocserv/{endpoint}") - assert response.status_code == 200 - assert read_json(ocserv_off / "turned_off.json") == read_json( - ocserv_off / target_file - ) - - -@pytest.mark.parametrize( - "endpoint,target_file", - [("enable", "turned_on.json"), ("disable", "turned_off.json")], -) -def test_switch_from_on(authorized_client, ocserv_on, endpoint, target_file): - response = authorized_client.post(f"/services/ocserv/{endpoint}") - assert response.status_code == 200 - assert read_json(ocserv_on / "turned_on.json") == read_json(ocserv_on / target_file) - - -@pytest.mark.parametrize( - "endpoint,target_file", - [("enable", "turned_on.json"), ("disable", "turned_off.json")], -) -def test_switch_twice(authorized_client, ocserv_off, endpoint, target_file): - response = authorized_client.post(f"/services/ocserv/{endpoint}") - assert response.status_code == 200 - response = authorized_client.post(f"/services/ocserv/{endpoint}") - assert response.status_code == 200 - assert read_json(ocserv_off / "turned_off.json") == read_json( - ocserv_off / target_file - ) - - -@pytest.mark.parametrize( - "endpoint,target_file", - [("enable", "turned_on.json"), ("disable", "turned_off.json")], -) -def test_on_attribute_deleted( - authorized_client, ocserv_enable_undefined, endpoint, target_file -): - response = authorized_client.post(f"/services/ocserv/{endpoint}") - assert response.status_code == 200 - assert read_json(ocserv_enable_undefined / "enable_undefined.json") == read_json( - ocserv_enable_undefined / target_file - ) - - -@pytest.mark.parametrize( - "endpoint,target_file", - [("enable", "turned_on.json"), ("disable", "turned_off.json")], -) -def test_on_ocserv_undefined( - authorized_client, ocserv_undefined, endpoint, target_file -): - response = authorized_client.post(f"/services/ocserv/{endpoint}") - assert response.status_code == 200 - assert read_json(ocserv_undefined / "undefined.json") == read_json( - ocserv_undefined / target_file - ) diff --git a/tests/test_rest_endpoints/services/test_ocserv/enable_undefined.json b/tests/test_rest_endpoints/services/test_ocserv/enable_undefined.json deleted file mode 100644 index e080110..0000000 --- a/tests/test_rest_endpoints/services/test_ocserv/enable_undefined.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "bitwarden": { - "enable": false - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "nextcloud": { - "adminPassword": "ADMIN", - "databasePassword": "ADMIN", - "enable": false - }, - "resticPassword": "PASS", - "ssh": { - "enable": true, - "passwordAuthentication": true, - "rootKeys": [ - "ssh-ed25519 KEY test@pc" - ] - }, - "username": "tester", - "gitea": { - "enable": false - }, - "ocserv": { - }, - "pleroma": { - "enable": true - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "sshKeys": [ - "ssh-rsa KEY test@pc" - ], - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - }, - "backup": { - "provider": "BACKBLAZE", - "accountId": "ID", - "accountKey": "KEY", - "bucket": "selfprivacy" - } -} \ No newline at end of file diff --git a/tests/test_rest_endpoints/services/test_ocserv/turned_off.json b/tests/test_rest_endpoints/services/test_ocserv/turned_off.json deleted file mode 100644 index 1c08123..0000000 --- a/tests/test_rest_endpoints/services/test_ocserv/turned_off.json +++ /dev/null @@ -1,57 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "bitwarden": { - "enable": false - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "nextcloud": { - "adminPassword": "ADMIN", - "databasePassword": "ADMIN", - "enable": false - }, - "resticPassword": "PASS", - "ssh": { - "enable": true, - "passwordAuthentication": true, - "rootKeys": [ - "ssh-ed25519 KEY test@pc" - ] - }, - "username": "tester", - "gitea": { - "enable": false - }, - "ocserv": { - "enable": false - }, - "pleroma": { - "enable": true - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "sshKeys": [ - "ssh-rsa KEY test@pc" - ], - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - }, - "backup": { - "provider": "BACKBLAZE", - "accountId": "ID", - "accountKey": "KEY", - "bucket": "selfprivacy" - } -} \ No newline at end of file diff --git a/tests/test_rest_endpoints/services/test_ocserv/turned_on.json b/tests/test_rest_endpoints/services/test_ocserv/turned_on.json deleted file mode 100644 index b80ad9e..0000000 --- a/tests/test_rest_endpoints/services/test_ocserv/turned_on.json +++ /dev/null @@ -1,57 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "bitwarden": { - "enable": false - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "nextcloud": { - "adminPassword": "ADMIN", - "databasePassword": "ADMIN", - "enable": false - }, - "resticPassword": "PASS", - "ssh": { - "enable": true, - "passwordAuthentication": true, - "rootKeys": [ - "ssh-ed25519 KEY test@pc" - ] - }, - "username": "tester", - "gitea": { - "enable": false - }, - "ocserv": { - "enable": true - }, - "pleroma": { - "enable": true - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "sshKeys": [ - "ssh-rsa KEY test@pc" - ], - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - }, - "backup": { - "provider": "BACKBLAZE", - "accountId": "ID", - "accountKey": "KEY", - "bucket": "selfprivacy" - } -} \ No newline at end of file diff --git a/tests/test_rest_endpoints/services/test_ocserv/undefined.json b/tests/test_rest_endpoints/services/test_ocserv/undefined.json deleted file mode 100644 index 12eb73a..0000000 --- a/tests/test_rest_endpoints/services/test_ocserv/undefined.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "bitwarden": { - "enable": false - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "nextcloud": { - "adminPassword": "ADMIN", - "databasePassword": "ADMIN", - "enable": false - }, - "resticPassword": "PASS", - "ssh": { - "enable": true, - "passwordAuthentication": true, - "rootKeys": [ - "ssh-ed25519 KEY test@pc" - ] - }, - "username": "tester", - "gitea": { - "enable": false - }, - "pleroma": { - "enable": true - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "sshKeys": [ - "ssh-rsa KEY test@pc" - ], - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - }, - "backup": { - "provider": "BACKBLAZE", - "accountId": "ID", - "accountKey": "KEY", - "bucket": "selfprivacy" - } -} \ No newline at end of file diff --git a/tests/test_rest_endpoints/services/test_pleroma.py b/tests/test_rest_endpoints/services/test_pleroma.py deleted file mode 100644 index 0d7f149..0000000 --- a/tests/test_rest_endpoints/services/test_pleroma.py +++ /dev/null @@ -1,125 +0,0 @@ -import json -import pytest - - -def read_json(file_path): - with open(file_path, "r") as f: - return json.load(f) - - -############################################################################### - - -@pytest.fixture -def pleroma_off(mocker, datadir): - mocker.patch("selfprivacy_api.utils.USERDATA_FILE", new=datadir / "turned_off.json") - assert read_json(datadir / "turned_off.json")["pleroma"]["enable"] == False - return datadir - - -@pytest.fixture -def pleroma_on(mocker, datadir): - mocker.patch("selfprivacy_api.utils.USERDATA_FILE", new=datadir / "turned_on.json") - assert read_json(datadir / "turned_on.json")["pleroma"]["enable"] == True - return datadir - - -@pytest.fixture -def pleroma_enable_undefined(mocker, datadir): - mocker.patch( - "selfprivacy_api.utils.USERDATA_FILE", new=datadir / "enable_undefined.json" - ) - assert "enable" not in read_json(datadir / "enable_undefined.json")["pleroma"] - return datadir - - -@pytest.fixture -def pleroma_undefined(mocker, datadir): - mocker.patch("selfprivacy_api.utils.USERDATA_FILE", new=datadir / "undefined.json") - assert "pleroma" not in read_json(datadir / "undefined.json") - return datadir - - -############################################################################### - - -@pytest.mark.parametrize("endpoint", ["enable", "disable"]) -def test_unauthorized(client, pleroma_off, endpoint): - response = client.post(f"/services/pleroma/{endpoint}") - assert response.status_code == 401 - - -@pytest.mark.parametrize("endpoint", ["enable", "disable"]) -def test_illegal_methods(authorized_client, pleroma_off, endpoint): - response = authorized_client.get(f"/services/pleroma/{endpoint}") - assert response.status_code == 405 - response = authorized_client.put(f"/services/pleroma/{endpoint}") - assert response.status_code == 405 - response = authorized_client.delete(f"/services/pleroma/{endpoint}") - assert response.status_code == 405 - - -@pytest.mark.parametrize( - "endpoint,target_file", - [("enable", "turned_on.json"), ("disable", "turned_off.json")], -) -def test_switch_from_off(authorized_client, pleroma_off, endpoint, target_file): - response = authorized_client.post(f"/services/pleroma/{endpoint}") - assert response.status_code == 200 - assert read_json(pleroma_off / "turned_off.json") == read_json( - pleroma_off / target_file - ) - - -@pytest.mark.parametrize( - "endpoint,target_file", - [("enable", "turned_on.json"), ("disable", "turned_off.json")], -) -def test_switch_from_on(authorized_client, pleroma_on, endpoint, target_file): - response = authorized_client.post(f"/services/pleroma/{endpoint}") - assert response.status_code == 200 - assert read_json(pleroma_on / "turned_on.json") == read_json( - pleroma_on / target_file - ) - - -@pytest.mark.parametrize( - "endpoint,target_file", - [("enable", "turned_on.json"), ("disable", "turned_off.json")], -) -def test_switch_twice(authorized_client, pleroma_off, endpoint, target_file): - response = authorized_client.post(f"/services/pleroma/{endpoint}") - assert response.status_code == 200 - response = authorized_client.post(f"/services/pleroma/{endpoint}") - assert response.status_code == 200 - assert read_json(pleroma_off / "turned_off.json") == read_json( - pleroma_off / target_file - ) - - -@pytest.mark.parametrize( - "endpoint,target_file", - [("enable", "turned_on.json"), ("disable", "turned_off.json")], -) -def test_on_attribute_deleted( - authorized_client, pleroma_enable_undefined, endpoint, target_file -): - response = authorized_client.post(f"/services/pleroma/{endpoint}") - assert response.status_code == 200 - assert read_json(pleroma_enable_undefined / "enable_undefined.json") == read_json( - pleroma_enable_undefined / target_file - ) - - -@pytest.mark.parametrize( - "endpoint,target_file", - [("enable", "turned_on.json"), ("disable", "turned_off.json")], -) -def test_on_pleroma_undefined( - authorized_client, pleroma_undefined, endpoint, target_file -): - response = authorized_client.post(f"/services/pleroma/{endpoint}") - assert response.status_code == 200 - assert read_json(pleroma_undefined / "undefined.json") == read_json( - pleroma_undefined / target_file - ) diff --git a/tests/test_rest_endpoints/services/test_pleroma/enable_undefined.json b/tests/test_rest_endpoints/services/test_pleroma/enable_undefined.json deleted file mode 100644 index 0903875..0000000 --- a/tests/test_rest_endpoints/services/test_pleroma/enable_undefined.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "bitwarden": { - "enable": false - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "nextcloud": { - "adminPassword": "ADMIN", - "databasePassword": "ADMIN", - "enable": false - }, - "resticPassword": "PASS", - "ssh": { - "enable": true, - "passwordAuthentication": true, - "rootKeys": [ - "ssh-ed25519 KEY test@pc" - ] - }, - "username": "tester", - "gitea": { - "enable": false - }, - "ocserv": { - "enable": false - }, - "pleroma": { - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "sshKeys": [ - "ssh-rsa KEY test@pc" - ], - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - }, - "backup": { - "provider": "BACKBLAZE", - "accountId": "ID", - "accountKey": "KEY", - "bucket": "selfprivacy" - } -} \ No newline at end of file diff --git a/tests/test_rest_endpoints/services/test_pleroma/turned_off.json b/tests/test_rest_endpoints/services/test_pleroma/turned_off.json deleted file mode 100644 index 813c01f..0000000 --- a/tests/test_rest_endpoints/services/test_pleroma/turned_off.json +++ /dev/null @@ -1,57 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "bitwarden": { - "enable": false - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "nextcloud": { - "adminPassword": "ADMIN", - "databasePassword": "ADMIN", - "enable": false - }, - "resticPassword": "PASS", - "ssh": { - "enable": true, - "passwordAuthentication": true, - "rootKeys": [ - "ssh-ed25519 KEY test@pc" - ] - }, - "username": "tester", - "gitea": { - "enable": false - }, - "ocserv": { - "enable": false - }, - "pleroma": { - "enable": false - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "sshKeys": [ - "ssh-rsa KEY test@pc" - ], - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - }, - "backup": { - "provider": "BACKBLAZE", - "accountId": "ID", - "accountKey": "KEY", - "bucket": "selfprivacy" - } -} \ No newline at end of file diff --git a/tests/test_rest_endpoints/services/test_pleroma/turned_on.json b/tests/test_rest_endpoints/services/test_pleroma/turned_on.json deleted file mode 100644 index 1c08123..0000000 --- a/tests/test_rest_endpoints/services/test_pleroma/turned_on.json +++ /dev/null @@ -1,57 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "bitwarden": { - "enable": false - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "nextcloud": { - "adminPassword": "ADMIN", - "databasePassword": "ADMIN", - "enable": false - }, - "resticPassword": "PASS", - "ssh": { - "enable": true, - "passwordAuthentication": true, - "rootKeys": [ - "ssh-ed25519 KEY test@pc" - ] - }, - "username": "tester", - "gitea": { - "enable": false - }, - "ocserv": { - "enable": false - }, - "pleroma": { - "enable": true - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "sshKeys": [ - "ssh-rsa KEY test@pc" - ], - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - }, - "backup": { - "provider": "BACKBLAZE", - "accountId": "ID", - "accountKey": "KEY", - "bucket": "selfprivacy" - } -} \ No newline at end of file diff --git a/tests/test_rest_endpoints/services/test_pleroma/undefined.json b/tests/test_rest_endpoints/services/test_pleroma/undefined.json deleted file mode 100644 index 77d8ad2..0000000 --- a/tests/test_rest_endpoints/services/test_pleroma/undefined.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "bitwarden": { - "enable": false - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "nextcloud": { - "adminPassword": "ADMIN", - "databasePassword": "ADMIN", - "enable": false - }, - "resticPassword": "PASS", - "ssh": { - "enable": true, - "passwordAuthentication": true, - "rootKeys": [ - "ssh-ed25519 KEY test@pc" - ] - }, - "username": "tester", - "gitea": { - "enable": false - }, - "ocserv": { - "enable": false - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "sshKeys": [ - "ssh-rsa KEY test@pc" - ], - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - }, - "backup": { - "provider": "BACKBLAZE", - "accountId": "ID", - "accountKey": "KEY", - "bucket": "selfprivacy" - } -} \ No newline at end of file diff --git a/tests/test_rest_endpoints/services/test_restic/no_values.json b/tests/test_rest_endpoints/services/test_restic/no_values.json deleted file mode 100644 index 3b4a2f5..0000000 --- a/tests/test_rest_endpoints/services/test_restic/no_values.json +++ /dev/null @@ -1,72 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "bitwarden": { - "enable": false - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "nextcloud": { - "adminPassword": "ADMIN", - "databasePassword": "ADMIN", - "enable": true - }, - "resticPassword": "PASS", - "ssh": { - "enable": true, - "passwordAuthentication": true, - "rootKeys": [ - "ssh-ed25519 KEY test@pc" - ] - }, - "username": "tester", - "gitea": { - "enable": false - }, - "ocserv": { - "enable": true - }, - "pleroma": { - "enable": true - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "sshKeys": [ - "ssh-rsa KEY test@pc" - ], - "users": [ - { - "username": "user1", - "hashedPassword": "HASHED_PASSWORD_1", - "sshKeys": [ - "ssh-rsa KEY user1@pc" - ] - }, - { - "username": "user2", - "hashedPassword": "HASHED_PASSWORD_2", - "sshKeys": [ - ] - }, - { - "username": "user3", - "hashedPassword": "HASHED_PASSWORD_3" - } - ], - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - }, - "backup": { - } -} \ No newline at end of file diff --git a/tests/test_rest_endpoints/services/test_restic/some_values.json b/tests/test_rest_endpoints/services/test_restic/some_values.json deleted file mode 100644 index c003d10..0000000 --- a/tests/test_rest_endpoints/services/test_restic/some_values.json +++ /dev/null @@ -1,76 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "bitwarden": { - "enable": false - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "nextcloud": { - "adminPassword": "ADMIN", - "databasePassword": "ADMIN", - "enable": true - }, - "resticPassword": "PASS", - "ssh": { - "enable": true, - "passwordAuthentication": true, - "rootKeys": [ - "ssh-ed25519 KEY test@pc" - ] - }, - "username": "tester", - "gitea": { - "enable": false - }, - "ocserv": { - "enable": true - }, - "pleroma": { - "enable": true - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "sshKeys": [ - "ssh-rsa KEY test@pc" - ], - "users": [ - { - "username": "user1", - "hashedPassword": "HASHED_PASSWORD_1", - "sshKeys": [ - "ssh-rsa KEY user1@pc" - ] - }, - { - "username": "user2", - "hashedPassword": "HASHED_PASSWORD_2", - "sshKeys": [ - ] - }, - { - "username": "user3", - "hashedPassword": "HASHED_PASSWORD_3" - } - ], - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - }, - "backup": { - "provider": "BACKBLAZE", - "accountId": "ID", - "accountKey": "KEY", - "bucket": "BUCKET" - } -} diff --git a/tests/test_rest_endpoints/services/test_restic/undefined.json b/tests/test_rest_endpoints/services/test_restic/undefined.json deleted file mode 100644 index 5bd1220..0000000 --- a/tests/test_rest_endpoints/services/test_restic/undefined.json +++ /dev/null @@ -1,70 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "bitwarden": { - "enable": false - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "nextcloud": { - "adminPassword": "ADMIN", - "databasePassword": "ADMIN", - "enable": true - }, - "resticPassword": "PASS", - "ssh": { - "enable": true, - "passwordAuthentication": true, - "rootKeys": [ - "ssh-ed25519 KEY test@pc" - ] - }, - "username": "tester", - "gitea": { - "enable": false - }, - "ocserv": { - "enable": true - }, - "pleroma": { - "enable": true - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "sshKeys": [ - "ssh-rsa KEY test@pc" - ], - "users": [ - { - "username": "user1", - "hashedPassword": "HASHED_PASSWORD_1", - "sshKeys": [ - "ssh-rsa KEY user1@pc" - ] - }, - { - "username": "user2", - "hashedPassword": "HASHED_PASSWORD_2", - "sshKeys": [ - ] - }, - { - "username": "user3", - "hashedPassword": "HASHED_PASSWORD_3" - } - ], - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - } -} \ No newline at end of file diff --git a/tests/test_rest_endpoints/services/test_services.py b/tests/test_rest_endpoints/services/test_services.py deleted file mode 100644 index 1108e8c..0000000 --- a/tests/test_rest_endpoints/services/test_services.py +++ /dev/null @@ -1,138 +0,0 @@ -import base64 -import json -import pytest - - -def read_json(file_path): - with open(file_path, "r", encoding="utf-8") as file: - return json.load(file) - - -def call_args_asserts(mocked_object): - assert mocked_object.call_count == 7 - assert mocked_object.call_args_list[0][0][0] == [ - "systemctl", - "show", - "dovecot2.service", - ] - assert mocked_object.call_args_list[1][0][0] == [ - "systemctl", - "show", - "postfix.service", - ] - assert mocked_object.call_args_list[2][0][0] == [ - "systemctl", - "show", - "vaultwarden.service", - ] - assert mocked_object.call_args_list[3][0][0] == [ - "systemctl", - "show", - "gitea.service", - ] - assert mocked_object.call_args_list[4][0][0] == [ - "systemctl", - "show", - "phpfpm-nextcloud.service", - ] - assert mocked_object.call_args_list[5][0][0] == [ - "systemctl", - "show", - "ocserv.service", - ] - assert mocked_object.call_args_list[6][0][0] == [ - "systemctl", - "show", - "pleroma.service", - ] - - -SUCCESSFUL_STATUS = b""" -Type=oneshot -ExitType=main -Restart=no -NotifyAccess=none -RestartUSec=100ms -LoadState=loaded -ActiveState=active -FreezerState=running -SubState=exited -""" - -FAILED_STATUS = b""" -Type=oneshot -ExitType=main -Restart=no -NotifyAccess=none -RestartUSec=100ms -LoadState=loaded -ActiveState=failed -FreezerState=running -SubState=exited -""" - - -@pytest.fixture -def mock_subproccess_popen(mocker): - mock = mocker.patch( - "subprocess.check_output", autospec=True, return_value=SUCCESSFUL_STATUS - ) - return mock - - -@pytest.fixture -def mock_broken_service(mocker): - mock = mocker.patch( - "subprocess.check_output", autospec=True, return_value=FAILED_STATUS - ) - return mock - - -############################################################################### - - -def test_unauthorized(client, mock_subproccess_popen): - """Test unauthorized""" - response = client.get("/services/status") - assert response.status_code == 401 - - -def test_illegal_methods(authorized_client, mock_subproccess_popen): - response = authorized_client.post("/services/status") - assert response.status_code == 405 - response = authorized_client.put("/services/status") - assert response.status_code == 405 - response = authorized_client.delete("/services/status") - assert response.status_code == 405 - - -def test_dkim_key(authorized_client, mock_subproccess_popen): - response = authorized_client.get("/services/status") - assert response.status_code == 200 - assert response.json() == { - "imap": 0, - "smtp": 0, - "http": 0, - "bitwarden": 0, - "gitea": 0, - "nextcloud": 0, - "ocserv": 0, - "pleroma": 0, - } - call_args_asserts(mock_subproccess_popen) - - -def test_no_dkim_key(authorized_client, mock_broken_service): - response = authorized_client.get("/services/status") - assert response.status_code == 200 - assert response.json() == { - "imap": 1, - "smtp": 1, - "http": 0, - "bitwarden": 1, - "gitea": 1, - "nextcloud": 1, - "ocserv": 1, - "pleroma": 1, - } - call_args_asserts(mock_broken_service) diff --git a/tests/test_rest_endpoints/services/test_ssh.py b/tests/test_rest_endpoints/services/test_ssh.py deleted file mode 100644 index b1c1ab8..0000000 --- a/tests/test_rest_endpoints/services/test_ssh.py +++ /dev/null @@ -1,521 +0,0 @@ -# pylint: disable=redefined-outer-name -# pylint: disable=unused-argument -import json -import pytest - - -def read_json(file_path): - with open(file_path, "r", encoding="utf-8") as file: - return json.load(file) - - -## FIXTURES ################################################### - - -@pytest.fixture -def ssh_off(mocker, datadir): - mocker.patch("selfprivacy_api.utils.USERDATA_FILE", new=datadir / "turned_off.json") - assert not read_json(datadir / "turned_off.json")["ssh"]["enable"] - assert read_json(datadir / "turned_off.json")["ssh"]["passwordAuthentication"] - return datadir - - -@pytest.fixture -def ssh_on(mocker, datadir): - mocker.patch("selfprivacy_api.utils.USERDATA_FILE", new=datadir / "turned_on.json") - assert read_json(datadir / "turned_off.json")["ssh"]["passwordAuthentication"] - assert read_json(datadir / "turned_on.json")["ssh"]["enable"] - return datadir - - -@pytest.fixture -def all_off(mocker, datadir): - mocker.patch("selfprivacy_api.utils.USERDATA_FILE", new=datadir / "all_off.json") - assert not read_json(datadir / "all_off.json")["ssh"]["passwordAuthentication"] - assert not read_json(datadir / "all_off.json")["ssh"]["enable"] - return datadir - - -@pytest.fixture -def undefined_settings(mocker, datadir): - mocker.patch("selfprivacy_api.utils.USERDATA_FILE", new=datadir / "undefined.json") - assert "ssh" not in read_json(datadir / "undefined.json") - return datadir - - -@pytest.fixture -def undefined_values(mocker, datadir): - mocker.patch( - "selfprivacy_api.utils.USERDATA_FILE", new=datadir / "undefined_values.json" - ) - assert "ssh" in read_json(datadir / "undefined_values.json") - assert "enable" not in read_json(datadir / "undefined_values.json")["ssh"] - assert ( - "passwordAuthentication" - not in read_json(datadir / "undefined_values.json")["ssh"] - ) - return datadir - - -@pytest.fixture -def root_and_admin_have_keys(mocker, datadir): - mocker.patch( - "selfprivacy_api.utils.USERDATA_FILE", - new=datadir / "root_and_admin_have_keys.json", - ) - assert read_json(datadir / "root_and_admin_have_keys.json")["ssh"]["enable"] - assert read_json(datadir / "root_and_admin_have_keys.json")["ssh"][ - "passwordAuthentication" - ] - assert read_json(datadir / "root_and_admin_have_keys.json")["ssh"]["rootKeys"] == [ - "ssh-ed25519 KEY test@pc" - ] - assert read_json(datadir / "root_and_admin_have_keys.json")["sshKeys"] == [ - "ssh-rsa KEY test@pc" - ] - return datadir - - -@pytest.fixture -def some_users(mocker, datadir): - mocker.patch("selfprivacy_api.utils.USERDATA_FILE", new=datadir / "some_users.json") - assert "users" in read_json(datadir / "some_users.json") - assert read_json(datadir / "some_users.json")["users"] == [ - { - "username": "user1", - "hashedPassword": "HASHED_PASSWORD_1", - "sshKeys": ["ssh-rsa KEY user1@pc"], - }, - {"username": "user2", "hashedPassword": "HASHED_PASSWORD_2", "sshKeys": []}, - {"username": "user3", "hashedPassword": "HASHED_PASSWORD_3"}, - ] - return datadir - - -## TEST 401 ###################################################### - - -@pytest.mark.parametrize("endpoint", ["ssh/enable", "ssh/keys/user"]) -def test_unauthorized(client, ssh_off, endpoint): - response = client.post(f"/services/{endpoint}") - assert response.status_code == 401 - - -@pytest.mark.parametrize("endpoint", ["ssh", "ssh/key/send"]) -def test_unauthorized_put(client, ssh_off, endpoint): - response = client.put(f"/services/{endpoint}") - assert response.status_code == 401 - - -## TEST ENABLE ###################################################### - - -def test_legacy_enable(authorized_client, ssh_off): - response = authorized_client.post("/services/ssh/enable") - assert response.status_code == 200 - assert read_json(ssh_off / "turned_off.json") == read_json( - ssh_off / "turned_on.json" - ) - - -def test_legacy_on_undefined(authorized_client, undefined_settings): - response = authorized_client.post("/services/ssh/enable") - assert response.status_code == 200 - data = read_json(undefined_settings / "undefined.json") - assert data["ssh"]["enable"] == True - - -def test_legacy_enable_when_enabled(authorized_client, ssh_on): - response = authorized_client.post("/services/ssh/enable") - assert response.status_code == 200 - assert read_json(ssh_on / "turned_on.json") == read_json(ssh_on / "turned_on.json") - - -## GET ON /ssh ###################################################### - - -def test_get_current_settings_ssh_off(authorized_client, ssh_off): - response = authorized_client.get("/services/ssh") - assert response.status_code == 200 - assert response.json() == {"enable": False, "passwordAuthentication": True} - - -def test_get_current_settings_ssh_on(authorized_client, ssh_on): - response = authorized_client.get("/services/ssh") - assert response.status_code == 200 - assert response.json() == {"enable": True, "passwordAuthentication": True} - - -def test_get_current_settings_all_off(authorized_client, all_off): - response = authorized_client.get("/services/ssh") - assert response.status_code == 200 - assert response.json() == {"enable": False, "passwordAuthentication": False} - - -def test_get_current_settings_undefined(authorized_client, undefined_settings): - response = authorized_client.get("/services/ssh") - assert response.status_code == 200 - assert response.json() == {"enable": True, "passwordAuthentication": True} - - -def test_get_current_settings_mostly_undefined(authorized_client, undefined_values): - response = authorized_client.get("/services/ssh") - assert response.status_code == 200 - assert response.json() == {"enable": True, "passwordAuthentication": False} - - -## PUT ON /ssh ###################################################### - -available_settings = [ - {"enable": True, "passwordAuthentication": True}, - {"enable": True, "passwordAuthentication": False}, - {"enable": False, "passwordAuthentication": True}, - {"enable": False, "passwordAuthentication": False}, - {"enable": True}, - {"enable": False}, - {"passwordAuthentication": True}, - {"passwordAuthentication": False}, -] - - -@pytest.mark.parametrize("settings", available_settings) -def test_set_settings_ssh_off(authorized_client, ssh_off, settings): - response = authorized_client.put("/services/ssh", json=settings) - assert response.status_code == 200 - data = read_json(ssh_off / "turned_off.json")["ssh"] - if "enable" in settings: - assert data["enable"] == settings["enable"] - if "passwordAuthentication" in settings: - assert data["passwordAuthentication"] == settings["passwordAuthentication"] - - -@pytest.mark.parametrize("settings", available_settings) -def test_set_settings_ssh_on(authorized_client, ssh_on, settings): - response = authorized_client.put("/services/ssh", json=settings) - assert response.status_code == 200 - data = read_json(ssh_on / "turned_on.json")["ssh"] - if "enable" in settings: - assert data["enable"] == settings["enable"] - if "passwordAuthentication" in settings: - assert data["passwordAuthentication"] == settings["passwordAuthentication"] - - -@pytest.mark.parametrize("settings", available_settings) -def test_set_settings_all_off(authorized_client, all_off, settings): - response = authorized_client.put("/services/ssh", json=settings) - assert response.status_code == 200 - data = read_json(all_off / "all_off.json")["ssh"] - if "enable" in settings: - assert data["enable"] == settings["enable"] - if "passwordAuthentication" in settings: - assert data["passwordAuthentication"] == settings["passwordAuthentication"] - - -@pytest.mark.parametrize("settings", available_settings) -def test_set_settings_undefined(authorized_client, undefined_settings, settings): - response = authorized_client.put("/services/ssh", json=settings) - assert response.status_code == 200 - data = read_json(undefined_settings / "undefined.json")["ssh"] - if "enable" in settings: - assert data["enable"] == settings["enable"] - if "passwordAuthentication" in settings: - assert data["passwordAuthentication"] == settings["passwordAuthentication"] - - -## PUT ON /ssh/key/send ###################################################### - - -def test_add_root_key(authorized_client, ssh_on): - response = authorized_client.put( - "/services/ssh/key/send", json={"public_key": "ssh-rsa KEY test@pc"} - ) - assert response.status_code == 201 - assert read_json(ssh_on / "turned_on.json")["ssh"]["rootKeys"] == [ - "ssh-rsa KEY test@pc", - ] - - -def test_add_root_key_on_undefined(authorized_client, undefined_settings): - response = authorized_client.put( - "/services/ssh/key/send", json={"public_key": "ssh-rsa KEY test@pc"} - ) - assert response.status_code == 201 - data = read_json(undefined_settings / "undefined.json") - assert data["ssh"]["rootKeys"] == ["ssh-rsa KEY test@pc"] - - -def test_add_root_key_one_more(authorized_client, root_and_admin_have_keys): - response = authorized_client.put( - "/services/ssh/key/send", json={"public_key": "ssh-rsa KEY test@pc"} - ) - assert response.status_code == 201 - assert read_json(root_and_admin_have_keys / "root_and_admin_have_keys.json")["ssh"][ - "rootKeys" - ] == [ - "ssh-ed25519 KEY test@pc", - "ssh-rsa KEY test@pc", - ] - - -def test_add_existing_root_key(authorized_client, root_and_admin_have_keys): - response = authorized_client.put( - "/services/ssh/key/send", json={"public_key": "ssh-ed25519 KEY test@pc"} - ) - assert response.status_code == 409 - assert read_json(root_and_admin_have_keys / "root_and_admin_have_keys.json")["ssh"][ - "rootKeys" - ] == [ - "ssh-ed25519 KEY test@pc", - ] - - -def test_add_invalid_root_key(authorized_client, ssh_on): - response = authorized_client.put( - "/services/ssh/key/send", json={"public_key": "INVALID KEY test@pc"} - ) - assert response.status_code == 400 - - -## /ssh/keys/{user} ###################################################### - - -def test_get_root_key(authorized_client, root_and_admin_have_keys): - response = authorized_client.get("/services/ssh/keys/root") - assert response.status_code == 200 - assert response.json() == ["ssh-ed25519 KEY test@pc"] - - -def test_get_root_key_when_none(authorized_client, ssh_on): - response = authorized_client.get("/services/ssh/keys/root") - assert response.status_code == 200 - assert response.json() == [] - - -def test_get_root_key_on_undefined(authorized_client, undefined_settings): - response = authorized_client.get("/services/ssh/keys/root") - assert response.status_code == 200 - assert response.json() == [] - - -def test_delete_root_key(authorized_client, root_and_admin_have_keys): - response = authorized_client.delete( - "/services/ssh/keys/root", json={"public_key": "ssh-ed25519 KEY test@pc"} - ) - assert response.status_code == 200 - assert ( - "rootKeys" - not in read_json(root_and_admin_have_keys / "root_and_admin_have_keys.json")[ - "ssh" - ] - or read_json(root_and_admin_have_keys / "root_and_admin_have_keys.json")["ssh"][ - "rootKeys" - ] - == [] - ) - - -def test_delete_root_nonexistent_key(authorized_client, root_and_admin_have_keys): - response = authorized_client.delete( - "/services/ssh/keys/root", json={"public_key": "ssh-rsa KEY test@pc"} - ) - assert response.status_code == 404 - assert read_json(root_and_admin_have_keys / "root_and_admin_have_keys.json")["ssh"][ - "rootKeys" - ] == [ - "ssh-ed25519 KEY test@pc", - ] - - -def test_delete_root_key_on_undefined(authorized_client, undefined_settings): - response = authorized_client.delete( - "/services/ssh/keys/root", json={"public_key": "ssh-ed25519 KEY test@pc"} - ) - assert response.status_code == 404 - assert "ssh" not in read_json(undefined_settings / "undefined.json") - - -def test_get_admin_key(authorized_client, root_and_admin_have_keys): - response = authorized_client.get("/services/ssh/keys/tester") - assert response.status_code == 200 - assert response.json() == ["ssh-rsa KEY test@pc"] - - -def test_get_admin_key_when_none(authorized_client, ssh_on): - response = authorized_client.get("/services/ssh/keys/tester") - assert response.status_code == 200 - assert response.json() == [] - - -def test_delete_admin_key(authorized_client, root_and_admin_have_keys): - response = authorized_client.delete( - "/services/ssh/keys/tester", json={"public_key": "ssh-rsa KEY test@pc"} - ) - assert response.status_code == 200 - assert ( - read_json(root_and_admin_have_keys / "root_and_admin_have_keys.json")["sshKeys"] - == [] - ) - - -def test_delete_nonexistent_admin_key(authorized_client, root_and_admin_have_keys): - response = authorized_client.delete( - "/services/ssh/keys/tester", json={"public_key": "ssh-rsa NO KEY test@pc"} - ) - assert response.status_code == 404 - assert read_json(root_and_admin_have_keys / "root_and_admin_have_keys.json")[ - "sshKeys" - ] == ["ssh-rsa KEY test@pc"] - - -def test_delete_admin_key_on_undefined(authorized_client, undefined_settings): - response = authorized_client.delete( - "/services/ssh/keys/tester", json={"public_key": "ssh-rsa KEY test@pc"} - ) - assert response.status_code == 404 - assert "sshKeys" not in read_json(undefined_settings / "undefined.json") - - -def test_add_admin_key(authorized_client, ssh_on): - response = authorized_client.post( - "/services/ssh/keys/tester", json={"public_key": "ssh-rsa KEY test@pc"} - ) - assert response.status_code == 201 - assert read_json(ssh_on / "turned_on.json")["sshKeys"] == [ - "ssh-rsa KEY test@pc", - ] - - -def test_add_admin_key_one_more(authorized_client, root_and_admin_have_keys): - response = authorized_client.post( - "/services/ssh/keys/tester", json={"public_key": "ssh-rsa KEY_2 test@pc"} - ) - assert response.status_code == 201 - assert read_json(root_and_admin_have_keys / "root_and_admin_have_keys.json")[ - "sshKeys" - ] == ["ssh-rsa KEY test@pc", "ssh-rsa KEY_2 test@pc"] - - -def test_add_existing_admin_key(authorized_client, root_and_admin_have_keys): - response = authorized_client.post( - "/services/ssh/keys/tester", json={"public_key": "ssh-rsa KEY test@pc"} - ) - assert response.status_code == 409 - assert read_json(root_and_admin_have_keys / "root_and_admin_have_keys.json")[ - "sshKeys" - ] == [ - "ssh-rsa KEY test@pc", - ] - - -def test_add_invalid_admin_key(authorized_client, ssh_on): - response = authorized_client.post( - "/services/ssh/keys/tester", json={"public_key": "INVALID KEY test@pc"} - ) - assert response.status_code == 400 - - -@pytest.mark.parametrize("user", [1, 2, 3]) -def test_get_user_key(authorized_client, some_users, user): - response = authorized_client.get(f"/services/ssh/keys/user{user}") - assert response.status_code == 200 - if user == 1: - assert response.json() == ["ssh-rsa KEY user1@pc"] - else: - assert response.json() == [] - - -def test_get_keys_of_nonexistent_user(authorized_client, some_users): - response = authorized_client.get("/services/ssh/keys/user4") - assert response.status_code == 404 - - -def test_get_keys_of_undefined_users(authorized_client, undefined_settings): - response = authorized_client.get("/services/ssh/keys/user1") - assert response.status_code == 404 - - -@pytest.mark.parametrize("user", [1, 2, 3]) -def test_add_user_key(authorized_client, some_users, user): - response = authorized_client.post( - f"/services/ssh/keys/user{user}", json={"public_key": "ssh-ed25519 KEY test@pc"} - ) - assert response.status_code == 201 - if user == 1: - assert read_json(some_users / "some_users.json")["users"][user - 1][ - "sshKeys" - ] == [ - "ssh-rsa KEY user1@pc", - "ssh-ed25519 KEY test@pc", - ] - else: - assert read_json(some_users / "some_users.json")["users"][user - 1][ - "sshKeys" - ] == ["ssh-ed25519 KEY test@pc"] - - -def test_add_existing_user_key(authorized_client, some_users): - response = authorized_client.post( - "/services/ssh/keys/user1", json={"public_key": "ssh-rsa KEY user1@pc"} - ) - assert response.status_code == 409 - assert read_json(some_users / "some_users.json")["users"][0]["sshKeys"] == [ - "ssh-rsa KEY user1@pc", - ] - - -def test_add_invalid_user_key(authorized_client, some_users): - response = authorized_client.post( - "/services/ssh/keys/user1", json={"public_key": "INVALID KEY user1@pc"} - ) - assert response.status_code == 400 - - -def test_delete_user_key(authorized_client, some_users): - response = authorized_client.delete( - "/services/ssh/keys/user1", json={"public_key": "ssh-rsa KEY user1@pc"} - ) - assert response.status_code == 200 - assert read_json(some_users / "some_users.json")["users"][0]["sshKeys"] == [] - - -@pytest.mark.parametrize("user", [2, 3]) -def test_delete_nonexistent_user_key(authorized_client, some_users, user): - response = authorized_client.delete( - f"/services/ssh/keys/user{user}", json={"public_key": "ssh-rsa KEY user1@pc"} - ) - assert response.status_code == 404 - if user == 2: - assert ( - read_json(some_users / "some_users.json")["users"][user - 1]["sshKeys"] - == [] - ) - if user == 3: - "sshKeys" not in read_json(some_users / "some_users.json")["users"][user - 1] - - -def test_add_keys_of_nonexistent_user(authorized_client, some_users): - response = authorized_client.post( - "/services/ssh/keys/user4", json={"public_key": "ssh-rsa KEY user4@pc"} - ) - assert response.status_code == 404 - - -def test_add_key_on_undefined_users(authorized_client, undefined_settings): - response = authorized_client.post( - "/services/ssh/keys/user1", json={"public_key": "ssh-rsa KEY user4@pc"} - ) - assert response.status_code == 404 - - -def test_delete_keys_of_nonexistent_user(authorized_client, some_users): - response = authorized_client.delete( - "/services/ssh/keys/user4", json={"public_key": "ssh-rsa KEY user4@pc"} - ) - assert response.status_code == 404 - - -def test_delete_key_when_undefined_users(authorized_client, undefined_settings): - response = authorized_client.delete( - "/services/ssh/keys/user1", json={"public_key": "ssh-rsa KEY user1@pc"} - ) - assert response.status_code == 404 diff --git a/tests/test_rest_endpoints/services/test_ssh/all_off.json b/tests/test_rest_endpoints/services/test_ssh/all_off.json deleted file mode 100644 index 051d364..0000000 --- a/tests/test_rest_endpoints/services/test_ssh/all_off.json +++ /dev/null @@ -1,57 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "bitwarden": { - "enable": false - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "nextcloud": { - "adminPassword": "ADMIN", - "databasePassword": "ADMIN", - "enable": true - }, - "resticPassword": "PASS", - "ssh": { - "enable": false, - "passwordAuthentication": false, - "rootKeys": [ - "ssh-ed25519 KEY test@pc" - ] - }, - "username": "tester", - "gitea": { - "enable": false - }, - "ocserv": { - "enable": true - }, - "pleroma": { - "enable": true - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "sshKeys": [ - "ssh-rsa KEY test@pc" - ], - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - }, - "backup": { - "provider": "BACKBLAZE", - "accountId": "ID", - "accountKey": "KEY", - "bucket": "selfprivacy" - } -} \ No newline at end of file diff --git a/tests/test_rest_endpoints/services/test_ssh/root_and_admin_have_keys.json b/tests/test_rest_endpoints/services/test_ssh/root_and_admin_have_keys.json deleted file mode 100644 index c1691ea..0000000 --- a/tests/test_rest_endpoints/services/test_ssh/root_and_admin_have_keys.json +++ /dev/null @@ -1,57 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "bitwarden": { - "enable": false - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "nextcloud": { - "adminPassword": "ADMIN", - "databasePassword": "ADMIN", - "enable": true - }, - "resticPassword": "PASS", - "ssh": { - "enable": true, - "passwordAuthentication": true, - "rootKeys": [ - "ssh-ed25519 KEY test@pc" - ] - }, - "username": "tester", - "gitea": { - "enable": false - }, - "ocserv": { - "enable": true - }, - "pleroma": { - "enable": true - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "sshKeys": [ - "ssh-rsa KEY test@pc" - ], - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - }, - "backup": { - "provider": "BACKBLAZE", - "accountId": "ID", - "accountKey": "KEY", - "bucket": "selfprivacy" - } -} \ No newline at end of file diff --git a/tests/test_rest_endpoints/services/test_ssh/some_users.json b/tests/test_rest_endpoints/services/test_ssh/some_users.json deleted file mode 100644 index df6380a..0000000 --- a/tests/test_rest_endpoints/services/test_ssh/some_users.json +++ /dev/null @@ -1,76 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "bitwarden": { - "enable": false - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "nextcloud": { - "adminPassword": "ADMIN", - "databasePassword": "ADMIN", - "enable": true - }, - "resticPassword": "PASS", - "ssh": { - "enable": true, - "passwordAuthentication": true, - "rootKeys": [ - "ssh-ed25519 KEY test@pc" - ] - }, - "username": "tester", - "gitea": { - "enable": false - }, - "ocserv": { - "enable": true - }, - "pleroma": { - "enable": true - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "sshKeys": [ - "ssh-rsa KEY test@pc" - ], - "users": [ - { - "username": "user1", - "hashedPassword": "HASHED_PASSWORD_1", - "sshKeys": [ - "ssh-rsa KEY user1@pc" - ] - }, - { - "username": "user2", - "hashedPassword": "HASHED_PASSWORD_2", - "sshKeys": [ - ] - }, - { - "username": "user3", - "hashedPassword": "HASHED_PASSWORD_3" - } - ], - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - }, - "backup": { - "provider": "BACKBLAZE", - "accountId": "ID", - "accountKey": "KEY", - "bucket": "selfprivacy" - } -} \ No newline at end of file diff --git a/tests/test_rest_endpoints/services/test_ssh/turned_off.json b/tests/test_rest_endpoints/services/test_ssh/turned_off.json deleted file mode 100644 index 3856c80..0000000 --- a/tests/test_rest_endpoints/services/test_ssh/turned_off.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "bitwarden": { - "enable": false - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "nextcloud": { - "adminPassword": "ADMIN", - "databasePassword": "ADMIN", - "enable": true - }, - "resticPassword": "PASS", - "ssh": { - "enable": false, - "passwordAuthentication": true - }, - "username": "tester", - "gitea": { - "enable": false - }, - "ocserv": { - "enable": true - }, - "pleroma": { - "enable": true - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - }, - "backup": { - "provider": "BACKBLAZE", - "accountId": "ID", - "accountKey": "KEY", - "bucket": "selfprivacy" - } -} \ No newline at end of file diff --git a/tests/test_rest_endpoints/services/test_ssh/turned_on.json b/tests/test_rest_endpoints/services/test_ssh/turned_on.json deleted file mode 100644 index e60c57f..0000000 --- a/tests/test_rest_endpoints/services/test_ssh/turned_on.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "bitwarden": { - "enable": false - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "nextcloud": { - "adminPassword": "ADMIN", - "databasePassword": "ADMIN", - "enable": true - }, - "resticPassword": "PASS", - "ssh": { - "enable": true, - "passwordAuthentication": true - }, - "username": "tester", - "gitea": { - "enable": false - }, - "ocserv": { - "enable": true - }, - "pleroma": { - "enable": true - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - }, - "backup": { - "provider": "BACKBLAZE", - "accountId": "ID", - "accountKey": "KEY", - "bucket": "selfprivacy" - } -} \ No newline at end of file diff --git a/tests/test_rest_endpoints/services/test_ssh/undefined.json b/tests/test_rest_endpoints/services/test_ssh/undefined.json deleted file mode 100644 index 7c9af37..0000000 --- a/tests/test_rest_endpoints/services/test_ssh/undefined.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "bitwarden": { - "enable": false - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "nextcloud": { - "adminPassword": "ADMIN", - "databasePassword": "ADMIN", - "enable": true - }, - "resticPassword": "PASS", - "username": "tester", - "gitea": { - "enable": false - }, - "ocserv": { - "enable": true - }, - "pleroma": { - "enable": true - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - }, - "backup": { - "provider": "BACKBLAZE", - "accountId": "ID", - "accountKey": "KEY", - "bucket": "selfprivacy" - } -} \ No newline at end of file diff --git a/tests/test_rest_endpoints/services/test_ssh/undefined_values.json b/tests/test_rest_endpoints/services/test_ssh/undefined_values.json deleted file mode 100644 index b7b03d3..0000000 --- a/tests/test_rest_endpoints/services/test_ssh/undefined_values.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "api": { - "token": "TEST_TOKEN", - "enableSwagger": false - }, - "bitwarden": { - "enable": false - }, - "databasePassword": "PASSWORD", - "domain": "test.tld", - "hashedMasterPassword": "HASHED_PASSWORD", - "hostname": "test-instance", - "nextcloud": { - "adminPassword": "ADMIN", - "databasePassword": "ADMIN", - "enable": true - }, - "resticPassword": "PASS", - "ssh": {}, - "username": "tester", - "gitea": { - "enable": false - }, - "ocserv": { - "enable": true - }, - "pleroma": { - "enable": true - }, - "autoUpgrade": { - "enable": true, - "allowReboot": true - }, - "timezone": "Europe/Moscow", - "sshKeys": [ - "ssh-rsa KEY test@pc" - ], - "dns": { - "provider": "CLOUDFLARE", - "apiKey": "TOKEN" - }, - "server": { - "provider": "HETZNER" - }, - "backup": { - "provider": "BACKBLAZE", - "accountId": "ID", - "accountKey": "KEY", - "bucket": "selfprivacy" - } -} \ No newline at end of file