Update tests
This commit is contained in:
@ -2,10 +2,13 @@
|
||||
|
||||
from collections.abc import AsyncIterator
|
||||
from contextlib import asynccontextmanager
|
||||
import allure
|
||||
import pytest
|
||||
|
||||
import httpx
|
||||
|
||||
from allure_commons.types import Severity
|
||||
|
||||
from sshecret.backend import Client
|
||||
|
||||
from sshecret.crypto import generate_private_key, generate_public_key_string
|
||||
@ -70,9 +73,12 @@ class BaseAdminTests:
|
||||
return client
|
||||
|
||||
|
||||
@allure.title("Admin API")
|
||||
class TestAdminAPI(BaseAdminTests):
|
||||
"""Tests of the Admin REST API."""
|
||||
|
||||
@allure.title("Test health test endpoint")
|
||||
@allure.severity(Severity.TRIVIAL)
|
||||
@pytest.mark.asyncio
|
||||
async def test_health_check(
|
||||
self, admin_server: tuple[str, tuple[str, str]]
|
||||
@ -82,6 +88,8 @@ class TestAdminAPI(BaseAdminTests):
|
||||
resp = await client.get("/health")
|
||||
assert resp.status_code == 200
|
||||
|
||||
@allure.title("Test login over API")
|
||||
@allure.severity(Severity.BLOCKER)
|
||||
@pytest.mark.asyncio
|
||||
async def test_admin_login(self, admin_server: AdminServer) -> None:
|
||||
"""Test admin login."""
|
||||
@ -95,9 +103,12 @@ class TestAdminAPI(BaseAdminTests):
|
||||
assert resp.status_code == 200
|
||||
|
||||
|
||||
@allure.title("Admin API Client API")
|
||||
class TestAdminApiClients(BaseAdminTests):
|
||||
"""Test client routes."""
|
||||
|
||||
@allure.title("Test creating a client")
|
||||
@allure.description("Ensure we can create a new client.")
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_client(self, admin_server: AdminServer) -> None:
|
||||
"""Test create_client."""
|
||||
@ -106,6 +117,8 @@ class TestAdminApiClients(BaseAdminTests):
|
||||
assert client.id is not None
|
||||
assert client.name == "testclient"
|
||||
|
||||
@allure.title("Test reading clients")
|
||||
@allure.description("Ensure we can retrieve a list of current clients.")
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_clients(self, admin_server: AdminServer) -> None:
|
||||
"""Test get_clients."""
|
||||
@ -124,6 +137,8 @@ class TestAdminApiClients(BaseAdminTests):
|
||||
client_name = entry.get("name")
|
||||
assert client_name in client_names
|
||||
|
||||
@allure.title("Test client deletion")
|
||||
@allure.description("Ensure we can delete a client.")
|
||||
@pytest.mark.asyncio
|
||||
async def test_delete_client(self, admin_server: AdminServer) -> None:
|
||||
"""Test delete_client."""
|
||||
@ -146,9 +161,12 @@ class TestAdminApiClients(BaseAdminTests):
|
||||
assert len(data) == 0
|
||||
|
||||
|
||||
@allure.title("Test secret management")
|
||||
class TestAdminApiSecrets(BaseAdminTests):
|
||||
"""Test secret management."""
|
||||
|
||||
@allure.title("Test adding a secret")
|
||||
@allure.description("Ensure that we can add a secret to a client.")
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_secret(self, admin_server: AdminServer) -> None:
|
||||
"""Test add_secret."""
|
||||
@ -162,6 +180,8 @@ class TestAdminApiSecrets(BaseAdminTests):
|
||||
resp = await http_client.post("api/v1/secrets/", json=data)
|
||||
assert resp.status_code == 200
|
||||
|
||||
@allure.title("Test read a secret")
|
||||
@allure.description("Ensure that we can retrieve a secret we have stored.")
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_secret(self, admin_server: AdminServer) -> None:
|
||||
"""Test get_secret."""
|
||||
@ -175,6 +195,8 @@ class TestAdminApiSecrets(BaseAdminTests):
|
||||
assert data["secret"] == "secretstring"
|
||||
assert "testclient" in data["clients"]
|
||||
|
||||
@allure.title("Test adding a secret with automatic value")
|
||||
@allure.description("Test that we can add a secret where we let the system come up with the value of a given length.")
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_secret_auto(self, admin_server: AdminServer) -> None:
|
||||
"""Test adding a secret with an auto-generated value."""
|
||||
@ -195,6 +217,8 @@ class TestAdminApiSecrets(BaseAdminTests):
|
||||
assert len(data["secret"]) == 17
|
||||
assert "testclient" in data["clients"]
|
||||
|
||||
@allure.title("Test updating a secret")
|
||||
@allure.description("Test that we can update the value of a stored secret.")
|
||||
@pytest.mark.asyncio
|
||||
async def test_update_secret(self, admin_server: AdminServer) -> None:
|
||||
"""Test updating secrets."""
|
||||
|
||||
Reference in New Issue
Block a user