Skip to content

Commit 346d215

Browse files
committed
fix: add test for interop request
1 parent 696acef commit 346d215

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ def session_env_config( # pylint: disable=R0915,R0914
110110
"uri": "https://nonexistent.localmaeher.dev.pvarki.fi:844/", # Not actually there
111111
"certcn": "nonexistent.localmaeher.dev.pvarki.fi",
112112
},
113+
"interoptest": {
114+
"api": "https://localhost:4657/",
115+
"uri": "https://interoptest.localmaeher.dev.pvarki.fi:844/", # Not actually there
116+
"certcn": "interoptest.localmaeher.dev.pvarki.fi",
117+
},
113118
},
114119
}
115120
)

tests/test_interop.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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

Comments
 (0)