Repository navigation
test: accept legal-hold refusals across simulator versions - #647
Conversation
goanpeca
left a comment
There was a problem hiding this comment.
Review: PR #647 (head 96df3af)
Request changes. The PR is right that real B2 refuses a delete under legal hold with 401 access_denied (see the b2_delete_file_version docs and F-139). But the check now passes on any Unauthorized, so a 401 unrelated to the legal hold would look like a successful refusal.
1 Important, 1 Nit. Two independent reviews (Claude and Codex) found the same problem and both reproduced it. The 21 focused tests and all 28 CI checks pass. Neither review re-ran the external simulator scenario.
Important: check the error code as well as the class
.sdkharness/tests/conformance/lock.legal_hold:271
b2sdk raises a plain Unauthorized for every 401 except bad_auth_token and expired_auth_token. That includes a key missing the deleteFiles capability. refused() compares only the class name, so a permission failure on the held-delete step counts as proof that the legal hold blocked the delete. 401 unauthorized and other 401 codes all pass.
Fix: accept Unauthorized only when error.code == 'access_denied'. Use the same refused(..., access_denied_401=True) pattern as lock.bypass_governance and lock.per_file_retention (#621).
Nit: test the behavior, not the source text
test/unit/test_sdkharness_lock_refusal.py:117
The new test searches for the text ('Unauthorized',) and can't catch the problem above. Add lock.legal_hold to LEAVES so the existing behavior tests cover it. Those tests should:
- accept
Unauthorizedwith codeaccess_denied; - reject any other
Unauthorizedcode,InvalidAuthToken, unexpected exceptions, and a delete that succeeds.
Before merging
- Duplicate PR: #645 (draft) changes the same check and already does both fixes above. Keep one PR and close the other.
- Old simulator shapes: this PR stops accepting the old simulator refusals (
AccessDenied,RetentionWriteError,Conflict,BadRequest). That works only if the central harness always uses a simulator that includes F-139. Otherwise keep accepting the old shapes for now.
|
@coderabbitai review |
|
@goanpeca Restored all four legacy refusals, gated |
Context
The native B2
b2_delete_file_versionerror table specifies a401 access_deniedresponse when Object Lock prevents a delete. The b2-simulator fidelity ledger's F-139 records the corresponding production measurement for a version under legal hold; b2sdk maps that response toUnauthorized.Root cause
The conformance check accepted the older simulator refusal classes but rejected the native B2 response. Requiring only
Unauthorizedwould instead reject older simulator versions and could mistake unrelated authorization errors for the expected refusal.Changes
Unauthorizedonly withcode == 'access_denied', alongsideAccessDenied,RetentionWriteError,ConflictandBadRequest, matching the adjacent lock checks.Verification
lock.legal_holdfailed on simulator57f44c6:refused with BadRequest, expected Unauthorized.lock.legal_holdreportsSDKHARNESS_RESULT conformance lock.legal_hold PASS -against both57f44c6(older simulator) and56c97a8(F-139 pin).uv run --locked --group test pytest test/unit/test_sdkharness_lock_refusal.py test/unit/test_sdkharness_contract.py test/unit/test_sdkharness_conformance_resilience_contract.py test/unit/test_sdkharness_fail_not_skip.py -q— 189 passed.NOX_PYTHONS=3.13 uv run --locked --group nox nox -vs lint towncrier_check— both sessions passed.