Fix root key deletion to not make system rebuild unpossible

pull/10/head
Inex Code 2022-03-20 19:32:31 +03:00
parent 72a9b11541
commit 4cbb08cb6e
5 changed files with 9 additions and 9 deletions

View File

@ -68,7 +68,7 @@ def create_app(test_config=None):
def spec():
if app.config["ENABLE_SWAGGER"] == "1":
swag = swagger(app)
swag["info"]["version"] = "1.2.0"
swag["info"]["version"] = "1.2.1"
swag["info"]["title"] = "SelfPrivacy API"
swag["info"]["description"] = "SelfPrivacy API"
swag["securityDefinitions"] = {

View File

@ -23,4 +23,4 @@ class ApiVersion(Resource):
401:
description: Unauthorized
"""
return {"version": "1.2.0"}
return {"version": "1.2.1"}

View File

@ -357,6 +357,9 @@ class SSHKeys(Resource):
for key in data["ssh"]["rootKeys"]:
if key == args["public_key"]:
data["ssh"]["rootKeys"].remove(key)
# If rootKeys became zero length, add empty string
if len(data["ssh"]["rootKeys"]) == 0:
data["ssh"]["rootKeys"].append("")
return {
"message": "SSH key deleted",
}, 200

View File

@ -2,7 +2,7 @@ from setuptools import setup, find_packages
setup(
name="selfprivacy_api",
version="1.2.0",
version="1.2.1",
packages=find_packages(),
scripts=[
"selfprivacy_api/app.py",

View File

@ -305,12 +305,9 @@ def test_delete_root_key(authorized_client, root_and_admin_have_keys):
"/services/ssh/keys/root", json={"public_key": "ssh-ed25519 KEY test@pc"}
)
assert response.status_code == 200
assert (
read_json(root_and_admin_have_keys / "root_and_admin_have_keys.json")["ssh"][
"rootKeys"
]
== []
)
assert 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):