Skip to content

Commit

Permalink
[16144] Added code to account for blob digest properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
wcutshall committed Nov 18, 2024
1 parent d0517ec commit c860dd9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -452,7 +453,8 @@ object UniversalPipelineTestUtils {
event,
Topic.FULL_ELR,
parentReport,
blobUrl
blobUrl,
reportContents,
)
}

Expand All @@ -464,6 +466,7 @@ object UniversalPipelineTestUtils {
topic: Topic,
parentReport: Report? = null,
bodyURL: String? = null,
reportContents: String,
): Report {
val report = Report(
fileFormat,
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c860dd9

Please sign in to comment.