mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-24 13:01:28 +00:00
refactor: move more services to sp-modules
This commit is contained in:
parent
75f4e8d40e
commit
91ff6eb989
|
@ -27,4 +27,4 @@ async def get_token_header(
|
||||||
|
|
||||||
def get_api_version() -> str:
|
def get_api_version() -> str:
|
||||||
"""Get API version"""
|
"""Get API version"""
|
||||||
return "2.4.2"
|
return "2.4.2-flakes"
|
||||||
|
|
|
@ -61,7 +61,9 @@ class Bitwarden(Service):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_enabled() -> bool:
|
def is_enabled() -> bool:
|
||||||
with ReadUserData() as user_data:
|
with ReadUserData() as user_data:
|
||||||
return user_data.get("bitwarden", {}).get("enable", False)
|
return (
|
||||||
|
user_data.get("modules", {}).get("bitwarden", {}).get("enable", False)
|
||||||
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_status() -> ServiceStatus:
|
def get_status() -> ServiceStatus:
|
||||||
|
@ -80,17 +82,21 @@ class Bitwarden(Service):
|
||||||
def enable():
|
def enable():
|
||||||
"""Enable Bitwarden service."""
|
"""Enable Bitwarden service."""
|
||||||
with WriteUserData() as user_data:
|
with WriteUserData() as user_data:
|
||||||
if "bitwarden" not in user_data:
|
if "modules" not in user_data:
|
||||||
user_data["bitwarden"] = {}
|
user_data["modules"] = {}
|
||||||
user_data["bitwarden"]["enable"] = True
|
if "bitwarden" not in user_data["modules"]:
|
||||||
|
user_data["modules"]["bitwarden"] = {}
|
||||||
|
user_data["modules"]["bitwarden"]["enable"] = True
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def disable():
|
def disable():
|
||||||
"""Disable Bitwarden service."""
|
"""Disable Bitwarden service."""
|
||||||
with WriteUserData() as user_data:
|
with WriteUserData() as user_data:
|
||||||
if "bitwarden" not in user_data:
|
if "modules" not in user_data:
|
||||||
user_data["bitwarden"] = {}
|
user_data["modules"] = {}
|
||||||
user_data["bitwarden"]["enable"] = False
|
if "bitwarden" not in user_data["modules"]:
|
||||||
|
user_data["modules"]["bitwarden"] = {}
|
||||||
|
user_data["modules"]["bitwarden"]["enable"] = False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def stop():
|
def stop():
|
||||||
|
|
|
@ -57,7 +57,7 @@ class Gitea(Service):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_enabled() -> bool:
|
def is_enabled() -> bool:
|
||||||
with ReadUserData() as user_data:
|
with ReadUserData() as user_data:
|
||||||
return user_data.get("gitea", {}).get("enable", False)
|
return user_data.get("modules", {}).get("gitea", {}).get("enable", False)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_status() -> ServiceStatus:
|
def get_status() -> ServiceStatus:
|
||||||
|
@ -75,17 +75,21 @@ class Gitea(Service):
|
||||||
def enable():
|
def enable():
|
||||||
"""Enable Gitea service."""
|
"""Enable Gitea service."""
|
||||||
with WriteUserData() as user_data:
|
with WriteUserData() as user_data:
|
||||||
if "gitea" not in user_data:
|
if "modules" not in user_data:
|
||||||
user_data["gitea"] = {}
|
user_data["modules"] = {}
|
||||||
user_data["gitea"]["enable"] = True
|
if "gitea" not in user_data["modules"]:
|
||||||
|
user_data["modules"]["gitea"] = {}
|
||||||
|
user_data["modules"]["gitea"]["enable"] = True
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def disable():
|
def disable():
|
||||||
"""Disable Gitea service."""
|
"""Disable Gitea service."""
|
||||||
with WriteUserData() as user_data:
|
with WriteUserData() as user_data:
|
||||||
if "gitea" not in user_data:
|
if "modules" not in user_data:
|
||||||
user_data["gitea"] = {}
|
user_data["modules"] = {}
|
||||||
user_data["gitea"]["enable"] = False
|
if "gitea" not in user_data["modules"]:
|
||||||
|
user_data["modules"]["gitea"] = {}
|
||||||
|
user_data["modules"]["gitea"]["enable"] = False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def stop():
|
def stop():
|
||||||
|
|
|
@ -58,7 +58,7 @@ class Jitsi(Service):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_enabled() -> bool:
|
def is_enabled() -> bool:
|
||||||
with ReadUserData() as user_data:
|
with ReadUserData() as user_data:
|
||||||
return user_data.get("jitsi", {}).get("enable", False)
|
return user_data.get("modules", {}).get("jitsi", {}).get("enable", False)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_status() -> ServiceStatus:
|
def get_status() -> ServiceStatus:
|
||||||
|
@ -70,17 +70,21 @@ class Jitsi(Service):
|
||||||
def enable():
|
def enable():
|
||||||
"""Enable Jitsi service."""
|
"""Enable Jitsi service."""
|
||||||
with WriteUserData() as user_data:
|
with WriteUserData() as user_data:
|
||||||
if "jitsi" not in user_data:
|
if "modules" not in user_data:
|
||||||
user_data["jitsi"] = {}
|
user_data["modules"] = {}
|
||||||
user_data["jitsi"]["enable"] = True
|
if "jitsi" not in user_data["modules"]:
|
||||||
|
user_data["modules"]["jitsi"] = {}
|
||||||
|
user_data["modules"]["jitsi"]["enable"] = True
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def disable():
|
def disable():
|
||||||
"""Disable Gitea service."""
|
"""Disable Gitea service."""
|
||||||
with WriteUserData() as user_data:
|
with WriteUserData() as user_data:
|
||||||
if "jitsi" not in user_data:
|
if "modules" not in user_data:
|
||||||
user_data["jitsi"] = {}
|
user_data["modules"] = {}
|
||||||
user_data["jitsi"]["enable"] = False
|
if "jitsi" not in user_data["modules"]:
|
||||||
|
user_data["modules"]["jitsi"] = {}
|
||||||
|
user_data["modules"]["jitsi"]["enable"] = False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def stop():
|
def stop():
|
||||||
|
|
|
@ -79,9 +79,9 @@ class Nextcloud(Service):
|
||||||
with WriteUserData() as user_data:
|
with WriteUserData() as user_data:
|
||||||
if "modules" not in user_data:
|
if "modules" not in user_data:
|
||||||
user_data["modules"] = {}
|
user_data["modules"] = {}
|
||||||
if "nextcloud" not in user_data:
|
if "nextcloud" not in user_data["modules"]:
|
||||||
user_data["nextcloud"] = {}
|
user_data["modules"]["nextcloud"] = {}
|
||||||
user_data["nextcloud"]["enable"] = True
|
user_data["modules"]["nextcloud"]["enable"] = True
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def disable():
|
def disable():
|
||||||
|
@ -89,9 +89,9 @@ class Nextcloud(Service):
|
||||||
with WriteUserData() as user_data:
|
with WriteUserData() as user_data:
|
||||||
if "modules" not in user_data:
|
if "modules" not in user_data:
|
||||||
user_data["modules"] = {}
|
user_data["modules"] = {}
|
||||||
if "nextcloud" not in user_data:
|
if "nextcloud" not in user_data["modules"]:
|
||||||
user_data["nextcloud"] = {}
|
user_data["modules"]["nextcloud"] = {}
|
||||||
user_data["nextcloud"]["enable"] = False
|
user_data["modules"]["nextcloud"]["enable"] = False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def stop():
|
def stop():
|
||||||
|
|
|
@ -54,7 +54,7 @@ class Ocserv(Service):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_enabled() -> bool:
|
def is_enabled() -> bool:
|
||||||
with ReadUserData() as user_data:
|
with ReadUserData() as user_data:
|
||||||
return user_data.get("ocserv", {}).get("enable", False)
|
return user_data.get("modules", {}).get("ocserv", {}).get("enable", False)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_status() -> ServiceStatus:
|
def get_status() -> ServiceStatus:
|
||||||
|
@ -63,16 +63,20 @@ class Ocserv(Service):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def enable():
|
def enable():
|
||||||
with WriteUserData() as user_data:
|
with WriteUserData() as user_data:
|
||||||
if "ocserv" not in user_data:
|
if "modules" not in user_data:
|
||||||
user_data["ocserv"] = {}
|
user_data["modules"] = {}
|
||||||
user_data["ocserv"]["enable"] = True
|
if "ocserv" not in user_data["modules"]:
|
||||||
|
user_data["modules"]["ocserv"] = {}
|
||||||
|
user_data["modules"]["ocserv"]["enable"] = True
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def disable():
|
def disable():
|
||||||
with WriteUserData() as user_data:
|
with WriteUserData() as user_data:
|
||||||
if "ocserv" not in user_data:
|
if "modules" not in user_data:
|
||||||
user_data["ocserv"] = {}
|
user_data["modules"] = {}
|
||||||
user_data["ocserv"]["enable"] = False
|
if "ocserv" not in user_data["modules"]:
|
||||||
|
user_data["modules"]["ocserv"] = {}
|
||||||
|
user_data["modules"]["ocserv"]["enable"] = False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def stop():
|
def stop():
|
||||||
|
|
|
@ -53,7 +53,7 @@ class Pleroma(Service):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_enabled() -> bool:
|
def is_enabled() -> bool:
|
||||||
with ReadUserData() as user_data:
|
with ReadUserData() as user_data:
|
||||||
return user_data.get("pleroma", {}).get("enable", False)
|
return user_data.get("modules", {}).get("pleroma", {}).get("enable", False)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_status() -> ServiceStatus:
|
def get_status() -> ServiceStatus:
|
||||||
|
@ -62,16 +62,20 @@ class Pleroma(Service):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def enable():
|
def enable():
|
||||||
with WriteUserData() as user_data:
|
with WriteUserData() as user_data:
|
||||||
if "pleroma" not in user_data:
|
if "modules" not in user_data:
|
||||||
user_data["pleroma"] = {}
|
user_data["modules"] = {}
|
||||||
user_data["pleroma"]["enable"] = True
|
if "pleroma" not in user_data["modules"]:
|
||||||
|
user_data["modules"]["pleroma"] = {}
|
||||||
|
user_data["modules"]["pleroma"]["enable"] = True
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def disable():
|
def disable():
|
||||||
with WriteUserData() as user_data:
|
with WriteUserData() as user_data:
|
||||||
if "pleroma" not in user_data:
|
if "modules" not in user_data:
|
||||||
user_data["pleroma"] = {}
|
user_data["modules"] = {}
|
||||||
user_data["pleroma"]["enable"] = False
|
if "pleroma" not in user_data["modules"]:
|
||||||
|
user_data["modules"]["pleroma"] = {}
|
||||||
|
user_data["modules"]["pleroma"]["enable"] = False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def stop():
|
def stop():
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="selfprivacy_api",
|
name="selfprivacy_api",
|
||||||
version="2.4.2",
|
version="2.4.2-flakes",
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
scripts=[
|
scripts=[
|
||||||
"selfprivacy_api/app.py",
|
"selfprivacy_api/app.py",
|
||||||
|
|
|
@ -3,9 +3,6 @@
|
||||||
"token": "TEST_TOKEN",
|
"token": "TEST_TOKEN",
|
||||||
"enableSwagger": false
|
"enableSwagger": false
|
||||||
},
|
},
|
||||||
"bitwarden": {
|
|
||||||
"enable": true
|
|
||||||
},
|
|
||||||
"databasePassword": "PASSWORD",
|
"databasePassword": "PASSWORD",
|
||||||
"domain": "test.tld",
|
"domain": "test.tld",
|
||||||
"hashedMasterPassword": "HASHED_PASSWORD",
|
"hashedMasterPassword": "HASHED_PASSWORD",
|
||||||
|
@ -19,18 +16,6 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"username": "tester",
|
"username": "tester",
|
||||||
"gitea": {
|
|
||||||
"enable": true
|
|
||||||
},
|
|
||||||
"ocserv": {
|
|
||||||
"enable": true
|
|
||||||
},
|
|
||||||
"pleroma": {
|
|
||||||
"enable": true
|
|
||||||
},
|
|
||||||
"jitsi": {
|
|
||||||
"enable": true
|
|
||||||
},
|
|
||||||
"autoUpgrade": {
|
"autoUpgrade": {
|
||||||
"enable": true,
|
"enable": true,
|
||||||
"allowReboot": true
|
"allowReboot": true
|
||||||
|
@ -50,6 +35,21 @@
|
||||||
"nextcloud": {
|
"nextcloud": {
|
||||||
"enable": true
|
"enable": true
|
||||||
},
|
},
|
||||||
|
"bitwarden": {
|
||||||
|
"enable": true
|
||||||
|
},
|
||||||
|
"gitea": {
|
||||||
|
"enable": true
|
||||||
|
},
|
||||||
|
"ocserv": {
|
||||||
|
"enable": true
|
||||||
|
},
|
||||||
|
"pleroma": {
|
||||||
|
"enable": true
|
||||||
|
},
|
||||||
|
"jitsi": {
|
||||||
|
"enable": true
|
||||||
|
},
|
||||||
"simple-nixos-mailserver": {
|
"simple-nixos-mailserver": {
|
||||||
"enable": true
|
"enable": true
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
|
||||||
)
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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
|
|
||||||
)
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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
|
|
||||||
)
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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
|
|
||||||
)
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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": {
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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)
|
|
|
@ -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
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue