Skip to content

Commit 1f5c4fd

Browse files
committed
Re-enable end-to-end tests, sourcing status endpoint from github secret, rather than fetching from APIM
1 parent 57e7208 commit 1f5c4fd

5 files changed

Lines changed: 41 additions & 13 deletions

File tree

.github/actions/e2e-tests/action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ runs:
1919
export PROXY_NAME=nhs-notify-supplier--internal-dev--nhs-notify-supplier
2020
export API_ENVIRONMENT=internal-dev
2121
export NON_PROD_PRIVATE_KEY="${GITHUB_WORKSPACE}/internal-dev-test-1.pem"
22+
export STATUS_ENDPOINT_API_KEY="${STATUS_ENDPOINT_API_KEY}"
2223
make .internal-dev-test

.github/workflows/stage-4-acceptance.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,10 @@ jobs:
9090
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
9191

9292
- name: "Run e2e tests"
93-
#uses: ./.github/actions/e2e-tests
93+
uses: ./.github/actions/e2e-tests
9494
env:
9595
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9696
NON_PROD_API_KEY: ${{ secrets.NON_PROD_API_KEY }}
9797
INTERNAL_DEV_TEST_PEM: ${{ secrets.INTERNAL_DEV_TEST_PEM }}
98+
STATUS_ENDPOINT_API_KEY: ${{ secrets.STATUS_ENDPOINT_API_KEY }}
9899
shell: bash
99-
run: |
100-
echo "E2E tests are currently disabled. See CCM-14778"

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ ${VERBOSE}.SILENT: \
131131
#####################
132132

133133
TEST_CMD := APIGEE_ACCESS_TOKEN="$(APIGEE_ACCESS_TOKEN)" \
134+
STATUS_ENDPOINT_API_KEY="$(STATUS_ENDPOINT_API_KEY)" \
134135
PYTHONPATH=. poetry run pytest --disable-warnings -vv \
135136
--color=yes \
136137
-n 4 \

tests/e2e-tests/api/test_endpoint.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
import pytest
22
import requests
3-
from os import getenv
43
from lib.errorhandler import ErrorHandler
5-
6-
def _get(url, headers=None, timeout=10):
7-
return requests.get(url, headers=headers or {}, timeout=timeout)
4+
from lib.fixtures import * # NOSONAR
85

96
@pytest.mark.smoketest
10-
def test_ping(nhsd_apim_proxy_url):
11-
resp = requests.get(nhsd_apim_proxy_url + "/_ping")
7+
def test_ping(url):
8+
resp = requests.get(url + "/_ping")
129
assert resp.status_code == 200
1310

1411
@pytest.mark.smoketest
1512
@pytest.mark.sandboxtest
1613
@pytest.mark.devtest
17-
def test_status(nhsd_apim_proxy_url, status_endpoint_auth_headers):
14+
def test_status(url, status_endpoint_api_key):
1815
resp = requests.get(
19-
f"{nhsd_apim_proxy_url}/_status", headers=status_endpoint_auth_headers
16+
f"{url}/_status", headers={"apikey": status_endpoint_api_key}
2017
)
2118

2219
ErrorHandler.handle_retry(resp)
@@ -25,9 +22,9 @@ def test_status(nhsd_apim_proxy_url, status_endpoint_auth_headers):
2522
@pytest.mark.smoketest
2623
@pytest.mark.sandboxtest
2724
@pytest.mark.devtest
28-
def test_401_status_without_api_key(nhsd_apim_proxy_url):
25+
def test_401_status_without_api_key(url):
2926
resp = requests.get(
30-
f"{nhsd_apim_proxy_url}/_status"
27+
f"{url}/_status"
3128
)
3229

3330
ErrorHandler.handle_retry(resp)

tests/e2e-tests/lib/fixtures.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,33 @@ def bearer_token(authentication_cache):
6262
else:
6363
url = f"https://{environment}.api.service.nhs.uk/nhs-notify-supplier"
6464
return authentication_cache.generate_authentication(environment, url)
65+
66+
@pytest.fixture(scope='session')
67+
def status_endpoint_api_key():
68+
"""
69+
Fetch the API key used to authenticate against the /_status endpoint.
70+
Checks STATUS_ENDPOINT_API_KEY env var first, then falls back to
71+
retrieving it from the mock-jwks proxy using NON_PROD_API_KEY.
72+
"""
73+
import requests
74+
75+
key = os.environ.get("STATUS_ENDPOINT_API_KEY", "")
76+
if key:
77+
return key
78+
79+
environment = os.environ["API_ENVIRONMENT"]
80+
non_prod_api_key = os.environ["NON_PROD_API_KEY"]
81+
82+
if environment == "prod":
83+
mock_jwks_base = "https://api.service.nhs.uk"
84+
elif environment == "ref":
85+
mock_jwks_base = "https://internal-dev.api.service.nhs.uk"
86+
else:
87+
mock_jwks_base = f"https://{environment}.api.service.nhs.uk"
88+
89+
resp = requests.get(
90+
f"{mock_jwks_base}/mock-jwks/status-endpoint-api-key",
91+
headers={"apikey": non_prod_api_key},
92+
)
93+
resp.raise_for_status()
94+
return resp.text

0 commit comments

Comments
 (0)