Skip to content

Commit 6feeb20

Browse files
committed
fix(extensions): reject a declared-but-empty sha256 instead of skipping verification
verify_archive_sha256 skipped on any falsy expected value, so a present-but-empty digest (e.g. sha256: "" reached via ...get("sha256")) silently disabled the integrity check instead of surfacing the authoring error. Guard on expected is None so only an absent digest skips; blank/whitespace/bare-prefix values fall through to the 64-hex validation and are rejected. Adds a regression test. Signed-off-by: Zied Jlassi <6190550+zied-jlassi@users.noreply.github.com>
1 parent 08225d6 commit 6feeb20

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/specify_cli/shared_infra.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ def verify_archive_sha256(
4545
error_cls: If ``expected`` is provided and is not a well-formed
4646
SHA-256 hex digest, or does not match ``data``.
4747
"""
48-
if not expected:
48+
# Skip only when no digest is declared at all (``None``). A declared but
49+
# empty/blank value (e.g. ``sha256: ""``) is an authoring error, not an
50+
# opt-out: let it fall through to the format check below so it is rejected
51+
# rather than silently disabling verification.
52+
if expected is None:
4953
logger.debug(
5054
"No sha256 declared for %r; archive integrity was not verified.",
5155
name,

tests/test_shared_infra_integrity.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,17 @@ def test_absent_digest_skips_and_logs_debug(caplog):
8585
"not verified" in r.getMessage() and "thing" in r.getMessage()
8686
for r in caplog.records
8787
)
88+
89+
90+
def test_blank_declared_digest_is_rejected():
91+
"""A present-but-empty ``sha256`` is an authoring error, not an opt-out.
92+
93+
Catalog entries reach the helper via ``...get("sha256")``; a blank value
94+
(``""``, whitespace, or a bare ``sha256:`` prefix) means the digest was
95+
declared but left empty. It must surface as a malformed digest rather than
96+
silently disabling the integrity check, which a bare ``if not expected``
97+
guard would have done.
98+
"""
99+
for blank in ("", " ", "sha256:"):
100+
with pytest.raises(_BoomError, match="[Ii]nvalid sha256"):
101+
verify_archive_sha256(b"data", blank, "thing", _BoomError)

0 commit comments

Comments
 (0)