Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fixed #1687 - Headers involved with signing sent with S3 keys should …
Browse files Browse the repository at this point in the history
…be case-insensitive for the user.
  • Loading branch information
toastdriven committed Aug 30, 2013
1 parent edb038a commit 89eae8c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
9 changes: 8 additions & 1 deletion boto/s3/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,14 @@ def get_metadata(self, name):
return self.metadata.get(name)

def set_metadata(self, name, value):
self.metadata[name] = value
# Ensure that metadata that is vital to signing is in the correct
# case. Applies to ``Content-Type`` & ``Content-MD5``.
if name.lower() == 'content-type':
self.metadata['Content-Type'] = value
elif name.lower() == 'content-md5':
self.metadata['Content-MD5'] = value
else:
self.metadata[name] = value

def update_metadata(self, d):
self.metadata.update(d)
Expand Down
11 changes: 11 additions & 0 deletions tests/integration/s3/test_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,14 @@ def test_setting_date(self):
check = self.bucket.get_key('test_date')
self.assertEqual(check.get_metadata('date'), u'20130524T155935Z')
self.assertTrue('x-amz-meta-date' in check._get_remote_metadata())

def test_header_casing(self):
key = self.bucket.new_key('test_header_case')
# Using anything but CamelCase on ``Content-Type`` or ``Content-MD5``
# used to cause a signature error (when using ``s3`` for signing).
key.set_metadata('Content-type', 'application/json')
key.set_metadata('Content-md5', 'XmUKnus7svY1frWsVskxXg==')
key.set_contents_from_string('{"abc": 123}')

check = self.bucket.get_key('test_header_case')
self.assertEqual(check.content_type, 'application/json')

0 comments on commit 89eae8c

Please sign in to comment.