Merge pull request #2483 from thincal/fix/list-objects-with-truncation

s3 list_object: return the NextMarker info if it's truncated
This commit is contained in:
Mike Grima 2019-10-22 09:57:15 -07:00 committed by GitHub
commit 1cde5d37eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 1 deletions

View File

@ -413,7 +413,7 @@ class ResponseObject(_TemplateEnvironmentMixin, ActionAuthenticatorMixin):
if marker:
result_keys = self._get_results_from_token(result_keys, marker)
result_keys, is_truncated, _ = self._truncate_result(result_keys, max_keys)
result_keys, is_truncated, next_marker = self._truncate_result(result_keys, max_keys)
template = self.response_template(S3_BUCKET_GET_RESPONSE)
return 200, {}, template.render(
@ -423,6 +423,7 @@ class ResponseObject(_TemplateEnvironmentMixin, ActionAuthenticatorMixin):
result_keys=result_keys,
result_folders=result_folders,
is_truncated=is_truncated,
next_marker=next_marker,
max_keys=max_keys
)
@ -1327,6 +1328,9 @@ S3_BUCKET_GET_RESPONSE = """<?xml version="1.0" encoding="UTF-8"?>
<MaxKeys>{{ max_keys }}</MaxKeys>
<Delimiter>{{ delimiter }}</Delimiter>
<IsTruncated>{{ is_truncated }}</IsTruncated>
{% if next_marker %}
<NextMarker>{{ next_marker }}</NextMarker>
{% endif %}
{% for key in result_keys %}
<Contents>
<Key>{{ key.name }}</Key>

View File

@ -1247,6 +1247,54 @@ def test_website_redirect_location():
resp['WebsiteRedirectLocation'].should.equal(url)
@mock_s3
def test_boto3_list_objects_truncated_response():
s3 = boto3.client('s3', region_name='us-east-1')
s3.create_bucket(Bucket='mybucket')
s3.put_object(Bucket='mybucket', Key='one', Body=b'1')
s3.put_object(Bucket='mybucket', Key='two', Body=b'22')
s3.put_object(Bucket='mybucket', Key='three', Body=b'333')
# First list
resp = s3.list_objects(Bucket='mybucket', MaxKeys=1)
listed_object = resp['Contents'][0]
assert listed_object['Key'] == 'one'
assert resp['MaxKeys'] == 1
assert resp['IsTruncated'] == True
assert resp['Prefix'] == 'None'
assert resp['Delimiter'] == 'None'
assert 'NextMarker' in resp
next_marker = resp["NextMarker"]
# Second list
resp = s3.list_objects(
Bucket='mybucket', MaxKeys=1, Marker=next_marker)
listed_object = resp['Contents'][0]
assert listed_object['Key'] == 'three'
assert resp['MaxKeys'] == 1
assert resp['IsTruncated'] == True
assert resp['Prefix'] == 'None'
assert resp['Delimiter'] == 'None'
assert 'NextMarker' in resp
next_marker = resp["NextMarker"]
# Third list
resp = s3.list_objects(
Bucket='mybucket', MaxKeys=1, Marker=next_marker)
listed_object = resp['Contents'][0]
assert listed_object['Key'] == 'two'
assert resp['MaxKeys'] == 1
assert resp['IsTruncated'] == False
assert resp['Prefix'] == 'None'
assert resp['Delimiter'] == 'None'
assert 'NextMarker' not in resp
@mock_s3
def test_boto3_list_keys_xml_escaped():
s3 = boto3.client('s3', region_name='us-east-1')