Not found tests and implementation.

This commit is contained in:
Itamar Turner-Trauring 2022-02-09 13:14:27 -05:00
parent 45ee5e3346
commit 5d9e0c9bca
2 changed files with 44 additions and 6 deletions

View File

@ -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

View File

@ -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):
"""