Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .sdkharness/tests/conformance/lock.legal_hold
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,13 @@ def step(name, action):
raise Failure(name, name_of) from error


def refused(name, action, expected):
def refused(name, action, expected, *, access_denied_401=False):
"""Assert something is REFUSED, and record what refused it.

`expected` is a tuple of exception class names. A different class -- or no
exception at all -- is a Failure, because the refusal IS the claim here.
With `access_denied_401`, Unauthorized is also accepted, but only when its
code is `access_denied`; other authorization failures remain failures.
"""
try:
action()
Expand All @@ -130,6 +132,12 @@ def refused(name, action, expected):
name_of = type(error).__name__
if name_of in expected:
return name_of
if (
access_denied_401
and name_of == 'Unauthorized'
and getattr(error, 'code', None) == 'access_denied'
):
return 'Unauthorized(access_denied)'
raise Failure(name, f"refused with {name_of}, expected {'/'.join(expected)}") from error
raise Failure(name, 'the call was permitted; the claim under test is that it is refused')

Expand Down Expand Up @@ -268,7 +276,10 @@ def run(target: str) -> None:
refused(
'delete while held',
lambda: bucket.delete_file_version(uploaded.id_, OBJECT_NAME),
# b2_delete_file_version error table and b2-simulator FIDELITY.md F-139:
# real B2 uses 401 access_denied; retain older simulator refusal shapes.
('AccessDenied', 'RetentionWriteError', 'Conflict', 'BadRequest'),
access_denied_401=True,
)

step(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make the sdkharness legal-hold delete check accept B2's `401 access_denied` response while retaining older simulator refusal shapes.
21 changes: 15 additions & 6 deletions test/unit/test_sdkharness_lock_refusal.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import pytest

CONFORMANCE = Path(__file__).parents[2] / '.sdkharness' / 'tests' / 'conformance'
LEAVES = ('lock.bypass_governance', 'lock.per_file_retention')
LEAVES = ('lock.bypass_governance', 'lock.per_file_retention', 'lock.legal_hold')
EXPECTED = ('AccessDenied', 'RetentionWriteError', 'Conflict', 'BadRequest')


Expand Down Expand Up @@ -64,14 +64,15 @@ def test_401_access_denied_counts_as_the_refusal(leaf):


@pytest.mark.parametrize('leaf', LEAVES)
def test_the_old_refusal_classes_are_still_accepted(leaf):
@pytest.mark.parametrize('error_name', EXPECTED)
def test_the_old_refusal_classes_are_still_accepted(leaf, error_name):
module = load_leaf(leaf)
AccessDenied = type('AccessDenied', (Exception,), {})
refusal_class = type(error_name, (Exception,), {})
assert (
module.refused(
'delete without bypass', raising(AccessDenied()), EXPECTED, access_denied_401=True
'delete without bypass', raising(refusal_class()), EXPECTED, access_denied_401=True
)
== 'AccessDenied'
== error_name
)


Expand All @@ -89,10 +90,18 @@ def test_an_allowed_operation_still_fails(leaf):
InvalidAuthToken('expired_auth_token'),
Unauthorized('bad_auth_token'),
Unauthorized('email_not_verified'),
Unauthorized('unauthorized'),
ServiceError('503'),
KeyError('404'),
],
ids=['bad-token', 'other-401-code', 'unverified-email', '5xx', 'not-found'],
ids=[
'bad-token',
'other-401-code',
'unverified-email',
'missing-capability',
'5xx',
'not-found',
],
)
def test_an_unrelated_refusal_still_fails(leaf, error):
module = load_leaf(leaf)
Expand Down
Loading