Fix case sensitivity on package name lookup (#5524)

* 90% working test

* wip

* Modify test, changelog, add implementation

* Revert "90% working test"

This reverts commit 64a8f1d806.

* fix typo

* spotless
This commit is contained in:
Tadgh 2023-12-05 09:43:00 -08:00 committed by GitHub
parent 4070b40fb1
commit 293cd3ef3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 4 deletions

View File

@ -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."

View File

@ -28,6 +28,6 @@ import java.util.Optional;
public interface INpmPackageDao extends JpaRepository<NpmPackageEntity, Long>, IHapiFhirJpaRepository {
@Query("SELECT p FROM NpmPackageEntity p WHERE p.myPackageId = :id")
@Query("SELECT p FROM NpmPackageEntity p WHERE lower(p.myPackageId) = lower(:id)")
Optional<NpmPackageEntity> findByPackageId(@Param("id") String thePackageId);
}

View File

@ -30,10 +30,11 @@ import java.util.Optional;
public interface INpmPackageVersionDao extends JpaRepository<NpmPackageVersionEntity, Long>, IHapiFhirJpaRepository {
@Query("SELECT p FROM NpmPackageVersionEntity p WHERE p.myPackageId = :id")
@Query("SELECT p FROM NpmPackageVersionEntity p WHERE lower(p.myPackageId) = lower(:id)")
Collection<NpmPackageVersionEntity> 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<NpmPackageVersionEntity> findByPackageIdAndVersion(
@Param("id") String thePackageId, @Param("version") String thePackageVersion);
@ -41,7 +42,7 @@ public interface INpmPackageVersionDao extends JpaRepository<NpmPackageVersionEn
* Uses a "like" expression on the version ID
*/
@Query(
"SELECT p.myVersionId FROM NpmPackageVersionEntity p WHERE p.myPackageId = :id AND p.myVersionId like :version")
"SELECT p.myVersionId FROM NpmPackageVersionEntity p WHERE lower(p.myPackageId) = lower(:id) AND p.myVersionId like :version")
List<String> findVersionIdsByPackageIdAndLikeVersion(
@Param("id") String theId, @Param("version") String thePartialVersionString);
}

View File

@ -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