Direct unit tests for advising share is corrupt.

This commit is contained in:
Itamar Turner-Trauring 2022-03-10 11:28:48 -05:00
parent 922ee4feb1
commit 7e25b43dba
2 changed files with 32 additions and 2 deletions

View File

@ -464,11 +464,9 @@ class HTTPServer(object):
)
def advise_corrupt_share(self, request, authorization, storage_index, share_number):
"""Indicate that given share is corrupt, with a text reason."""
# TODO 3879 test success path
try:
bucket = self._storage_server.get_buckets(storage_index)[share_number]
except KeyError:
# TODO 3879 test this path
raise _HTTPError(http.NOT_FOUND)
info = loads(request.content.read())

View File

@ -1055,3 +1055,35 @@ class ImmutableHTTPAPITests(SyncTestCase):
secret = b"A" * 32
with assert_fails_with_http_code(self, http.NOT_FOUND):
result_of(self.imm_client.add_or_renew_lease(storage_index, secret, secret))
def test_advise_corrupt_share(self):
"""
Advising share was corrupted succeeds from HTTP client's perspective,
and calls appropriate method on server.
"""
corrupted = []
self.http.storage_server.advise_corrupt_share = lambda *args: corrupted.append(
args
)
storage_index, _ = self.upload(13)
reason = "OHNO \u1235"
result_of(self.imm_client.advise_corrupt_share(storage_index, 13, reason))
self.assertEqual(
corrupted, [(b"immutable", storage_index, 13, reason.encode("utf-8"))]
)
def test_advise_corrupt_share_unknown(self):
"""
Advising an unknown share was corrupted results in 404.
"""
storage_index, _ = self.upload(13)
reason = "OHNO \u1235"
result_of(self.imm_client.advise_corrupt_share(storage_index, 13, reason))
for (si, share_number) in [(storage_index, 11), (urandom(16), 13)]:
with assert_fails_with_http_code(self, http.NOT_FOUND):
result_of(
self.imm_client.advise_corrupt_share(si, share_number, reason)
)