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.

tests/test_wiki_sbom.py:86

Show on the map →

Called by none

Calls _write, read_sbom

Checks

  • assert package == ("demo", "MIT")
  • assert components == [

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-051measuredtest_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
lines 88–88package, components = read_sbom(_write(tmp_path, "bom.cdx.json", _CDX))lines 89–89assert package == ("demo", "MIT")lines 90–92assert components == [ Component("left-pad", "1.3.0", "WTFPL", "library", "pkg:npm/left-pad@1.3.0", "SHA-256:cd34") ]

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.

tests/test_wiki_sbom.py:126

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

requirementlinkedpath to the implementer
REQ-DDB-GUARD-012measuredtest_a_malformed_sbom_section_is_refused_by_name → load_wiki_config → _requirements_section → read_requirements_section
REQ-DDB-WIKI-051catalog
REQ-DDB-WIKI-054inferredtest_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
lines 128–128from clew.wiki.config import load_wiki_configlines 130–130(tmp_path / ".clew.yaml").write_text("wiki:\n sbom: {files: sbom.json}\n")lines 131–131config, problems = load_wiki_config(tmp_path, None)lines 132–135assert any("wiki.sbom.files" in p for p in problems) and config.sbom_files == ( "sbom.spdx.json", "bom.cdx.json", )

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.

tests/test_wiki_sbom.py:76

Show on the map →

Called by none

Calls _write, read_sbom

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

requirementlinkedpath to the implementer
REQ-DDB-WIKI-051measuredtest_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
lines 78–78package, components = read_sbom(_write(tmp_path, "sbom.spdx.json", _SPDX))lines 79–79assert package == ("demo", "MIT")lines 80–82assert components[0] == Component( "zlib", "1.3.1", "Zlib", "library", "https://example.invalid/zlib.tar.gz", "SHA256:ab12" )lines 83–83assert components[1].licence == "NOASSERTION" and components[1].kind == "file"

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.

tests/test_wiki_sbom.py:95

Show on the map →

Called by none

Calls _write, read_sbom, sbom_html

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

requirementlinkedpath to the implementer
REQ-DDB-WIKI-051measuredtest_noassertion_and_unaccepted_licences_are_flagged → read_sbom
REQ-DDB-WIKI-054inferredtest_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
lines 97–97spdx = read_sbom(_write(tmp_path, "sbom.spdx.json", _SPDX))lines 98–98cdx = read_sbom(_write(tmp_path, "bom.cdx.json", _CDX))lines 99–99html = sbom_html([("sbom.spdx.json", *spdx), ("bom.cdx.json", *cdx)], ("MIT", "Zlib"), {}, 0)lines 100–103rows = { name: html.split(f"<code>{name}</code>", 1)[1].split("</tr>", 1)[0] for name in ("zlib", "weights", "left-pad") }lines 104–104assert 'class="flag' not in rows["zlib"]lines 105–105assert 'class="flag noassertion"' in rows["weights"]lines 106–106assert 'class="flag unaccepted"' in rows["left-pad"]

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.

tests/test_wiki_sbom.py:116

Show on the map →

Called by none

Calls sbom_html

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

requirementlinkedpath to the implementer
REQ-DDB-WIKI-051measuredtest_the_repositorys_files_licences_are_summarised → sbom_html
REQ-DDB-WIKI-054inferredtest_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
lines 118–118html = sbom_html([], (), {"MIT": 40, "Apache-2.0": 2}, 7)lines 119–119files = html.split('<section class="file-licences">', 1)[1]lines 120–122assert ( "MIT" in files and ">40<" in files and "7 indexed files carry no SPDX identifier" in files )lines 123–123assert "No SBOM" in html

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.

tests/test_wiki_sbom.py:109

Show on the map →

Called by none

Calls sbom_html

Checks

  • assert 'class="flag unaccepted"' not in html and "No accepted-licence list" in html

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-051measuredtest_without_an_accepted_list_nothing_is_called_unaccepted → sbom_html
REQ-DDB-WIKI-054inferredtest_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

Activity · 3 steps
lines 111–111comps = [Component("left-pad", "1.3.0", "WTFPL", "library", "", "")]lines 112–112html = sbom_html([("bom.cdx.json", ("demo", "MIT"), comps)], (), {}, 0)lines 113–113assert 'class="flag unaccepted"' not in html and "No accepted-licence list" in html