Skip to content

Commit 0c70552

Browse files
try to fix redirection url
1 parent e98a3ba commit 0c70552

File tree

7 files changed

+71
-14
lines changed

7 files changed

+71
-14
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<AssignMessage async="false" continueOnError="false" enabled="true" name="AssignMessage.AddBaseUrlHeader">
2+
<Set>
3+
<Headers>
4+
<Header name="x-ers-sandbox-baseurl">https://{request.header.Host}/{proxy.basepath}</Header>
5+
</Headers>
6+
</Set>
7+
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
8+
<AssignTo createNew="false"/>
9+
</AssignMessage>

proxies/sandbox/apiproxy/targets/sandbox.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
<Response/>
88
</PostFlow>
99
<PreFlow name="PreFlow">
10-
<Request/>
11-
<Response></Response>
10+
<Request>
11+
<Step>
12+
<Name>AssignMessage.AddBaseUrlHeader</Name>
13+
</Step>
14+
</Request>
15+
<Response/>
1216
</PreFlow>
1317
<HTTPTargetConnection>{{ HOSTED_TARGET_CONNECTION }}</HTTPTargetConnection>
1418
</TargetEndpoint>

sandbox/src/app.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ const addCommonHeaders = function (request, response) {
1010
response.headers = {}
1111
}
1212

13-
if (request.headers["x-correlation-id"]) {
14-
response.headers["X-Correlation-ID"] = request.headers["x-correlation-id"]
13+
if (!request.path.includes("ObjectStore")) {
14+
if (request.headers["x-correlation-id"]) {
15+
response.headers["X-Correlation-ID"] = request.headers["x-correlation-id"]
16+
}
17+
response.headers["X-Request-ID"] = '58621d65-d5ad-4c3a-959f-0438e355990e-1'
1518
}
16-
response.headers["X-Request-ID"] = '58621d65-d5ad-4c3a-959f-0438e355990e-1'
1719
}
1820

1921
const preResponse = function (request, h) {

sandbox/src/routes/r4/retrieveAttachment.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@ module.exports = [
1111
handler: (request, h) => {
1212

1313
const allowedBusinessFunctions = ["REFERRING_CLINICIAN", "REFERRING_CLINICIAN_ADMIN", "SERVICE_PROVIDER_CLINICIAN", "SERVICE_PROVIDER_CLINICIAN_ADMIN"];
14-
14+
1515
const validationResult = businessFunctionValidator.validateBusinessFunction(request, h, allowedBusinessFunctions);
1616
if (validationResult) {
1717
return validationResult;
1818
}
1919

2020
const binaryId = request.params.binaryId;
21-
const url = request.url.href;
2221
const objectStore = "/ObjectStore/d497bbe3-f88b-45f1-b3d4-9c563e4c0f5f";
23-
const location = url.split('/FHIR')[0] + objectStore;
22+
const location = request.headers['x-ers-sandbox-baseurl'] + objectStore;
2423

2524
if ((validationUtil.hasLegacyPrefix(binaryId) || validationUtil.isValidUuid(binaryId)) && request.method === 'get') {
2625
const response = h.response().code(307);
@@ -29,7 +28,6 @@ module.exports = [
2928
} else {
3029
return h.file('r4/R4-SandboxErrorOutcome.json').code(400);
3130
}
32-
3331
}
3432
}
3533
]

tests/sandbox/SandboxTest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pytest
88
from tests import asserts
99

10-
from tests.data import Actor, RenamedHeader, UserAuthenticationLevel
10+
from tests.data import Actor, RenamedHeader
1111
from .utils import HttpMethod
1212

1313

tests/sandbox/r4/test_a042_get_attachment.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,15 @@ def test_success(
6161
actor: Actor,
6262
id: str,
6363
sandbox_url: str,
64+
environment: str,
6465
):
65-
actual_response = call_endpoint_url_with_pathParams(actor, {"binaryId": id})
66+
request_headers = (
67+
{"x-ers-sandbox-baseurl": sandbox_url} if environment == "local" else {}
68+
)
69+
70+
actual_response = call_endpoint_url_with_pathParams(
71+
actor, {"binaryId": id}, request_headers
72+
)
6673

6774
asserts.assert_status_code(307, actual_response.status_code)
6875

tests/sandbox/r4/test_a042_get_attachment_follow_redirection.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
from requests import Response
77
from tests.sandbox.SandboxTest import SandboxTest
8-
from tests.data import Actor
8+
from tests.data import Actor, RenamedHeader
99
from tests.sandbox.utils import HttpMethod
10+
from pytest_check import check
1011

1112

1213
@pytest.mark.sandbox
@@ -65,9 +66,15 @@ def test_success(
6566
],
6667
actor: Actor,
6768
id: str,
69+
sandbox_url: str,
70+
environment: str,
6871
):
72+
request_headers = (
73+
{"x-ers-sandbox-baseurl": sandbox_url} if environment == "local" else {}
74+
)
75+
6976
actual_response = call_endpoint_url_with_pathParams(
70-
actor, {"binaryId": id}, allow_redirects=True
77+
actor, {"binaryId": id}, request_headers, allow_redirects=True
7178
)
7279

7380
asserts.assert_status_code(200, actual_response.status_code)
@@ -76,7 +83,6 @@ def test_success(
7683
"content-disposition": """attachment; filename="=?UTF-8?Q?The_filenam=C3=A9.pdf?="; filename*=UTF-8''The%20filenam%C3%A9.pdf""",
7784
"content-type": "application/pdf",
7885
"content-length": "23681",
79-
"x-request-id": "58621d65-d5ad-4c3a-959f-0438e355990e-1",
8086
"vary": "origin",
8187
"access-control-expose-headers": "x-correlation-id,x-request-id,content-type,Location,ETag,Content-Disposition,Content-Length,Cache-Control",
8288
"cache-control": "no-cache",
@@ -90,3 +96,34 @@ def test_success(
9096
assert_content_length=True,
9197
assert_ignored_headers=False,
9298
)
99+
100+
def test_with_correlation_id(
101+
self,
102+
call_endpoint: Callable[[Actor], Response],
103+
authorised_actors: Iterable[Actor],
104+
default_headers: Dict[str, str],
105+
sandbox_url: str,
106+
environment: str,
107+
):
108+
"""
109+
Overrides parent test. It's expected that following the redirection will result in a response from the object store without a correlation id.
110+
"""
111+
request_headers = {RenamedHeader.CORRELATION_ID.original: "test"}
112+
113+
if environment == "local":
114+
request_headers["x-ers-sandbox-baseurl"] = sandbox_url
115+
116+
response = call_endpoint(
117+
authorised_actors[0],
118+
headers=request_headers,
119+
)
120+
121+
# Check that the response completed successfully.
122+
assert (
123+
response.status_code // 200 == 1
124+
), "Supplied request did not complete successfully."
125+
126+
with check:
127+
assert (
128+
RenamedHeader.CORRELATION_ID.original not in response.headers
129+
), "Object store expected not to return a correlation id."

0 commit comments

Comments
 (0)