Skip to content

Commit 9b3864f

Browse files
committed
Merge branch '6.0.0-alpha.1' into OHM-1082-add-eslint-alpha
2 parents 1b09d54 + c718948 commit 9b3864f

File tree

2 files changed

+120
-17
lines changed

2 files changed

+120
-17
lines changed

src/api/audits.js

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ export async function addAudit(ctx) {
9191
}
9292
}
9393

94+
function checkPatientID(patientID) {
95+
return /^[\d\w-]*$/.test(patientID) // PatientID should only be alpha numerical and may contain hyphens
96+
}
97+
9498
/*
9599
* Retrieves the list of Audits
96100
*/
@@ -144,28 +148,58 @@ export async function getAudits(ctx) {
144148
if (filters['participantObjectIdentification.participantObjectID']) {
145149
// filter by AND on same property for patientID and objectID
146150
if (filters['participantObjectIdentification.participantObjectID'].type) {
147-
const patientID = new RegExp(
148-
filters[
149-
'participantObjectIdentification.participantObjectID'
150-
].patientID
151-
)
152-
const objectID = new RegExp(
153-
filters[
154-
'participantObjectIdentification.participantObjectID'
155-
].objectID
151+
const patientID = JSON.parse(
152+
filters['participantObjectIdentification.participantObjectID']
153+
.patientID
156154
)
157-
filters.$and = [
158-
{'participantObjectIdentification.participantObjectID': patientID},
159-
{'participantObjectIdentification.participantObjectID': objectID}
160-
]
161-
// remove participantObjectIdentification.participantObjectID property as we create a new '$and' operator
162-
delete filters['participantObjectIdentification.participantObjectID']
155+
if (checkPatientID(patientID.substring(0, patientID.indexOf('\\^')))) {
156+
const patientIDRegEx = new RegExp(patientID)
157+
const objectIDRegEx = new RegExp(
158+
filters[
159+
'participantObjectIdentification.participantObjectID'
160+
].objectID
161+
)
162+
filters.$and = [
163+
{
164+
'participantObjectIdentification.participantObjectID':
165+
patientIDRegEx
166+
},
167+
{
168+
'participantObjectIdentification.participantObjectID':
169+
objectIDRegEx
170+
}
171+
]
172+
// remove participantObjectIdentification.participantObjectID property as we create a new '$and' operator
173+
delete filters['participantObjectIdentification.participantObjectID']
174+
} else {
175+
utils.logAndSetResponse(
176+
ctx,
177+
400,
178+
'Special characters (except for hyphens(-)) not allowed in PatientID filter field',
179+
'error'
180+
)
181+
return
182+
}
163183
} else {
164184
const participantObjectID = JSON.parse(
165185
filters['participantObjectIdentification.participantObjectID']
166186
)
167-
filters['participantObjectIdentification.participantObjectID'] =
168-
new RegExp(`${participantObjectID}`)
187+
if (
188+
checkPatientID(
189+
participantObjectID.substring(0, participantObjectID.indexOf('\\^'))
190+
)
191+
) {
192+
filters['participantObjectIdentification.participantObjectID'] =
193+
new RegExp(`${participantObjectID}`)
194+
} else {
195+
utils.logAndSetResponse(
196+
ctx,
197+
400,
198+
'Special characters (except for hyphens(-)) not allowed in PatientID filter field',
199+
'error'
200+
)
201+
return
202+
}
169203
}
170204
}
171205

test/integration/auditAPITests.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,75 @@ describe('API Integration Tests', () => {
204204
res.body.length.should.equal(countBefore + 1)
205205
})
206206

207+
it('should call getAudits with incorrect participantObjectID ', async () => {
208+
let filters = {
209+
'participantObjectIdentification.participantObjectID':
210+
'"!1234\\\\^\\\\^\\\\^.*&.*&.*"'
211+
}
212+
filters = JSON.stringify(filters)
213+
const res = await request(BASE_URL)
214+
.get(
215+
`/audits?filterPage=0&filterLimit=10&filters=${encodeURIComponent(
216+
filters
217+
)}`
218+
)
219+
.set('auth-username', testUtils.rootUser.email)
220+
.set('auth-ts', authDetails.authTS)
221+
.set('auth-salt', authDetails.authSalt)
222+
.set('auth-token', authDetails.authToken)
223+
.expect(400)
224+
225+
res.statusCode.should.be.exactly(400)
226+
})
227+
228+
it('should call getAudits with correct participantObjectID ($and) ', async () => {
229+
let filters = {
230+
'participantObjectIdentification.participantObjectID': {
231+
type: 'AND',
232+
patientID: '"1234\\\\^\\\\^\\\\^.*&.*&.*"',
233+
objectID: '123'
234+
}
235+
}
236+
filters = JSON.stringify(filters)
237+
const res = await request(BASE_URL)
238+
.get(
239+
`/audits?filterPage=0&filterLimit=10&filters=${encodeURIComponent(
240+
filters
241+
)}`
242+
)
243+
.set('auth-username', testUtils.rootUser.email)
244+
.set('auth-ts', authDetails.authTS)
245+
.set('auth-salt', authDetails.authSalt)
246+
.set('auth-token', authDetails.authToken)
247+
.expect(200)
248+
249+
res.statusCode.should.be.exactly(200)
250+
})
251+
252+
it('should call getAudits with incorrect participantObjectID ($and) ', async () => {
253+
let filters = {
254+
'participantObjectIdentification.participantObjectID': {
255+
type: 'AND',
256+
patientID: '"!1234\\\\^\\\\^\\\\^.*&.*&.*"',
257+
objectID: '123'
258+
}
259+
}
260+
filters = JSON.stringify(filters)
261+
const res = await request(BASE_URL)
262+
.get(
263+
`/audits?filterPage=0&filterLimit=10&filters=${encodeURIComponent(
264+
filters
265+
)}`
266+
)
267+
.set('auth-username', testUtils.rootUser.email)
268+
.set('auth-ts', authDetails.authTS)
269+
.set('auth-salt', authDetails.authSalt)
270+
.set('auth-token', authDetails.authToken)
271+
.expect(400)
272+
273+
res.statusCode.should.be.exactly(400)
274+
})
275+
207276
it("should generate an 'audit log used' audit when using non-basic representation", async () => {
208277
const result = await new AuditModel(auditData).save()
209278

0 commit comments

Comments
 (0)