|
| 1 | +"""Test the interop route""" |
| 2 | + |
| 3 | +import logging |
| 4 | + |
| 5 | +import pytest |
| 6 | +from async_asgi_testclient import TestClient |
| 7 | + |
| 8 | +from rasenmaeher_api.web.api.product.schema import ProductAddRequest |
| 9 | + |
| 10 | +LOGGER = logging.getLogger(__name__) |
| 11 | + |
| 12 | + |
| 13 | +@pytest.mark.asyncio |
| 14 | +async def test_valid_products(ginosession: None, unauth_client: TestClient) -> None: |
| 15 | + """Test requesting interop with product 'fake'""" |
| 16 | + _ = ginosession |
| 17 | + client = unauth_client |
| 18 | + client.headers.update({"X-ClientCert-DN": "CN=interoptest.localmaeher.dev.pvarki.fi,O=N/A"}) |
| 19 | + req = ProductAddRequest( |
| 20 | + certcn="interoptest.localmaeher.dev.pvarki.fi", |
| 21 | + x509cert="-----BEGIN CERTIFICATE-----\\nMIIEwjCC...\\n-----END CERTIFICATE-----\\n", |
| 22 | + ) |
| 23 | + payload = req.dict() |
| 24 | + resp = await client.post("/api/v1/product/interop/fake", json=payload) |
| 25 | + assert resp.status_code == 200 |
| 26 | + |
| 27 | + |
| 28 | +@pytest.mark.asyncio |
| 29 | +async def test_invalid_requester(ginosession: None, unauth_client: TestClient) -> None: |
| 30 | + """Test requesting interop with product 'fake' with product that is not valid""" |
| 31 | + _ = ginosession |
| 32 | + client = unauth_client |
| 33 | + client.headers.update({"X-ClientCert-DN": "CN=callsigndude,O=N/A"}) |
| 34 | + req = ProductAddRequest( |
| 35 | + certcn="callsigndude", |
| 36 | + x509cert="-----BEGIN CERTIFICATE-----\\nMIIEwjCC...\\n-----END CERTIFICATE-----\\n", |
| 37 | + ) |
| 38 | + payload = req.dict() |
| 39 | + resp = await client.post("/api/v1/product/interop/fake", json=payload) |
| 40 | + assert resp.status_code == 403 |
| 41 | + |
| 42 | + |
| 43 | +@pytest.mark.asyncio |
| 44 | +async def test_invalid_tgt(ginosession: None, unauth_client: TestClient) -> None: |
| 45 | + """Test requesting interop with product 'nosuch'""" |
| 46 | + _ = ginosession |
| 47 | + client = unauth_client |
| 48 | + client.headers.update({"X-ClientCert-DN": "CN=interoptest.localmaeher.dev.pvarki.fi,O=N/A"}) |
| 49 | + req = ProductAddRequest( |
| 50 | + certcn="interoptest.localmaeher.dev.pvarki.fi", |
| 51 | + x509cert="-----BEGIN CERTIFICATE-----\\nMIIEwjCC...\\n-----END CERTIFICATE-----\\n", |
| 52 | + ) |
| 53 | + payload = req.dict() |
| 54 | + resp = await client.post("/api/v1/product/interop/nosuch", json=payload) |
| 55 | + assert resp.status_code == 404 |
0 commit comments