Skip to content

Commit

Permalink
fix(reporter): Process only valid scancodes in FossIdReporter
Browse files Browse the repository at this point in the history
The algorithm to obtain the scancodes to be processed produced an
empty scancode for scan results produced by other scanners.
The `FossIdReporter` then tried to create a report for this scancode,
too, which did not cause the reporter to fail, but generated an
exception in the logs. Fix this by correctly determining the scancodes
for which reports should be generated.

Signed-off-by: Oliver Heger <oliver.heger@bosch.io>
  • Loading branch information
oheger-bosch authored and sschuberth committed Dec 12, 2023
1 parent 57f85f0 commit 686f953
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion plugins/reporters/fossid/src/main/kotlin/FossIdReporter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class FossIdReporter : Reporter {
return runBlocking(Dispatchers.IO) {
val scanResults = input.ortResult.getScanResults().values.flatten()
val scanCodes = scanResults.flatMapTo(mutableSetOf()) {
it.additionalData[SCAN_CODE_KEY].orEmpty().split(',')
it.additionalData[SCAN_CODE_KEY]?.split(',').orEmpty()
}

scanCodes.map { scanCode ->
Expand Down
20 changes: 19 additions & 1 deletion plugins/reporters/fossid/src/test/kotlin/FossIdReporterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,17 @@ class FossIdReporterTest : WordSpec({

result shouldContainExactly listOf(FILE_SAMPLE)
}

"ignore scan results without a scancode" {
val (serviceMock, reporterMock) = createReporterMock()
val input = createReporterInput(SCANCODE_1)

reporterMock.generateReport(input)

coVerify(exactly = 1) {
serviceMock.generateReport(any(), any(), any(), any(), any(), any())
}
}
}
})

Expand Down Expand Up @@ -275,7 +286,14 @@ private fun createReporterInput(vararg scanCodes: String): ReporterInput {
val results = scanCodes.associateByTo(
destination = sortedMapOf(),
keySelector = { Identifier.EMPTY.copy(name = it) },
valueTransform = { listOf(createScanResult(it)) }
valueTransform = { code ->
val unmatchedScanResult = ScanResult(
provenance = UnknownProvenance,
scanner = ScannerDetails.EMPTY.copy(name = "otherScanner"),
summary = ScanSummary.EMPTY
)
listOf(createScanResult(code), unmatchedScanResult)
}
)

return ReporterInput(
Expand Down

0 comments on commit 686f953

Please sign in to comment.