fix missing
parent
23ae42ac41
commit
3a1143cf56
|
@ -55,6 +55,7 @@ def create_user_util(username, password):
|
|||
|
||||
def delete_user_util(username):
|
||||
with WriteUserData() as data:
|
||||
ensure_ssh_and_users_fields_exist(data)
|
||||
|
||||
if username == data["username"] or username == "root":
|
||||
return False, "Cannot delete main or root user", 400
|
||||
|
@ -78,6 +79,8 @@ def update_user_util(username, password):
|
|||
hashed_password = hash_password(password)
|
||||
|
||||
with WriteUserData() as data:
|
||||
ensure_ssh_and_users_fields_exist(data)
|
||||
|
||||
if username == data["username"]:
|
||||
data["hashedMasterPassword"] = hashed_password
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import typing
|
|||
import strawberry
|
||||
|
||||
from selfprivacy_api.graphql.common_types.user import User, get_user_by_username
|
||||
from selfprivacy_api.utils import ReadUserData
|
||||
from selfprivacy_api.utils import ReadUserData, ensure_ssh_and_users_fields_exist
|
||||
from selfprivacy_api.graphql import IsAuthenticated
|
||||
|
||||
|
||||
|
@ -12,6 +12,8 @@ def get_users() -> typing.List[User]:
|
|||
"""Get users"""
|
||||
user_list = []
|
||||
with ReadUserData() as data:
|
||||
ensure_ssh_and_users_fields_exist(data)
|
||||
|
||||
for user in data["users"]:
|
||||
user_list.append(get_user_by_username(user["username"]))
|
||||
|
||||
|
|
|
@ -178,6 +178,7 @@ def hash_password(password):
|
|||
def ensure_ssh_and_users_fields_exist(data):
|
||||
if "ssh" not in data:
|
||||
data["ssh"] = []
|
||||
data["ssh"]["rootKeys"] = []
|
||||
|
||||
elif data["ssh"].get("rootKeys") is None:
|
||||
data["ssh"]["rootKeys"] = []
|
||||
|
|
|
@ -468,7 +468,10 @@ def test_graphql_add_existing_user(authorized_client, one_user, mock_subprocess_
|
|||
assert response.json["data"]["createUser"]["success"] is False
|
||||
|
||||
assert response.json["data"]["createUser"]["user"]["username"] == "user1"
|
||||
assert response.json["data"]["createUser"]["user"]["sshKeys"][0] == "ssh-rsa KEY user1@pc"
|
||||
assert (
|
||||
response.json["data"]["createUser"]["user"]["sshKeys"][0]
|
||||
== "ssh-rsa KEY user1@pc"
|
||||
)
|
||||
|
||||
|
||||
def test_graphql_add_main_user(authorized_client, one_user, mock_subprocess_popen):
|
||||
|
@ -492,7 +495,11 @@ def test_graphql_add_main_user(authorized_client, one_user, mock_subprocess_pope
|
|||
assert response.json["data"]["createUser"]["success"] is False
|
||||
|
||||
assert response.json["data"]["createUser"]["user"]["username"] == "tester"
|
||||
assert response.json["data"]["createUser"]["user"]["sshKeys"][0] == "ssh-rsa KEY test@pc"
|
||||
assert (
|
||||
response.json["data"]["createUser"]["user"]["sshKeys"][0]
|
||||
== "ssh-rsa KEY test@pc"
|
||||
)
|
||||
|
||||
|
||||
def test_graphql_add_long_username(authorized_client, one_user, mock_subprocess_popen):
|
||||
response = authorized_client.post(
|
||||
|
|
Loading…
Reference in New Issue