rename many things
parent
612e237a28
commit
50d0c835d0
|
@ -1,11 +1,11 @@
|
||||||
import typing
|
import typing
|
||||||
|
from enum import Enum
|
||||||
import strawberry
|
import strawberry
|
||||||
|
|
||||||
|
from selfprivacy_api.utils import ReadUserData
|
||||||
from selfprivacy_api.graphql.mutations.mutation_interface import (
|
from selfprivacy_api.graphql.mutations.mutation_interface import (
|
||||||
MutationReturnInterface,
|
MutationReturnInterface,
|
||||||
)
|
)
|
||||||
from enum import Enum
|
|
||||||
|
|
||||||
from selfprivacy_api.utils import ReadUserData, ensure_ssh_and_users_fields_exist
|
|
||||||
|
|
||||||
|
|
||||||
@strawberry.enum
|
@strawberry.enum
|
||||||
|
@ -17,7 +17,6 @@ class UserType(Enum):
|
||||||
|
|
||||||
@strawberry.type
|
@strawberry.type
|
||||||
class User:
|
class User:
|
||||||
"""Users management"""
|
|
||||||
|
|
||||||
user_type: UserType
|
user_type: UserType
|
||||||
username: str
|
username: str
|
||||||
|
@ -32,6 +31,21 @@ class UserMutationReturn(MutationReturnInterface):
|
||||||
user: typing.Optional[User]
|
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]:
|
def get_user_by_username(username: str) -> typing.Optional[User]:
|
||||||
with ReadUserData() as data:
|
with ReadUserData() as data:
|
||||||
ensure_ssh_and_users_fields_exist(data)
|
ensure_ssh_and_users_fields_exist(data)
|
||||||
|
|
|
@ -2,13 +2,13 @@
|
||||||
"""Users management module"""
|
"""Users management module"""
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
|
|
||||||
|
|
||||||
import strawberry
|
import strawberry
|
||||||
|
|
||||||
|
from selfprivacy_api.graphql import IsAuthenticated
|
||||||
from selfprivacy_api.graphql.mutations.ssh_utils import (
|
from selfprivacy_api.graphql.mutations.ssh_utils import (
|
||||||
create_ssh_key,
|
create_ssh_key,
|
||||||
delete_ssh_key,
|
remove_ssh_key,
|
||||||
)
|
)
|
||||||
from selfprivacy_api.graphql import IsAuthenticated
|
|
||||||
from selfprivacy_api.graphql.common_types.user import (
|
from selfprivacy_api.graphql.common_types.user import (
|
||||||
UserMutationReturn,
|
UserMutationReturn,
|
||||||
get_user_by_username,
|
get_user_by_username,
|
||||||
|
@ -28,8 +28,8 @@ class SshMutations:
|
||||||
"""Mutations ssh"""
|
"""Mutations ssh"""
|
||||||
|
|
||||||
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
||||||
def create_ssh(self, ssh_input: SshMutationInput) -> UserMutationReturn:
|
def add_ssh_key(self, ssh_input: SshMutationInput) -> UserMutationReturn:
|
||||||
"""Create a new ssh"""
|
"""Add a new ssh key"""
|
||||||
|
|
||||||
success, message, code = create_ssh_key(ssh_input.username, ssh_input.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])
|
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
||||||
def delete_ssh(self, ssh_input: SshMutationInput) -> UserMutationReturn:
|
def remove_ssh_key(self, ssh_input: SshMutationInput) -> UserMutationReturn:
|
||||||
"""Delete ssh key from user"""
|
"""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(
|
return UserMutationReturn(
|
||||||
success=success,
|
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 (
|
from selfprivacy_api.utils import (
|
||||||
WriteUserData,
|
WriteUserData,
|
||||||
ensure_ssh_and_users_fields_exist,
|
|
||||||
validate_ssh_public_key,
|
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"""
|
"""Create a new ssh key"""
|
||||||
|
|
||||||
if not validate_ssh_public_key(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
|
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"""
|
"""Delete a ssh key"""
|
||||||
|
|
||||||
with WriteUserData() as data:
|
with WriteUserData() as data:
|
||||||
|
|
|
@ -11,9 +11,9 @@ from selfprivacy_api.graphql.mutations.mutation_interface import (
|
||||||
GenericMutationReturn,
|
GenericMutationReturn,
|
||||||
)
|
)
|
||||||
from selfprivacy_api.graphql.mutations.users_utils import (
|
from selfprivacy_api.graphql.mutations.users_utils import (
|
||||||
create_user_util,
|
create_user,
|
||||||
delete_user_util,
|
delete_user,
|
||||||
update_user_util,
|
update_user,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ class UserMutations:
|
||||||
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
||||||
def create_user(self, user: UserMutationInput) -> UserMutationReturn:
|
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(
|
return UserMutationReturn(
|
||||||
success=success,
|
success=success,
|
||||||
|
@ -43,7 +43,7 @@ class UserMutations:
|
||||||
|
|
||||||
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
||||||
def delete_user(self, username: str) -> GenericMutationReturn:
|
def delete_user(self, username: str) -> GenericMutationReturn:
|
||||||
success, message, code = delete_user_util(username)
|
success, message, code = delete_user(username)
|
||||||
|
|
||||||
return GenericMutationReturn(
|
return GenericMutationReturn(
|
||||||
success=success,
|
success=success,
|
||||||
|
@ -55,7 +55,7 @@ class UserMutations:
|
||||||
def update_user(self, user: UserMutationInput) -> UserMutationReturn:
|
def update_user(self, user: UserMutationInput) -> UserMutationReturn:
|
||||||
"""Update user mutation"""
|
"""Update user mutation"""
|
||||||
|
|
||||||
success, message, code = update_user_util(user.username, user.password)
|
success, message, code = update_user(user.username, user.password)
|
||||||
|
|
||||||
return UserMutationReturn(
|
return UserMutationReturn(
|
||||||
success=success,
|
success=success,
|
||||||
|
|
|
@ -2,13 +2,27 @@ import re
|
||||||
from selfprivacy_api.utils import (
|
from selfprivacy_api.utils import (
|
||||||
WriteUserData,
|
WriteUserData,
|
||||||
ReadUserData,
|
ReadUserData,
|
||||||
ensure_ssh_and_users_fields_exist,
|
|
||||||
is_username_forbidden,
|
is_username_forbidden,
|
||||||
)
|
)
|
||||||
from selfprivacy_api.utils import hash_password
|
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"""
|
"""Create a new user"""
|
||||||
|
|
||||||
# Check if password is null or none
|
# Check if password is null or none
|
||||||
|
@ -44,13 +58,17 @@ def create_user_util(username, password):
|
||||||
ensure_ssh_and_users_fields_exist(data)
|
ensure_ssh_and_users_fields_exist(data)
|
||||||
|
|
||||||
data["users"].append(
|
data["users"].append(
|
||||||
{"username": username, "hashedPassword": hashed_password, "sshKeys": []}
|
{
|
||||||
|
"username": username,
|
||||||
|
"hashedPassword": hashed_password,
|
||||||
|
"sshKeys": [],
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
return True, "User was successfully created!", 201
|
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:
|
with WriteUserData() as data:
|
||||||
ensure_ssh_and_users_fields_exist(data)
|
ensure_ssh_and_users_fields_exist(data)
|
||||||
|
|
||||||
|
@ -68,7 +86,7 @@ def delete_user_util(username):
|
||||||
return True, "User was deleted", 200
|
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
|
# Check if password is null or none
|
||||||
if password == "":
|
if password == "":
|
||||||
return False, "Password is null", 400
|
return False, "Password is null", 400
|
||||||
|
|
|
@ -3,8 +3,12 @@
|
||||||
import typing
|
import typing
|
||||||
import strawberry
|
import strawberry
|
||||||
|
|
||||||
from selfprivacy_api.graphql.common_types.user import User, get_user_by_username
|
from selfprivacy_api.graphql.common_types.user import (
|
||||||
from selfprivacy_api.utils import ReadUserData, ensure_ssh_and_users_fields_exist
|
User,
|
||||||
|
ensure_ssh_and_users_fields_exist,
|
||||||
|
get_user_by_username,
|
||||||
|
)
|
||||||
|
from selfprivacy_api.utils import ReadUserData
|
||||||
from selfprivacy_api.graphql import IsAuthenticated
|
from selfprivacy_api.graphql import IsAuthenticated
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -173,18 +173,3 @@ def hash_password(password):
|
||||||
hashed_password = hashed_password.decode("ascii")
|
hashed_password = hashed_password.decode("ascii")
|
||||||
hashed_password = hashed_password.rstrip()
|
hashed_password = hashed_password.rstrip()
|
||||||
return hashed_password
|
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
|
# pylint: disable=unused-argument
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from tests.common import (
|
from tests.common import read_json
|
||||||
read_json,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class ProcessMock:
|
class ProcessMock:
|
||||||
|
@ -44,9 +42,9 @@ def some_users(mocker, datadir):
|
||||||
# TESTS ########################################################
|
# TESTS ########################################################
|
||||||
|
|
||||||
|
|
||||||
API_CREATE_SSH_MUTATION = """
|
API_CREATE_SSH_KEY_MUTATION = """
|
||||||
mutation createSsh($sshInput: SshMutationInput!) {
|
mutation addSshKey($sshInput: SshMutationInput!) {
|
||||||
createSsh(sshInput: $sshInput) {
|
addSshKey(sshInput: $sshInput) {
|
||||||
success
|
success
|
||||||
message
|
message
|
||||||
code
|
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(
|
response = client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_CREATE_SSH_MUTATION,
|
"query": API_CREATE_SSH_KEY_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"sshInput": {
|
"sshInput": {
|
||||||
"username": "user1",
|
"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
|
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(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_CREATE_SSH_MUTATION,
|
"query": API_CREATE_SSH_KEY_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"sshInput": {
|
"sshInput": {
|
||||||
"username": "user1",
|
"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.status_code == 200
|
||||||
assert response.json.get("data") is not None
|
assert response.json.get("data") is not None
|
||||||
|
|
||||||
assert response.json["data"]["createSsh"]["code"] == 201
|
assert response.json["data"]["addSshKey"]["code"] == 201
|
||||||
assert response.json["data"]["createSsh"]["message"] is not None
|
assert response.json["data"]["addSshKey"]["message"] is not None
|
||||||
assert response.json["data"]["createSsh"]["success"] is True
|
assert response.json["data"]["addSshKey"]["success"] is True
|
||||||
|
|
||||||
assert response.json["data"]["createSsh"]["user"]["username"] == "user1"
|
assert response.json["data"]["addSshKey"]["user"]["username"] == "user1"
|
||||||
assert response.json["data"]["createSsh"]["user"]["sshKeys"] == [
|
assert response.json["data"]["addSshKey"]["user"]["sshKeys"] == [
|
||||||
"ssh-rsa KEY user1@pc",
|
"ssh-rsa KEY user1@pc",
|
||||||
"ssh-rsa KEY test_key@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(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_CREATE_SSH_MUTATION,
|
"query": API_CREATE_SSH_KEY_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"sshInput": {
|
"sshInput": {
|
||||||
"username": "root",
|
"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.status_code == 200
|
||||||
assert response.json.get("data") is not None
|
assert response.json.get("data") is not None
|
||||||
|
|
||||||
assert response.json["data"]["createSsh"]["code"] == 201
|
assert response.json["data"]["addSshKey"]["code"] == 201
|
||||||
assert response.json["data"]["createSsh"]["message"] is not None
|
assert response.json["data"]["addSshKey"]["message"] is not None
|
||||||
assert response.json["data"]["createSsh"]["success"] is True
|
assert response.json["data"]["addSshKey"]["success"] is True
|
||||||
|
|
||||||
assert response.json["data"]["createSsh"]["user"]["username"] == "root"
|
assert response.json["data"]["addSshKey"]["user"]["username"] == "root"
|
||||||
assert response.json["data"]["createSsh"]["user"]["sshKeys"] == [
|
assert response.json["data"]["addSshKey"]["user"]["sshKeys"] == [
|
||||||
"ssh-ed25519 KEY test@pc",
|
"ssh-ed25519 KEY test@pc",
|
||||||
"ssh-rsa KEY test_key@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(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_CREATE_SSH_MUTATION,
|
"query": API_CREATE_SSH_KEY_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"sshInput": {
|
"sshInput": {
|
||||||
"username": "tester",
|
"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.status_code == 200
|
||||||
assert response.json.get("data") is not None
|
assert response.json.get("data") is not None
|
||||||
|
|
||||||
assert response.json["data"]["createSsh"]["code"] == 201
|
assert response.json["data"]["addSshKey"]["code"] == 201
|
||||||
assert response.json["data"]["createSsh"]["message"] is not None
|
assert response.json["data"]["addSshKey"]["message"] is not None
|
||||||
assert response.json["data"]["createSsh"]["success"] is True
|
assert response.json["data"]["addSshKey"]["success"] is True
|
||||||
|
|
||||||
assert response.json["data"]["createSsh"]["user"]["username"] == "tester"
|
assert response.json["data"]["addSshKey"]["user"]["username"] == "tester"
|
||||||
assert response.json["data"]["createSsh"]["user"]["sshKeys"] == [
|
assert response.json["data"]["addSshKey"]["user"]["sshKeys"] == [
|
||||||
"ssh-rsa KEY test@pc",
|
"ssh-rsa KEY test@pc",
|
||||||
"ssh-rsa KEY test_key@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(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_CREATE_SSH_MUTATION,
|
"query": API_CREATE_SSH_KEY_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"sshInput": {
|
"sshInput": {
|
||||||
"username": "user1",
|
"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.status_code == 200
|
||||||
assert response.json.get("data") is not None
|
assert response.json.get("data") is not None
|
||||||
|
|
||||||
assert response.json["data"]["createSsh"]["code"] == 400
|
assert response.json["data"]["addSshKey"]["code"] == 400
|
||||||
assert response.json["data"]["createSsh"]["message"] is not None
|
assert response.json["data"]["addSshKey"]["message"] is not None
|
||||||
assert response.json["data"]["createSsh"]["success"] is False
|
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(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_CREATE_SSH_MUTATION,
|
"query": API_CREATE_SSH_KEY_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"sshInput": {
|
"sshInput": {
|
||||||
"username": "user666",
|
"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.status_code == 200
|
||||||
assert response.json.get("data") is not None
|
assert response.json.get("data") is not None
|
||||||
|
|
||||||
assert response.json["data"]["createSsh"]["code"] == 404
|
assert response.json["data"]["addSshKey"]["code"] == 404
|
||||||
assert response.json["data"]["createSsh"]["message"] is not None
|
assert response.json["data"]["addSshKey"]["message"] is not None
|
||||||
assert response.json["data"]["createSsh"]["success"] is False
|
assert response.json["data"]["addSshKey"]["success"] is False
|
||||||
|
|
||||||
|
|
||||||
API_DELETE_SSH_MUTATION = """
|
API_REMOVE_SSH_KEY_MUTATION = """
|
||||||
mutation deleteSsh($sshInput: SshMutationInput!) {
|
mutation removeSshKey($sshInput: SshMutationInput!) {
|
||||||
deleteSsh(sshInput: $sshInput) {
|
removeSshKey(sshInput: $sshInput) {
|
||||||
success
|
success
|
||||||
message
|
message
|
||||||
code
|
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(
|
response = client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_DELETE_SSH_MUTATION,
|
"query": API_REMOVE_SSH_KEY_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"sshInput": {
|
"sshInput": {
|
||||||
"username": "user1",
|
"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
|
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(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_DELETE_SSH_MUTATION,
|
"query": API_REMOVE_SSH_KEY_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"sshInput": {
|
"sshInput": {
|
||||||
"username": "user1",
|
"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.status_code == 200
|
||||||
assert response.json.get("data") is not None
|
assert response.json.get("data") is not None
|
||||||
|
|
||||||
assert response.json["data"]["deleteSsh"]["code"] == 200
|
assert response.json["data"]["removeSshKey"]["code"] == 200
|
||||||
assert response.json["data"]["deleteSsh"]["message"] is not None
|
assert response.json["data"]["removeSshKey"]["message"] is not None
|
||||||
assert response.json["data"]["deleteSsh"]["success"] is True
|
assert response.json["data"]["removeSshKey"]["success"] is True
|
||||||
|
|
||||||
assert response.json["data"]["deleteSsh"]["user"]["username"] == "user1"
|
assert response.json["data"]["removeSshKey"]["user"]["username"] == "user1"
|
||||||
assert response.json["data"]["deleteSsh"]["user"]["sshKeys"] == []
|
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(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_DELETE_SSH_MUTATION,
|
"query": API_REMOVE_SSH_KEY_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"sshInput": {
|
"sshInput": {
|
||||||
"username": "root",
|
"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.status_code == 200
|
||||||
assert response.json.get("data") is not None
|
assert response.json.get("data") is not None
|
||||||
|
|
||||||
assert response.json["data"]["deleteSsh"]["code"] == 200
|
assert response.json["data"]["removeSshKey"]["code"] == 200
|
||||||
assert response.json["data"]["deleteSsh"]["message"] is not None
|
assert response.json["data"]["removeSshKey"]["message"] is not None
|
||||||
assert response.json["data"]["deleteSsh"]["success"] is True
|
assert response.json["data"]["removeSshKey"]["success"] is True
|
||||||
|
|
||||||
assert response.json["data"]["deleteSsh"]["user"]["username"] == "root"
|
assert response.json["data"]["removeSshKey"]["user"]["username"] == "root"
|
||||||
assert response.json["data"]["deleteSsh"]["user"]["sshKeys"] == []
|
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(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_DELETE_SSH_MUTATION,
|
"query": API_REMOVE_SSH_KEY_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"sshInput": {
|
"sshInput": {
|
||||||
"username": "tester",
|
"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.status_code == 200
|
||||||
assert response.json.get("data") is not None
|
assert response.json.get("data") is not None
|
||||||
|
|
||||||
assert response.json["data"]["deleteSsh"]["code"] == 200
|
assert response.json["data"]["removeSshKey"]["code"] == 200
|
||||||
assert response.json["data"]["deleteSsh"]["message"] is not None
|
assert response.json["data"]["removeSshKey"]["message"] is not None
|
||||||
assert response.json["data"]["deleteSsh"]["success"] is True
|
assert response.json["data"]["removeSshKey"]["success"] is True
|
||||||
|
|
||||||
assert response.json["data"]["deleteSsh"]["user"]["username"] == "tester"
|
assert response.json["data"]["removeSshKey"]["user"]["username"] == "tester"
|
||||||
assert response.json["data"]["deleteSsh"]["user"]["sshKeys"] == []
|
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(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_DELETE_SSH_MUTATION,
|
"query": API_REMOVE_SSH_KEY_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"sshInput": {
|
"sshInput": {
|
||||||
"username": "user1",
|
"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.status_code == 200
|
||||||
assert response.json.get("data") is not None
|
assert response.json.get("data") is not None
|
||||||
|
|
||||||
assert response.json["data"]["deleteSsh"]["code"] == 404
|
assert response.json["data"]["removeSshKey"]["code"] == 404
|
||||||
assert response.json["data"]["deleteSsh"]["message"] is not None
|
assert response.json["data"]["removeSshKey"]["message"] is not None
|
||||||
assert response.json["data"]["deleteSsh"]["success"] is False
|
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(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_DELETE_SSH_MUTATION,
|
"query": API_REMOVE_SSH_KEY_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"sshInput": {
|
"sshInput": {
|
||||||
"username": "user666",
|
"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.status_code == 200
|
||||||
assert response.json.get("data") is not None
|
assert response.json.get("data") is not None
|
||||||
|
|
||||||
assert response.json["data"]["deleteSsh"]["code"] == 404
|
assert response.json["data"]["removeSshKey"]["code"] == 404
|
||||||
assert response.json["data"]["deleteSsh"]["message"] is not None
|
assert response.json["data"]["removeSshKey"]["message"] is not None
|
||||||
assert response.json["data"]["deleteSsh"]["success"] is False
|
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(
|
response = authorized_client.get(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
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
|
assert response.json["data"]["users"]["getUser"] is None
|
||||||
|
|
||||||
|
|
||||||
API_CHANGE_USERS_MUTATION = """
|
API_CREATE_USERS_MUTATION = """
|
||||||
mutation createUser($user: UserMutationInput!) {
|
mutation createUser($user: UserMutationInput!) {
|
||||||
createUser(user: $user) {
|
createUser(user: $user) {
|
||||||
success
|
success
|
||||||
|
@ -310,7 +312,7 @@ def test_graphql_add_user_unauthorize(client, one_user, mock_subprocess_popen):
|
||||||
response = client.post(
|
response = client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_CHANGE_USERS_MUTATION,
|
"query": API_CREATE_USERS_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"user": {
|
"user": {
|
||||||
"username": "user2",
|
"username": "user2",
|
||||||
|
@ -327,7 +329,7 @@ def test_graphql_add_user(authorized_client, one_user, mock_subprocess_popen):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_CHANGE_USERS_MUTATION,
|
"query": API_CREATE_USERS_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"user": {
|
"user": {
|
||||||
"username": "user2",
|
"username": "user2",
|
||||||
|
@ -353,7 +355,7 @@ def test_graphql_add_undefined_settings(
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_CHANGE_USERS_MUTATION,
|
"query": API_CREATE_USERS_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"user": {
|
"user": {
|
||||||
"username": "user2",
|
"username": "user2",
|
||||||
|
@ -379,7 +381,7 @@ def test_graphql_add_without_password(
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_CHANGE_USERS_MUTATION,
|
"query": API_CREATE_USERS_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"user": {
|
"user": {
|
||||||
"username": "user2",
|
"username": "user2",
|
||||||
|
@ -402,7 +404,7 @@ def test_graphql_add_without_both(authorized_client, one_user, mock_subprocess_p
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_CHANGE_USERS_MUTATION,
|
"query": API_CREATE_USERS_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"user": {
|
"user": {
|
||||||
"username": "",
|
"username": "",
|
||||||
|
@ -428,7 +430,7 @@ def test_graphql_add_system_username(
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_CHANGE_USERS_MUTATION,
|
"query": API_CREATE_USERS_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"user": {
|
"user": {
|
||||||
"username": username,
|
"username": username,
|
||||||
|
@ -451,7 +453,7 @@ def test_graphql_add_existing_user(authorized_client, one_user, mock_subprocess_
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_CHANGE_USERS_MUTATION,
|
"query": API_CREATE_USERS_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"user": {
|
"user": {
|
||||||
"username": "user1",
|
"username": "user1",
|
||||||
|
@ -478,7 +480,7 @@ def test_graphql_add_main_user(authorized_client, one_user, mock_subprocess_pope
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_CHANGE_USERS_MUTATION,
|
"query": API_CREATE_USERS_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"user": {
|
"user": {
|
||||||
"username": "tester",
|
"username": "tester",
|
||||||
|
@ -505,7 +507,7 @@ def test_graphql_add_long_username(authorized_client, one_user, mock_subprocess_
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_CHANGE_USERS_MUTATION,
|
"query": API_CREATE_USERS_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"user": {
|
"user": {
|
||||||
"username": "a" * 32,
|
"username": "a" * 32,
|
||||||
|
@ -531,7 +533,7 @@ def test_graphql_add_invalid_username(
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_CHANGE_USERS_MUTATION,
|
"query": API_CREATE_USERS_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"user": {
|
"user": {
|
||||||
"username": username,
|
"username": username,
|
||||||
|
@ -550,7 +552,7 @@ def test_graphql_add_invalid_username(
|
||||||
assert response.json["data"]["createUser"]["user"] is None
|
assert response.json["data"]["createUser"]["user"] is None
|
||||||
|
|
||||||
|
|
||||||
API_DELETE_USERS_MUTATION = """
|
API_DELETE_USER_MUTATION = """
|
||||||
mutation deleteUser($username: String!) {
|
mutation deleteUser($username: String!) {
|
||||||
deleteUser(username: $username) {
|
deleteUser(username: $username) {
|
||||||
success
|
success
|
||||||
|
@ -565,7 +567,7 @@ def test_graphql_delete_user_unauthorized(client, some_users, mock_subprocess_po
|
||||||
response = client.post(
|
response = client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_DELETE_USERS_MUTATION,
|
"query": API_DELETE_USER_MUTATION,
|
||||||
"variables": {"username": "user1"},
|
"variables": {"username": "user1"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -577,7 +579,7 @@ def test_graphql_delete_user(authorized_client, some_users, mock_subprocess_pope
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_DELETE_USERS_MUTATION,
|
"query": API_DELETE_USER_MUTATION,
|
||||||
"variables": {"username": "user1"},
|
"variables": {"username": "user1"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -590,13 +592,13 @@ def test_graphql_delete_user(authorized_client, some_users, mock_subprocess_pope
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("username", ["", "def"])
|
@pytest.mark.parametrize("username", ["", "def"])
|
||||||
def test_graphql_delete_404users(
|
def test_graphql_delete_nonexistent_users(
|
||||||
authorized_client, some_users, mock_subprocess_popen, username
|
authorized_client, some_users, mock_subprocess_popen, username
|
||||||
):
|
):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_DELETE_USERS_MUTATION,
|
"query": API_DELETE_USER_MUTATION,
|
||||||
"variables": {"username": username},
|
"variables": {"username": username},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -615,7 +617,7 @@ def test_graphql_delete_system_users(
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_DELETE_USERS_MUTATION,
|
"query": API_DELETE_USER_MUTATION,
|
||||||
"variables": {"username": username},
|
"variables": {"username": username},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -634,7 +636,7 @@ def test_graphql_delete_main_user(authorized_client, some_users, mock_subprocess
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_DELETE_USERS_MUTATION,
|
"query": API_DELETE_USER_MUTATION,
|
||||||
"variables": {"username": "tester"},
|
"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
|
assert response.json["data"]["deleteUser"]["success"] is False
|
||||||
|
|
||||||
|
|
||||||
API_UPDATE_USERS_MUTATION = """
|
API_UPDATE_USER_MUTATION = """
|
||||||
mutation updateUser($user: UserMutationInput!) {
|
mutation updateUser($user: UserMutationInput!) {
|
||||||
updateUser(user: $user) {
|
updateUser(user: $user) {
|
||||||
success
|
success
|
||||||
|
@ -665,7 +667,7 @@ def test_graphql_update_user_unauthorized(client, some_users, mock_subprocess_po
|
||||||
response = client.post(
|
response = client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_UPDATE_USERS_MUTATION,
|
"query": API_UPDATE_USER_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"user": {
|
"user": {
|
||||||
"username": "user1",
|
"username": "user1",
|
||||||
|
@ -682,7 +684,7 @@ def test_graphql_update_user(authorized_client, some_users, mock_subprocess_pope
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_UPDATE_USERS_MUTATION,
|
"query": API_UPDATE_USER_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"user": {
|
"user": {
|
||||||
"username": "user1",
|
"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
|
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(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_UPDATE_USERS_MUTATION,
|
"query": API_UPDATE_USER_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"user": {
|
"user": {
|
||||||
"username": "user666",
|
"username": "user666",
|
||||||
|
|
Loading…
Reference in New Issue