Skip to content

Commit 4c12ac7

Browse files
committed
test(osv): Narrow down two assertions
Assert the returned vulnerabilities which is the focus of the tests. Signed-off-by: Frank Viernau <[email protected]>
1 parent e2f8a24 commit 4c12ac7

3 files changed

Lines changed: 164 additions & 197 deletions

File tree

plugins/advisors/osv/src/funTest/kotlin/OsvFunTest.kt

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,10 @@ import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
2626
import io.kotest.matchers.shouldBe
2727
import io.kotest.matchers.shouldNot
2828

29-
import java.time.Instant
30-
31-
import org.ossreviewtoolkit.model.AdvisorResult
3229
import org.ossreviewtoolkit.model.Identifier
3330
import org.ossreviewtoolkit.model.Package
3431
import org.ossreviewtoolkit.model.VcsInfo
35-
import org.ossreviewtoolkit.plugins.advisors.api.normalizeVulnerabilityData
32+
import org.ossreviewtoolkit.model.vulnerabilities.Vulnerability
3633
import org.ossreviewtoolkit.utils.test.identifierToPackage
3734
import org.ossreviewtoolkit.utils.test.readResourceValue
3835

@@ -80,13 +77,15 @@ class OsvFunTest : WordSpec({
8077
identifierToPackage(it)
8178
}
8279

83-
val packageFindings = osv.retrievePackageFindings(packages).mapKeys { it.key.id }
80+
val packageFindings = osv.retrievePackageFindings(packages).entries.associate {
81+
it.key.id to it.value.vulnerabilities
82+
}
8483

85-
val expectedResult = readResourceValue<Map<Identifier, AdvisorResult>>(
84+
val expectedResult = readResourceValue<Map<Identifier, List<Vulnerability>>>(
8685
"/retrieve-package-findings-expected-result.yml"
8786
)
8887

89-
packageFindings.patchTimes() shouldBe expectedResult.patchTimes()
88+
packageFindings shouldBe expectedResult
9089
}
9190

9291
"return the vulnerabilities for the commit of Hadoop 3.3.1" {
@@ -95,25 +94,17 @@ class OsvFunTest : WordSpec({
9594
vcsProcessed = VcsInfo.EMPTY.copy(revision = "a3b9c37a397ad4188041dd80621bdeefc46885f2")
9695
)
9796

98-
val packageFindings = osv.retrievePackageFindings(setOf(pkg)).mapKeys { it.key.id }
97+
val packageFindings = osv.retrievePackageFindings(setOf(pkg)).entries.associate {
98+
it.key.id to it.value.vulnerabilities
99+
}
99100

100-
val expectedResult = readResourceValue<Map<Identifier, AdvisorResult>>(
101+
val expectedResult = readResourceValue<Map<Identifier, List<Vulnerability>>>(
101102
"/hadoop-commit-has-expected-result.yml"
102103
)
103104

104-
packageFindings.patchTimes() shouldBe expectedResult.patchTimes()
105+
packageFindings shouldBe expectedResult
105106
}
106107
}
107108
})
108109

109110
private fun createOsv(): Osv = OsvFactory.create()
110-
111-
private fun Map<Identifier, AdvisorResult>.patchTimes(): Map<Identifier, AdvisorResult> =
112-
mapValues { (_, advisorResult) ->
113-
advisorResult.normalizeVulnerabilityData().copy(
114-
summary = advisorResult.summary.copy(
115-
startTime = Instant.EPOCH,
116-
endTime = Instant.EPOCH
117-
)
118-
)
119-
}
Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
11
---
22
':::':
3-
advisor:
4-
name: "OSV"
5-
summary:
6-
start_time: "2026-04-11T13:48:17.178933551Z"
7-
end_time: "2026-04-11T13:48:18.413494698Z"
8-
vulnerabilities:
9-
- id: "CVE-2022-26612"
10-
description: "In Apache Hadoop, The unTar function uses unTarUsingJava function\
11-
\ on Windows and the built-in tar utility on Unix and other OSes. As a result,\
12-
\ a TAR entry may create a symlink under the expected extraction directory which\
13-
\ points to an external directory. A subsequent TAR entry may extract an arbitrary\
14-
\ file into the external directory using the symlink name. This however would\
15-
\ be caught by the same targetDirPath check on Unix because of the getCanonicalPath\
16-
\ call. However on Windows, getCanonicalPath doesn't resolve symbolic links,\
17-
\ which bypasses the check. unpackEntries during TAR extraction follows symbolic\
18-
\ links which allows writing outside expected base directory on Windows. This\
19-
\ was addressed in Apache Hadoop 3.2.3"
20-
references:
21-
- url: "https://security.netapp.com/advisory/ntap-20220519-0004/"
22-
scoring_system: "CVSS_V3"
23-
severity: null
24-
score: null
25-
vector: "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H"
26-
- url: "https://lists.apache.org/thread/hslo7wzw2449gv1jyjk8g6ttd7935fyz"
27-
scoring_system: "CVSS_V3"
28-
severity: null
29-
score: null
30-
vector: "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H"
3+
- id: "CVE-2022-26612"
4+
description: "In Apache Hadoop, The unTar function uses unTarUsingJava function\
5+
\ on Windows and the built-in tar utility on Unix and other OSes. As a result,\
6+
\ a TAR entry may create a symlink under the expected extraction directory which\
7+
\ points to an external directory. A subsequent TAR entry may extract an arbitrary\
8+
\ file into the external directory using the symlink name. This however would\
9+
\ be caught by the same targetDirPath check on Unix because of the getCanonicalPath\
10+
\ call. However on Windows, getCanonicalPath doesn't resolve symbolic links, which\
11+
\ bypasses the check. unpackEntries during TAR extraction follows symbolic links\
12+
\ which allows writing outside expected base directory on Windows. This was addressed\
13+
\ in Apache Hadoop 3.2.3"
14+
references:
15+
- url: "https://security.netapp.com/advisory/ntap-20220519-0004/"
16+
scoring_system: "CVSS_V3"
17+
severity: null
18+
score: null
19+
vector: "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H"
20+
- url: "https://lists.apache.org/thread/hslo7wzw2449gv1jyjk8g6ttd7935fyz"
21+
scoring_system: "CVSS_V3"
22+
severity: null
23+
score: null
24+
vector: "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H"

0 commit comments

Comments
 (0)