-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(VulnerableCode): Add a template test for the public instance
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
1 parent
561ef19
commit b330f35
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
) | ||
} | ||
}) |