From 70d0bd0597b46015c45489ba57b5b566abe5e395 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Tue, 1 Feb 2022 10:41:12 -0500 Subject: [PATCH] Test and document what happens for non-existent storage index. --- docs/proposed/http-storage-node-protocol.rst | 3 +++ src/allmydata/storage/http_server.py | 2 -- src/allmydata/test/test_storage_http.py | 8 ++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/proposed/http-storage-node-protocol.rst b/docs/proposed/http-storage-node-protocol.rst index f47a50d3e..9c09eb362 100644 --- a/docs/proposed/http-storage-node-protocol.rst +++ b/docs/proposed/http-storage-node-protocol.rst @@ -635,6 +635,9 @@ indicated storage index. For example:: [1, 5] +An unknown storage index results in empty list, so that lack of existence of +storage index is not leaked. + ``GET /v1/immutable/:storage_index/:share_number`` !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! diff --git a/src/allmydata/storage/http_server.py b/src/allmydata/storage/http_server.py index f4ba865ca..f885baa22 100644 --- a/src/allmydata/storage/http_server.py +++ b/src/allmydata/storage/http_server.py @@ -266,8 +266,6 @@ class HTTPServer(object): List shares for the given storage index. """ storage_index = si_a2b(storage_index.encode("ascii")) - - # TODO in future ticket, handle KeyError as 404 share_numbers = list(self._storage_server.get_buckets(storage_index).keys()) return self._cbor(request, share_numbers) diff --git a/src/allmydata/test/test_storage_http.py b/src/allmydata/test/test_storage_http.py index 4ddfff62e..b2def5581 100644 --- a/src/allmydata/test/test_storage_http.py +++ b/src/allmydata/test/test_storage_http.py @@ -413,6 +413,14 @@ class ImmutableHTTPAPITests(SyncTestCase): # Now shares 1 and 3 exist: self.assertEqual(result_of(im_client.list_shares(storage_index)), {1, 3}) + def test_list_shares_unknown_storage_index(self): + """ + Listing unknown storage index's shares results in empty list of shares. + """ + im_client = StorageClientImmutables(self.http.client) + storage_index = b"".join(bytes([i]) for i in range(16)) + self.assertEqual(result_of(im_client.list_shares(storage_index)), set()) + def test_multiple_shares_uploaded_to_different_place(self): """ If a storage index has multiple shares, uploads to different shares are