Delete rootKeys field instead of adding empty element

pull/10/head
Inex Code 2022-03-20 19:48:00 +03:00
parent 4cbb08cb6e
commit 6cd896f977
5 changed files with 10 additions and 7 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -305,9 +305,12 @@ def test_delete_root_key(authorized_client, root_and_admin_have_keys):
"/services/ssh/keys/root", json={"public_key": "ssh-ed25519 KEY test@pc"} "/services/ssh/keys/root", json={"public_key": "ssh-ed25519 KEY test@pc"}
) )
assert response.status_code == 200 assert response.status_code == 200
assert read_json(root_and_admin_have_keys / "root_and_admin_have_keys.json")["ssh"][ assert (
"rootKeys" "rootKeys"
] == [""] not in read_json(root_and_admin_have_keys / "root_and_admin_have_keys.json")[
"ssh"
]
)
def test_delete_root_nonexistent_key(authorized_client, root_and_admin_have_keys): def test_delete_root_nonexistent_key(authorized_client, root_and_admin_have_keys):