Skip to content

test: accept legal-hold refusals across simulator versions - #647

Merged
ffumero2003 merged 2 commits into
masterfrom
test/legal-hold-delete-refusal-expectation
Nov 13, 2026
Merged

ffumero2003 merged 2 commits into
masterfrom
test/legal-hold-delete-refusal-expectation

Conversation

@ffumero2003

@ffumero2003 ffumero2003 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Context

The native B2 b2_delete_file_version error table specifies a 401 access_denied response 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 to Unauthorized.

Root cause

The conformance check accepted the older simulator refusal classes but rejected the native B2 response. Requiring only Unauthorized would instead reject older simulator versions and could mistake unrelated authorization errors for the expected refusal.

Changes

  • Accept Unauthorized only with code == 'access_denied', alongside AccessDenied, RetentionWriteError, Conflict and BadRequest, matching the adjacent lock checks.
  • Add legal hold to the shared behavioral tests, cover all four legacy classes, and reject unrelated authorization failures, including a missing-capability response.
  • Update the test-tooling changelog fragment. No production SDK code changes.

Verification

  • Before the revision, lock.legal_hold failed on simulator 57f44c6: refused with BadRequest, expected Unauthorized.
  • After the revision, lock.legal_hold reports SDKHARNESS_RESULT conformance lock.legal_hold PASS - against both 57f44c6 (older simulator) and 56c97a8 (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.

@goanpeca goanpeca left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Unauthorized with code access_denied;
  • reject any other Unauthorized code, 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.

@goanpeca

Copy link
Copy Markdown

@coderabbitai review

@ffumero2003 ffumero2003 changed the title test: expect Unauthorized for native delete under legal hold (matches real B2) test: accept legal-hold refusals across simulator versions Nov 13, 2026
@ffumero2003

Copy link
Copy Markdown
Contributor Author

@goanpeca Restored all four legacy refusals, gated Unauthorized on access_denied, and added behavioral coverage; the legal-hold check passes on both older and F-139 simulators.

@ffumero2003
ffumero2003 requested a review from goanpeca November 13, 2026 15:07
@ffumero2003
ffumero2003 merged commit 028bb54 into master Nov 13, 2026
51 of 53 checks passed
@ffumero2003
ffumero2003 deleted the test/legal-hold-delete-refusal-expectation branch November 13, 2026 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants