Skip to content

Commit 6e4b36a

Browse files
authored
Case-sensitivity in Conditional Update based on tokens (#7125)
* [7124] fix conditional update case sensitivity * [7124] add changelog and more test
1 parent 518af1e commit 6e4b36a

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
type: fix
3+
issue: 7125
4+
jira: SMILE-10427
5+
title: "Previously, conditional updates based on tokens were case-insensitive. As a result, a new resource would be
6+
created if the token value in the URL used a different case than the one in the request body, leading to incorrect
7+
search results when using token-based search parameters. This issue has now been resolved."

hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamToken.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,15 +350,15 @@ public boolean matches(IQueryParameterType theParam) {
350350

351351
// Only match on system if it wasn't specified
352352
if (token.getSystem() == null || token.getSystem().isEmpty()) {
353-
if (valueString.equalsIgnoreCase(tokenValueString)) {
353+
if (valueString.equals(tokenValueString)) {
354354
retVal = true;
355355
}
356356
} else if (tokenValueString == null || tokenValueString.isEmpty()) {
357-
if (token.getSystem().equalsIgnoreCase(getSystem())) {
357+
if (token.getSystem().equals(getSystem())) {
358358
retVal = true;
359359
}
360360
} else {
361-
if (token.getSystem().equalsIgnoreCase(getSystem()) && valueString.equalsIgnoreCase(tokenValueString)) {
361+
if (token.getSystem().equals(getSystem()) && valueString.equals(tokenValueString)) {
362362
retVal = true;
363363
}
364364
}

hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamTokenTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package ca.uhn.fhir.jpa.model.entity;
22

33
import ca.uhn.fhir.jpa.model.config.PartitionSettings;
4+
import ca.uhn.fhir.rest.param.TokenParam;
45
import org.junit.jupiter.api.Test;
56
import org.junit.jupiter.params.ParameterizedTest;
67
import org.junit.jupiter.params.provider.CsvSource;
78

9+
import static org.assertj.core.api.Assertions.assertThat;
810
import static org.junit.jupiter.api.Assertions.assertEquals;
911
import static org.junit.jupiter.api.Assertions.assertNotEquals;
12+
import static org.junit.jupiter.api.Assertions.assertTrue;
1013

1114
public class ResourceIndexedSearchParamTokenTest {
1215

@@ -94,4 +97,23 @@ public void testEqualsAndHashCode_withDifferentParams_equalsIsFalseAndHashCodeIs
9497
assertNotEquals(param2, param, theMessage);
9598
assertNotEquals(param.hashCode(), param2.hashCode(), theMessage);
9699
}
100+
101+
@ParameterizedTest
102+
@CsvSource({
103+
"system, value, true",
104+
", value, true",
105+
"system, , true",
106+
"SYSTEM, value, false",
107+
"system, VALUE, false",
108+
", VALUE, false",
109+
"SYSTEM, , false",
110+
"diffS, diffV, false",
111+
})
112+
public void testMatches(String theSystem, String theValue, boolean theExpected) {
113+
ResourceIndexedSearchParamToken param = new ResourceIndexedSearchParamToken(
114+
new PartitionSettings(), "Patient", "name", "system", "value");
115+
116+
TokenParam tokenParam = new TokenParam(theSystem, theValue);
117+
assertThat(param.matches(tokenParam)).isEqualTo(theExpected);
118+
}
97119
}

hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4CreateTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,16 @@ public void testConditionalCreateFailsIfMatchUrlDoesntMatch_InTransaction() {
456456
}
457457
}
458458

459+
@Test
460+
public void testConditionalCreateFailsIfMatchUrlCaseIsDifferent() {
461+
Observation obs = new Observation();
462+
obs.addIdentifier().setValue("XXX");
463+
assertThatThrownBy(() -> myObservationDao.create(obs, "identifier=xxx", newSrd()))
464+
.isInstanceOf(InvalidRequestException.class)
465+
.hasMessage(Msg.code(929) +
466+
"Failed to process conditional create. The supplied resource did not satisfy the conditional URL.");
467+
}
468+
459469
@Test
460470
public void testCreateResource_withConditionalCreate_willAddSearchUrlEntity(){
461471
// given

0 commit comments

Comments
 (0)