test_wiki_sbom.py¶
tests/test_wiki_sbom.py
The SBOM page: the repository's own SBOM rendered, beside its files' licences (#70, P5.8).
test_a_cyclonedx_sbom_reads_the_same_shape
None test_wiki_sbom.test_a_cyclonedx_sbom_reads_the_same_shape(tmp_path)
CycloneDX JSON: metadata's component, components with expression licences and purls.
Checks
assert package == ("demo", "MIT")assert components == [
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-WIKI-051 | measured | test_a_cyclonedx_sbom_reads_the_same_shape → read_sbom |
Source · 9 lines
def test_a_cyclonedx_sbom_reads_the_same_shape(tmp_path) -> None:
"""@brief CycloneDX JSON: metadata's component, components with expression licences and purls."""
package, components = read_sbom(_write(tmp_path, "bom.cdx.json", _CDX))
assert package == ("demo", "MIT")
assert components == [
Component("left-pad", "1.3.0", "WTFPL", "library", "pkg:npm/left-pad@1.3.0", "SHA-256:cd34")
]
Activity · 3 steps
test_a_malformed_sbom_section_is_refused_by_name
None test_wiki_sbom.test_a_malformed_sbom_section_is_refused_by_name(tmp_path)
`files: sbom.json` (a string, not a list) is a problem naming the key.
Checks
assert any("wiki.sbom.files" in p for p in problems) and config.sbom_files == ("sbom.spdx.json", "bom.cdx.json", )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-012 | measured | test_a_malformed_sbom_section_is_refused_by_name → load_wiki_config → _requirements_section → read_requirements_section |
| REQ-DDB-WIKI-051 | catalog | |
| REQ-DDB-WIKI-054 | inferred | test_a_malformed_sbom_section_is_refused_by_name → load_wiki_config → _comments → all |
Source · 10 lines
def test_a_malformed_sbom_section_is_refused_by_name(tmp_path) -> None:
"""@brief `files: sbom.json` (a string, not a list) is a problem naming the key."""
from clew.wiki.config import load_wiki_config
(tmp_path / ".clew.yaml").write_text("wiki:\n sbom: {files: sbom.json}\n")
config, problems = load_wiki_config(tmp_path, None)
assert any("wiki.sbom.files" in p for p in problems) and config.sbom_files == (
"sbom.spdx.json",
"bom.cdx.json",
)1 more lines, not shown
Activity · 4 steps
test_an_spdx_sbom_reads_its_package_and_components
None test_wiki_sbom.test_an_spdx_sbom_reads_its_package_and_components(tmp_path)
SPDX 2.3: the described package's licence, and every other package a component.
Checks
assert package == ("demo", "MIT")assert components[0] == Component("zlib", "1.3.1", "Zlib", "library", "https://example.invalid/zlib.tar.gz", "SHA256:ab12" )assert components[1].licence == "NOASSERTION" and components[1].kind == "file"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-WIKI-051 | measured | test_an_spdx_sbom_reads_its_package_and_components → read_sbom |
Source · 10 lines
def test_an_spdx_sbom_reads_its_package_and_components(tmp_path) -> None:
"""@brief SPDX 2.3: the described package's licence, and every other package a component."""
package, components = read_sbom(_write(tmp_path, "sbom.spdx.json", _SPDX))
assert package == ("demo", "MIT")
assert components[0] == Component(
"zlib", "1.3.1", "Zlib", "library", "https://example.invalid/zlib.tar.gz", "SHA256:ab12"
)
assert components[1].licence == "NOASSERTION" and components[1].kind == "file"
Activity · 4 steps
test_noassertion_and_unaccepted_licences_are_flagged
None test_wiki_sbom.test_noassertion_and_unaccepted_licences_are_flagged(tmp_path)
Against the accepted list: Zlib passes, NOASSERTION and WTFPL are flagged.
Checks
assert 'class="flag' not in rows["zlib"]assert 'class="flag noassertion"' in rows["weights"]assert 'class="flag unaccepted"' in rows["left-pad"]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-WIKI-051 | measured | test_noassertion_and_unaccepted_licences_are_flagged → read_sbom |
| REQ-DDB-WIKI-054 | inferred | test_noassertion_and_unaccepted_licences_are_flagged → sbom_html → _row → _accepted → all |
Source · 14 lines
def test_noassertion_and_unaccepted_licences_are_flagged(tmp_path) -> None:
"""@brief Against the accepted list: Zlib passes, NOASSERTION and WTFPL are flagged."""
spdx = read_sbom(_write(tmp_path, "sbom.spdx.json", _SPDX))
cdx = read_sbom(_write(tmp_path, "bom.cdx.json", _CDX))
html = sbom_html([("sbom.spdx.json", *spdx), ("bom.cdx.json", *cdx)], ("MIT", "Zlib"), {}, 0)
rows = {
name: html.split(f"<code>{name}</code>", 1)[1].split("</tr>", 1)[0]
for name in ("zlib", "weights", "left-pad")
}
assert 'class="flag' not in rows["zlib"]
assert 'class="flag noassertion"' in rows["weights"]
assert 'class="flag unaccepted"' in rows["left-pad"]
Activity · 7 steps
test_the_repositorys_files_licences_are_summarised
None test_wiki_sbom.test_the_repositorys_files_licences_are_summarised()
S5: counts by licence, and how many indexed files carry no identifier.
Checks
assert ("MIT" in files and ">40<" in files and "7 indexed files carry no SPDX identifier" in files )assert "No SBOM" in html
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-WIKI-051 | measured | test_the_repositorys_files_licences_are_summarised → sbom_html |
| REQ-DDB-WIKI-054 | inferred | test_the_repositorys_files_licences_are_summarised → sbom_html → _row → _accepted → all |
Source · 10 lines
def test_the_repositorys_files_licences_are_summarised() -> None:
"""@brief S5: counts by licence, and how many indexed files carry no identifier."""
html = sbom_html([], (), {"MIT": 40, "Apache-2.0": 2}, 7)
files = html.split('<section class="file-licences">', 1)[1]
assert (
"MIT" in files and ">40<" in files and "7 indexed files carry no SPDX identifier" in files
)
assert "No SBOM" in html
Activity · 4 steps
test_without_an_accepted_list_nothing_is_called_unaccepted
None test_wiki_sbom.test_without_an_accepted_list_nothing_is_called_unaccepted()
No policy declared: NOASSERTION still flagged, "not accepted" never claimed, and said.
Checks
assert 'class="flag unaccepted"' not in html and "No accepted-licence list" in html
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-WIKI-051 | measured | test_without_an_accepted_list_nothing_is_called_unaccepted → sbom_html |
| REQ-DDB-WIKI-054 | inferred | test_without_an_accepted_list_nothing_is_called_unaccepted → sbom_html → _row → _accepted → all |
Source · 7 lines
def test_without_an_accepted_list_nothing_is_called_unaccepted() -> None:
"""@brief No policy declared: NOASSERTION still flagged, "not accepted" never claimed, and said."""
comps = [Component("left-pad", "1.3.0", "WTFPL", "library", "", "")]
html = sbom_html([("bom.cdx.json", ("demo", "MIT"), comps)], (), {}, 0)
assert 'class="flag unaccepted"' not in html and "No accepted-licence list" in html