rename many things
parent
612e237a28
commit
50d0c835d0
|
@ -1,11 +1,11 @@
|
|||
import typing
|
||||
from enum import Enum
|
||||
import strawberry
|
||||
|
||||
from selfprivacy_api.utils import ReadUserData
|
||||
from selfprivacy_api.graphql.mutations.mutation_interface import (
|
||||
MutationReturnInterface,
|
||||
)
|
||||
from enum import Enum
|
||||
|
||||
from selfprivacy_api.utils import ReadUserData, ensure_ssh_and_users_fields_exist
|
||||
|
||||
|
||||
@strawberry.enum
|
||||
|
@ -17,7 +17,6 @@ class UserType(Enum):
|
|||
|
||||
@strawberry.type
|
||||
class User:
|
||||
"""Users management"""
|
||||
|
||||
user_type: UserType
|
||||
username: str
|
||||
|
@ -32,6 +31,21 @@ class UserMutationReturn(MutationReturnInterface):
|
|||
user: typing.Optional[User]
|
||||
|
||||
|
||||
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"] = []
|
||||
|
||||
if "sshKeys" not in data:
|
||||
data["sshKeys"] = []
|
||||
|
||||
if "users" not in data:
|
||||
data["users"] = []
|
||||
|
||||
|
||||
def get_user_by_username(username: str) -> typing.Optional[User]:
|
||||
with ReadUserData() as data:
|
||||
ensure_ssh_and_users_fields_exist(data)
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
"""Users management module"""
|
||||
# pylint: disable=too-few-public-methods
|
||||
|
||||
|
||||
import strawberry
|
||||
|
||||
from selfprivacy_api.graphql import IsAuthenticated
|
||||
from selfprivacy_api.graphql.mutations.ssh_utils import (
|
||||
create_ssh_key,
|
||||
delete_ssh_key,
|
||||
remove_ssh_key,
|
||||
)
|
||||
from selfprivacy_api.graphql import IsAuthenticated
|
||||
from selfprivacy_api.graphql.common_types.user import (
|
||||
UserMutationReturn,
|
||||
get_user_by_username,
|
||||
|
@ -28,8 +28,8 @@ class SshMutations:
|
|||
"""Mutations ssh"""
|
||||
|
||||
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
||||
def create_ssh(self, ssh_input: SshMutationInput) -> UserMutationReturn:
|
||||
"""Create a new ssh"""
|
||||
def add_ssh_key(self, ssh_input: SshMutationInput) -> UserMutationReturn:
|
||||
"""Add a new ssh key"""
|
||||
|
||||
success, message, code = create_ssh_key(ssh_input.username, ssh_input.ssh_key)
|
||||
|
||||
|
@ -41,10 +41,10 @@ class SshMutations:
|
|||
)
|
||||
|
||||
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
||||
def delete_ssh(self, ssh_input: SshMutationInput) -> UserMutationReturn:
|
||||
"""Delete ssh key from user"""
|
||||
def remove_ssh_key(self, ssh_input: SshMutationInput) -> UserMutationReturn:
|
||||
"""Remove ssh key from user"""
|
||||
|
||||
success, message, code = delete_ssh_key(ssh_input.username, ssh_input.ssh_key)
|
||||
success, message, code = remove_ssh_key(ssh_input.username, ssh_input.ssh_key)
|
||||
|
||||
return UserMutationReturn(
|
||||
success=success,
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
from selfprivacy_api.graphql.common_types.user import ensure_ssh_and_users_fields_exist
|
||||
from selfprivacy_api.utils import (
|
||||
WriteUserData,
|
||||
ensure_ssh_and_users_fields_exist,
|
||||
validate_ssh_public_key,
|
||||
)
|
||||
|
||||
|
||||
def create_ssh_key(username, ssh_key):
|
||||
def create_ssh_key(username: str, ssh_key: str) -> tuple[bool, str, int]:
|
||||
"""Create a new ssh key"""
|
||||
|
||||
if not validate_ssh_public_key(ssh_key):
|
||||
|
@ -43,7 +43,7 @@ def create_ssh_key(username, ssh_key):
|
|||
return False, "User not found", 404
|
||||
|
||||
|
||||
def delete_ssh_key(username, ssh_key):
|
||||
def remove_ssh_key(username: str, ssh_key: str) -> tuple[bool, str, int]:
|
||||
"""Delete a ssh key"""
|
||||
|
||||
with WriteUserData() as data:
|
||||
|
|
|
@ -11,9 +11,9 @@ from selfprivacy_api.graphql.mutations.mutation_interface import (
|
|||
GenericMutationReturn,
|
||||
)
|
||||
from selfprivacy_api.graphql.mutations.users_utils import (
|
||||
create_user_util,
|
||||
delete_user_util,
|
||||
update_user_util,
|
||||
create_user,
|
||||
delete_user,
|
||||
update_user,
|
||||
)
|
||||
|
||||
|
||||
|
@ -32,7 +32,7 @@ class UserMutations:
|
|||
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
||||
def create_user(self, user: UserMutationInput) -> UserMutationReturn:
|
||||
|
||||
success, message, code = create_user_util(user.username, user.password)
|
||||
success, message, code = create_user(user.username, user.password)
|
||||
|
||||
return UserMutationReturn(
|
||||
success=success,
|
||||
|
@ -43,7 +43,7 @@ class UserMutations:
|
|||
|
||||
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
||||
def delete_user(self, username: str) -> GenericMutationReturn:
|
||||
success, message, code = delete_user_util(username)
|
||||
success, message, code = delete_user(username)
|
||||
|
||||
return GenericMutationReturn(
|
||||
success=success,
|
||||
|
@ -55,7 +55,7 @@ class UserMutations:
|
|||
def update_user(self, user: UserMutationInput) -> UserMutationReturn:
|
||||
"""Update user mutation"""
|
||||
|
||||
success, message, code = update_user_util(user.username, user.password)
|
||||
success, message, code = update_user(user.username, user.password)
|
||||
|
||||
return UserMutationReturn(
|
||||
success=success,
|
||||
|
|
|
@ -2,13 +2,27 @@ import re
|
|||
from selfprivacy_api.utils import (
|
||||
WriteUserData,
|
||||
ReadUserData,
|
||||
ensure_ssh_and_users_fields_exist,
|
||||
is_username_forbidden,
|
||||
)
|
||||
from selfprivacy_api.utils import hash_password
|
||||
|
||||
|
||||
def create_user_util(username, 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"] = []
|
||||
|
||||
if "sshKeys" not in data:
|
||||
data["sshKeys"] = []
|
||||
|
||||
if "users" not in data:
|
||||
data["users"] = []
|
||||
|
||||
|
||||
def create_user(username: str, password: str) -> tuple[bool, str, int]:
|
||||
"""Create a new user"""
|
||||
|
||||
# Check if password is null or none
|
||||
|
@ -44,13 +58,17 @@ def create_user_util(username, password):
|
|||
ensure_ssh_and_users_fields_exist(data)
|
||||
|
||||
data["users"].append(
|
||||
{"username": username, "hashedPassword": hashed_password, "sshKeys": []}
|
||||
{
|
||||
"username": username,
|
||||
"hashedPassword": hashed_password,
|
||||
"sshKeys": [],
|
||||
}
|
||||
)
|
||||
|
||||
return True, "User was successfully created!", 201
|
||||
|
||||
|
||||
def delete_user_util(username):
|
||||
def delete_user(username: str) -> tuple[bool, str, int]:
|
||||
with WriteUserData() as data:
|
||||
ensure_ssh_and_users_fields_exist(data)
|
||||
|
||||
|
@ -68,7 +86,7 @@ def delete_user_util(username):
|
|||
return True, "User was deleted", 200
|
||||
|
||||
|
||||
def update_user_util(username, password):
|
||||
def update_user(username: str, password: str) -> tuple[bool, str, int]:
|
||||
# Check if password is null or none
|
||||
if password == "":
|
||||
return False, "Password is null", 400
|
||||
|
|
|
@ -3,8 +3,12 @@
|
|||
import typing
|
||||
import strawberry
|
||||
|
||||
from selfprivacy_api.graphql.common_types.user import User, get_user_by_username
|
||||
from selfprivacy_api.utils import ReadUserData, ensure_ssh_and_users_fields_exist
|
||||
from selfprivacy_api.graphql.common_types.user import (
|
||||
User,
|
||||
ensure_ssh_and_users_fields_exist,
|
||||
get_user_by_username,
|
||||
)
|
||||
from selfprivacy_api.utils import ReadUserData
|
||||
from selfprivacy_api.graphql import IsAuthenticated
|
||||
|
||||
|
||||
|
|
|
@ -173,18 +173,3 @@ def hash_password(password):
|
|||
hashed_password = hashed_password.decode("ascii")
|
||||
hashed_password = hashed_password.rstrip()
|
||||
return hashed_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"] = []
|
||||
|
||||
if "sshKeys" not in data:
|
||||
data["sshKeys"] = []
|
||||
|
||||
if "users" not in data:
|
||||
data["users"] = []
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
# pylint: disable=unused-argument
|
||||
import pytest
|
||||
|
||||
from tests.common import (
|
||||
read_json,
|
||||
)
|
||||
from tests.common import read_json
|
||||
|
||||
|
||||
class ProcessMock:
|
||||
|
@ -44,9 +42,9 @@ def some_users(mocker, datadir):
|
|||
# TESTS ########################################################
|
||||
|
||||
|
||||
API_CREATE_SSH_MUTATION = """
|
||||
mutation createSsh($sshInput: SshMutationInput!) {
|
||||
createSsh(sshInput: $sshInput) {
|
||||
API_CREATE_SSH_KEY_MUTATION = """
|
||||
mutation addSshKey($sshInput: SshMutationInput!) {
|
||||
addSshKey(sshInput: $sshInput) {
|
||||
success
|
||||
message
|
||||
code
|
||||
|
@ -59,11 +57,11 @@ mutation createSsh($sshInput: SshMutationInput!) {
|
|||
"""
|
||||
|
||||
|
||||
def test_graphql_add_ssh_unauthorized(client, some_users, mock_subprocess_popen):
|
||||
def test_graphql_add_ssh_key_unauthorized(client, some_users, mock_subprocess_popen):
|
||||
response = client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_CREATE_SSH_MUTATION,
|
||||
"query": API_CREATE_SSH_KEY_MUTATION,
|
||||
"variables": {
|
||||
"sshInput": {
|
||||
"username": "user1",
|
||||
|
@ -76,11 +74,11 @@ def test_graphql_add_ssh_unauthorized(client, some_users, mock_subprocess_popen)
|
|||
assert response.json.get("data") is None
|
||||
|
||||
|
||||
def test_graphql_add_ssh(authorized_client, some_users, mock_subprocess_popen):
|
||||
def test_graphql_add_ssh_key(authorized_client, some_users, mock_subprocess_popen):
|
||||
response = authorized_client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_CREATE_SSH_MUTATION,
|
||||
"query": API_CREATE_SSH_KEY_MUTATION,
|
||||
"variables": {
|
||||
"sshInput": {
|
||||
"username": "user1",
|
||||
|
@ -92,22 +90,22 @@ def test_graphql_add_ssh(authorized_client, some_users, mock_subprocess_popen):
|
|||
assert response.status_code == 200
|
||||
assert response.json.get("data") is not None
|
||||
|
||||
assert response.json["data"]["createSsh"]["code"] == 201
|
||||
assert response.json["data"]["createSsh"]["message"] is not None
|
||||
assert response.json["data"]["createSsh"]["success"] is True
|
||||
assert response.json["data"]["addSshKey"]["code"] == 201
|
||||
assert response.json["data"]["addSshKey"]["message"] is not None
|
||||
assert response.json["data"]["addSshKey"]["success"] is True
|
||||
|
||||
assert response.json["data"]["createSsh"]["user"]["username"] == "user1"
|
||||
assert response.json["data"]["createSsh"]["user"]["sshKeys"] == [
|
||||
assert response.json["data"]["addSshKey"]["user"]["username"] == "user1"
|
||||
assert response.json["data"]["addSshKey"]["user"]["sshKeys"] == [
|
||||
"ssh-rsa KEY user1@pc",
|
||||
"ssh-rsa KEY test_key@pc",
|
||||
]
|
||||
|
||||
|
||||
def test_graphql_add_root_ssh(authorized_client, some_users, mock_subprocess_popen):
|
||||
def test_graphql_add_root_ssh_key(authorized_client, some_users, mock_subprocess_popen):
|
||||
response = authorized_client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_CREATE_SSH_MUTATION,
|
||||
"query": API_CREATE_SSH_KEY_MUTATION,
|
||||
"variables": {
|
||||
"sshInput": {
|
||||
"username": "root",
|
||||
|
@ -119,22 +117,22 @@ def test_graphql_add_root_ssh(authorized_client, some_users, mock_subprocess_pop
|
|||
assert response.status_code == 200
|
||||
assert response.json.get("data") is not None
|
||||
|
||||
assert response.json["data"]["createSsh"]["code"] == 201
|
||||
assert response.json["data"]["createSsh"]["message"] is not None
|
||||
assert response.json["data"]["createSsh"]["success"] is True
|
||||
assert response.json["data"]["addSshKey"]["code"] == 201
|
||||
assert response.json["data"]["addSshKey"]["message"] is not None
|
||||
assert response.json["data"]["addSshKey"]["success"] is True
|
||||
|
||||
assert response.json["data"]["createSsh"]["user"]["username"] == "root"
|
||||
assert response.json["data"]["createSsh"]["user"]["sshKeys"] == [
|
||||
assert response.json["data"]["addSshKey"]["user"]["username"] == "root"
|
||||
assert response.json["data"]["addSshKey"]["user"]["sshKeys"] == [
|
||||
"ssh-ed25519 KEY test@pc",
|
||||
"ssh-rsa KEY test_key@pc",
|
||||
]
|
||||
|
||||
|
||||
def test_graphql_add_main_ssh(authorized_client, some_users, mock_subprocess_popen):
|
||||
def test_graphql_add_main_ssh_key(authorized_client, some_users, mock_subprocess_popen):
|
||||
response = authorized_client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_CREATE_SSH_MUTATION,
|
||||
"query": API_CREATE_SSH_KEY_MUTATION,
|
||||
"variables": {
|
||||
"sshInput": {
|
||||
"username": "tester",
|
||||
|
@ -146,22 +144,22 @@ def test_graphql_add_main_ssh(authorized_client, some_users, mock_subprocess_pop
|
|||
assert response.status_code == 200
|
||||
assert response.json.get("data") is not None
|
||||
|
||||
assert response.json["data"]["createSsh"]["code"] == 201
|
||||
assert response.json["data"]["createSsh"]["message"] is not None
|
||||
assert response.json["data"]["createSsh"]["success"] is True
|
||||
assert response.json["data"]["addSshKey"]["code"] == 201
|
||||
assert response.json["data"]["addSshKey"]["message"] is not None
|
||||
assert response.json["data"]["addSshKey"]["success"] is True
|
||||
|
||||
assert response.json["data"]["createSsh"]["user"]["username"] == "tester"
|
||||
assert response.json["data"]["createSsh"]["user"]["sshKeys"] == [
|
||||
assert response.json["data"]["addSshKey"]["user"]["username"] == "tester"
|
||||
assert response.json["data"]["addSshKey"]["user"]["sshKeys"] == [
|
||||
"ssh-rsa KEY test@pc",
|
||||
"ssh-rsa KEY test_key@pc",
|
||||
]
|
||||
|
||||
|
||||
def test_graphql_add_bad_ssh(authorized_client, some_users, mock_subprocess_popen):
|
||||
def test_graphql_add_bad_ssh_key(authorized_client, some_users, mock_subprocess_popen):
|
||||
response = authorized_client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_CREATE_SSH_MUTATION,
|
||||
"query": API_CREATE_SSH_KEY_MUTATION,
|
||||
"variables": {
|
||||
"sshInput": {
|
||||
"username": "user1",
|
||||
|
@ -173,16 +171,18 @@ def test_graphql_add_bad_ssh(authorized_client, some_users, mock_subprocess_pope
|
|||
assert response.status_code == 200
|
||||
assert response.json.get("data") is not None
|
||||
|
||||
assert response.json["data"]["createSsh"]["code"] == 400
|
||||
assert response.json["data"]["createSsh"]["message"] is not None
|
||||
assert response.json["data"]["createSsh"]["success"] is False
|
||||
assert response.json["data"]["addSshKey"]["code"] == 400
|
||||
assert response.json["data"]["addSshKey"]["message"] is not None
|
||||
assert response.json["data"]["addSshKey"]["success"] is False
|
||||
|
||||
|
||||
def test_graphql_add_ssh_404user(authorized_client, some_users, mock_subprocess_popen):
|
||||
def test_graphql_add_ssh_key_nonexistent_user(
|
||||
authorized_client, some_users, mock_subprocess_popen
|
||||
):
|
||||
response = authorized_client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_CREATE_SSH_MUTATION,
|
||||
"query": API_CREATE_SSH_KEY_MUTATION,
|
||||
"variables": {
|
||||
"sshInput": {
|
||||
"username": "user666",
|
||||
|
@ -194,14 +194,14 @@ def test_graphql_add_ssh_404user(authorized_client, some_users, mock_subprocess_
|
|||
assert response.status_code == 200
|
||||
assert response.json.get("data") is not None
|
||||
|
||||
assert response.json["data"]["createSsh"]["code"] == 404
|
||||
assert response.json["data"]["createSsh"]["message"] is not None
|
||||
assert response.json["data"]["createSsh"]["success"] is False
|
||||
assert response.json["data"]["addSshKey"]["code"] == 404
|
||||
assert response.json["data"]["addSshKey"]["message"] is not None
|
||||
assert response.json["data"]["addSshKey"]["success"] is False
|
||||
|
||||
|
||||
API_DELETE_SSH_MUTATION = """
|
||||
mutation deleteSsh($sshInput: SshMutationInput!) {
|
||||
deleteSsh(sshInput: $sshInput) {
|
||||
API_REMOVE_SSH_KEY_MUTATION = """
|
||||
mutation removeSshKey($sshInput: SshMutationInput!) {
|
||||
removeSshKey(sshInput: $sshInput) {
|
||||
success
|
||||
message
|
||||
code
|
||||
|
@ -214,11 +214,11 @@ mutation deleteSsh($sshInput: SshMutationInput!) {
|
|||
"""
|
||||
|
||||
|
||||
def test_graphql_dell_ssh_unauthorized(client, some_users, mock_subprocess_popen):
|
||||
def test_graphql_remove_ssh_key_unauthorized(client, some_users, mock_subprocess_popen):
|
||||
response = client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_DELETE_SSH_MUTATION,
|
||||
"query": API_REMOVE_SSH_KEY_MUTATION,
|
||||
"variables": {
|
||||
"sshInput": {
|
||||
"username": "user1",
|
||||
|
@ -231,11 +231,11 @@ def test_graphql_dell_ssh_unauthorized(client, some_users, mock_subprocess_popen
|
|||
assert response.json.get("data") is None
|
||||
|
||||
|
||||
def test_graphql_dell_ssh(authorized_client, some_users, mock_subprocess_popen):
|
||||
def test_graphql_remove_ssh_key(authorized_client, some_users, mock_subprocess_popen):
|
||||
response = authorized_client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_DELETE_SSH_MUTATION,
|
||||
"query": API_REMOVE_SSH_KEY_MUTATION,
|
||||
"variables": {
|
||||
"sshInput": {
|
||||
"username": "user1",
|
||||
|
@ -247,19 +247,21 @@ def test_graphql_dell_ssh(authorized_client, some_users, mock_subprocess_popen):
|
|||
assert response.status_code == 200
|
||||
assert response.json.get("data") is not None
|
||||
|
||||
assert response.json["data"]["deleteSsh"]["code"] == 200
|
||||
assert response.json["data"]["deleteSsh"]["message"] is not None
|
||||
assert response.json["data"]["deleteSsh"]["success"] is True
|
||||
assert response.json["data"]["removeSshKey"]["code"] == 200
|
||||
assert response.json["data"]["removeSshKey"]["message"] is not None
|
||||
assert response.json["data"]["removeSshKey"]["success"] is True
|
||||
|
||||
assert response.json["data"]["deleteSsh"]["user"]["username"] == "user1"
|
||||
assert response.json["data"]["deleteSsh"]["user"]["sshKeys"] == []
|
||||
assert response.json["data"]["removeSshKey"]["user"]["username"] == "user1"
|
||||
assert response.json["data"]["removeSshKey"]["user"]["sshKeys"] == []
|
||||
|
||||
|
||||
def test_graphql_dell_root_ssh(authorized_client, some_users, mock_subprocess_popen):
|
||||
def test_graphql_remove_root_ssh_key(
|
||||
authorized_client, some_users, mock_subprocess_popen
|
||||
):
|
||||
response = authorized_client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_DELETE_SSH_MUTATION,
|
||||
"query": API_REMOVE_SSH_KEY_MUTATION,
|
||||
"variables": {
|
||||
"sshInput": {
|
||||
"username": "root",
|
||||
|
@ -271,19 +273,21 @@ def test_graphql_dell_root_ssh(authorized_client, some_users, mock_subprocess_po
|
|||
assert response.status_code == 200
|
||||
assert response.json.get("data") is not None
|
||||
|
||||
assert response.json["data"]["deleteSsh"]["code"] == 200
|
||||
assert response.json["data"]["deleteSsh"]["message"] is not None
|
||||
assert response.json["data"]["deleteSsh"]["success"] is True
|
||||
assert response.json["data"]["removeSshKey"]["code"] == 200
|
||||
assert response.json["data"]["removeSshKey"]["message"] is not None
|
||||
assert response.json["data"]["removeSshKey"]["success"] is True
|
||||
|
||||
assert response.json["data"]["deleteSsh"]["user"]["username"] == "root"
|
||||
assert response.json["data"]["deleteSsh"]["user"]["sshKeys"] == []
|
||||
assert response.json["data"]["removeSshKey"]["user"]["username"] == "root"
|
||||
assert response.json["data"]["removeSshKey"]["user"]["sshKeys"] == []
|
||||
|
||||
|
||||
def test_graphql_dell_main_ssh(authorized_client, some_users, mock_subprocess_popen):
|
||||
def test_graphql_remove_main_ssh_key(
|
||||
authorized_client, some_users, mock_subprocess_popen
|
||||
):
|
||||
response = authorized_client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_DELETE_SSH_MUTATION,
|
||||
"query": API_REMOVE_SSH_KEY_MUTATION,
|
||||
"variables": {
|
||||
"sshInput": {
|
||||
"username": "tester",
|
||||
|
@ -295,19 +299,21 @@ def test_graphql_dell_main_ssh(authorized_client, some_users, mock_subprocess_po
|
|||
assert response.status_code == 200
|
||||
assert response.json.get("data") is not None
|
||||
|
||||
assert response.json["data"]["deleteSsh"]["code"] == 200
|
||||
assert response.json["data"]["deleteSsh"]["message"] is not None
|
||||
assert response.json["data"]["deleteSsh"]["success"] is True
|
||||
assert response.json["data"]["removeSshKey"]["code"] == 200
|
||||
assert response.json["data"]["removeSshKey"]["message"] is not None
|
||||
assert response.json["data"]["removeSshKey"]["success"] is True
|
||||
|
||||
assert response.json["data"]["deleteSsh"]["user"]["username"] == "tester"
|
||||
assert response.json["data"]["deleteSsh"]["user"]["sshKeys"] == []
|
||||
assert response.json["data"]["removeSshKey"]["user"]["username"] == "tester"
|
||||
assert response.json["data"]["removeSshKey"]["user"]["sshKeys"] == []
|
||||
|
||||
|
||||
def test_graphql_dell_404ssh(authorized_client, some_users, mock_subprocess_popen):
|
||||
def test_graphql_remove_nonexistent_ssh_key(
|
||||
authorized_client, some_users, mock_subprocess_popen
|
||||
):
|
||||
response = authorized_client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_DELETE_SSH_MUTATION,
|
||||
"query": API_REMOVE_SSH_KEY_MUTATION,
|
||||
"variables": {
|
||||
"sshInput": {
|
||||
"username": "user1",
|
||||
|
@ -319,16 +325,18 @@ def test_graphql_dell_404ssh(authorized_client, some_users, mock_subprocess_pope
|
|||
assert response.status_code == 200
|
||||
assert response.json.get("data") is not None
|
||||
|
||||
assert response.json["data"]["deleteSsh"]["code"] == 404
|
||||
assert response.json["data"]["deleteSsh"]["message"] is not None
|
||||
assert response.json["data"]["deleteSsh"]["success"] is False
|
||||
assert response.json["data"]["removeSshKey"]["code"] == 404
|
||||
assert response.json["data"]["removeSshKey"]["message"] is not None
|
||||
assert response.json["data"]["removeSshKey"]["success"] is False
|
||||
|
||||
|
||||
def test_graphql_dell_ssh_404user(authorized_client, some_users, mock_subprocess_popen):
|
||||
def test_graphql_remove_ssh_key_nonexistent_user(
|
||||
authorized_client, some_users, mock_subprocess_popen
|
||||
):
|
||||
response = authorized_client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_DELETE_SSH_MUTATION,
|
||||
"query": API_REMOVE_SSH_KEY_MUTATION,
|
||||
"variables": {
|
||||
"sshInput": {
|
||||
"username": "user666",
|
||||
|
@ -340,6 +348,6 @@ def test_graphql_dell_ssh_404user(authorized_client, some_users, mock_subprocess
|
|||
assert response.status_code == 200
|
||||
assert response.json.get("data") is not None
|
||||
|
||||
assert response.json["data"]["deleteSsh"]["code"] == 404
|
||||
assert response.json["data"]["deleteSsh"]["message"] is not None
|
||||
assert response.json["data"]["deleteSsh"]["success"] is False
|
||||
assert response.json["data"]["removeSshKey"]["code"] == 404
|
||||
assert response.json["data"]["removeSshKey"]["message"] is not None
|
||||
assert response.json["data"]["removeSshKey"]["success"] is False
|
||||
|
|
|
@ -275,7 +275,9 @@ def test_graphql_get_main_user(authorized_client, one_user, mock_subprocess_pope
|
|||
]
|
||||
|
||||
|
||||
def test_graphql_get_404user(authorized_client, one_user, mock_subprocess_popen):
|
||||
def test_graphql_get_nonexistent_user(
|
||||
authorized_client, one_user, mock_subprocess_popen
|
||||
):
|
||||
response = authorized_client.get(
|
||||
"/graphql",
|
||||
json={
|
||||
|
@ -291,7 +293,7 @@ def test_graphql_get_404user(authorized_client, one_user, mock_subprocess_popen)
|
|||
assert response.json["data"]["users"]["getUser"] is None
|
||||
|
||||
|
||||
API_CHANGE_USERS_MUTATION = """
|
||||
API_CREATE_USERS_MUTATION = """
|
||||
mutation createUser($user: UserMutationInput!) {
|
||||
createUser(user: $user) {
|
||||
success
|
||||
|
@ -310,7 +312,7 @@ def test_graphql_add_user_unauthorize(client, one_user, mock_subprocess_popen):
|
|||
response = client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_CHANGE_USERS_MUTATION,
|
||||
"query": API_CREATE_USERS_MUTATION,
|
||||
"variables": {
|
||||
"user": {
|
||||
"username": "user2",
|
||||
|
@ -327,7 +329,7 @@ def test_graphql_add_user(authorized_client, one_user, mock_subprocess_popen):
|
|||
response = authorized_client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_CHANGE_USERS_MUTATION,
|
||||
"query": API_CREATE_USERS_MUTATION,
|
||||
"variables": {
|
||||
"user": {
|
||||
"username": "user2",
|
||||
|
@ -353,7 +355,7 @@ def test_graphql_add_undefined_settings(
|
|||
response = authorized_client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_CHANGE_USERS_MUTATION,
|
||||
"query": API_CREATE_USERS_MUTATION,
|
||||
"variables": {
|
||||
"user": {
|
||||
"username": "user2",
|
||||
|
@ -379,7 +381,7 @@ def test_graphql_add_without_password(
|
|||
response = authorized_client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_CHANGE_USERS_MUTATION,
|
||||
"query": API_CREATE_USERS_MUTATION,
|
||||
"variables": {
|
||||
"user": {
|
||||
"username": "user2",
|
||||
|
@ -402,7 +404,7 @@ def test_graphql_add_without_both(authorized_client, one_user, mock_subprocess_p
|
|||
response = authorized_client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_CHANGE_USERS_MUTATION,
|
||||
"query": API_CREATE_USERS_MUTATION,
|
||||
"variables": {
|
||||
"user": {
|
||||
"username": "",
|
||||
|
@ -428,7 +430,7 @@ def test_graphql_add_system_username(
|
|||
response = authorized_client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_CHANGE_USERS_MUTATION,
|
||||
"query": API_CREATE_USERS_MUTATION,
|
||||
"variables": {
|
||||
"user": {
|
||||
"username": username,
|
||||
|
@ -451,7 +453,7 @@ def test_graphql_add_existing_user(authorized_client, one_user, mock_subprocess_
|
|||
response = authorized_client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_CHANGE_USERS_MUTATION,
|
||||
"query": API_CREATE_USERS_MUTATION,
|
||||
"variables": {
|
||||
"user": {
|
||||
"username": "user1",
|
||||
|
@ -478,7 +480,7 @@ def test_graphql_add_main_user(authorized_client, one_user, mock_subprocess_pope
|
|||
response = authorized_client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_CHANGE_USERS_MUTATION,
|
||||
"query": API_CREATE_USERS_MUTATION,
|
||||
"variables": {
|
||||
"user": {
|
||||
"username": "tester",
|
||||
|
@ -505,7 +507,7 @@ def test_graphql_add_long_username(authorized_client, one_user, mock_subprocess_
|
|||
response = authorized_client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_CHANGE_USERS_MUTATION,
|
||||
"query": API_CREATE_USERS_MUTATION,
|
||||
"variables": {
|
||||
"user": {
|
||||
"username": "a" * 32,
|
||||
|
@ -531,7 +533,7 @@ def test_graphql_add_invalid_username(
|
|||
response = authorized_client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_CHANGE_USERS_MUTATION,
|
||||
"query": API_CREATE_USERS_MUTATION,
|
||||
"variables": {
|
||||
"user": {
|
||||
"username": username,
|
||||
|
@ -550,7 +552,7 @@ def test_graphql_add_invalid_username(
|
|||
assert response.json["data"]["createUser"]["user"] is None
|
||||
|
||||
|
||||
API_DELETE_USERS_MUTATION = """
|
||||
API_DELETE_USER_MUTATION = """
|
||||
mutation deleteUser($username: String!) {
|
||||
deleteUser(username: $username) {
|
||||
success
|
||||
|
@ -565,7 +567,7 @@ def test_graphql_delete_user_unauthorized(client, some_users, mock_subprocess_po
|
|||
response = client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_DELETE_USERS_MUTATION,
|
||||
"query": API_DELETE_USER_MUTATION,
|
||||
"variables": {"username": "user1"},
|
||||
},
|
||||
)
|
||||
|
@ -577,7 +579,7 @@ def test_graphql_delete_user(authorized_client, some_users, mock_subprocess_pope
|
|||
response = authorized_client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_DELETE_USERS_MUTATION,
|
||||
"query": API_DELETE_USER_MUTATION,
|
||||
"variables": {"username": "user1"},
|
||||
},
|
||||
)
|
||||
|
@ -590,13 +592,13 @@ def test_graphql_delete_user(authorized_client, some_users, mock_subprocess_pope
|
|||
|
||||
|
||||
@pytest.mark.parametrize("username", ["", "def"])
|
||||
def test_graphql_delete_404users(
|
||||
def test_graphql_delete_nonexistent_users(
|
||||
authorized_client, some_users, mock_subprocess_popen, username
|
||||
):
|
||||
response = authorized_client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_DELETE_USERS_MUTATION,
|
||||
"query": API_DELETE_USER_MUTATION,
|
||||
"variables": {"username": username},
|
||||
},
|
||||
)
|
||||
|
@ -615,7 +617,7 @@ def test_graphql_delete_system_users(
|
|||
response = authorized_client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_DELETE_USERS_MUTATION,
|
||||
"query": API_DELETE_USER_MUTATION,
|
||||
"variables": {"username": username},
|
||||
},
|
||||
)
|
||||
|
@ -634,7 +636,7 @@ def test_graphql_delete_main_user(authorized_client, some_users, mock_subprocess
|
|||
response = authorized_client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_DELETE_USERS_MUTATION,
|
||||
"query": API_DELETE_USER_MUTATION,
|
||||
"variables": {"username": "tester"},
|
||||
},
|
||||
)
|
||||
|
@ -646,7 +648,7 @@ def test_graphql_delete_main_user(authorized_client, some_users, mock_subprocess
|
|||
assert response.json["data"]["deleteUser"]["success"] is False
|
||||
|
||||
|
||||
API_UPDATE_USERS_MUTATION = """
|
||||
API_UPDATE_USER_MUTATION = """
|
||||
mutation updateUser($user: UserMutationInput!) {
|
||||
updateUser(user: $user) {
|
||||
success
|
||||
|
@ -665,7 +667,7 @@ def test_graphql_update_user_unauthorized(client, some_users, mock_subprocess_po
|
|||
response = client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_UPDATE_USERS_MUTATION,
|
||||
"query": API_UPDATE_USER_MUTATION,
|
||||
"variables": {
|
||||
"user": {
|
||||
"username": "user1",
|
||||
|
@ -682,7 +684,7 @@ def test_graphql_update_user(authorized_client, some_users, mock_subprocess_pope
|
|||
response = authorized_client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_UPDATE_USERS_MUTATION,
|
||||
"query": API_UPDATE_USER_MUTATION,
|
||||
"variables": {
|
||||
"user": {
|
||||
"username": "user1",
|
||||
|
@ -705,11 +707,13 @@ def test_graphql_update_user(authorized_client, some_users, mock_subprocess_pope
|
|||
assert mock_subprocess_popen.call_count == 1
|
||||
|
||||
|
||||
def test_graphql_update_404user(authorized_client, some_users, mock_subprocess_popen):
|
||||
def test_graphql_update_nonexistent_user(
|
||||
authorized_client, some_users, mock_subprocess_popen
|
||||
):
|
||||
response = authorized_client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_UPDATE_USERS_MUTATION,
|
||||
"query": API_UPDATE_USER_MUTATION,
|
||||
"variables": {
|
||||
"user": {
|
||||
"username": "user666",
|
||||
|
|
Loading…
Reference in New Issue