Merge pull request #2683 from me-d4l/feature/ignore-package-id-case
Make package ID handling case-insensitive (#2682)
This commit is contained in:
commit
f34dd7ecd8
|
@ -195,7 +195,7 @@ public class JpaPackageCache extends BasePackageCacheManager implements IHapiPac
|
||||||
ourLog.info("Parsing package .tar.gz ({} bytes) from {}", bytes.length, theSourceDesc);
|
ourLog.info("Parsing package .tar.gz ({} bytes) from {}", bytes.length, theSourceDesc);
|
||||||
|
|
||||||
NpmPackage npmPackage = NpmPackage.fromPackage(new ByteArrayInputStream(bytes));
|
NpmPackage npmPackage = NpmPackage.fromPackage(new ByteArrayInputStream(bytes));
|
||||||
if (!npmPackage.id().equals(thePackageId)) {
|
if (!npmPackage.id().equalsIgnoreCase(thePackageId)) {
|
||||||
throw new InvalidRequestException("Package ID " + npmPackage.id() + " doesn't match expected: " + thePackageId);
|
throw new InvalidRequestException("Package ID " + npmPackage.id() + " doesn't match expected: " + thePackageId);
|
||||||
}
|
}
|
||||||
if (!PackageVersionComparator.isEquivalent(thePackageVersionId, npmPackage.version())) {
|
if (!PackageVersionComparator.isEquivalent(thePackageVersionId, npmPackage.version())) {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import ca.uhn.fhir.interceptor.api.IInterceptorService;
|
||||||
import ca.uhn.fhir.jpa.dao.data.INpmPackageDao;
|
import ca.uhn.fhir.jpa.dao.data.INpmPackageDao;
|
||||||
import ca.uhn.fhir.jpa.dao.data.INpmPackageVersionDao;
|
import ca.uhn.fhir.jpa.dao.data.INpmPackageVersionDao;
|
||||||
import ca.uhn.fhir.jpa.dao.r4.BaseJpaR4Test;
|
import ca.uhn.fhir.jpa.dao.r4.BaseJpaR4Test;
|
||||||
|
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
|
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
|
||||||
import ca.uhn.fhir.rest.server.interceptor.partition.RequestTenantPartitionInterceptor;
|
import ca.uhn.fhir.rest.server.interceptor.partition.RequestTenantPartitionInterceptor;
|
||||||
import org.hl7.fhir.utilities.npm.NpmPackage;
|
import org.hl7.fhir.utilities.npm.NpmPackage;
|
||||||
|
@ -14,8 +15,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
public class JpaPackageCacheTest extends BaseJpaR4Test {
|
public class JpaPackageCacheTest extends BaseJpaR4Test {
|
||||||
|
@ -114,4 +118,22 @@ public class JpaPackageCacheTest extends BaseJpaR4Test {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPackageIdHandlingIsNotCaseSensitive() throws IOException {
|
||||||
|
String packageNameAllLowercase = "hl7.fhir.us.davinci-cdex";
|
||||||
|
String packageNameUppercase = packageNameAllLowercase.toUpperCase(Locale.ROOT);
|
||||||
|
InputStream stream = IgInstallerDstu3Test.class.getResourceAsStream("/packages/package-davinci-cdex-0.2.0.tgz");
|
||||||
|
|
||||||
|
// 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"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNonMatchingPackageIdsCauseError() throws IOException {
|
||||||
|
String incorrectPackageName = "hl7.fhir.us.davinci-nonsense";
|
||||||
|
InputStream stream = IgInstallerDstu3Test.class.getResourceAsStream("/packages/package-davinci-cdex-0.2.0.tgz");
|
||||||
|
|
||||||
|
assertThrows(InvalidRequestException.class, () -> myPackageCacheManager.addPackageToCache(incorrectPackageName, "0.2.0", stream, "hl7.fhir.us.davinci-cdex"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue