Skip to content
Snippets Groups Projects
Commit 44879ab5 authored by vlorentz's avatar vlorentz
Browse files

npm, maven: ignore blatantly invalid licenses

They cause noisy logs
parent b056d431
No related branches found
No related tags found
1 merge request!382npm, maven: ignore blatantly invalid licenses
...@@ -75,6 +75,9 @@ class MavenMapping(XmlMapping, SingleFileIntrinsicMapping): ...@@ -75,6 +75,9 @@ class MavenMapping(XmlMapping, SingleFileIntrinsicMapping):
and isinstance(artifact_id, str) and isinstance(artifact_id, str)
): ):
repo = os.path.join(url, *group_id.split("."), artifact_id) repo = os.path.join(url, *group_id.split("."), artifact_id)
if "${" in repo:
# Often use as templating in pom.xml files collected from VCSs
return
graph.add((root, SCHEMA.codeRepository, URIRef(repo))) graph.add((root, SCHEMA.codeRepository, URIRef(repo)))
def normalize_groupId(self, id_): def normalize_groupId(self, id_):
......
...@@ -270,6 +270,12 @@ class NpmMapping(JsonMapping, SingleFileIntrinsicMapping): ...@@ -270,6 +270,12 @@ class NpmMapping(JsonMapping, SingleFileIntrinsicMapping):
rdflib.term.URIRef('https://spdx.org/licenses/MIT') rdflib.term.URIRef('https://spdx.org/licenses/MIT')
""" """
if isinstance(s, str): if isinstance(s, str):
if s.startswith("SEE LICENSE IN "):
# Very common pattern, because it is an example in the specification.
# It is followed by the filename; and the indexer architecture currently
# does not allow accessing that from metadata mappings.
# (Plus, an hypothetical license mapping would eventually pick it up)
return
return SPDX + s return SPDX + s
def normalize_keywords(self, lst): def normalize_keywords(self, lst):
......
...@@ -353,6 +353,47 @@ def test_compute_metadata_maven_multiple(): ...@@ -353,6 +353,47 @@ def test_compute_metadata_maven_multiple():
} }
def test_compute_metadata_maven_invalid_repository():
raw_content = b"""
<project>
<name>Maven Default Project</name>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.2.3</version>
<repositories>
<repository>
<id>tcc-transaction-internal-releases</id>
<name>internal repository for released artifacts</name>
<url>${repo.internal.releases.url}</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
<comments>A business-friendly OSS license</comments>
</license>
</licenses>
</project>"""
result = MAPPINGS["MavenMapping"]().translate(raw_content)
assert result == {
"@context": "https://doi.org/10.5063/schema/codemeta-2.0",
"type": "SoftwareSourceCode",
"name": "Maven Default Project",
"schema:identifier": "com.mycompany.app",
"version": "1.2.3",
"license": "https://www.apache.org/licenses/LICENSE-2.0.txt",
}
@settings(suppress_health_check=[HealthCheck.too_slow]) @settings(suppress_health_check=[HealthCheck.too_slow])
@given( @given(
xml_document_strategy( xml_document_strategy(
......
...@@ -361,6 +361,24 @@ def test_npm_invalid_uris(): ...@@ -361,6 +361,24 @@ def test_npm_invalid_uris():
} }
def test_npm_invalid_licenses():
package_json = rb"""{
"version": "1.0.0",
"license": "SEE LICENSE IN LICENSE.md",
"author": {
"name": "foo",
"url": "http://example.org"
}
}"""
result = MAPPINGS["NpmMapping"]().translate(package_json)
assert result == {
"@context": "https://doi.org/10.5063/schema/codemeta-2.0",
"type": "SoftwareSourceCode",
"author": [{"name": "foo", "type": "Person", "url": "http://example.org"}],
"version": "1.0.0",
}
@settings(suppress_health_check=[HealthCheck.too_slow]) @settings(suppress_health_check=[HealthCheck.too_slow])
@given(json_document_strategy(keys=list(MAPPINGS["NpmMapping"].mapping))) # type: ignore @given(json_document_strategy(keys=list(MAPPINGS["NpmMapping"].mapping))) # type: ignore
def test_npm_adversarial(doc): def test_npm_adversarial(doc):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment