Skip to content

Commit

Permalink
signV4: Fix signature issue while doing multipart upload. (#504)
Browse files Browse the repository at this point in the history
Setting query params in the following manner fails to
generate the proper query params used for validating
signature.

```
query = {'test': None}
```
Generates a url of form `/?test` doesn't work.

```
query = {'test': ''}
```

Generates a url of form `/?test=`  works.
  • Loading branch information
harshavardhana authored Apr 17, 2017
1 parent 2f4a95a commit 340f88c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
4 changes: 2 additions & 2 deletions minio/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ def _list_incomplete_uploads(self, bucket_name, prefix=None,

# Initialize query parameters.
query = {
'uploads': None,
'uploads': '',
'max-uploads': 1000
}

Expand Down Expand Up @@ -1700,7 +1700,7 @@ def _new_multipart_upload(self, bucket_name, object_name,

response = self._url_open('POST', bucket_name=bucket_name,
object_name=object_name,
query={'uploads': None},
query={'uploads': ''},
headers=metadata)

return parse_new_multipart_upload(response.data)
Expand Down
20 changes: 18 additions & 2 deletions tests/functional/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,23 @@ def main():
file_stat.st_size)
file_data.close()

with open('largefile', 'wb') as file_data:
for i in range(0, 104857):
file_data.write(fake.text().encode('utf-8'))
file_data.close()

# Fput a file
client.fput_object(bucket_name, object_name+'-f', 'testfile')
if is_s3:
client.fput_object(bucket_name, object_name+'-f', 'testfile',
metadata={'x-amz-storage-class': 'STANDARD_IA'})

# Fput a large file.
client.fput_object(bucket_name, object_name+'-large', 'largefile')
if is_s3:
client.fput_object(bucket_name, object_name+'-large', 'largefile',
metadata={'x-amz-storage-class': 'STANDARD_IA'})

# Copy a file
client.copy_object(bucket_name, object_name+'-copy',
'/'+bucket_name+'/'+object_name+'-f')
Expand All @@ -120,6 +131,9 @@ def main():
# Fetch stats on your object.
client.stat_object(bucket_name, object_name+'-f')

# Fetch stats on your large object.
client.stat_object(bucket_name, object_name+'-large')

# Fetch stats on your object.
client.stat_object(bucket_name, object_name+'-copy')

Expand Down Expand Up @@ -182,9 +196,10 @@ def main():
policy.set_expires(expires_date)
client.presigned_post_policy(policy)

# Remove an object.
# Remove all objects.
client.remove_object(bucket_name, object_name)
client.remove_object(bucket_name, object_name+'-f')
client.remove_object(bucket_name, object_name+'-large')
client.remove_object(bucket_name, object_name+'-copy')

policy_name = client.get_bucket_policy(bucket_name)
Expand Down Expand Up @@ -220,7 +235,7 @@ def main():
had_errs = False
for del_err in del_errs:
had_errs = True
# print("Err is {}".format(del_err))
print("Remove objects err is {}".format(del_err))
if had_errs:
print("Removing objects FAILED - it had unexpected errors.")
raise
Expand All @@ -237,6 +252,7 @@ def main():
os.remove('testfile')
os.remove('newfile')
os.remove('newfile-f')
os.remove('largefile')

if __name__ == "__main__":
# Execute only if run as a script
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/list_incomplete_uploads_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_empty_list_uploads_test(self, mock_connection):
mock_connection.return_value = mock_server
mock_server.mock_add_request(
MockResponse('GET',
'https://localhost:9000/bucket/?max-uploads=1000&uploads',
'https://localhost:9000/bucket/?max-uploads=1000&uploads=',
{'User-Agent': _DEFAULT_USER_AGENT}, 200, content=mock_data))
client = Minio('localhost:9000')
upload_iter = client._list_incomplete_uploads('bucket', '', True, False)
Expand Down Expand Up @@ -102,7 +102,7 @@ def test_list_uploads_works(self, mock_connection):
mock_connection.return_value = mock_server
mock_server.mock_add_request(
MockResponse('GET',
'https://localhost:9000/bucket/?delimiter=%2F&max-uploads=1000&uploads',
'https://localhost:9000/bucket/?delimiter=%2F&max-uploads=1000&uploads=',
{'User-Agent': _DEFAULT_USER_AGENT},
200, content=mock_data))

Expand Down Expand Up @@ -203,7 +203,7 @@ def test_list_multipart_uploads_works(self, mock_connection):
mock_connection.return_value = mock_server
mock_server.mock_add_request(
MockResponse('GET',
'https://localhost:9000/bucket/?max-uploads=1000&uploads',
'https://localhost:9000/bucket/?max-uploads=1000&uploads=',
{'User-Agent': _DEFAULT_USER_AGENT}, 200, content=mock_data1))

client = Minio('localhost:9000')
Expand All @@ -214,7 +214,7 @@ def test_list_multipart_uploads_works(self, mock_connection):
'https://localhost:9000/bucket/?'
'key-marker=keymarker&'
'max-uploads=1000&'
'upload-id-marker=uploadidmarker&uploads',
'upload-id-marker=uploadidmarker&uploads=',
{'User-Agent': _DEFAULT_USER_AGENT}, 200, content=mock_data2))
uploads.append(upload)

Expand Down

0 comments on commit 340f88c

Please sign in to comment.