@@ -55,6 +55,33 @@ def unknown_param_options_post
5555 }
5656 end
5757
58+ # '...' consists solely of chain separators, causing Criterium.Parse to return nil
59+ # (the chain path is empty after splitting on '.'). This exercises the malformed
60+ # parameter code path added in issue #1267.
61+ # Returns a new hash each call because the FHIR client mutates the options hash.
62+ def malformed_param_options
63+ {
64+ search : {
65+ compartment : nil ,
66+ parameters : {
67+ '...' => 'foobar'
68+ }
69+ }
70+ }
71+ end
72+
73+ def malformed_param_options_post
74+ {
75+ search : {
76+ flag : true ,
77+ compartment : nil ,
78+ parameters : {
79+ '...' => 'foobar'
80+ }
81+ }
82+ }
83+ end
84+
5885 test 'I1160A' , 'Unknown search parameter: server returns HTTP 200 (lenient behaviour)' do
5986 metadata {
6087 links "#{ BASE_SPEC_LINK } /search.html#errors"
@@ -187,6 +214,138 @@ def unknown_param_options_post
187214 )
188215 end
189216
217+ test 'I1267A' , 'Malformed search parameter: server returns HTTP 200 (lenient behaviour)' do
218+ metadata {
219+ links "#{ BASE_SPEC_LINK } /search.html#errors"
220+ links "#{ REST_SPEC_LINK } #search"
221+ links 'https://github.com/FirelyTeam/spark/issues/1267'
222+ validates resource : 'QuestionnaireResponse' , methods : [ 'search' ]
223+ }
224+
225+ reply = @client . search ( version_namespace . const_get ( :QuestionnaireResponse ) , malformed_param_options )
226+
227+ assert_response_ok ( reply )
228+ assert_bundle_response ( reply )
229+ end
230+
231+ test 'I1267B' , 'Malformed search parameter: Bundle includes an OperationOutcome entry with search.mode=outcome' do
232+ metadata {
233+ links "#{ BASE_SPEC_LINK } /search.html#errors"
234+ links "#{ REST_SPEC_LINK } #search"
235+ links 'https://github.com/FirelyTeam/spark/issues/1267'
236+ validates resource : 'QuestionnaireResponse' , methods : [ 'search' ]
237+ }
238+
239+ reply = @client . search ( version_namespace . const_get ( :QuestionnaireResponse ) , malformed_param_options )
240+ assert_response_ok ( reply )
241+ assert_bundle_response ( reply )
242+
243+ outcome_entries = reply . resource . entry . select do |e |
244+ e . resource . is_a? ( version_namespace . const_get ( :OperationOutcome ) ) &&
245+ e . search &.mode == 'outcome'
246+ end
247+
248+ assert (
249+ outcome_entries . any? ,
250+ 'Expected the searchset Bundle to contain at least one OperationOutcome entry with search.mode=outcome for the malformed parameter "..."' ,
251+ reply . body
252+ )
253+ end
254+
255+ test 'I1267C' , 'Malformed search parameter: OperationOutcome issue severity is warning' do
256+ metadata {
257+ links "#{ BASE_SPEC_LINK } /search.html#errors"
258+ links "#{ REST_SPEC_LINK } #search"
259+ links 'https://github.com/FirelyTeam/spark/issues/1267'
260+ validates resource : 'QuestionnaireResponse' , methods : [ 'search' ]
261+ }
262+
263+ reply = @client . search ( version_namespace . const_get ( :QuestionnaireResponse ) , malformed_param_options )
264+ assert_response_ok ( reply )
265+ assert_bundle_response ( reply )
266+
267+ outcome_entry = reply . resource . entry . find do |e |
268+ e . resource . is_a? ( version_namespace . const_get ( :OperationOutcome ) ) &&
269+ e . search &.mode == 'outcome'
270+ end
271+
272+ assert ( outcome_entry , 'No OperationOutcome entry with search.mode=outcome found in the Bundle' , reply . body )
273+
274+ issue = outcome_entry . resource . issue . first
275+ assert ( issue , 'OperationOutcome has no issues' , reply . body )
276+ assert (
277+ issue . severity == 'warning' ,
278+ "Expected OperationOutcome issue severity to be 'warning' but was '#{ issue . severity } '" ,
279+ reply . body
280+ )
281+ end
282+
283+ test 'I1267D' , 'Malformed search parameter via POST _search: server returns HTTP 200 (lenient behaviour)' do
284+ metadata {
285+ links "#{ BASE_SPEC_LINK } /search.html#errors"
286+ links "#{ REST_SPEC_LINK } #search"
287+ links 'https://github.com/FirelyTeam/spark/issues/1267'
288+ validates resource : 'QuestionnaireResponse' , methods : [ 'search' ]
289+ }
290+
291+ reply = @client . search ( version_namespace . const_get ( :QuestionnaireResponse ) , malformed_param_options_post )
292+
293+ assert_response_ok ( reply )
294+ assert_bundle_response ( reply )
295+ end
296+
297+ test 'I1267E' , 'Malformed search parameter via POST _search: Bundle includes an OperationOutcome entry with search.mode=outcome' do
298+ metadata {
299+ links "#{ BASE_SPEC_LINK } /search.html#errors"
300+ links "#{ REST_SPEC_LINK } #search"
301+ links 'https://github.com/FirelyTeam/spark/issues/1267'
302+ validates resource : 'QuestionnaireResponse' , methods : [ 'search' ]
303+ }
304+
305+ reply = @client . search ( version_namespace . const_get ( :QuestionnaireResponse ) , malformed_param_options_post )
306+ assert_response_ok ( reply )
307+ assert_bundle_response ( reply )
308+
309+ outcome_entries = reply . resource . entry . select do |e |
310+ e . resource . is_a? ( version_namespace . const_get ( :OperationOutcome ) ) &&
311+ e . search &.mode == 'outcome'
312+ end
313+
314+ assert (
315+ outcome_entries . any? ,
316+ 'Expected the searchset Bundle to contain at least one OperationOutcome entry with search.mode=outcome for the malformed parameter "..."' ,
317+ reply . body
318+ )
319+ end
320+
321+ test 'I1267F' , 'Malformed search parameter via POST _search: OperationOutcome issue severity is warning' do
322+ metadata {
323+ links "#{ BASE_SPEC_LINK } /search.html#errors"
324+ links "#{ REST_SPEC_LINK } #search"
325+ links 'https://github.com/FirelyTeam/spark/issues/1267'
326+ validates resource : 'QuestionnaireResponse' , methods : [ 'search' ]
327+ }
328+
329+ reply = @client . search ( version_namespace . const_get ( :QuestionnaireResponse ) , malformed_param_options_post )
330+ assert_response_ok ( reply )
331+ assert_bundle_response ( reply )
332+
333+ outcome_entry = reply . resource . entry . find do |e |
334+ e . resource . is_a? ( version_namespace . const_get ( :OperationOutcome ) ) &&
335+ e . search &.mode == 'outcome'
336+ end
337+
338+ assert ( outcome_entry , 'No OperationOutcome entry with search.mode=outcome found in the Bundle' , reply . body )
339+
340+ issue = outcome_entry . resource . issue . first
341+ assert ( issue , 'OperationOutcome has no issues' , reply . body )
342+ assert (
343+ issue . severity == 'warning' ,
344+ "Expected OperationOutcome issue severity to be 'warning' but was '#{ issue . severity } '" ,
345+ reply . body
346+ )
347+ end
348+
190349 end
191350 end
192351end
0 commit comments