Skip to content

Commit a406b3b

Browse files
refactor validation checks to common dir
1 parent a7e6641 commit a406b3b

File tree

5 files changed

+23
-13
lines changed

5 files changed

+23
-13
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @file validationUtil.js
3+
* @description Provides utility functions.
4+
*/
5+
6+
function isValidUuid(string) {
7+
return /^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i.test(string);
8+
}
9+
10+
function hasLegacyPrefix(string) {
11+
return string.startsWith('att-');
12+
}
13+
14+
module.exports = {
15+
isValidUuid,
16+
hasLegacyPrefix,
17+
};

sandbox/src/routes/r4/retrieveAttachment.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const businessFunctionValidator = require('../../services/businessFunctionValidator')
2+
const validationUtil = require('../common/validationUtil')
23

34
module.exports = [
45
/**
@@ -20,11 +21,8 @@ module.exports = [
2021
const url = request.url.href;
2122
const objectStore = "/ObjectStore/d497bbe3-f88b-45f1-b3d4-9c563e4c0f5f";
2223
const location = url.split('/FHIR')[0] + objectStore;
23-
const uuidPattern = /^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
24-
const attPattern = /^att-\d+-\d+$/;
2524

26-
27-
if ((uuidPattern.test(binaryId) || attPattern.test(binaryId)) && request.method === 'get') {
25+
if ((validationUtil.hasLegacyPrefix(binaryId) || validationUtil.isValidUuid(binaryId)) && request.method === 'get') {
2826
const response = h.response().code(307);
2927
response.headers["Location"] = location;
3028
return response;

sandbox/src/routes/stu3/services/mockResponseProvider.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
const validationUtil = require('../../common/validationUtil')
22
const fs = require('fs')
33
const lodash = require('lodash')
44

@@ -170,22 +170,18 @@ module.exports = {
170170

171171
if (attachmentId) {
172172

173-
if (attachmentId.startsWith('att-')) {
173+
if (validationUtil.hasLegacyPrefix(attachmentId)) {
174174
return { responsePath: 'stu3/retrieveAttachment/responses/example_attachment.pdf', filename: 'example_attachment.pdf', responseCode: 200 };
175175
}
176176

177-
if (this.isvalidUuid(attachmentId)) {
177+
if (validationUtil.isValidUuid(attachmentId)) {
178178
return { responsePath: 'stu3/retrieveAttachment/responses/example_attachment.pdf', filename: 'example_attachment.pdf', responseCode: 200 };
179179
}
180180
}
181181

182182
return {};
183183
},
184184

185-
isvalidUuid: function(string) {
186-
return /^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i.test(string);
187-
},
188-
189185
getExampleResponseForRetrieveReferralRequest: function (request) {
190186
const ubrn = request.params.ubrn;
191187
const version = request.params.version

sandbox/src/services/businessFunctionValidator.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ module.exports = {
1313
if (requestedBusinessFunction === 'SERVICE_PROVIDER_CLINICIAN_ADMIN') {
1414
if (!oboUserId) {
1515
return h.response('SANDBOX_ERROR: When this endpoint is accessed using the e-RS SERVICE_PROVIDER_CLINICIAN_ADMIN Business Function then an On-Behalf-Of User ID must be provided').code(403)
16-
.code(403)
1716
}
1817
}
1918
else {

tests/sandbox/stu3/test_a006_get_attachment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,4 @@ def test_failure_not_a_uuid(
103103
response = call_endpoint_url_with_pathParams(
104104
actor, {"attachmentLogicalID": "f1bb2b1-30db-48f9-8906-8b703adca5fb"}
105105
)
106-
asserts.assert_status_code(404, response.status_code)
106+
asserts.assert_status_code(422, response.status_code)

0 commit comments

Comments
 (0)