mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-23 14:52:26 +00:00
Not found tests and implementation.
This commit is contained in:
parent
45ee5e3346
commit
5d9e0c9bca
@ -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
|
||||
|
@ -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):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user