Skip to content

Commit c99fc2c

Browse files
tests
1 parent aef9500 commit c99fc2c

File tree

5 files changed

+57
-35
lines changed

5 files changed

+57
-35
lines changed

tests/e2e-tests/endpoint_tests.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
import pytest
3+
import requests
4+
5+
def _get(url, headers=None, timeout=10):
6+
return requests.get(url, headers=headers or {}, timeout=timeout)
7+
8+
@pytest.mark.smoketest
9+
def test_ping(nhsd_apim_proxy_url):
10+
resp = requests.get(nhsd_apim_proxy_url + "/_ping")
11+
assert resp.status_code == 200
12+
print("Ping Response Body:", resp.text)
13+
14+
@pytest.mark.smoketest
15+
def test_401_status_without_api_key(nhsd_apim_proxy_url):
16+
resp = requests.get(
17+
f"{nhsd_apim_proxy_url}/_status"
18+
)
19+
assert resp.status_code == 401
20+
21+
@pytest.mark.smoketest
22+
@pytest.mark.nhsd_apim_authorization(access="application", level="level3")
23+
def test_invalid_jwt_rejected(nhsd_apim_proxy_url, nhsd_apim_auth_headers):
24+
"""
25+
Best-effort: if gateway validates JWTs, an invalid token should be rejected.
26+
If JWT not used in this env, test is skipped.
27+
"""
28+
headers = {
29+
**nhsd_apim_auth_headers,
30+
"headerauth1": "headervalue1",
31+
"x-request-id": "123456"
32+
}
33+
print(headers)
34+
# If no Authorization configured in project headers, skip
35+
if "Authorization" not in headers:
36+
pytest.skip("JWT auth not configured for this environment")
37+
38+
bad_headers = dict(headers)
39+
bad_headers["Authorization"] = "Bearer invalid.invalid.invalid"
40+
status = _get(f"{nhsd_apim_proxy_url}/_status", headers=bad_headers).status_code
41+
assert status in (401, 403), "Expected gateway to reject invalid JWT"

tests/e2e-tests/get_letters_tests.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11

22
import pytest
33
import requests
4-
import json
5-
import time
6-
from lib import Generators
4+
from lib import generators as Generators
75

86
from pytest_nhsd_apim.apigee_apis import (
97
DeveloperAppsAPI,
@@ -60,24 +58,3 @@ def test_app_level0_access_post(nhsd_apim_proxy_url, nhsd_apim_auth_headers, _cr
6058
json = data
6159
)
6260
assert resp.status_code == 200
63-
64-
65-
66-
@pytest.mark.nhsd_apim_authorization(access="application", level="level3")
67-
def test_ping(nhsd_apim_proxy_url):
68-
resp = requests.get(nhsd_apim_proxy_url + "/_ping")
69-
70-
print("\nCalled:\n" + nhsd_apim_proxy_url + "/_ping" )
71-
print("\nResponse status code: ", resp.status_code)
72-
73-
assert resp.status_code == 200
74-
75-
@pytest.mark.nhsd_apim_authorization(access="application", level="level3")
76-
def test_401_status_without_api_key(nhsd_apim_proxy_url):
77-
resp = requests.get(
78-
f"{nhsd_apim_proxy_url}/_status"
79-
)
80-
81-
error_handler.handle_retry(resp)
82-
83-
assert resp.status_code == 401

tests/e2e-tests/lib/generators.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
2-
class Generators():
3-
@staticmethod
1+
class Generators:
2+
@staticmethod
43
def generate_valid_create_message_body(environment="sandbox"):
54
return {
6-
{
7-
"data": {
8-
"attributes": {
5+
"data": {
6+
"attributes": {
97
"status": "PENDING"
10-
},
11-
"id": "2WL5eYSWGzCHlGmzNxuqVusPxDg",
12-
"type": "Letter"
13-
}
8+
},
9+
"id": "2WL5eYSWGzCHlGmzNxuqVusPxDg",
10+
"type": "Letter"
1411
}
1512
}

tests/e2e-tests/poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/e2e-tests/pytest.ini

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[pytest]
2+
python_files = *_tests.py
3+
norecursedirs = .venv .eggs build dist utils
4+
addopts = --strict-markers
5+
markers =
6+
e2e: end to end tests
7+
smoketest: suitable to run against all environments even production

0 commit comments

Comments
 (0)