Skip to content

Commit

Permalink
test(VulnerableCode): Add a template test for the public instance
Browse files Browse the repository at this point in the history
The test is disabled unless an API key is added. This eases local
debugging of the service.

Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
  • Loading branch information
sschuberth committed Oct 31, 2023
1 parent 561ef19 commit b330f35
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions advisor/src/funTest/kotlin/VulnerableCodeFunTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2023 The ORT Project Authors (see <https://github.com/oss-review-toolkit/ort/blob/main/NOTICE>)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* License-Filename: LICENSE
*/

package org.ossreviewtoolkit.advisor

import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.collections.shouldContainAll

import org.ossreviewtoolkit.advisor.advisors.VulnerableCode
import org.ossreviewtoolkit.advisor.advisors.VulnerableCodeConfiguration
import org.ossreviewtoolkit.model.Identifier
import org.ossreviewtoolkit.model.Package
import org.ossreviewtoolkit.model.utils.toPurl

class VulnerableCodeFunTest : StringSpec({
// Enter an API key to enable the test.
val apiKey = ""

"Findings should be returned for a vulnerable package".config(enabledIf = { apiKey.isNotEmpty() }) {
val vc = VulnerableCode("VulnerableCode", VulnerableCodeConfiguration(apiKey = apiKey))
val id = Identifier("Maven:com.google.guava:guava:19.0")
val pkg = Package.EMPTY.copy(id, purl = id.toPurl())

val findings = vc.retrievePackageFindings(setOf(pkg))

findings.values.flatMap { it.vulnerabilities }.map { it.id } shouldContainAll setOf(
"CVE-2018-10237",
"CVE-2020-8908",
"CVE-2023-2976"
)
}
})

0 comments on commit b330f35

Please sign in to comment.