diff --git a/model/src/test/kotlin/IdentifierTest.kt b/model/src/test/kotlin/IdentifierTest.kt index 53631e36ca7e9..ec74a24082c42 100644 --- a/model/src/test/kotlin/IdentifierTest.kt +++ b/model/src/test/kotlin/IdentifierTest.kt @@ -25,12 +25,6 @@ import io.kotest.inspectors.forAll import io.kotest.matchers.maps.containExactly import io.kotest.matchers.should import io.kotest.matchers.shouldBe -import io.kotest.matchers.string.shouldNotContain -import io.kotest.matchers.string.shouldNotStartWith -import io.kotest.matchers.string.shouldStartWith - -import org.ossreviewtoolkit.model.utils.createPurl -import org.ossreviewtoolkit.model.utils.toPurl class IdentifierTest : WordSpec({ "String representations" should { @@ -124,93 +118,6 @@ class IdentifierTest : WordSpec({ } } - "purl representations" should { - "not suffix the scheme with '//'" { - val purl = Identifier("type", "namespace", "name", "version").toPurl() - - purl shouldStartWith "pkg:" - purl shouldNotStartWith "pkg://" - } - - "not percent-encode the type" { - val purl = Identifier("azAZ09.+-", "namespace", "name", "version").toPurl() - - purl shouldNotContain "%" - } - - "ignore case in type" { - val purl = Identifier("MaVeN", "namespace", "name", "version").toPurl() - - purl shouldBe purl.lowercase() - } - - "use the generic type if it is not a known package manager" { - val purl = Identifier("FooBar", "namespace", "name", "version").toPurl() - - purl shouldStartWith "pkg:generic" - } - - "not use '/' for empty namespaces" { - val purl = Identifier("generic", "", "name", "version").toPurl() - - purl shouldBe "pkg:generic/name@version" - } - - "percent-encode namespaces with segments" { - val purl = Identifier("generic", "name/space", "name", "version").toPurl() - - purl shouldBe "pkg:generic/name%2Fspace/name@version" - } - - "percent-encode the name" { - val purl = Identifier("generic", "namespace", "fancy name", "version").toPurl() - - purl shouldBe "pkg:generic/namespace/fancy%20name@version" - } - - "percent-encode the version" { - val purl = Identifier("generic", "namespace", "name", "release candidate").toPurl() - - purl shouldBe "pkg:generic/namespace/name@release%20candidate" - } - - "allow qualifiers" { - val purl = createPurl( - "type", - "namespace", - "name", - "version", - mapOf("argName" to "argValue") - ) - - purl shouldBe "pkg:type/namespace/name@version?argName=argValue" - } - - "allow multiple qualifiers" { - val purl = createPurl( - "type", - "namespace", - "name", - "version", - mapOf("argName1" to "argValue1", "argName2" to "argValue2") - ) - - purl shouldBe "pkg:type/namespace/name@version?argName1=argValue1&argName2=argValue2" - } - - "allow subpath" { - val purl = createPurl( - "type", - "namespace", - "name", - "version", - subpath = "value1/value2" - ) - - purl shouldBe "pkg:type/namespace/name@version#value1/value2" - } - } - "Checking the organization" should { "work as expected" { assertSoftly { diff --git a/model/src/test/kotlin/utils/PurlExtensionsTest.kt b/model/src/test/kotlin/utils/PurlExtensionsTest.kt index 0daeddae96ecf..d496066b38f63 100644 --- a/model/src/test/kotlin/utils/PurlExtensionsTest.kt +++ b/model/src/test/kotlin/utils/PurlExtensionsTest.kt @@ -21,6 +21,9 @@ package org.ossreviewtoolkit.model.utils import io.kotest.core.spec.style.WordSpec import io.kotest.matchers.shouldBe +import io.kotest.matchers.string.shouldNotContain +import io.kotest.matchers.string.shouldNotStartWith +import io.kotest.matchers.string.shouldStartWith import org.ossreviewtoolkit.model.ArtifactProvenance import org.ossreviewtoolkit.model.Hash @@ -33,6 +36,93 @@ import org.ossreviewtoolkit.model.VcsInfo import org.ossreviewtoolkit.model.VcsType class PurlExtensionsTest : WordSpec({ + "purl representations" should { + "not suffix the scheme with '//'" { + val purl = Identifier("type", "namespace", "name", "version").toPurl() + + purl shouldStartWith "pkg:" + purl shouldNotStartWith "pkg://" + } + + "not percent-encode the type" { + val purl = Identifier("azAZ09.+-", "namespace", "name", "version").toPurl() + + purl shouldNotContain "%" + } + + "ignore case in type" { + val purl = Identifier("MaVeN", "namespace", "name", "version").toPurl() + + purl shouldBe purl.lowercase() + } + + "use the generic type if it is not a known package manager" { + val purl = Identifier("FooBar", "namespace", "name", "version").toPurl() + + purl shouldStartWith "pkg:generic" + } + + "not use '/' for empty namespaces" { + val purl = Identifier("generic", "", "name", "version").toPurl() + + purl shouldBe "pkg:generic/name@version" + } + + "percent-encode namespaces with segments" { + val purl = Identifier("generic", "name/space", "name", "version").toPurl() + + purl shouldBe "pkg:generic/name%2Fspace/name@version" + } + + "percent-encode the name" { + val purl = Identifier("generic", "namespace", "fancy name", "version").toPurl() + + purl shouldBe "pkg:generic/namespace/fancy%20name@version" + } + + "percent-encode the version" { + val purl = Identifier("generic", "namespace", "name", "release candidate").toPurl() + + purl shouldBe "pkg:generic/namespace/name@release%20candidate" + } + + "allow qualifiers" { + val purl = createPurl( + "type", + "namespace", + "name", + "version", + mapOf("argName" to "argValue") + ) + + purl shouldBe "pkg:type/namespace/name@version?argName=argValue" + } + + "allow multiple qualifiers" { + val purl = createPurl( + "type", + "namespace", + "name", + "version", + mapOf("argName1" to "argValue1", "argName2" to "argValue2") + ) + + purl shouldBe "pkg:type/namespace/name@version?argName1=argValue1&argName2=argValue2" + } + + "allow subpath" { + val purl = createPurl( + "type", + "namespace", + "name", + "version", + subpath = "value1/value2" + ) + + purl shouldBe "pkg:type/namespace/name@version#value1/value2" + } + } + "Provenance conversion" should { "work for extras of an artifact's provenance" { val provenance = ArtifactProvenance(