Skip to content

Commit 65d1071

Browse files
committed
test(scanoss): Add a functional test for the different instances
Choose between the `osskb.org` (free) and `scanoss.com` (commercial) instances based on the API key provided, if any. The test file was taken from [1] to match their example at [2]. The "-snippet" variant was created from that by stripping comments and only keeping a few functions. [1]: https://github.com/unoconv/unoconv/blob/0.8.2/unoconv [2]: https://www.softwaretransparency.org/osskb Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
1 parent 660946f commit 65d1071

6 files changed

Lines changed: 2019 additions & 0 deletions

File tree

plugins/scanners/scanoss/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ dependencies {
3939

4040
funTestApi(testFixtures(projects.scanner))
4141

42+
funTestImplementation(projects.utils.testUtils)
43+
4244
testImplementation(projects.utils.testUtils)
4345

4446
testImplementation(libs.mockk)
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright (C) 2026 The ORT Project Copyright Holders <https://github.com/oss-review-toolkit/ort/blob/main/NOTICE>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
* License-Filename: LICENSE
18+
*/
19+
20+
package org.ossreviewtoolkit.plugins.scanners.scanoss
21+
22+
import com.scanoss.rest.ScanApi
23+
24+
import io.kotest.core.spec.style.StringSpec
25+
import io.kotest.matchers.collections.beEmpty
26+
import io.kotest.matchers.collections.shouldBeSingleton
27+
import io.kotest.matchers.maps.shouldContainExactly
28+
import io.kotest.matchers.should
29+
import io.kotest.matchers.shouldBe
30+
31+
import org.ossreviewtoolkit.model.PackageType
32+
import org.ossreviewtoolkit.model.RepositoryProvenance
33+
import org.ossreviewtoolkit.model.TextLocation
34+
import org.ossreviewtoolkit.model.VcsInfo
35+
import org.ossreviewtoolkit.model.VcsType
36+
import org.ossreviewtoolkit.plugins.api.Secret
37+
import org.ossreviewtoolkit.scanner.ScanContext
38+
import org.ossreviewtoolkit.utils.spdx.toSpdx
39+
import org.ossreviewtoolkit.utils.test.extractResource
40+
41+
class ScanOssFunTest : StringSpec({
42+
val apiKey = System.getenv("SCANOSS_API_KEY")
43+
val scanner = if (apiKey != null) {
44+
ScanOssFactory.create(ScanApi.DEFAULT_BASE_URL2, Secret(apiKey))
45+
} else {
46+
ScanOssFactory.create()
47+
}
48+
49+
val scanContext = ScanContext(labels = emptyMap(), packageType = PackageType.PACKAGE)
50+
51+
"File matches contain the expected findings" {
52+
val unoconv = extractResource("/unoconv")
53+
54+
val summary = scanner.scanPath(unoconv, scanContext)
55+
56+
summary.licenseFindings.shouldBeSingleton {
57+
it.license shouldBe "GPL-2.0-only".toSpdx()
58+
it.score shouldBe 100.0f
59+
}
60+
61+
summary.snippetFindings should beEmpty()
62+
63+
// Copyrights (and vulnerabilities) are commercial features.
64+
if (apiKey != null) {
65+
summary.copyrightFindings.shouldBeSingleton {
66+
it.statement shouldBe "Copyright 2007-2010 Dag Wieers <dag@wieers.com>"
67+
}
68+
}
69+
}
70+
71+
"Snippet matches contain the expected findings" {
72+
val unoconv = extractResource("/unoconv-snippet")
73+
74+
val summary = scanner.scanPath(unoconv, scanContext)
75+
76+
summary.licenseFindings should beEmpty()
77+
summary.copyrightFindings should beEmpty()
78+
79+
summary.snippetFindings.shouldBeSingleton {
80+
it.snippets.shouldBeSingleton { snippet ->
81+
snippet.score shouldBe 95.0f
82+
snippet.location shouldBe TextLocation("unoconv-0.6/unoconv", 19, 186)
83+
snippet.provenance shouldBe RepositoryProvenance(
84+
vcsInfo = VcsInfo(VcsType.GIT, "https://github.com/unoconv/unoconv.git", ""),
85+
resolvedRevision = "."
86+
)
87+
snippet.purl shouldBe "pkg:github/unoconv/unoconv"
88+
snippet.license shouldBe "GPL-2.0-only".toSpdx()
89+
snippet.additionalData shouldContainExactly if (apiKey != null) {
90+
mapOf(
91+
"file_hash" to "38e743a8566d3df4a2dc4432f8d6b091",
92+
"file_url" to "https://api.scanoss.com/file_contents/38e743a8566d3df4a2dc4432f8d6b091",
93+
"source_hash" to "21f8df5092922255fd8b42be5e6b59a7"
94+
)
95+
} else {
96+
mapOf(
97+
"file_hash" to "38e743a8566d3df4a2dc4432f8d6b091",
98+
"file_url" to " ",
99+
"source_hash" to "21f8df5092922255fd8b42be5e6b59a7"
100+
)
101+
}
102+
}
103+
}
104+
}
105+
})

0 commit comments

Comments
 (0)