Skip to content

Commit a00c6e2

Browse files
[WIP] Pass X-Forwarded headers and remove post-processing logic (#623)
Pass X-Forwarded headers and remove post-processing logic BLUEBUTTON-132 BLUEBUTTON-133
1 parent 57ca9b0 commit a00c6e2

File tree

6 files changed

+31
-25
lines changed

6 files changed

+31
-25
lines changed

apps/fhir/bluebutton/serializers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def localize(request=None,
1010
resource_type=None):
1111

1212
rewrite_list = build_rewrite_list(crosswalk)
13+
1314
host_path = get_host_url(request, resource_type)[:-1]
1415

1516
text_in = get_response_text(fhir_response=response)

apps/fhir/bluebutton/tests/test_read.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def test_search_request(self):
182182
expected_request = {
183183
'method': 'GET',
184184
'url': ("https://fhir.backend.bluebutton.hhsdevcloud.us/"
185-
"baseDstu3/Patient/?_format=application%2Fjson%2Bfhir&_id=20140000008325"),
185+
"v1/fhir/Patient/?_format=application%2Fjson%2Bfhir&_id=20140000008325"),
186186
'headers': {
187187
'User-Agent': 'python-requests/2.18.4',
188188
'Accept-Encoding': 'gzip, deflate',
@@ -194,7 +194,7 @@ def test_search_request(self):
194194
'BlueButton-OriginatingIpAddress': '127.0.0.1',
195195
'keep-alive': 'timeout=120, max=10',
196196
'BlueButton-OriginalUrl': '/v1/fhir/Patient',
197-
'BlueButton-BackendCall': 'https://fhir.backend.bluebutton.hhsdevcloud.us/baseDstu3/Patient/',
197+
'BlueButton-BackendCall': 'https://fhir.backend.bluebutton.hhsdevcloud.us/v1/fhir/Patient/',
198198
}
199199
}
200200

@@ -252,7 +252,7 @@ def test_search_request(self):
252252

253253
@all_requests
254254
def catchall(url, req):
255-
self.assertIn("https://fhir.backend.bluebutton.hhsdevcloud.us/baseDstu3/Patient/", req.url)
255+
self.assertIn("https://fhir.backend.bluebutton.hhsdevcloud.us/v1/fhir/Patient/", req.url)
256256
self.assertIn("_format=application%2Fjson%2Bfhir", req.url)
257257
self.assertIn("_id=20140000008325", req.url)
258258
self.assertEqual(expected_request['method'], req.method)
@@ -291,7 +291,7 @@ def test_search_request_not_found(self):
291291
expected_request = {
292292
'method': 'GET',
293293
'url': ("https://fhir.backend.bluebutton.hhsdevcloud.us/"
294-
"baseDstu3/Patient/?_format=application%2Fjson%2Bfhir&_id=20140000008325"),
294+
"v1/fhir/Patient/?_format=application%2Fjson%2Bfhir&_id=20140000008325"),
295295
'headers': {
296296
'User-Agent': 'python-requests/2.18.4',
297297
'Accept-Encoding': 'gzip, deflate',
@@ -303,13 +303,13 @@ def test_search_request_not_found(self):
303303
'BlueButton-OriginatingIpAddress': '127.0.0.1',
304304
'keep-alive': 'timeout=120, max=10',
305305
'BlueButton-OriginalUrl': '/v1/fhir/Patient',
306-
'BlueButton-BackendCall': 'https://fhir.backend.bluebutton.hhsdevcloud.us/baseDstu3/Patient/',
306+
'BlueButton-BackendCall': 'https://fhir.backend.bluebutton.hhsdevcloud.us/v1/fhir/Patient/',
307307
}
308308
}
309309

310310
@all_requests
311311
def catchall(url, req):
312-
self.assertIn("https://fhir.backend.bluebutton.hhsdevcloud.us/baseDstu3/Patient/", req.url)
312+
self.assertIn("https://fhir.backend.bluebutton.hhsdevcloud.us/v1/fhir/Patient/", req.url)
313313
self.assertIn("_format=application%2Fjson%2Bfhir", req.url)
314314
self.assertIn("_id=20140000008325", req.url)
315315
self.assertEqual(expected_request['method'], req.method)
@@ -348,7 +348,7 @@ def catchall(url, req):
348348
"link": [
349349
{
350350
"relation": "self",
351-
"url": "http://hapi.fhir.org/baseDstu3/ExplanationOfBenefit?_pretty=true&patient=1234"
351+
"url": "http://hapi.fhir.org/v1/fhir/ExplanationOfBenefit?_pretty=true&patient=1234"
352352
},
353353
],
354354
},
@@ -370,7 +370,7 @@ def test_search_request_failed(self):
370370
expected_request = {
371371
'method': 'GET',
372372
'url': ("https://fhir.backend.bluebutton.hhsdevcloud.us/"
373-
"baseDstu3/Patient/?_format=application%2Fjson%2Bfhir&_id=20140000008325"),
373+
"v1/fhir/Patient/?_format=application%2Fjson%2Bfhir&_id=20140000008325"),
374374
'headers': {
375375
'User-Agent': 'python-requests/2.18.4',
376376
'Accept-Encoding': 'gzip, deflate',
@@ -382,13 +382,13 @@ def test_search_request_failed(self):
382382
'BlueButton-OriginatingIpAddress': '127.0.0.1',
383383
'keep-alive': 'timeout=120, max=10',
384384
'BlueButton-OriginalUrl': '/v1/fhir/Patient',
385-
'BlueButton-BackendCall': 'https://fhir.backend.bluebutton.hhsdevcloud.us/baseDstu3/Patient/',
385+
'BlueButton-BackendCall': 'https://fhir.backend.bluebutton.hhsdevcloud.us/v1/fhir/Patient/',
386386
}
387387
}
388388

389389
@all_requests
390390
def catchall(url, req):
391-
self.assertIn("https://fhir.backend.bluebutton.hhsdevcloud.us/baseDstu3/Patient/", req.url)
391+
self.assertIn("https://fhir.backend.bluebutton.hhsdevcloud.us/v1/fhir/Patient/", req.url)
392392
self.assertIn("_format=application%2Fjson%2Bfhir", req.url)
393393
self.assertIn("_id=20140000008325", req.url)
394394
self.assertEqual(expected_request['method'], req.method)
@@ -415,7 +415,7 @@ def test_search_request_failed_no_fhir_id(self):
415415
expected_request = {
416416
'method': 'GET',
417417
'url': ("https://fhir.backend.bluebutton.hhsdevcloud.us/"
418-
"baseDstu3/Patient/?_format=application%2Fjson%2Bfhir&_id=20140000008325"),
418+
"v1/fhir/Patient/?_format=application%2Fjson%2Bfhir&_id=20140000008325"),
419419
'headers': {
420420
'User-Agent': 'python-requests/2.18.4',
421421
'Accept-Encoding': 'gzip, deflate',
@@ -427,7 +427,7 @@ def test_search_request_failed_no_fhir_id(self):
427427
'BlueButton-OriginatingIpAddress': '127.0.0.1',
428428
'keep-alive': 'timeout=120, max=10',
429429
'BlueButton-OriginalUrl': '/v1/fhir/Patient',
430-
'BlueButton-BackendCall': 'https://fhir.backend.bluebutton.hhsdevcloud.us/baseDstu3/Patient/',
430+
'BlueButton-BackendCall': 'https://fhir.backend.bluebutton.hhsdevcloud.us/v1/fhir/Patient/',
431431
}
432432
}
433433

@@ -447,7 +447,7 @@ def fhir_request(url, req):
447447

448448
@all_requests
449449
def catchall(url, req):
450-
self.assertIn("https://fhir.backend.bluebutton.hhsdevcloud.us/baseDstu3/Patient/", req.url)
450+
self.assertIn("https://fhir.backend.bluebutton.hhsdevcloud.us/v1/fhir/Patient/", req.url)
451451
self.assertIn("_format=application%2Fjson%2Bfhir", req.url)
452452
self.assertIn("_id=20140000008325", req.url)
453453
self.assertEqual(expected_request['method'], req.method)
@@ -507,7 +507,7 @@ def test_read_request(self):
507507

508508
expected_request = {
509509
'method': 'GET',
510-
'url': 'https://fhir.backend.bluebutton.hhsdevcloud.us/baseDstu3/Patient/20140000008325/?_format=json',
510+
'url': 'https://fhir.backend.bluebutton.hhsdevcloud.us/v1/fhir/Patient/20140000008325/?_format=json',
511511
'headers': {
512512
'User-Agent': 'python-requests/2.18.4',
513513
'Accept-Encoding': 'gzip, deflate',
@@ -519,7 +519,7 @@ def test_read_request(self):
519519
'BlueButton-OriginatingIpAddress': '127.0.0.1',
520520
'keep-alive': 'timeout=120, max=10',
521521
'BlueButton-OriginalUrl': '/v1/fhir/Patient/20140000008325',
522-
'BlueButton-BackendCall': 'https://fhir.backend.bluebutton.hhsdevcloud.us/baseDstu3/Patient/20140000008325/',
522+
'BlueButton-BackendCall': 'https://fhir.backend.bluebutton.hhsdevcloud.us/v1/fhir/Patient/20140000008325/',
523523
}
524524
}
525525

apps/fhir/bluebutton/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ def set_default_header(request, header=None):
182182
header = {}
183183

184184
header['keep-alive'] = settings.REQUEST_EOB_KEEP_ALIVE
185+
if request.is_secure():
186+
header['X-Forwarded-Proto'] = "https"
187+
else:
188+
header['X-Forwarded-Proto'] = "http"
189+
190+
header['X-Forwarded-Host'] = request.get_host()
185191

186192
return header
187193

apps/fhir/bluebutton/views/generic.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from ..authentication import OAuth2ResourceOwner
1818
from ..permissions import (HasCrosswalk, ResourcePermission)
1919
from ..exceptions import UpstreamServerException
20-
from ..serializers import localize
2120
from ..utils import (build_fhir_response,
2221
FhirServerVerify,
2322
get_resourcerouter)
@@ -106,10 +105,7 @@ def fetch_data(self, request, resource_type, *args, **kwargs):
106105

107106
self.validate_response(response)
108107

109-
out_data = localize(request=request,
110-
response=response,
111-
crosswalk=request.crosswalk,
112-
resource_type=resource_type)
108+
out_data = r.json()
113109

114110
self.check_object_permissions(request, out_data)
115111

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{"model": "server.resourcerouter", "pk": 1, "fields": {"name": "HHS IDEA Lab Sandbox[Default]", "server_address": "https://fhir.backend.bluebutton.hhsdevcloud.us", "server_path": "/", "server_release": "baseDstu3/", "server_search_expiry": 1800, "fhir_url": "https://fhir.backend.bluebutton.hhsdevcloud.us/baseDstu3/", "shard_by": "Patient", "client_auth": true, "cert_file": "./ca.cert.pem", "key_file": "./ca.key.nocrypt.pem", "server_verify": false, "wait_time": 30, "supported_resource": [1, 2, 3]}}, {"model": "server.supportedresourcetype", "pk": 1, "fields": {"resource_name": "Patient", "fhir_source": 1, "resourceType": "Patient", "secure_access": true, "json_schema": "{}", "get": true, "read": true, "vread": true, "history": true, "search": true, "put": false, "create": false, "update": false, "patch": false, "delete": false, "override_url_id": true, "override_search": false, "search_block": "Patient, patient", "search_add": ""}}, {"model": "server.supportedresourcetype", "pk": 2, "fields": {"resource_name": "Coverage", "fhir_source": 1, "resourceType": "Coverage", "secure_access": true, "json_schema": "{}", "get": true, "read": true, "vread": true, "history": true, "search": true, "put": false, "create": false, "update": false, "patch": false, "delete": false, "override_url_id": false, "override_search": false, "search_block": "Patient, patient", "search_add": "beneficiary=Patient/%PATIENT%"}}, {"model": "server.supportedresourcetype", "pk": 3, "fields": {"resource_name": "ExplanationOfBenefit", "fhir_source": 1, "resourceType": "ExplanationOfBenefit", "secure_access": true, "json_schema": "{}", "get": true, "read": true, "vread": true, "history": true, "search": true, "put": false, "create": false, "update": false, "patch": false, "delete": false, "override_url_id": false, "override_search": true, "search_block": "patient, Patient", "search_add": "patient=%PATIENT%"}}]
1+
[{"model": "server.resourcerouter", "pk": 1, "fields": {"name": "HHS IDEA Lab Sandbox[Default]", "server_address": "https://fhir.backend.bluebutton.hhsdevcloud.us", "server_path": "/", "server_release": "v1/fhir/", "server_search_expiry": 1800, "fhir_url": "https://fhir.backend.bluebutton.hhsdevcloud.us/v1/fhir/", "shard_by": "Patient", "client_auth": true, "cert_file": "./ca.cert.pem", "key_file": "./ca.key.nocrypt.pem", "server_verify": false, "wait_time": 30, "supported_resource": [1, 2, 3]}}, {"model": "server.supportedresourcetype", "pk": 1, "fields": {"resource_name": "Patient", "fhir_source": 1, "resourceType": "Patient", "secure_access": true, "json_schema": "{}", "get": true, "read": true, "vread": true, "history": true, "search": true, "put": false, "create": false, "update": false, "patch": false, "delete": false, "override_url_id": true, "override_search": false, "search_block": "Patient, patient", "search_add": ""}}, {"model": "server.supportedresourcetype", "pk": 2, "fields": {"resource_name": "Coverage", "fhir_source": 1, "resourceType": "Coverage", "secure_access": true, "json_schema": "{}", "get": true, "read": true, "vread": true, "history": true, "search": true, "put": false, "create": false, "update": false, "patch": false, "delete": false, "override_url_id": false, "override_search": false, "search_block": "Patient, patient", "search_add": "beneficiary=Patient/%PATIENT%"}}, {"model": "server.supportedresourcetype", "pk": 3, "fields": {"resource_name": "ExplanationOfBenefit", "fhir_source": 1, "resourceType": "ExplanationOfBenefit", "secure_access": true, "json_schema": "{}", "get": true, "read": true, "vread": true, "history": true, "search": true, "put": false, "create": false, "update": false, "patch": false, "delete": false, "override_url_id": false, "override_search": true, "search_block": "patient, Patient", "search_add": "patient=%PATIENT%"}}]

apps/testclient/tests.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def test_get_patient_negative(self):
8989
self.testclient_setup['patient_uri'], self.another_patient)
9090
response = self.client.get(uri)
9191
print(response.content)
92-
self.assertEqual(response.status_code, 403)
92+
self.assertEqual(response.status_code, 404)
9393

9494
def test_get_eob(self):
9595
"""
@@ -103,6 +103,9 @@ def test_get_eob(self):
103103
self.assertEqual(response.status_code, 200)
104104
self.assertEqual(response['Content-Type'], "application/json")
105105
self.assertEqual(len(response_data['entry']), 12)
106+
self.assertEqual(
107+
response_data['entry'][0]['fullUrl'],
108+
"http://testserver/v1/fhir/ExplanationOfBenefit/carrier-20587716665")
106109
self.assertContains(response, "ExplanationOfBenefit")
107110

108111
def test_bad_count(self):
@@ -118,20 +121,20 @@ def test_bad_offset(self):
118121
self.assertEqual(response.status_code, 400)
119122

120123
def test_offset_math(self):
121-
uri = "%s?patient=%s&count=12&startIndex=133" % (
124+
uri = "%s?patient=%s&count=12&startIndex=25" % (
122125
self.testclient_setup['eob_uri'], self.patient)
123126
response = self.client.get(uri)
124127
response_data = response.json()
125128
self.assertEqual(response.status_code, 200)
129+
self.assertEqual(response_data['total'], 32)
126130
self.assertEqual(len(response_data['entry']), 7)
127-
self.assertEqual(response_data['total'], 140)
128131
previous_links = [data['url'] for data in response_data['link'] if data['relation'] == 'previous']
129132
next_links = [data['url'] for data in response_data['link'] if data['relation'] == 'next']
130133
first_links = [data['url'] for data in response_data['link'] if data['relation'] == 'first']
131134
self.assertEqual(len(previous_links), 1)
132135
self.assertEqual(len(next_links), 0)
133136
self.assertEqual(len(first_links), 1)
134-
self.assertIn('startIndex=121', previous_links[0])
137+
self.assertIn('startIndex=13', previous_links[0])
135138
self.assertIn('startIndex=0', first_links[0])
136139
self.assertContains(response, "ExplanationOfBenefit")
137140

0 commit comments

Comments
 (0)