test_repair_commit_signature_integrity.py
python
sha256:751c1b982a8fd7f58c1533afe636b781f965ed98ba7f9fc9dac1dfbcbfee1939
merge: integrate repair-commit signature verification into dev
Opus 5.5
patch
11 days ago
| 1 | """TDD: repair-commit must never store a signature that does not verify. |
| 2 | |
| 3 | ``wire_repair_commit`` checks that the submitted identity fields reproduce |
| 4 | ``commit_id`` and then force-overwrites ``signature`` / ``signer_public_key`` / |
| 5 | ``signer_key_id`` on the stored row. The signature is outside the commit id, so |
| 6 | the identity check says nothing about it: any well-formed value — garbage, a |
| 7 | stripped empty string, or a signature over a *different* commit id — is stored |
| 8 | under the unchanged id and re-served to every clone. |
| 9 | |
| 10 | That is the shape of staging ``gabriel/muse`` commit ``2f17e909``: its stored |
| 11 | signature is a valid Ed25519 signature by the commit's own key, but over the |
| 12 | v2 provenance payload of the commit's pre-migration id ``035b7539`` (a parent |
| 13 | cascade re-id carried the signature across without re-signing). Every fresh |
| 14 | clone fails ``muse verify`` on it. The repair endpoint is the only path that can |
| 15 | correct it, and today it would accept a wrong value just as readily as the right |
| 16 | one, silently replacing a verified record with an unverifiable one. |
| 17 | |
| 18 | Contract (RCS_01..RCS_14): the record exactly as it will be re-served after the |
| 19 | repair — submitted identity fields plus the row's own agent/model/toolchain/ |
| 20 | prompt fields — must carry a signature that verifies, or carry no signature at |
| 21 | all when the commit id binds no signer. Otherwise the repair is refused with |
| 22 | ``ObjectHashMismatch`` (422 at the route) before anything is written: no cache |
| 23 | invalidation, no prebuild job, no other row touched. A repair never changes the |
| 24 | stored structured_delta. |
| 25 | |
| 26 | All keys are synthetic, generated per test. |
| 27 | """ |
| 28 | from __future__ import annotations |
| 29 | |
| 30 | import hashlib |
| 31 | from datetime import datetime, timezone |
| 32 | |
| 33 | import pytest |
| 34 | from cryptography.exceptions import InvalidSignature |
| 35 | from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey, Ed25519PublicKey |
| 36 | from sqlalchemy.ext.asyncio import AsyncSession |
| 37 | |
| 38 | from muse.core.ids import hash_commit |
| 39 | from muse.core.provenance import encode_public_key, provenance_payload, sign_commit_ed25519 |
| 40 | from muse.core.types import decode_pubkey, decode_sig, public_key_fingerprint |
| 41 | from musehub.db.musehub_repo_models import MusehubCommit, MusehubCommitRef |
| 42 | from musehub.services.musehub_wire_push import wire_repair_commit |
| 43 | from musehub.services.musehub_wire_shared import ObjectHashMismatch, _to_wire_commit |
| 44 | from musehub.types.json_types import JSONObject |
| 45 | from tests.factories import create_repo |
| 46 | |
| 47 | OWNER = "gabriel" |
| 48 | AGENT = "claude-code" |
| 49 | MODEL = "claude-sonnet-4-6" |
| 50 | SNAPSHOT = "sha256:" + hashlib.sha256(b"rcs-snapshot").hexdigest() |
| 51 | PARENT = "sha256:" + hashlib.sha256(b"rcs-parent").hexdigest() |
| 52 | OLD_PARENT = "sha256:" + hashlib.sha256(b"rcs-parent-before-reid").hexdigest() |
| 53 | COMMITTED_AT = datetime(2026, 5, 21, 3, 27, 48, 41574, tzinfo=timezone.utc) |
| 54 | |
| 55 | |
| 56 | def _ident(key: Ed25519PrivateKey | None, *, parent: str = PARENT, message: str = "rcs commit") -> JSONObject: |
| 57 | """Identity fields for a commit signed (or not) by *key*, with its commit id.""" |
| 58 | pub = encode_public_key(key)[1] if key is not None else "" |
| 59 | at = COMMITTED_AT.isoformat() |
| 60 | cid = hash_commit( |
| 61 | parent_ids=[parent], snapshot_id=SNAPSHOT, message=message, |
| 62 | committed_at_iso=at, author=OWNER, signer_public_key=pub, |
| 63 | ) |
| 64 | return { |
| 65 | "commit_id": cid, "branch": "dev", "snapshot_id": SNAPSHOT, "message": message, |
| 66 | "committed_at": at, "parent_commit_id": parent, "parent2_commit_id": None, |
| 67 | "author": OWNER, "signer_public_key": pub, |
| 68 | } |
| 69 | |
| 70 | |
| 71 | def _sign(key: Ed25519PrivateKey, commit_id: str, *, agent: str = AGENT, model: str = MODEL) -> str: |
| 72 | payload = provenance_payload( |
| 73 | commit_id, author=OWNER, agent_id=agent, model_id=model, |
| 74 | toolchain_id="", prompt_hash="", committed_at=COMMITTED_AT.isoformat(), |
| 75 | ) |
| 76 | return sign_commit_ed25519(payload, key) |
| 77 | |
| 78 | |
| 79 | def _key_id(key: Ed25519PrivateKey) -> str: |
| 80 | return public_key_fingerprint(encode_public_key(key)[0]) |
| 81 | |
| 82 | |
| 83 | def _served_verifies(row: MusehubCommit) -> bool: |
| 84 | """Independent check of the record the serve path will hand to clients.""" |
| 85 | w = _to_wire_commit(row) |
| 86 | if not w.signer_public_key: |
| 87 | return not w.signature |
| 88 | payload = provenance_payload( |
| 89 | w.commit_id, author=w.author, agent_id=w.agent_id, model_id=w.model_id, |
| 90 | toolchain_id=w.toolchain_id, prompt_hash=w.prompt_hash, committed_at=w.committed_at, |
| 91 | ) |
| 92 | try: |
| 93 | Ed25519PublicKey.from_public_bytes(decode_pubkey(w.signer_public_key)[1]).verify( |
| 94 | decode_sig(w.signature)[1], payload.encode() |
| 95 | ) |
| 96 | return True |
| 97 | except (InvalidSignature, ValueError): |
| 98 | return False |
| 99 | |
| 100 | |
| 101 | async def _seed(session: AsyncSession, ident: JSONObject, signature: str, key_id: str) -> tuple[str, MusehubCommit]: |
| 102 | repo = await create_repo(session, owner=OWNER, slug="rcs-repo", name="rcs-repo") |
| 103 | row = MusehubCommit( |
| 104 | commit_id=str(ident["commit_id"]), branch="dev", message=str(ident["message"]), |
| 105 | author=OWNER, timestamp=COMMITTED_AT, committed_at_raw=str(ident["committed_at"]), |
| 106 | parent_ids=[str(ident["parent_commit_id"])], snapshot_id=SNAPSHOT, |
| 107 | agent_id=AGENT, model_id=MODEL, toolchain_id="", prompt_hash="", |
| 108 | signature=signature, signer_public_key=str(ident["signer_public_key"]), signer_key_id=key_id, |
| 109 | structured_delta=None, |
| 110 | ) |
| 111 | session.add(row) |
| 112 | session.add(MusehubCommitRef(repo_id=repo.repo_id, commit_id=row.commit_id)) |
| 113 | await session.commit() |
| 114 | return repo.repo_id, row |
| 115 | |
| 116 | |
| 117 | async def _reload(session: AsyncSession, commit_id: str) -> MusehubCommit: |
| 118 | session.expire_all() |
| 119 | row = await session.get(MusehubCommit, commit_id) |
| 120 | assert row is not None |
| 121 | return row |
| 122 | |
| 123 | |
| 124 | def _payload(ident: JSONObject, signature: str, key_id: str, **extra: str) -> JSONObject: |
| 125 | return {**ident, "signature": signature, "signer_key_id": key_id, "agent_id": AGENT, "model_id": MODEL, **extra} |
| 126 | |
| 127 | |
| 128 | @pytest.mark.asyncio |
| 129 | async def test_rcs_01_identical_valid_repair_is_idempotent(db_session: AsyncSession) -> None: |
| 130 | key = Ed25519PrivateKey.generate() |
| 131 | ident = _ident(key) |
| 132 | good = _sign(key, str(ident["commit_id"])) |
| 133 | repo_id, row = await _seed(db_session, ident, good, _key_id(key)) |
| 134 | assert _served_verifies(row) |
| 135 | for _ in range(2): |
| 136 | assert await wire_repair_commit(db_session, repo_id, _payload(ident, good, _key_id(key)), OWNER) == {"repaired": True} |
| 137 | row = await _reload(db_session, str(ident["commit_id"])) |
| 138 | assert row.signature == good and _served_verifies(row) |
| 139 | |
| 140 | |
| 141 | @pytest.mark.asyncio |
| 142 | async def test_rcs_02_valid_row_not_replaced_by_garbage_signature(db_session: AsyncSession) -> None: |
| 143 | key = Ed25519PrivateKey.generate() |
| 144 | ident = _ident(key) |
| 145 | good = _sign(key, str(ident["commit_id"])) |
| 146 | repo_id, _ = await _seed(db_session, ident, good, _key_id(key)) |
| 147 | garbage = _sign(Ed25519PrivateKey.generate(), str(ident["commit_id"])) # well-formed, wrong key |
| 148 | with pytest.raises(ObjectHashMismatch, match="signature"): |
| 149 | await wire_repair_commit(db_session, repo_id, _payload(ident, garbage, _key_id(key)), OWNER) |
| 150 | row = await _reload(db_session, str(ident["commit_id"])) |
| 151 | assert row.signature == good and _served_verifies(row), "a verified signature was replaced" |
| 152 | |
| 153 | |
| 154 | @pytest.mark.asyncio |
| 155 | async def test_rcs_03_valid_row_not_replaced_by_stale_signature_over_old_id(db_session: AsyncSession) -> None: |
| 156 | """The 2f17e909 shape: same key, valid signature, but over the pre-re-id commit id.""" |
| 157 | key = Ed25519PrivateKey.generate() |
| 158 | ident = _ident(key) |
| 159 | old_id = str(_ident(key, parent=OLD_PARENT)["commit_id"]) |
| 160 | good, stale = _sign(key, str(ident["commit_id"])), _sign(key, old_id) |
| 161 | assert stale != good |
| 162 | repo_id, _ = await _seed(db_session, ident, good, _key_id(key)) |
| 163 | with pytest.raises(ObjectHashMismatch, match="signature"): |
| 164 | await wire_repair_commit(db_session, repo_id, _payload(ident, stale, _key_id(key)), OWNER) |
| 165 | row = await _reload(db_session, str(ident["commit_id"])) |
| 166 | assert row.signature == good and _served_verifies(row) |
| 167 | |
| 168 | |
| 169 | @pytest.mark.asyncio |
| 170 | async def test_rcs_04_stale_row_repaired_with_verifying_signature(db_session: AsyncSession) -> None: |
| 171 | """The remediation path for 2f17e909: stale stored signature, verifying replacement.""" |
| 172 | key = Ed25519PrivateKey.generate() |
| 173 | ident = _ident(key) |
| 174 | old_id = str(_ident(key, parent=OLD_PARENT)["commit_id"]) |
| 175 | good, stale = _sign(key, str(ident["commit_id"])), _sign(key, old_id) |
| 176 | repo_id, row = await _seed(db_session, ident, stale, _key_id(key)) |
| 177 | assert not _served_verifies(row), "fixture must reproduce the staging failure" |
| 178 | assert await wire_repair_commit(db_session, repo_id, _payload(ident, good, _key_id(key)), OWNER) == {"repaired": True} |
| 179 | row = await _reload(db_session, str(ident["commit_id"])) |
| 180 | assert row.signature == good and _served_verifies(row) |
| 181 | |
| 182 | |
| 183 | @pytest.mark.asyncio |
| 184 | async def test_rcs_05_stale_row_not_replaced_by_another_unverifiable_signature(db_session: AsyncSession) -> None: |
| 185 | key = Ed25519PrivateKey.generate() |
| 186 | ident = _ident(key) |
| 187 | stale = _sign(key, str(_ident(key, parent=OLD_PARENT)["commit_id"])) |
| 188 | repo_id, _ = await _seed(db_session, ident, stale, _key_id(key)) |
| 189 | garbage = _sign(Ed25519PrivateKey.generate(), str(ident["commit_id"])) |
| 190 | with pytest.raises(ObjectHashMismatch, match="signature"): |
| 191 | await wire_repair_commit(db_session, repo_id, _payload(ident, garbage, _key_id(key)), OWNER) |
| 192 | row = await _reload(db_session, str(ident["commit_id"])) |
| 193 | assert row.signature == stale, "an unverifiable repair must leave the row exactly as it was" |
| 194 | |
| 195 | |
| 196 | @pytest.mark.asyncio |
| 197 | async def test_rcs_06_signed_commit_cannot_be_stripped_to_empty_signature(db_session: AsyncSession) -> None: |
| 198 | key = Ed25519PrivateKey.generate() |
| 199 | ident = _ident(key) |
| 200 | good = _sign(key, str(ident["commit_id"])) |
| 201 | repo_id, _ = await _seed(db_session, ident, good, _key_id(key)) |
| 202 | with pytest.raises(ObjectHashMismatch, match="signature"): |
| 203 | await wire_repair_commit(db_session, repo_id, _payload(ident, "", ""), OWNER) |
| 204 | row = await _reload(db_session, str(ident["commit_id"])) |
| 205 | assert row.signature == good and _served_verifies(row) |
| 206 | |
| 207 | |
| 208 | @pytest.mark.asyncio |
| 209 | async def test_rcs_07_unsigned_commit_cannot_gain_a_signature(db_session: AsyncSession) -> None: |
| 210 | ident = _ident(None) |
| 211 | repo_id, _ = await _seed(db_session, ident, "", "") |
| 212 | stray = _sign(Ed25519PrivateKey.generate(), str(ident["commit_id"])) |
| 213 | with pytest.raises(ObjectHashMismatch, match="signature"): |
| 214 | await wire_repair_commit(db_session, repo_id, _payload(ident, stray, ""), OWNER) |
| 215 | row = await _reload(db_session, str(ident["commit_id"])) |
| 216 | assert row.signature == "" and _served_verifies(row) |
| 217 | |
| 218 | |
| 219 | @pytest.mark.asyncio |
| 220 | async def test_rcs_08_unsigned_commit_repair_to_unsigned_state_still_allowed(db_session: AsyncSession) -> None: |
| 221 | ident = _ident(None) |
| 222 | repo_id, _ = await _seed(db_session, ident, "", "") |
| 223 | assert await wire_repair_commit(db_session, repo_id, _payload(ident, "", ""), OWNER) == {"repaired": True} |
| 224 | |
| 225 | |
| 226 | @pytest.mark.asyncio |
| 227 | async def test_rcs_09_signature_must_cover_the_rows_served_provenance_fields(db_session: AsyncSession) -> None: |
| 228 | """Repair keeps the row's agent/model fields, so a signature made over different |
| 229 | ones would be served unverifiable even though it verifies for the submitter.""" |
| 230 | key = Ed25519PrivateKey.generate() |
| 231 | ident = _ident(key) |
| 232 | good = _sign(key, str(ident["commit_id"])) |
| 233 | repo_id, _ = await _seed(db_session, ident, good, _key_id(key)) |
| 234 | other = _sign(key, str(ident["commit_id"]), agent="other-agent", model="other-model") |
| 235 | with pytest.raises(ObjectHashMismatch, match="signature"): |
| 236 | await wire_repair_commit( |
| 237 | db_session, repo_id, |
| 238 | _payload(ident, other, _key_id(key), agent_id="other-agent", model_id="other-model"), |
| 239 | OWNER, |
| 240 | ) |
| 241 | row = await _reload(db_session, str(ident["commit_id"])) |
| 242 | assert row.signature == good and _served_verifies(row) |
| 243 | |
| 244 | |
| 245 | @pytest.mark.asyncio |
| 246 | async def test_rcs_11_signer_key_swap_is_rejected(db_session: AsyncSession) -> None: |
| 247 | """A self-consistent record from a different key cannot take over the commit: |
| 248 | the signer key is bound into the commit id.""" |
| 249 | key, intruder = Ed25519PrivateKey.generate(), Ed25519PrivateKey.generate() |
| 250 | ident = _ident(key) |
| 251 | good = _sign(key, str(ident["commit_id"])) |
| 252 | repo_id, _ = await _seed(db_session, ident, good, _key_id(key)) |
| 253 | swapped = {**ident, "signer_public_key": encode_public_key(intruder)[1]} |
| 254 | with pytest.raises(ObjectHashMismatch): |
| 255 | await wire_repair_commit( |
| 256 | db_session, repo_id, _payload(swapped, _sign(intruder, str(ident["commit_id"])), _key_id(intruder)), OWNER, |
| 257 | ) |
| 258 | row = await _reload(db_session, str(ident["commit_id"])) |
| 259 | assert row.signature == good and row.signer_public_key == ident["signer_public_key"] |
| 260 | |
| 261 | |
| 262 | @pytest.mark.asyncio |
| 263 | async def test_rcs_12_repair_preserves_existing_semantic_history(db_session: AsyncSession) -> None: |
| 264 | """Re-attesting a stale signature must leave a stored structured_delta, and every |
| 265 | other non-repaired field, exactly as it was, whatever the payload carries.""" |
| 266 | key = Ed25519PrivateKey.generate() |
| 267 | ident = _ident(key) |
| 268 | old_id = str(_ident(key, parent=OLD_PARENT)["commit_id"]) |
| 269 | repo_id, row = await _seed(db_session, ident, _sign(key, old_id), _key_id(key)) |
| 270 | delta = {"domain": "code", "ops": [{"op": "insert", "address": "a.py::f"}], "summary": "1 added"} |
| 271 | row.structured_delta, row.sem_ver_bump, row.breaking_changes = delta, "minor", ["a.py"] |
| 272 | await db_session.commit() |
| 273 | payload = _payload(ident, _sign(key, str(ident["commit_id"])), _key_id(key)) |
| 274 | payload.update(structured_delta={"domain": "code", "ops": []}, sem_ver_bump="none", breaking_changes=[]) |
| 275 | assert await wire_repair_commit(db_session, repo_id, payload, OWNER) == {"repaired": True} |
| 276 | row = await _reload(db_session, str(ident["commit_id"])) |
| 277 | assert row.structured_delta == delta |
| 278 | assert (row.sem_ver_bump, row.breaking_changes) == ("minor", ["a.py"]) |
| 279 | assert (row.agent_id, row.model_id) == (AGENT, MODEL) |
| 280 | assert _served_verifies(row) |
| 281 | |
| 282 | |
| 283 | @pytest.mark.asyncio |
| 284 | async def test_rcs_13_repair_never_touches_other_commit_rows(db_session: AsyncSession) -> None: |
| 285 | key = Ed25519PrivateKey.generate() |
| 286 | ident = _ident(key) |
| 287 | stale = _sign(key, str(_ident(key, parent=OLD_PARENT)["commit_id"])) |
| 288 | repo_id, _ = await _seed(db_session, ident, stale, _key_id(key)) |
| 289 | other = _ident(key, message="unrelated commit") |
| 290 | other_sig = _sign(key, str(other["commit_id"])) |
| 291 | db_session.add(MusehubCommit( |
| 292 | commit_id=str(other["commit_id"]), branch="dev", message="unrelated commit", author=OWNER, |
| 293 | timestamp=COMMITTED_AT, committed_at_raw=str(other["committed_at"]), parent_ids=[PARENT], |
| 294 | snapshot_id=SNAPSHOT, agent_id=AGENT, model_id=MODEL, toolchain_id="", prompt_hash="", |
| 295 | signature=other_sig, signer_public_key=str(other["signer_public_key"]), signer_key_id=_key_id(key), |
| 296 | )) |
| 297 | db_session.add(MusehubCommitRef(repo_id=repo_id, commit_id=str(other["commit_id"]))) |
| 298 | await db_session.commit() |
| 299 | |
| 300 | def snapshot(r: MusehubCommit) -> tuple: |
| 301 | return (r.message, r.author, r.timestamp, r.parent_ids, r.snapshot_id, r.signature, |
| 302 | r.signer_public_key, r.signer_key_id, r.structured_delta) |
| 303 | |
| 304 | before = snapshot(await _reload(db_session, str(other["commit_id"]))) |
| 305 | assert await wire_repair_commit( |
| 306 | db_session, repo_id, _payload(ident, _sign(key, str(ident["commit_id"])), _key_id(key)), OWNER, |
| 307 | ) == {"repaired": True} |
| 308 | with pytest.raises(ObjectHashMismatch): |
| 309 | await wire_repair_commit(db_session, repo_id, _payload(ident, "ed25519:!!!", _key_id(key)), OWNER) |
| 310 | assert snapshot(await _reload(db_session, str(other["commit_id"]))) == before |
| 311 | |
| 312 | |
| 313 | @pytest.mark.asyncio |
| 314 | async def test_rcs_14_rejected_repair_performs_no_database_writes(db_session: AsyncSession) -> None: |
| 315 | """A refused repair must not invalidate the fetch cache or enqueue a prebuild: |
| 316 | the refusal happens before any write, not after a partial one.""" |
| 317 | from sqlalchemy import func, select |
| 318 | from musehub.db.musehub_jobs_models import MusehubBackgroundJob |
| 319 | from musehub.db.musehub_repo_models import MusehubFetchMPackCache |
| 320 | from tests.factories import create_branch |
| 321 | |
| 322 | key = Ed25519PrivateKey.generate() |
| 323 | ident = _ident(key) |
| 324 | good = _sign(key, str(ident["commit_id"])) |
| 325 | repo_id, _ = await _seed(db_session, ident, good, _key_id(key)) |
| 326 | await create_branch(db_session, repo_id, name="dev", head_commit_id=str(ident["commit_id"])) |
| 327 | db_session.add(MusehubFetchMPackCache( |
| 328 | cache_id="sha256:" + hashlib.sha256(b"rcs-cache").hexdigest(), repo_id=repo_id, |
| 329 | tip_commit_id=str(ident["commit_id"]), mpack_id="sha256:" + hashlib.sha256(b"rcs-mpack").hexdigest(), |
| 330 | )) |
| 331 | await db_session.commit() |
| 332 | |
| 333 | async def counts() -> tuple[int, int]: |
| 334 | cache = (await db_session.execute( |
| 335 | select(func.count()).select_from(MusehubFetchMPackCache).where(MusehubFetchMPackCache.repo_id == repo_id) |
| 336 | )).scalar_one() |
| 337 | jobs = (await db_session.execute( |
| 338 | select(func.count()).select_from(MusehubBackgroundJob).where(MusehubBackgroundJob.repo_id == repo_id) |
| 339 | )).scalar_one() |
| 340 | return cache, jobs |
| 341 | |
| 342 | assert await counts() == (1, 0) |
| 343 | with pytest.raises(ObjectHashMismatch, match="signature"): |
| 344 | await wire_repair_commit( |
| 345 | db_session, repo_id, _payload(ident, _sign(Ed25519PrivateKey.generate(), str(ident["commit_id"])), _key_id(key)), OWNER, |
| 346 | ) |
| 347 | await db_session.rollback() |
| 348 | assert await counts() == (1, 0), "a refused repair invalidated the cache or enqueued a rebuild" |
| 349 | row = await _reload(db_session, str(ident["commit_id"])) |
| 350 | assert row.signature == good |
| 351 | |
| 352 | |
| 353 | @pytest.mark.asyncio |
| 354 | async def test_rcs_15_signer_key_id_may_stay_or_become_the_fingerprint_only(db_session: AsyncSession) -> None: |
| 355 | """2f17e909's stored key id is a legacy value, not today's fingerprint format. |
| 356 | A re-attestation may keep it or upgrade it to the key's fingerprint, never relabel it.""" |
| 357 | key = Ed25519PrivateKey.generate() |
| 358 | ident = _ident(key) |
| 359 | legacy_kid = "0123456789abcdef" |
| 360 | stale = _sign(key, str(_ident(key, parent=OLD_PARENT)["commit_id"])) |
| 361 | good = _sign(key, str(ident["commit_id"])) |
| 362 | repo_id, _ = await _seed(db_session, ident, stale, legacy_kid) |
| 363 | with pytest.raises(ObjectHashMismatch, match="signer_key_id"): |
| 364 | await wire_repair_commit(db_session, repo_id, _payload(ident, good, "sha256:" + "0" * 64), OWNER) |
| 365 | row = await _reload(db_session, str(ident["commit_id"])) |
| 366 | assert (row.signature, row.signer_key_id) == (stale, legacy_kid) |
| 367 | assert await wire_repair_commit(db_session, repo_id, _payload(ident, good, legacy_kid), OWNER) == {"repaired": True} |
| 368 | row = await _reload(db_session, str(ident["commit_id"])) |
| 369 | assert (row.signature, row.signer_key_id) == (good, legacy_kid) and _served_verifies(row) |
| 370 | assert await wire_repair_commit(db_session, repo_id, _payload(ident, good, _key_id(key)), OWNER) == {"repaired": True} |
| 371 | assert (await _reload(db_session, str(ident["commit_id"]))).signer_key_id == _key_id(key) |
| 372 | |
| 373 | |
| 374 | @pytest.mark.asyncio |
| 375 | @pytest.mark.parametrize("bad", ["not-a-signature", "ed25519:!!!", "rsa:AAAA"]) |
| 376 | async def test_rcs_10_malformed_signature_is_a_422_not_a_stored_value(db_session: AsyncSession, bad: str) -> None: |
| 377 | key = Ed25519PrivateKey.generate() |
| 378 | ident = _ident(key) |
| 379 | good = _sign(key, str(ident["commit_id"])) |
| 380 | repo_id, _ = await _seed(db_session, ident, good, _key_id(key)) |
| 381 | with pytest.raises(ObjectHashMismatch, match="signature"): |
| 382 | await wire_repair_commit(db_session, repo_id, _payload(ident, bad, _key_id(key)), OWNER) |
| 383 | row = await _reload(db_session, str(ident["commit_id"])) |
| 384 | assert row.signature == good |
File History
2 commits
sha256:751c1b982a8fd7f58c1533afe636b781f965ed98ba7f9fc9dac1dfbcbfee1939
merge: integrate repair-commit signature verification into dev
Opus 5.5
patch
11 days ago
sha256:905e9e0d60cc79dd8334d2c07cef65ba69321f4854817a6c49fb58883f4c7b23
fix(repair-commit): refuse to store a signature that does n…
Opus 5.5
patch
11 days ago