From 5d9e0c9bca14ace590b842250efa69bb092d0b48 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 9 Feb 2022 13:14:27 -0500 Subject: [PATCH] Not found tests and implementation. --- src/allmydata/storage/http_server.py | 9 ++++-- src/allmydata/test/test_storage_http.py | 41 ++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/allmydata/storage/http_server.py b/src/allmydata/storage/http_server.py index 4613a73c3..e7aa12f55 100644 --- a/src/allmydata/storage/http_server.py +++ b/src/allmydata/storage/http_server.py @@ -302,8 +302,13 @@ class HTTPServer(object): offset, end = range_header.ranges[0] assert end != None # TODO support this case - # TODO if not found, 404 - bucket = self._storage_server.get_buckets(storage_index)[share_number] + try: + bucket = self._storage_server.get_buckets(storage_index)[share_number] + except KeyError: + request.setResponseCode(http.NOT_FOUND) + return b"" + + # TODO limit memory usage data = bucket.read(offset, end - offset) request.setResponseCode(http.PARTIAL_CONTENT) # TODO set content-range on response. We we need to expand the diff --git a/src/allmydata/test/test_storage_http.py b/src/allmydata/test/test_storage_http.py index ac52303f6..b96eebb96 100644 --- a/src/allmydata/test/test_storage_http.py +++ b/src/allmydata/test/test_storage_http.py @@ -654,19 +654,52 @@ class ImmutableHTTPAPITests(SyncTestCase): ) self.assertEqual(e.exception.code, http.NOT_FOUND) + def upload(self, share_number): + """ + Create a share, return (storage_index). + """ + (upload_secret, _, storage_index, _) = self.create_upload({share_number}, 26) + result_of( + self.im_client.write_share_chunk( + storage_index, + share_number, + upload_secret, + 0, + b"abcdefghijklmnopqrstuvwxyz", + ) + ) + return storage_index + def test_read_of_wrong_storage_index_fails(self): """ Reading from unknown storage index results in 404. - - TBD in https://tahoe-lafs.org/trac/tahoe-lafs/ticket/3860 """ + with self.assertRaises(ClientException) as e: + result_of( + self.im_client.read_share_chunk( + b"1" * 16, + 1, + 0, + 10, + ) + ) + self.assertEqual(e.exception.code, http.NOT_FOUND) def test_read_of_wrong_share_number_fails(self): """ Reading from unknown storage index results in 404. - - TBD in https://tahoe-lafs.org/trac/tahoe-lafs/ticket/3860 """ + storage_index = self.upload(1) + with self.assertRaises(ClientException) as e: + result_of( + self.im_client.read_share_chunk( + storage_index, + 7, # different share number + 0, + 10, + ) + ) + self.assertEqual(e.exception.code, http.NOT_FOUND) def test_read_with_negative_offset_fails(self): """