fix tests but fixed

pull/12/head
def 2022-07-27 19:49:10 +02:00
parent bda2a7c1f7
commit 4f86d7c0fb
3 changed files with 94 additions and 30 deletions

View File

@ -53,7 +53,6 @@ def create_app(test_config=None):
pass
elif request.path.startswith("/auth/recovery_token/use"):
pass
# TODO: REMOVE THIS
elif request.path.startswith("/graphql"):
pass
else:

View File

@ -7,6 +7,7 @@ from tests.common import (
)
class ProcessMock:
"""Mock subprocess.Popen"""
@ -25,7 +26,6 @@ def mock_subprocess_popen(mocker):
mock = mocker.patch("subprocess.Popen", autospec=True, return_value=ProcessMock)
return mock
@pytest.fixture
def some_users(mocker, datadir):
mocker.patch("selfprivacy_api.utils.USERDATA_FILE", new=datadir / "some_users.json")
@ -41,6 +41,7 @@ def some_users(mocker, datadir):
return datadir
# TESTS ########################################################
@ -75,7 +76,6 @@ def test_graphql_add_ssh_unauthorized(client, some_users, mock_subprocess_popen)
assert response.status_code == 200
assert response.json.get("data") is None
def test_graphql_add_ssh(authorized_client, some_users, mock_subprocess_popen):
response = authorized_client.post(
"/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"]["user"]["username"] == "user1"
# assert response.json["data"]["createSsh"]["user"]["sshKeys"] == [ # i know
# "ssh-rsa KEY test_key@pc"
# ]
assert response.json["data"]["createSsh"]["user"]["sshKeys"] == [
"ssh-rsa KEY tester@pc",
"ssh-rsa KEY test_key@pc"
]
def test_graphql_add_root_ssh(authorized_client, some_users, mock_subprocess_popen):
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"]["user"]["username"] == "root"
# assert response.json["data"]["createSsh"]["user"]["sshKeys"] == [ # i know
# "ssh-rsa KEY test_key@pc"
# ]
assert response.json["data"]["createSsh"]["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):
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"]["user"]["username"] == "tester"
# assert response.json["data"]["createSsh"]["user"]["sshKeys"] == [ # i know
# "ssh-rsa KEY test_key@pc"
# ]
assert response.json["data"]["createSsh"]["user"]["sshKeys"] == [
"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(
"/graphql",
json={
@ -210,7 +211,6 @@ mutation deleteSsh($input: SshMutationsInput!) {
}
"""
def test_graphql_dell_ssh_unauthorized(client, some_users, mock_subprocess_popen):
response = client.post(
"/graphql",
@ -227,7 +227,6 @@ def test_graphql_dell_ssh_unauthorized(client, some_users, mock_subprocess_popen
assert response.status_code == 200
assert response.json.get("data") is None
def test_graphql_dell_ssh(authorized_client, some_users, mock_subprocess_popen):
response = authorized_client.post(
"/graphql",
@ -236,7 +235,7 @@ def test_graphql_dell_ssh(authorized_client, some_users, mock_subprocess_popen):
"variables": {
"input": {
"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"]["user"]["username"] == "user1"
# assert response.json["data"]["deleteSsh"]["user"]["sshKeys"] == [ # i know
# "ssh-rsa KEY test_key@pc"
# ]
assert response.json["data"]["deleteSsh"]["user"]["sshKeys"] == [
"ssh-rsa KEY user1@pc"
]
def test_graphql_dell_root_ssh(authorized_client, some_users, mock_subprocess_popen):
response = authorized_client.post(
@ -262,7 +260,7 @@ def test_graphql_dell_root_ssh(authorized_client, some_users, mock_subprocess_po
"variables": {
"input": {
"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"]["user"]["username"] == "root"
# assert response.json["data"]["deleteSsh"]["user"]["sshKeys"] == [ # i know
# "ssh-rsa KEY test_key@pc"
# ]
assert response.json["data"]["deleteSsh"]["user"]["sshKeys"] == []
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"]["user"]["username"] == "tester"
assert response.json["data"]["deleteSsh"]["user"]["sshKeys"] == [ # i know
"ssh-rsa KEY test_key@pc"
]
assert response.json["data"]["deleteSsh"]["user"]["sshKeys"] == []
def test_graphql_dell_404ssh(authorized_client, some_users, mock_subprocess_popen):
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"]["message"] is not None
assert response.json["data"]["deleteSsh"]["success"] is False

View File

@ -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"
}
]
}