@@ -36,18 +36,21 @@ import io.kotest.matchers.collections.beEmpty
36
36
import io.kotest.matchers.collections.containExactly
37
37
import io.kotest.matchers.collections.containExactlyInAnyOrder
38
38
import io.kotest.matchers.collections.shouldHaveSize
39
- import io.kotest.matchers.nulls.shouldNotBeNull
39
+ import io.kotest.matchers.maps.shouldNotBeEmpty
40
40
import io.kotest.matchers.should
41
41
import io.kotest.matchers.shouldBe
42
42
43
43
import java.io.File
44
44
import java.net.URI
45
45
46
+ import kotlinx.coroutines.runBlocking
47
+
46
48
import org.ossreviewtoolkit.model.Identifier
49
+ import org.ossreviewtoolkit.model.OrtResult
47
50
import org.ossreviewtoolkit.model.Severity
48
51
import org.ossreviewtoolkit.model.Vulnerability
49
- import org.ossreviewtoolkit.model.config.AdvisorConfiguration
50
52
import org.ossreviewtoolkit.model.config.VulnerableCodeConfiguration
53
+ import org.ossreviewtoolkit.model.readValue
51
54
import org.ossreviewtoolkit.model.utils.toPurl
52
55
import org.ossreviewtoolkit.utils.test.shouldNotBeNull
53
56
@@ -71,7 +74,7 @@ class VulnerableCodeTest : WordSpec({
71
74
wiremock.resetAll()
72
75
}
73
76
74
- " VulnerabilityCode " should {
77
+ " VulnerableCode " should {
75
78
" return vulnerability information" {
76
79
stubFor(
77
80
post(urlPathEqualTo("/api/packages/bulk_search"))
@@ -87,10 +90,12 @@ class VulnerableCodeTest : WordSpec({
87
90
stubVulnerability("v2", "CVE -2009-1382", 11.0f)
88
91
stubVulnerability("v3", "CVE -2019-CoV19 ", 77.0f)
89
92
90
- val advisor = createAdvisor(wiremock)
91
- val result = advisor.retrieveVulnerabilityInformation(resultFile()).advisor?.results?.advisorResults
93
+ val vulnerableCode = createVulnerableCode(wiremock)
94
+ val packagesToAdvise = resultFile().readValue<OrtResult >().getPackages(false).map { it.pkg }
95
+
96
+ val result = vulnerableCode.retrievePackageVulnerabilities(packagesToAdvise).mapKeys { it.key.id }
92
97
93
- result.shouldNotBeNull ()
98
+ result.shouldNotBeEmpty ()
94
99
result.keys should containExactlyInAnyOrder(idLang, idStruts)
95
100
96
101
val langResults = result.getValue(idLang)
@@ -141,8 +146,10 @@ class VulnerableCodeTest : WordSpec({
141
146
)
142
147
)
143
148
144
- val advisor = createAdvisor(wiremock)
145
- advisor.retrieveVulnerabilityInformation(resultFile()).advisor?.results?.advisorResults shouldNotBeNull {
149
+ val vulnerableCode = createVulnerableCode(wiremock)
150
+ val packagesToAdvise = resultFile().readValue<OrtResult >().getPackages(false).map { it.pkg }
151
+
152
+ vulnerableCode.retrievePackageVulnerabilities(packagesToAdvise).mapKeys { it.key.id } shouldNotBeNull {
146
153
val strutsResults = getValue(idStruts)
147
154
val expStrutsVulnerabilities = listOf(
148
155
Vulnerability (
@@ -211,7 +218,7 @@ private val idHamcrest = Identifier("Maven:org.hamcrest:hamcrest-core:1.3")
211
218
private val packageIdentifiers = listOf (idJUnit, idLang, idText, idStruts, idHamcrest)
212
219
213
220
/* *
214
- * The list of packages referenced by the test result. These packages should be requested by the advisor .
221
+ * The list of packages referenced by the test result. These packages should be requested by the vulnerability provider .
215
222
*/
216
223
private val packages = packageIdentifiers.map { it.toPurl() }
217
224
@@ -227,12 +234,16 @@ private val packagesRequestJson = generateListRequest(packages, "packages")
227
234
private val vulnerabilityDetailsTemplate = File (TEST_FILES_ROOT ).resolve(VULNERABILITY_TEMPLATE ).readText()
228
235
229
236
/* *
230
- * Run a test with the VulnerabilityCode advisor against the given [test server][wiremock] and expect the
237
+ * Run a test with the VulnerabilityCode provider against the given [test server][wiremock] and expect the
231
238
* operation to fail. In this case, for all packages a result with an error issue should have been created.
232
239
*/
233
240
private fun expectErrorResult (wiremock : WireMockServer ) {
234
- val advisor = createAdvisor(wiremock)
235
- val result = advisor.retrieveVulnerabilityInformation(resultFile()).advisor?.results?.advisorResults
241
+ val vulnerableCode = createVulnerableCode(wiremock)
242
+ val packagesToAdvise = resultFile().readValue<OrtResult >().getPackages(false ).map { it.pkg }
243
+
244
+ val result = runBlocking {
245
+ vulnerableCode.retrievePackageVulnerabilities(packagesToAdvise).mapKeys { it.key.id }
246
+ }
236
247
237
248
result shouldNotBeNull {
238
249
keys should containExactly(packageIdentifiers)
@@ -250,17 +261,17 @@ private fun expectErrorResult(wiremock: WireMockServer) {
250
261
}
251
262
252
263
/* *
253
- * Create a configuration for the [VulnerableCode] advisor that points to the local [wireMockServer].
264
+ * Create a configuration for the [VulnerableCode] vulnerability provider that points to the local [wireMockServer].
254
265
*/
255
- private fun createConfig (wireMockServer : WireMockServer ): AdvisorConfiguration {
266
+ private fun createConfig (wireMockServer : WireMockServer ): VulnerableCodeConfiguration {
256
267
val url = " http://localhost:${wireMockServer.port()} "
257
- return AdvisorConfiguration (vulnerableCode = VulnerableCodeConfiguration (url) )
268
+ return VulnerableCodeConfiguration (url)
258
269
}
259
270
260
271
/* *
261
- * Create a test advisor instance that communicates with the local [wireMockServer].
272
+ * Create a test instance of [VulnerableCode] that communicates with the local [wireMockServer].
262
273
*/
263
- private fun createAdvisor (wireMockServer : WireMockServer ): VulnerableCode =
274
+ private fun createVulnerableCode (wireMockServer : WireMockServer ): VulnerableCode =
264
275
VulnerableCode (ADVISOR_NAME , createConfig(wireMockServer))
265
276
266
277
/* *
0 commit comments