-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue #1351 - Check SearchParameter search restrictions
Signed-off-by: Troy Biesterfeld <tbieste@us.ibm.com>
- Loading branch information
Showing
4 changed files
with
313 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
fhir-search/src/test/java/com/ibm/fhir/search/parameters/SearchParameterRestrictionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/* | ||
* (C) Copyright IBM Corp. 2019, 2020 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.ibm.fhir.search.parameters; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
import com.ibm.fhir.config.FHIRConfiguration; | ||
import com.ibm.fhir.config.FHIRRequestContext; | ||
import com.ibm.fhir.model.resource.Patient; | ||
import com.ibm.fhir.search.exception.FHIRSearchException; | ||
import com.ibm.fhir.search.test.BaseSearchTest; | ||
import com.ibm.fhir.search.util.SearchUtil; | ||
|
||
/** | ||
* Tests the detection of search restrictions defined by a SearchParameter. | ||
*/ | ||
public class SearchParameterRestrictionTest extends BaseSearchTest { | ||
|
||
private static final String TENANT_ID = "tenant7"; | ||
|
||
@Override | ||
@BeforeClass | ||
public void setup() { | ||
FHIRConfiguration.setConfigHome("src/test/resources"); | ||
} | ||
|
||
@Test | ||
public void testMultipleOrAllowed() throws Exception { | ||
FHIRRequestContext.set(new FHIRRequestContext(TENANT_ID)); | ||
|
||
Map<String, List<String>> queryParameters = new HashMap<>(); | ||
queryParameters.put("multiple-birth-count", Collections.singletonList("eq2,eq3,eq4")); | ||
|
||
SearchUtil.parseQueryParameters(Patient.class, queryParameters); | ||
} | ||
|
||
@Test(expectedExceptions = { FHIRSearchException.class }) | ||
public void testMultipleOrDisllowed() throws Exception { | ||
FHIRRequestContext.set(new FHIRRequestContext(TENANT_ID)); | ||
|
||
Map<String, List<String>> queryParameters = new HashMap<>(); | ||
queryParameters.put("multiple-birth-count-basic", Collections.singletonList("eq2,eq3")); | ||
|
||
SearchUtil.parseQueryParameters(Patient.class, queryParameters); | ||
} | ||
|
||
@Test | ||
public void testMultipleAndAllowed() throws Exception { | ||
FHIRRequestContext.set(new FHIRRequestContext(TENANT_ID)); | ||
|
||
Map<String, List<String>> queryParameters = new HashMap<>(); | ||
queryParameters.put("multiple-birth-count", Arrays.asList("eq2","eq3")); | ||
|
||
SearchUtil.parseQueryParameters(Patient.class, queryParameters); | ||
} | ||
|
||
@Test(expectedExceptions = { FHIRSearchException.class }) | ||
public void testMultipleAndDisallowed() throws Exception { | ||
FHIRRequestContext.set(new FHIRRequestContext(TENANT_ID)); | ||
|
||
Map<String, List<String>> queryParameters = new HashMap<>(); | ||
queryParameters.put("multiple-birth-count-basic", Arrays.asList("eq2","eq3")); | ||
|
||
SearchUtil.parseQueryParameters(Patient.class, queryParameters); | ||
} | ||
|
||
@Test | ||
public void testComparatorAllowed() throws Exception { | ||
FHIRRequestContext.set(new FHIRRequestContext(TENANT_ID)); | ||
|
||
Map<String, List<String>> queryParameters = new HashMap<>(); | ||
queryParameters.put("multiple-birth-count", Collections.singletonList("eq2")); | ||
|
||
SearchUtil.parseQueryParameters(Patient.class, queryParameters); | ||
} | ||
|
||
@Test(expectedExceptions = { FHIRSearchException.class }) | ||
public void testComparatorDisallowed() throws Exception { | ||
FHIRRequestContext.set(new FHIRRequestContext(TENANT_ID)); | ||
|
||
Map<String, List<String>> queryParameters = new HashMap<>(); | ||
queryParameters.put("multiple-birth-count-basic", Collections.singletonList("eq2")); | ||
|
||
SearchUtil.parseQueryParameters(Patient.class, queryParameters); | ||
} | ||
|
||
@Test | ||
public void testOtherComparatorDisallowed() throws Exception { | ||
FHIRRequestContext.set(new FHIRRequestContext(TENANT_ID)); | ||
|
||
Map<String, List<String>> queryParameters = new HashMap<>(); | ||
queryParameters.put("multiple-birth-count-basic", Collections.singletonList("gt2")); | ||
|
||
SearchUtil.parseQueryParameters(Patient.class, queryParameters); | ||
} | ||
|
||
@Test | ||
public void testModifierAllowed() throws Exception { | ||
FHIRRequestContext.set(new FHIRRequestContext(TENANT_ID)); | ||
|
||
Map<String, List<String>> queryParameters = new HashMap<>(); | ||
queryParameters.put("multiple-birth-count:missing", Collections.singletonList("true")); | ||
|
||
SearchUtil.parseQueryParameters(Patient.class, queryParameters); | ||
} | ||
|
||
@Test(expectedExceptions = { FHIRSearchException.class }) | ||
public void testModifierDisallowed() throws Exception { | ||
FHIRRequestContext.set(new FHIRRequestContext(TENANT_ID)); | ||
|
||
Map<String, List<String>> queryParameters = new HashMap<>(); | ||
queryParameters.put("multiple-birth-count-basic:missing", Collections.singletonList("true")); | ||
|
||
SearchUtil.parseQueryParameters(Patient.class, queryParameters); | ||
} | ||
|
||
} |
90 changes: 90 additions & 0 deletions
90
fhir-search/src/test/resources/config/tenant7/extension-search-parameters.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
{ | ||
"resourceType": "Bundle", | ||
"id": "searchParams", | ||
"meta": { | ||
"lastUpdated": "2020-07-30T22:37:54.724+11:00" | ||
}, | ||
"type": "collection", | ||
"entry": [{ | ||
"fullUrl": "http://ibm.com/fhir/SearchParameter/Patient-multiple-birth-count", | ||
"resource": { | ||
"resourceType": "SearchParameter", | ||
"id": "Patient-multiple-birth-count", | ||
"url": "http://hl7.org/fhir/SearchParameter/Patient-multiple-birth-count", | ||
"version": "4.0.0", | ||
"name": "multiple-birth-count", | ||
"status": "draft", | ||
"experimental": false, | ||
"date": "2018-12-27T22:37:54+11:00", | ||
"publisher": "IBM FHIR Server Test", | ||
"contact": [{ | ||
"telecom": [{ | ||
"system": "url", | ||
"value": "http://ibm.com/fhir" | ||
}] | ||
}, | ||
{ | ||
"telecom": [{ | ||
"system": "url", | ||
"value": "http://ibm.com/fhir" | ||
}] | ||
}], | ||
"description": "The multiple birth count has been provided and satisfies this search value", | ||
"code": "multiple-birth-count", | ||
"base": ["Patient"], | ||
"type": "number", | ||
"expression": "(Patient.multipleBirth as integer)", | ||
"xpath": "f:Patient/f:multipleBirthInteger", | ||
"xpathUsage": "normal", | ||
"multipleOr": true, | ||
"multipleAnd": true, | ||
"modifier": ["missing"], | ||
"comparator": ["eq", | ||
"ne", | ||
"gt", | ||
"ge", | ||
"lt", | ||
"le", | ||
"sa", | ||
"eb", | ||
"ap"] | ||
} | ||
}, | ||
{ | ||
"fullUrl": "http://ibm.com/fhir/SearchParameter/Patient-multiple-birth-count-basic", | ||
"resource": { | ||
"resourceType": "SearchParameter", | ||
"id": "Patient-multiple-birth-count-basic", | ||
"url": "http://hl7.org/fhir/SearchParameter/Patient-multiple-birth-count-basic", | ||
"version": "4.0.0", | ||
"name": "multiple-birth-count-basic", | ||
"status": "draft", | ||
"experimental": false, | ||
"date": "2018-12-27T22:37:54+11:00", | ||
"publisher": "IBM FHIR Server Test", | ||
"contact": [{ | ||
"telecom": [{ | ||
"system": "url", | ||
"value": "http://ibm.com/fhir" | ||
}] | ||
}, | ||
{ | ||
"telecom": [{ | ||
"system": "url", | ||
"value": "http://ibm.com/fhir" | ||
}] | ||
}], | ||
"description": "The multiple birth count has been provided and satisfies this search value", | ||
"code": "multiple-birth-count-basic", | ||
"base": ["Patient"], | ||
"type": "number", | ||
"expression": "(Patient.multipleBirth as integer)", | ||
"xpath": "f:Patient/f:multipleBirthInteger", | ||
"xpathUsage": "normal", | ||
"multipleOr": false, | ||
"multipleAnd": false, | ||
"modifier": ["type"], | ||
"comparator": ["gt"] | ||
} | ||
}] | ||
} |
9 changes: 9 additions & 0 deletions
9
fhir-search/src/test/resources/config/tenant7/fhir-server-config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"__comment": "FHIR Server configuration", | ||
"fhirServer": { | ||
"_comment": "Just hiding this property because 'include-all' should be the default", | ||
"_searchParameterFilter": { | ||
"*": "*" | ||
} | ||
} | ||
} |