fix tests but fixed
parent
bda2a7c1f7
commit
4f86d7c0fb
|
@ -53,7 +53,6 @@ def create_app(test_config=None):
|
||||||
pass
|
pass
|
||||||
elif request.path.startswith("/auth/recovery_token/use"):
|
elif request.path.startswith("/auth/recovery_token/use"):
|
||||||
pass
|
pass
|
||||||
# TODO: REMOVE THIS
|
|
||||||
elif request.path.startswith("/graphql"):
|
elif request.path.startswith("/graphql"):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -7,6 +7,7 @@ from tests.common import (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ProcessMock:
|
class ProcessMock:
|
||||||
"""Mock subprocess.Popen"""
|
"""Mock subprocess.Popen"""
|
||||||
|
|
||||||
|
@ -25,7 +26,6 @@ def mock_subprocess_popen(mocker):
|
||||||
mock = mocker.patch("subprocess.Popen", autospec=True, return_value=ProcessMock)
|
mock = mocker.patch("subprocess.Popen", autospec=True, return_value=ProcessMock)
|
||||||
return mock
|
return mock
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def some_users(mocker, datadir):
|
def some_users(mocker, datadir):
|
||||||
mocker.patch("selfprivacy_api.utils.USERDATA_FILE", new=datadir / "some_users.json")
|
mocker.patch("selfprivacy_api.utils.USERDATA_FILE", new=datadir / "some_users.json")
|
||||||
|
@ -41,6 +41,7 @@ def some_users(mocker, datadir):
|
||||||
return datadir
|
return datadir
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# TESTS ########################################################
|
# TESTS ########################################################
|
||||||
|
|
||||||
|
|
||||||
|
@ -75,7 +76,6 @@ def test_graphql_add_ssh_unauthorized(client, some_users, mock_subprocess_popen)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
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(authorized_client, some_users, mock_subprocess_popen):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
|
@ -97,10 +97,10 @@ def test_graphql_add_ssh(authorized_client, some_users, mock_subprocess_popen):
|
||||||
assert response.json["data"]["createSsh"]["success"] is True
|
assert response.json["data"]["createSsh"]["success"] is True
|
||||||
|
|
||||||
assert response.json["data"]["createSsh"]["user"]["username"] == "user1"
|
assert response.json["data"]["createSsh"]["user"]["username"] == "user1"
|
||||||
# assert response.json["data"]["createSsh"]["user"]["sshKeys"] == [ # i know
|
assert response.json["data"]["createSsh"]["user"]["sshKeys"] == [
|
||||||
# "ssh-rsa KEY test_key@pc"
|
"ssh-rsa KEY tester@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(authorized_client, some_users, mock_subprocess_popen):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
|
@ -123,10 +123,10 @@ def test_graphql_add_root_ssh(authorized_client, some_users, mock_subprocess_pop
|
||||||
assert response.json["data"]["createSsh"]["success"] is True
|
assert response.json["data"]["createSsh"]["success"] is True
|
||||||
|
|
||||||
assert response.json["data"]["createSsh"]["user"]["username"] == "root"
|
assert response.json["data"]["createSsh"]["user"]["username"] == "root"
|
||||||
# assert response.json["data"]["createSsh"]["user"]["sshKeys"] == [ # i know
|
assert response.json["data"]["createSsh"]["user"]["sshKeys"] == [
|
||||||
# "ssh-rsa KEY test_key@pc"
|
"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(authorized_client, some_users, mock_subprocess_popen):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
|
@ -149,12 +149,13 @@ def test_graphql_add_main_ssh(authorized_client, some_users, mock_subprocess_pop
|
||||||
assert response.json["data"]["createSsh"]["success"] is True
|
assert response.json["data"]["createSsh"]["success"] is True
|
||||||
|
|
||||||
assert response.json["data"]["createSsh"]["user"]["username"] == "tester"
|
assert response.json["data"]["createSsh"]["user"]["username"] == "tester"
|
||||||
# assert response.json["data"]["createSsh"]["user"]["sshKeys"] == [ # i know
|
assert response.json["data"]["createSsh"]["user"]["sshKeys"] == [
|
||||||
# "ssh-rsa KEY test_key@pc"
|
"ssh-rsa KEY tester@pc",
|
||||||
# ]
|
"ssh-rsa KEY test_key@pc"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_add_404ssh(authorized_client, some_users, mock_subprocess_popen):
|
def test_graphql_add_bad_ssh(authorized_client, some_users, mock_subprocess_popen):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
|
@ -210,7 +211,6 @@ mutation deleteSsh($input: SshMutationsInput!) {
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_dell_ssh_unauthorized(client, some_users, mock_subprocess_popen):
|
def test_graphql_dell_ssh_unauthorized(client, some_users, mock_subprocess_popen):
|
||||||
response = client.post(
|
response = client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
|
@ -227,7 +227,6 @@ def test_graphql_dell_ssh_unauthorized(client, some_users, mock_subprocess_popen
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
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_dell_ssh(authorized_client, some_users, mock_subprocess_popen):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
|
@ -236,7 +235,7 @@ def test_graphql_dell_ssh(authorized_client, some_users, mock_subprocess_popen):
|
||||||
"variables": {
|
"variables": {
|
||||||
"input": {
|
"input": {
|
||||||
"username": "user1",
|
"username": "user1",
|
||||||
"sshKey": "ssh-rsa KEY test_key@pc",
|
"sshKey": "ssh-rsa KEY user1@pc",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -249,10 +248,9 @@ def test_graphql_dell_ssh(authorized_client, some_users, mock_subprocess_popen):
|
||||||
assert response.json["data"]["deleteSsh"]["success"] is True
|
assert response.json["data"]["deleteSsh"]["success"] is True
|
||||||
|
|
||||||
assert response.json["data"]["deleteSsh"]["user"]["username"] == "user1"
|
assert response.json["data"]["deleteSsh"]["user"]["username"] == "user1"
|
||||||
# assert response.json["data"]["deleteSsh"]["user"]["sshKeys"] == [ # i know
|
assert response.json["data"]["deleteSsh"]["user"]["sshKeys"] == [
|
||||||
# "ssh-rsa KEY test_key@pc"
|
"ssh-rsa KEY user1@pc"
|
||||||
# ]
|
]
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_dell_root_ssh(authorized_client, some_users, mock_subprocess_popen):
|
def test_graphql_dell_root_ssh(authorized_client, some_users, mock_subprocess_popen):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
|
@ -262,7 +260,7 @@ def test_graphql_dell_root_ssh(authorized_client, some_users, mock_subprocess_po
|
||||||
"variables": {
|
"variables": {
|
||||||
"input": {
|
"input": {
|
||||||
"username": "root",
|
"username": "root",
|
||||||
"sshKey": "ssh-rsa KEY root@pc",
|
"sshKey": "ssh-ed25519 KEY test@pc",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -275,9 +273,7 @@ def test_graphql_dell_root_ssh(authorized_client, some_users, mock_subprocess_po
|
||||||
assert response.json["data"]["deleteSsh"]["success"] is True
|
assert response.json["data"]["deleteSsh"]["success"] is True
|
||||||
|
|
||||||
assert response.json["data"]["deleteSsh"]["user"]["username"] == "root"
|
assert response.json["data"]["deleteSsh"]["user"]["username"] == "root"
|
||||||
# assert response.json["data"]["deleteSsh"]["user"]["sshKeys"] == [ # i know
|
assert response.json["data"]["deleteSsh"]["user"]["sshKeys"] == []
|
||||||
# "ssh-rsa KEY test_key@pc"
|
|
||||||
# ]
|
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_dell_main_ssh(authorized_client, some_users, mock_subprocess_popen):
|
def test_graphql_dell_main_ssh(authorized_client, some_users, mock_subprocess_popen):
|
||||||
|
@ -301,10 +297,7 @@ def test_graphql_dell_main_ssh(authorized_client, some_users, mock_subprocess_po
|
||||||
assert response.json["data"]["deleteSsh"]["success"] is True
|
assert response.json["data"]["deleteSsh"]["success"] is True
|
||||||
|
|
||||||
assert response.json["data"]["deleteSsh"]["user"]["username"] == "tester"
|
assert response.json["data"]["deleteSsh"]["user"]["username"] == "tester"
|
||||||
assert response.json["data"]["deleteSsh"]["user"]["sshKeys"] == [ # i know
|
assert response.json["data"]["deleteSsh"]["user"]["sshKeys"] == []
|
||||||
"ssh-rsa KEY test_key@pc"
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_dell_404ssh(authorized_client, some_users, mock_subprocess_popen):
|
def test_graphql_dell_404ssh(authorized_client, some_users, mock_subprocess_popen):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
|
@ -346,3 +339,4 @@ def test_graphql_dell_ssh_404user(authorized_client, some_users, mock_subprocess
|
||||||
assert response.json["data"]["deleteSsh"]["code"] == 404
|
assert response.json["data"]["deleteSsh"]["code"] == 404
|
||||||
assert response.json["data"]["deleteSsh"]["message"] is not None
|
assert response.json["data"]["deleteSsh"]["message"] is not None
|
||||||
assert response.json["data"]["deleteSsh"]["success"] is False
|
assert response.json["data"]["deleteSsh"]["success"] is False
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
{
|
||||||
|
"backblaze": {
|
||||||
|
"accountId": "ID",
|
||||||
|
"accountKey": "KEY",
|
||||||
|
"bucket": "selfprivacy"
|
||||||
|
},
|
||||||
|
"api": {
|
||||||
|
"token": "TEST_TOKEN",
|
||||||
|
"enableSwagger": false
|
||||||
|
},
|
||||||
|
"bitwarden": {
|
||||||
|
"enable": false
|
||||||
|
},
|
||||||
|
"cloudflare": {
|
||||||
|
"apiKey": "TOKEN"
|
||||||
|
},
|
||||||
|
"databasePassword": "PASSWORD",
|
||||||
|
"domain": "test.tld",
|
||||||
|
"hashedMasterPassword": "HASHED_PASSWORD",
|
||||||
|
"hostname": "test-instance",
|
||||||
|
"nextcloud": {
|
||||||
|
"adminPassword": "ADMIN",
|
||||||
|
"databasePassword": "ADMIN",
|
||||||
|
"enable": true
|
||||||
|
},
|
||||||
|
"resticPassword": "PASS",
|
||||||
|
"ssh": {
|
||||||
|
"enable": true,
|
||||||
|
"passwordAuthentication": true,
|
||||||
|
"rootKeys": [
|
||||||
|
"ssh-ed25519 KEY test@pc"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"username": "tester",
|
||||||
|
"gitea": {
|
||||||
|
"enable": false
|
||||||
|
},
|
||||||
|
"ocserv": {
|
||||||
|
"enable": true
|
||||||
|
},
|
||||||
|
"pleroma": {
|
||||||
|
"enable": true
|
||||||
|
},
|
||||||
|
"autoUpgrade": {
|
||||||
|
"enable": true,
|
||||||
|
"allowReboot": true
|
||||||
|
},
|
||||||
|
"timezone": "Europe/Moscow",
|
||||||
|
"sshKeys": [
|
||||||
|
"ssh-rsa KEY test@pc"
|
||||||
|
],
|
||||||
|
"users": [
|
||||||
|
{
|
||||||
|
"username": "user1",
|
||||||
|
"hashedPassword": "HASHED_PASSWORD_1",
|
||||||
|
"sshKeys": [
|
||||||
|
"ssh-rsa KEY user1@pc"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"username": "user2",
|
||||||
|
"hashedPassword": "HASHED_PASSWORD_2",
|
||||||
|
"sshKeys": [
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"username": "user3",
|
||||||
|
"hashedPassword": "HASHED_PASSWORD_3"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue