From c860dd92d8265b314b1283fe8181d6381d89b80b Mon Sep 17 00:00:00 2001 From: Bill Cutshall Date: Mon, 18 Nov 2024 10:23:32 -0500 Subject: [PATCH] [16144] Added code to account for blob digest properly. --- .../src/main/kotlin/fhirengine/engine/FHIRTranslator.kt | 5 +++-- .../src/test/kotlin/common/UniversalPipelineTestUtils.kt | 6 +++++- .../test/kotlin/fhirengine/engine/FhirTranslatorTests.kt | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/prime-router/src/main/kotlin/fhirengine/engine/FHIRTranslator.kt b/prime-router/src/main/kotlin/fhirengine/engine/FHIRTranslator.kt index c18a171327c..4a976e0150f 100644 --- a/prime-router/src/main/kotlin/fhirengine/engine/FHIRTranslator.kt +++ b/prime-router/src/main/kotlin/fhirengine/engine/FHIRTranslator.kt @@ -118,9 +118,10 @@ class FHIRTranslator( logger.trace("Preparing to send original message") val originalReport = reportService.getRootReport(message.reportId) val bodyBytes = BlobAccess.downloadBlobAsByteArray(originalReport.bodyUrl) + val originalDigest = BlobUtils.digestToString(originalReport.blobDigest) val localDigest = BlobUtils.digestToString(sha256Digest(bodyBytes)) - check(message.digest == localDigest) { - "Downloaded file does not match expected file\n${message.digest} | $localDigest" + check(originalDigest == localDigest) { + "Downloaded file does not match expected file\n$localDigest | $originalDigest" } // get a Report from the message diff --git a/prime-router/src/test/kotlin/common/UniversalPipelineTestUtils.kt b/prime-router/src/test/kotlin/common/UniversalPipelineTestUtils.kt index 45f03b9514e..d1cab36103a 100644 --- a/prime-router/src/test/kotlin/common/UniversalPipelineTestUtils.kt +++ b/prime-router/src/test/kotlin/common/UniversalPipelineTestUtils.kt @@ -3,6 +3,7 @@ package gov.cdc.prime.router.common import assertk.assertThat import assertk.assertions.hasSize import assertk.assertions.isEqualTo +import gov.cdc.prime.reportstream.shared.BlobUtils.sha256Digest import gov.cdc.prime.router.ClientSource import gov.cdc.prime.router.CustomerStatus import gov.cdc.prime.router.DeepOrganization @@ -452,7 +453,8 @@ object UniversalPipelineTestUtils { event, Topic.FULL_ELR, parentReport, - blobUrl + blobUrl, + reportContents, ) } @@ -464,6 +466,7 @@ object UniversalPipelineTestUtils { topic: Topic, parentReport: Report? = null, bodyURL: String? = null, + reportContents: String, ): Report { val report = Report( fileFormat, @@ -493,6 +496,7 @@ object UniversalPipelineTestUtils { .setBodyUrl(report.bodyURL) .setSendingOrg(universalPipelineOrganization.name) .setSendingOrgClient("Test Sender") + .setBlobDigest(sha256Digest(reportContents.toByteArray(Charsets.UTF_8))) ReportStreamTestDatabaseContainer.testDatabaseAccess.insertReportFile( reportFile, txn, action diff --git a/prime-router/src/test/kotlin/fhirengine/engine/FhirTranslatorTests.kt b/prime-router/src/test/kotlin/fhirengine/engine/FhirTranslatorTests.kt index 0d07f09b839..78b57c8be18 100644 --- a/prime-router/src/test/kotlin/fhirengine/engine/FhirTranslatorTests.kt +++ b/prime-router/src/test/kotlin/fhirengine/engine/FhirTranslatorTests.kt @@ -252,6 +252,7 @@ class FhirTranslatorTests { every { rootReport.sendingOrg } returns oneOrganization.name every { rootReport.sendingOrgClient } returns oneOrganization.receivers[0].fullName every { rootReport.bodyUrl } returns BLOB_URL + every { rootReport.blobDigest } returns reportId.toString().toByteArray(Charsets.UTF_8) every { reportServiceMock.getRootReport(any()) } returns rootReport every { reportServiceMock.getRootReports(any()) } returns listOf(rootReport) every { reportServiceMock.getRootItemIndex(any(), any()) } returns 1