From 7e25b43dbaff26449fe5dbef0b2f2d32a3ada883 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Thu, 10 Mar 2022 11:28:48 -0500 Subject: [PATCH] Direct unit tests for advising share is corrupt. --- src/allmydata/storage/http_server.py | 2 -- src/allmydata/test/test_storage_http.py | 32 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/allmydata/storage/http_server.py b/src/allmydata/storage/http_server.py index 5d357b846..d122b95b4 100644 --- a/src/allmydata/storage/http_server.py +++ b/src/allmydata/storage/http_server.py @@ -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()) diff --git a/src/allmydata/test/test_storage_http.py b/src/allmydata/test/test_storage_http.py index 31505a00f..70a9f1c16 100644 --- a/src/allmydata/test/test_storage_http.py +++ b/src/allmydata/test/test_storage_http.py @@ -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) + )