diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_0_0/5523-case-sensitive-package-ids.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_0_0/5523-case-sensitive-package-ids.yaml new file mode 100644 index 00000000000..a2b9b590398 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_0_0/5523-case-sensitive-package-ids.yaml @@ -0,0 +1,5 @@ +--- +type: fix +issue: 5523 +jira: SMILE-7729 +title: "Previously, it was possible to store NPM Packages where the package name's case did not match the package ID's case, e.g. `my-package` was different than `MY-PACKAGE`. Names are now normalized to lower case before queries occur." diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/INpmPackageDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/INpmPackageDao.java index 6df63c7d233..d9d9716161f 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/INpmPackageDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/INpmPackageDao.java @@ -28,6 +28,6 @@ import java.util.Optional; public interface INpmPackageDao extends JpaRepository, IHapiFhirJpaRepository { - @Query("SELECT p FROM NpmPackageEntity p WHERE p.myPackageId = :id") + @Query("SELECT p FROM NpmPackageEntity p WHERE lower(p.myPackageId) = lower(:id)") Optional findByPackageId(@Param("id") String thePackageId); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/INpmPackageVersionDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/INpmPackageVersionDao.java index 26d4076401e..3a27873e811 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/INpmPackageVersionDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/INpmPackageVersionDao.java @@ -30,10 +30,11 @@ import java.util.Optional; public interface INpmPackageVersionDao extends JpaRepository, IHapiFhirJpaRepository { - @Query("SELECT p FROM NpmPackageVersionEntity p WHERE p.myPackageId = :id") + @Query("SELECT p FROM NpmPackageVersionEntity p WHERE lower(p.myPackageId) = lower(:id)") Collection findByPackageId(@Param("id") String thePackageId); - @Query("SELECT p FROM NpmPackageVersionEntity p WHERE p.myPackageId = :id AND p.myVersionId = :version") + @Query( + "SELECT p FROM NpmPackageVersionEntity p WHERE lower(p.myPackageId) = lower(:id) AND p.myVersionId = :version") Optional findByPackageIdAndVersion( @Param("id") String thePackageId, @Param("version") String thePackageVersion); @@ -41,7 +42,7 @@ public interface INpmPackageVersionDao extends JpaRepository findVersionIdsByPackageIdAndLikeVersion( @Param("id") String theId, @Param("version") String thePartialVersionString); } diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/packages/JpaPackageCacheTest.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/packages/JpaPackageCacheTest.java index 3ca0078506c..fdad3b86b7d 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/packages/JpaPackageCacheTest.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/packages/JpaPackageCacheTest.java @@ -177,6 +177,9 @@ public class JpaPackageCacheTest extends BaseJpaR4Test { // The package has the ID in lower-case, so for the test we input the first parameter in upper-case & check that no error is thrown assertDoesNotThrow(() -> myPackageCacheManager.addPackageToCache(packageNameUppercase, "0.2.0", stream, "hl7.fhir.us.davinci-cdex")); + + // Ensure uninstalling it also works! + assertDoesNotThrow(() -> myPackageCacheManager.uninstallPackage(packageNameUppercase, "0.2.0")); } @Test