Delete rootKeys field instead of adding empty element

This commit is contained in:
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():
if app.config["ENABLE_SWAGGER"] == "1":
swag = swagger(app)
swag["info"]["version"] = "1.2.1"
swag["info"]["version"] = "1.2.2"
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.1"}
return {"version": "1.2.2"}

View file

@ -357,9 +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 rootKeys became zero length, delete it
if len(data["ssh"]["rootKeys"]) == 0:
data["ssh"]["rootKeys"].append("")
del data["ssh"]["rootKeys"]
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.1",
version="1.2.2",
packages=find_packages(),
scripts=[
"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"}
)
assert response.status_code == 200
assert read_json(root_and_admin_have_keys / "root_and_admin_have_keys.json")["ssh"][
assert (
"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):