Skip to content

Commit

Permalink
Document current license SPDX behaviour
Browse files Browse the repository at this point in the history
As a step towards resolving npm#6966, we should document how SPDX SBOM
generation works with a single string license or license expression.
  • Loading branch information
jamietanna committed Nov 6, 2023
1 parent e91d5c6 commit 002be85
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
90 changes: 90 additions & 0 deletions tap-snapshots/test/lib/utils/sbom-spdx.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -504,3 +504,93 @@ exports[`test/lib/utils/sbom-spdx.js TAP single node - with integrity > must mat
]
}
`

exports[`test/lib/utils/sbom-spdx.js TAP single node - with license expression > must match snapshot 1`] = `
{
"spdxVersion": "SPDX-2.3",
"dataLicense": "CC0-1.0",
"SPDXID": "SPDXRef-DOCUMENT",
"name": "[email protected]",
"documentNamespace": "docns",
"creationInfo": {
"created": "2020-01-01T00:00:00.000Z",
"creators": [
"Tool: npm/cli-10.0.0 "
]
},
"documentDescribes": [
"SPDXRef-Package-root-1.0.0"
],
"packages": [
{
"name": "root",
"SPDXID": "SPDXRef-Package-root-1.0.0",
"versionInfo": "1.0.0",
"packageFileName": "",
"downloadLocation": "NOASSERTION",
"filesAnalyzed": false,
"homepage": "NOASSERTION",
"licenseDeclared": "(MIT OR Apache-2.0)",
"externalRefs": [
{
"referenceCategory": "PACKAGE-MANAGER",
"referenceType": "purl",
"referenceLocator": "pkg:npm/[email protected]"
}
]
}
],
"relationships": [
{
"spdxElementId": "SPDXRef-DOCUMENT",
"relatedSpdxElement": "SPDXRef-Package-root-1.0.0",
"relationshipType": "DESCRIBES"
}
]
}
`

exports[`test/lib/utils/sbom-spdx.js TAP single node - with single license > must match snapshot 1`] = `
{
"spdxVersion": "SPDX-2.3",
"dataLicense": "CC0-1.0",
"SPDXID": "SPDXRef-DOCUMENT",
"name": "[email protected]",
"documentNamespace": "docns",
"creationInfo": {
"created": "2020-01-01T00:00:00.000Z",
"creators": [
"Tool: npm/cli-10.0.0 "
]
},
"documentDescribes": [
"SPDXRef-Package-root-1.0.0"
],
"packages": [
{
"name": "root",
"SPDXID": "SPDXRef-Package-root-1.0.0",
"versionInfo": "1.0.0",
"packageFileName": "",
"downloadLocation": "NOASSERTION",
"filesAnalyzed": false,
"homepage": "NOASSERTION",
"licenseDeclared": "ISC",
"externalRefs": [
{
"referenceCategory": "PACKAGE-MANAGER",
"referenceType": "purl",
"referenceLocator": "pkg:npm/[email protected]"
}
]
}
],
"relationships": [
{
"spdxElementId": "SPDXRef-DOCUMENT",
"relatedSpdxElement": "SPDXRef-Package-root-1.0.0",
"relationshipType": "DESCRIBES"
}
]
}
`
16 changes: 16 additions & 0 deletions test/lib/utils/sbom-spdx.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ t.test('single node - application package type', t => {
t.end()
})

t.test('single node - with single license', t => {
const pkg = { ...rootPkg, license: 'ISC' }
const node = { ...root, package: pkg }
const res = spdxOutput({ npm, nodes: [node] })
t.matchSnapshot(JSON.stringify(res))
t.end()
})

t.test('single node - with license expression', t => {
const pkg = { ...rootPkg, license: '(MIT OR Apache-2.0)' }
const node = { ...root, package: pkg }
const res = spdxOutput({ npm, nodes: [node] })
t.matchSnapshot(JSON.stringify(res))
t.end()
})

t.test('single node - with description', t => {
const pkg = { ...rootPkg, description: 'Package description' }
const node = { ...root, package: pkg }
Expand Down

0 comments on commit 002be85

Please sign in to comment.