From 4f86d7c0fb9641971f46ac9f58e0659e34ed44db Mon Sep 17 00:00:00 2001 From: def Date: Wed, 27 Jul 2022 19:49:10 +0200 Subject: [PATCH] fix tests but fixed --- selfprivacy_api/app.py | 1 - tests/test_graphql/test_ssh.py | 52 +++++++-------- tests/test_graphql/test_ssh/some_users.json | 71 +++++++++++++++++++++ 3 files changed, 94 insertions(+), 30 deletions(-) create mode 100644 tests/test_graphql/test_ssh/some_users.json diff --git a/selfprivacy_api/app.py b/selfprivacy_api/app.py index 77281e8..15142f0 100644 --- a/selfprivacy_api/app.py +++ b/selfprivacy_api/app.py @@ -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: diff --git a/tests/test_graphql/test_ssh.py b/tests/test_graphql/test_ssh.py index 0c69463..be795e1 100644 --- a/tests/test_graphql/test_ssh.py +++ b/tests/test_graphql/test_ssh.py @@ -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 + diff --git a/tests/test_graphql/test_ssh/some_users.json b/tests/test_graphql/test_ssh/some_users.json new file mode 100644 index 0000000..569253a --- /dev/null +++ b/tests/test_graphql/test_ssh/some_users.json @@ -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" + } + ] +} \ No newline at end of file