Make package ID handling case-insensitive

This commit is contained in:
morten.ernebjerg 2021-05-27 14:57:07 +02:00
parent c8c596aff4
commit cbfca6a560
No known key found for this signature in database
GPG Key ID: BC2238A2F5F14F98
2 changed files with 13 additions and 1 deletions

View File

@ -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())) {

View File

@ -14,7 +14,9 @@ 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.fail; import static org.junit.jupiter.api.Assertions.fail;
@ -114,4 +116,14 @@ 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, packageNameAllLowercase));
}
} }