Skip to content

Commit d95ae72

Browse files
[ERSSUP-74395]-[DW]-[Add support for referrer app restricted calls]-[AST]
1 parent ecc449d commit d95ae72

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

proxies/live/apiproxy/policies/AssignMessage.Set.nhsd-ers-business-function-header-app-restricted.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
<AssignMessage async="false" continueOnError="false" enabled="true" name="AssignMessage.Set.nhsd-ers-business-function-header-app-restricted">
2+
<AssignVariable>
3+
<Name>business-function-header-value</Name>
4+
<Ref>app.app-restricted-business-function</Ref>
5+
<Value>PROVIDER_AUTHORISED_APPLICATION</Value>
6+
<!-- default value in case variable above is not defined -->
7+
</AssignVariable>
28
<Set>
39
<Headers>
4-
<Header name="x-ers-business-function">AUTHORISED_APPLICATION</Header>
10+
<Header name="x-ers-business-function">{business-function-header-value}</Header>
511
</Headers>
612
</Set>
713
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>

tests/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ def app_restricted_user_id(is_mocked_environment):
101101
return "000000000101" if is_mocked_environment else "555032000100"
102102

103103

104+
@pytest.fixture(
105+
scope="session",
106+
params=["PROVIDER_AUTHORISED_APPLICATION", "REFERRER_AUTHORISED_APPLICATION"],
107+
)
108+
def app_restricted_business_function(request):
109+
return request.param
110+
111+
104112
@pytest.fixture()
105113
def client():
106114
config = ApigeeNonProdCredentials()
@@ -252,6 +260,7 @@ async def app_restricted_app(
252260
asid,
253261
app_restricted_ods_code,
254262
app_restricted_user_id,
263+
app_restricted_business_function,
255264
):
256265
# Setup
257266
app = await make_app(
@@ -260,6 +269,7 @@ async def app_restricted_app(
260269
"asid": asid,
261270
"app-restricted-ods-code": app_restricted_ods_code,
262271
"app-restricted-user-id": app_restricted_user_id,
272+
"app-restricted-business-function": app_restricted_business_function,
263273
"jwks-resource-url": jwt_public_key_url,
264274
},
265275
)

tests/integration/test_app_restricted.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
_EXPECTED_CORRELATION_ID = "123123-123123-123123-123123"
1616

1717
_SPECIALTY_REF_DATA_URL = "/FHIR/STU3/CodeSystem/SPECIALTY"
18-
_AUTHORISED_APPLICATION = "AUTHORISED_APPLICATION"
18+
_PROVIDER_AUTHORISED_APPLICATION = "PROVIDER_AUTHORISED_APPLICATION"
19+
_REFERRER_AUTHORISED_APPLICATION = "REFERRER_AUTHORISED_APPLICATION"
1920
_EXPECTED_ACCESS_MODE = "application-restricted"
2021

2122

@@ -27,11 +28,11 @@ async def test_authorised_application_not_supported_for_user_restricted(
2728
):
2829
access_code = await authenticate_user(referring_clinician)
2930

30-
# attempt to use AUTHORISED_APPLICATION with an RC
31+
# attempt to use REFERRER_AUTHORISED_APPLICATION with an RC
3132
client_request_headers = {
3233
_HEADER_AUTHORIZATION: "Bearer " + access_code,
3334
RenamedHeader.CORRELATION_ID.original: _EXPECTED_CORRELATION_ID,
34-
RenamedHeader.BUSINESS_FUNCTION.original: _AUTHORISED_APPLICATION,
35+
RenamedHeader.BUSINESS_FUNCTION.original: _REFERRER_AUTHORISED_APPLICATION,
3536
RenamedHeader.ODS_CODE.original: referring_clinician.org_code,
3637
_HEADER_REQUEST_ID: "DUMMY", # this must be less than 10 characters
3738
}
@@ -63,7 +64,8 @@ def test_authorised_application_supported_for_app_restricted(
6364
"header,value",
6465
[
6566
(RenamedHeader.ODS_CODE.renamed, "ABC"),
66-
(RenamedHeader.BUSINESS_FUNCTION.renamed, _AUTHORISED_APPLICATION),
67+
(RenamedHeader.BUSINESS_FUNCTION.renamed, _PROVIDER_AUTHORISED_APPLICATION),
68+
(RenamedHeader.BUSINESS_FUNCTION.renamed, _REFERRER_AUTHORISED_APPLICATION),
6769
(_HEADER_USER_ID, "1"),
6870
],
6971
)
@@ -91,6 +93,7 @@ def test_headers_on_echo_target(
9193
asid,
9294
app_restricted_ods_code,
9395
app_restricted_user_id,
96+
app_restricted_business_function,
9497
):
9598
client_request_headers = {
9699
_HEADER_ECHO: "", # enable echo target
@@ -102,7 +105,12 @@ def test_headers_on_echo_target(
102105
# Make the API call
103106
response = requests.get(service_url, headers=client_request_headers)
104107
self.assert_ok_echo_response(
105-
response, service_url, asid, app_restricted_ods_code, app_restricted_user_id
108+
response,
109+
service_url,
110+
asid,
111+
app_restricted_ods_code,
112+
app_restricted_user_id,
113+
app_restricted_business_function,
106114
)
107115

108116
def assert_ok_echo_response(
@@ -112,6 +120,7 @@ def assert_ok_echo_response(
112120
asid,
113121
app_restricted_ods_code,
114122
app_restricted_user_id,
123+
app_restricted_business_function,
115124
):
116125
assert (
117126
response.status_code == 200
@@ -180,7 +189,7 @@ def assert_ok_echo_response(
180189
)
181190
assert (
182191
target_request_headers[RenamedHeader.BUSINESS_FUNCTION.renamed]
183-
== _AUTHORISED_APPLICATION
192+
== app_restricted_business_function
184193
)
185194
assert (
186195
target_request_headers[RenamedHeader.ODS_CODE.renamed]
@@ -198,6 +207,7 @@ def test_access_mode_header_overwritten_on_echo_target(
198207
asid,
199208
app_restricted_ods_code,
200209
app_restricted_user_id,
210+
app_restricted_business_function,
201211
):
202212
client_request_headers = {
203213
_HEADER_ECHO: "", # enable echo target
@@ -210,5 +220,10 @@ def test_access_mode_header_overwritten_on_echo_target(
210220
# Make the API call
211221
response = requests.get(service_url, headers=client_request_headers)
212222
self.assert_ok_echo_response(
213-
response, service_url, asid, app_restricted_ods_code, app_restricted_user_id
223+
response,
224+
service_url,
225+
asid,
226+
app_restricted_ods_code,
227+
app_restricted_user_id,
228+
app_restricted_business_function,
214229
)

0 commit comments

Comments
 (0)