From 94b90aa49c3810a4f23ef5df6be94d06be340d41 Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Mon, 27 Jul 2020 11:38:12 -0700 Subject: [PATCH] s3api: Allow lower-cased regions when making buckets Related-Bug: 1888444 Change-Id: I5188b277e8d7fb2c9835e63b951fb944782b4819 --- .../middleware/s3api/controllers/bucket.py | 3 ++- .../common/middleware/s3api/test_bucket.py | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/swift/common/middleware/s3api/controllers/bucket.py b/swift/common/middleware/s3api/controllers/bucket.py index 55603cb597..c94c521bac 100644 --- a/swift/common/middleware/s3api/controllers/bucket.py +++ b/swift/common/middleware/s3api/controllers/bucket.py @@ -344,7 +344,8 @@ class BucketController(Controller): self.logger.error(e) raise - if location != self.conf.location: + if location not in (self.conf.location, + self.conf.location.lower()): # s3api cannot support multiple regions currently. raise InvalidLocationConstraint() diff --git a/test/unit/common/middleware/s3api/test_bucket.py b/test/unit/common/middleware/s3api/test_bucket.py index 3d44a7a903..79f5cf79b0 100644 --- a/test/unit/common/middleware/s3api/test_bucket.py +++ b/test/unit/common/middleware/s3api/test_bucket.py @@ -1220,6 +1220,29 @@ class TestS3ApiBucket(S3ApiTestCase): # Even crazier: it doesn't seem to matter self._test_bucket_PUT_with_location('foo') + def test_bucket_PUT_with_mixed_case_location(self): + self.s3api.conf.location = 'RegionOne' + elem = Element('CreateBucketConfiguration') + # We've observed some clients (like aws-sdk-net) shift regions + # to lower case + SubElement(elem, 'LocationConstraint').text = 'regionone' + headers = { + 'Authorization': 'AWS4-HMAC-SHA256 ' + ', '.join([ + 'Credential=test:tester/%s/regionone/s3/aws4_request' % + self.get_v4_amz_date_header().split('T', 1)[0], + 'SignedHeaders=host', + 'Signature=X', + ]), + 'Date': self.get_date_header(), + 'x-amz-content-sha256': 'UNSIGNED-PAYLOAD', + } + req = Request.blank('/bucket', + environ={'REQUEST_METHOD': 'PUT'}, + headers=headers, + body=tostring(elem)) + status, headers, body = self.call_s3api(req) + self.assertEqual(status.split()[0], '200', body) + def test_bucket_PUT_with_canned_acl(self): req = Request.blank('/bucket', environ={'REQUEST_METHOD': 'PUT'},