Skip to content

Commit 1ee4f6b

Browse files
[ERSSUP-89806]-[]-[Added IT for user attempting to use app-restricted business functions]-[JW]
1 parent 5459598 commit 1ee4f6b

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

tests/integration/test_headers.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,43 @@ async def test_headers_on_echo_target(
7373
expected_amr,
7474
)
7575

76+
@pytest.mark.asyncio
77+
@pytest.mark.parametrize(
78+
"business_function",
79+
["PROVIDER_AUTHORISED_APPLICATION", "REFERRER_AUTHORISED_APPLICATION"],
80+
)
81+
async def test_headers_on_echo_target_with_app_restricted_business_function(
82+
self, business_function, authenticate_user, service_url
83+
):
84+
user = Actor.RC
85+
access_code = await authenticate_user(user)
86+
client_request_headers = {
87+
_HEADER_ECHO: "", # enable echo target
88+
_HEADER_AUTHORIZATION: "Bearer " + access_code,
89+
_HEADER_REQUEST_ID: "DUMMY-VALUE",
90+
RenamedHeader.REFERRAL_ID.original: _EXPECTED_REFERRAL_ID,
91+
RenamedHeader.CORRELATION_ID.original: _EXPECTED_CORRELATION_ID,
92+
RenamedHeader.BUSINESS_FUNCTION.original: business_function,
93+
RenamedHeader.ODS_CODE.original: user.org_code,
94+
RenamedHeader.FILENAME.original: _EXPECTED_FILENAME,
95+
RenamedHeader.COMM_RULE_ORG.original: _EXPECTED_COMM_RULE_ORG,
96+
RenamedHeader.OBO_USER_ID.original: _EXPECTED_OBO_USER_ID,
97+
}
98+
99+
# Make the API call
100+
response = requests.get(service_url, headers=client_request_headers)
101+
102+
assert response.status_code == 403, (
103+
"Expected a 403 response when attempting to call the endpoint, but instead received a "
104+
+ str(response.status_code)
105+
)
106+
107+
response_body = response.text()
108+
assert response_body == "Forbidden", (
109+
"Expected the text 'Forbidden' to be returned in the body of the response when attempting to call the endpoint, but instead received "
110+
+ response_body
111+
)
112+
76113
@pytest.mark.asyncio
77114
@pytest.mark.parametrize(
78115
"endpoint_url,is_r4",
@@ -475,7 +512,7 @@ def test_unknown_access_code(
475512
assert renamed_header.renamed not in client_response_headers
476513

477514
@pytest.mark.asyncio
478-
@pytest.mark.parametrize("service_name", [(None)])
515+
@pytest.mark.parametrize("service_name", [None])
479516
async def test_access_code_not_supported(
480517
self, referring_clinician, authenticate_user, service_url
481518
):

0 commit comments

Comments
 (0)