83 lines
3.3 KiB
Python
83 lines
3.3 KiB
Python
# #region Test.CleanRelease.ManifestBuilder [C:3] [TYPE Module] [SEMANTICS test,clean-release,manifest,builder]
|
|
# @BRIEF Tests for manifest_builder.py — build_distribution_manifest and build_manifest legacy wrapper.
|
|
# @RELATION BINDS_TO -> [ManifestBuilder]
|
|
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent.parent.parent.parent / "src"))
|
|
|
|
import pytest
|
|
|
|
|
|
# #region TestBuildDistributionManifest [C:2] [TYPE Module]
|
|
class TestBuildDistributionManifest:
|
|
def test_builds_manifest(self):
|
|
from src.services.clean_release.manifest_builder import build_distribution_manifest
|
|
artifacts = [
|
|
{"path": "bin/app", "category": "app", "classification": "allowed", "reason": "test", "checksum": "abc"},
|
|
{"path": "lib/vuln.dll", "category": "malware", "classification": "excluded-prohibited", "reason": "blocked", "checksum": "def"},
|
|
]
|
|
manifest = build_distribution_manifest(
|
|
manifest_id="man-1",
|
|
candidate_id="cand-1",
|
|
policy_id="policy-1",
|
|
generated_by="tester",
|
|
artifacts=artifacts,
|
|
)
|
|
assert manifest.manifest_id == "man-1"
|
|
assert manifest.candidate_id == "cand-1"
|
|
assert len(manifest.content_json.get("items", [])) == 2
|
|
assert manifest.summary.included_count == 1
|
|
assert manifest.summary.excluded_count == 1
|
|
assert manifest.summary.prohibited_detected_count == 1
|
|
assert manifest.deterministic_hash is not None
|
|
|
|
def test_builds_manifest_without_checksum(self):
|
|
from src.services.clean_release.manifest_builder import build_distribution_manifest
|
|
artifacts = [
|
|
{"path": "bin/app", "category": "app", "classification": "required-system", "reason": "system"},
|
|
]
|
|
manifest = build_distribution_manifest(
|
|
manifest_id="man-2",
|
|
candidate_id="cand-2",
|
|
policy_id="policy-2",
|
|
generated_by="tester",
|
|
artifacts=artifacts,
|
|
)
|
|
items = manifest.content_json.get("items", [])
|
|
assert len(items) == 1
|
|
assert items[0].get("checksum") is None
|
|
assert manifest.summary.included_count == 1
|
|
assert manifest.summary.excluded_count == 0
|
|
|
|
|
|
# #endregion TestBuildDistributionManifest
|
|
|
|
|
|
# #region TestBuildManifestLegacy [C:2] [TYPE Module]
|
|
class TestBuildManifestLegacy:
|
|
def test_build_manifest_legacy_delegates(self):
|
|
"""build_manifest legacy wrapper (line 129) delegates to build_distribution_manifest."""
|
|
from src.services.clean_release.manifest_builder import build_distribution_manifest, build_manifest
|
|
artifacts = [
|
|
{"path": "bin/app", "category": "app", "classification": "allowed", "reason": "test", "checksum": "abc"},
|
|
]
|
|
m1 = build_distribution_manifest(
|
|
manifest_id="man-3", candidate_id="cand-3",
|
|
policy_id="policy-3", generated_by="tester",
|
|
artifacts=artifacts,
|
|
)
|
|
m2 = build_manifest(
|
|
manifest_id="man-3", candidate_id="cand-3",
|
|
policy_id="policy-3", generated_by="tester",
|
|
artifacts=artifacts,
|
|
)
|
|
assert m1.manifest_id == m2.manifest_id
|
|
assert m1.deterministic_hash == m2.deterministic_hash
|
|
|
|
|
|
# #endregion TestBuildManifestLegacy
|
|
|
|
# #endregion Test.CleanRelease.ManifestBuilder
|