def test_registered_defaults(self): filter_factory(CONF) swift_info = utils.get_swift_info() self.assertTrue('swift3' in swift_info) self.assertEqual(swift_info['swift3'].get('max_bucket_listing'), CONF.max_bucket_listing) self.assertEqual(swift_info['swift3'].get('max_parts_listing'), CONF.max_parts_listing) self.assertEqual(swift_info['swift3'].get('max_upload_part_num'), CONF.max_upload_part_num) self.assertEqual(swift_info['swift3'].get('max_multi_delete_objects'), CONF.max_multi_delete_objects)
def test_registered_defaults(self): filter_factory(CONF) swift_info = utils.get_swift_info() self.assertTrue('swift3' in swift_info) self.assertEqual(swift_info['swift3'].get('max_bucket_listing'), CONF.max_bucket_listing) self.assertEqual(swift_info['swift3'].get('max_parts_listing'), CONF.max_parts_listing) self.assertEqual(swift_info['swift3'].get('max_upload_part_num'), CONF.max_upload_part_num) self.assertEqual(swift_info['swift3'].get('max_multi_delete_objects'), CONF.max_multi_delete_objects)
def test_bucket_GET_is_truncated(self): local_app = swift3.filter_factory({})(FakeAppBucket()) bucket_name = 'junk' req = Request.blank('/%s' % bucket_name, environ={ 'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'max-keys=3' }, headers={'Authorization': 'AWS test:tester:hmac'}) resp = local_app(req.environ, local_app.app.do_start_response) dom = xml.dom.minidom.parseString("".join(resp)) self.assertEquals( dom.getElementsByTagName('IsTruncated')[0].childNodes[0].nodeValue, 'false') req = Request.blank('/%s' % bucket_name, environ={ 'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'max-keys=2' }, headers={'Authorization': 'AWS test:tester:hmac'}) resp = local_app(req.environ, local_app.app.do_start_response) dom = xml.dom.minidom.parseString("".join(resp)) self.assertEquals( dom.getElementsByTagName('IsTruncated')[0].childNodes[0].nodeValue, 'true')
def test_object_acl_GET(self): local_app = swift3.filter_factory({})(FakeAppObject()) req = Request.blank('/bucket/object?acl', environ={'REQUEST_METHOD': 'GET'}, headers={'Authorization': 'AWS test:tester:hmac'}) resp = local_app(req.environ, local_app.app.do_start_response) self._check_acl('test:tester', resp)
def test_bucket_GET_max_keys(self): class FakeApp(object): def __call__(self, env, start_response): self.query_string = env['QUERY_STRING'] start_response('200 OK', []) return '[]' fake_app = FakeApp() local_app = swift3.filter_factory({})(fake_app) bucket_name = 'junk' req = Request.blank('/%s' % bucket_name, environ={'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'max-keys=5'}, headers={'Authorization': 'AWS test:tester:hmac'}) resp = local_app(req.environ, lambda *args: None) dom = xml.dom.minidom.parseString("".join(resp)) self.assertEquals(dom.getElementsByTagName('MaxKeys')[0]. childNodes[0].nodeValue, '5') args = dict(cgi.parse_qsl(fake_app.query_string)) self.assert_(args['limit'] == '6') req = Request.blank('/%s' % bucket_name, environ={'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'max-keys=5000'}, headers={'Authorization': 'AWS test:tester:hmac'}) resp = local_app(req.environ, lambda *args: None) dom = xml.dom.minidom.parseString("".join(resp)) self.assertEquals(dom.getElementsByTagName('MaxKeys')[0]. childNodes[0].nodeValue, '1000') args = dict(cgi.parse_qsl(fake_app.query_string)) self.assertEquals(args['limit'], '1001')
def setUp(self): self.app = FakeApp() self.swift = self.app.swift self.swift3 = swift3.filter_factory({})(self.app) self.swift.register('GET', '/something', swob.HTTPOk, {}, 'FAKE APP') self.setup_buckets() self.setup_objects() self.object_body = 'hello' self.response_headers = {'Content-Type': 'text/html', 'Content-Length': len(self.object_body), 'x-object-meta-test': 'swift', 'etag': '1b2cf535f27731c974343645a3985328', 'last-modified': '2011-01-05T02:19:14.275290'} self.swift.register('PUT', '/v1/AUTH_test/bucket', swob.HTTPCreated, {}, None) self.swift.register('POST', '/v1/AUTH_test/bucket', swob.HTTPNoContent, {}, None) self.swift.register('DELETE', '/v1/AUTH_test/bucket', swob.HTTPNoContent, {}, None) self.swift.register('GET', '/v1/AUTH_test/bucket/object', swob.HTTPOk, self.response_headers, self.object_body) self.swift.register('PUT', '/v1/AUTH_test/bucket/object', swob.HTTPCreated, {}, None) self.swift.register('DELETE', '/v1/AUTH_test/bucket/object', swob.HTTPNoContent, {}, None)
def test_bucket_GET_versions(self): app = Mock(wraps=FakeAppBucket()) local_app = swift3.filter_factory({})(app) bucket_name = 'junk' req = Request.blank('/%s?versions' % bucket_name, environ={'REQUEST_METHOD': 'GET'}, headers={'Authorization': 'AWS test:tester:hmac'}) resp = local_app(req.environ, local_app.app.do_start_response) dom = xml.dom.minidom.parseString("".join(resp)) self.assertEquals(dom.firstChild.nodeName, 'ListVersionsResult') name = dom.getElementsByTagName('Name')[0].childNodes[0].nodeValue self.assertEquals(name, bucket_name) objects = [n for n in dom.getElementsByTagName('Version')] dobjects = [n for n in dom.getElementsByTagName('DeleteMarker')] self.assertEquals(len(objects) + len(dobjects), len(FakeAppBucket().vobjects)) self.assertEquals(len(dobjects), 1) for o in objects: for node in o.childNodes: if node.nodeName =='LastModified': self.assertTrue(node.childNodes[0].nodeValue.endswith('Z')) break
def test_bucket_PUT(self): local_app = swift3.filter_factory({})(FakeAppBucket(201)) req = Request.blank('/bucket', environ={'REQUEST_METHOD': 'PUT'}, headers={'Authorization': 'AWS test:tester:hmac'}) local_app(req.environ, local_app.app.do_start_response) self.assertEquals(local_app.app.response_args[0].split()[0], '200')
def test_object_PUT_headers(self): class FakeApp(object): def __call__(self, env, start_response): self.req = Request(env) start_response('200 OK', []) return [] app = FakeApp() local_app = swift3.filter_factory({})(app) req = Request.blank('/bucket/object', environ={'REQUEST_METHOD': 'PUT'}, headers={ 'Authorization': 'AWS test:tester:hmac', 'X-Amz-Storage-Class': 'REDUCED_REDUNDANCY', 'X-Amz-Meta-Something': 'oh hai', 'X-Amz-Copy-Source': '/some/source', 'Content-MD5': 'ffoHqOWd280dyE1MT4KuoQ==' }) req.date = datetime.now() req.content_type = 'text/plain' resp = local_app(req.environ, lambda *args: None) self.assertEquals(app.req.headers['ETag'], '7dfa07a8e59ddbcd1dc84d4c4f82aea1') self.assertEquals(app.req.headers['X-Object-Meta-Something'], 'oh hai') self.assertEquals(app.req.headers['X-Copy-From'], '/some/source')
def test_bucket_GET_max_keys(self): class FakeApp(object): def __call__(self, env, start_response): self.query_string = env['QUERY_STRING'] start_response('200 OK', []) return '[]' fake_app = FakeApp() local_app = swift3.filter_factory({})(fake_app) bucket_name = 'junk' req = Request.blank('/%s' % bucket_name, environ={'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'max-keys=5'}, headers={'Authorization': 'AWS test:tester:hmac'}) resp = local_app(req.environ, lambda *args: None) dom = xml.dom.minidom.parseString("".join(resp)) self.assertEquals(dom.getElementsByTagName('MaxKeys')[0]. childNodes[0].nodeValue, '5') args = dict(cgi.parse_qsl(fake_app.query_string)) self.assert_(args['limit'] == '6') req = Request.blank('/%s' % bucket_name, environ={'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'max-keys=5000'}, headers={'Authorization': 'AWS test:tester:hmac'}) resp = local_app(req.environ, lambda *args: None) dom = xml.dom.minidom.parseString("".join(resp)) self.assertEquals(dom.getElementsByTagName('MaxKeys')[0]. childNodes[0].nodeValue, '1000') args = dict(cgi.parse_qsl(fake_app.query_string)) self.assertEquals(args['limit'], '1001')
def test_bucket_PUT(self): local_app = swift3.filter_factory({})(FakeAppBucket(201)) req = Request.blank( "/bucket", environ={"REQUEST_METHOD": "PUT"}, headers={"Authorization": "AWS test:tester:hmac"} ) local_app(req.environ, local_app.app.do_start_response) self.assertEquals(local_app.app.response_args[0].split()[0], "200")
def test_object_PUT_headers(self): class FakeApp(object): def __call__(self, env, start_response): self.req = Request(env) start_response("200 OK", []) return [] app = FakeApp() local_app = swift3.filter_factory({})(app) req = Request.blank( "/bucket/object", environ={"REQUEST_METHOD": "PUT"}, headers={ "Authorization": "AWS test:tester:hmac", "X-Amz-Storage-Class": "REDUCED_REDUNDANCY", "X-Amz-Meta-Something": "oh hai", "X-Amz-Copy-Source": "/some/source", "Content-MD5": "ffoHqOWd280dyE1MT4KuoQ==", }, ) req.date = datetime.now() req.content_type = "text/plain" resp = local_app(req.environ, lambda *args: None) self.assertEquals(app.req.headers["ETag"], "7dfa07a8e59ddbcd1dc84d4c4f82aea1") self.assertEquals(app.req.headers["X-Object-Meta-Something"], "oh hai") self.assertEquals(app.req.headers["X-Copy-From"], "/some/source")
def test_object_DELETE(self): local_app = swift3.filter_factory({})(FakeAppObject(204)) req = Request.blank( "/bucket/object", environ={"REQUEST_METHOD": "DELETE"}, headers={"Authorization": "AWS test:tester:hmac"} ) resp = local_app(req.environ, local_app.app.do_start_response) self.assertEquals(local_app.app.response_args[0].split()[0], "204")
def test_bucket_GET(self): local_app = swift3.filter_factory({})(FakeAppBucket()) bucket_name = 'junk' req = Request.blank('/%s' % bucket_name, environ={'REQUEST_METHOD': 'GET'}, headers={'Authorization': 'AWS test:tester:hmac'}) resp = local_app(req.environ, local_app.app.do_start_response) self.assertEquals(local_app.app.response_args[0].split()[0], '200') dom = xml.dom.minidom.parseString("".join(resp)) self.assertEquals(dom.firstChild.nodeName, 'ListBucketResult') name = dom.getElementsByTagName('Name')[0].childNodes[0].nodeValue self.assertEquals(name, bucket_name) objects = [n for n in dom.getElementsByTagName('Contents')] names = [] for o in objects: if o.childNodes[0].nodeName == 'Key': names.append(o.childNodes[0].childNodes[0].nodeValue) if o.childNodes[1].nodeName == 'LastModified': self.assertTrue( o.childNodes[1].childNodes[0].nodeValue.endswith('Z')) self.assertEquals(len(names), len(FakeAppBucket().objects)) for i in FakeAppBucket().objects: self.assertTrue(i[0] in names)
def test_object_DELETE(self): local_app = swift3.filter_factory({})(FakeAppObject(204)) req = Request.blank('/bucket/object', environ={'REQUEST_METHOD': 'DELETE'}, headers={'Authorization': 'AWS test:tester:hmac'}) local_app(req.environ, local_app.app.do_start_response) self.assertEquals(local_app.app.response_args[0].split()[0], '204')
def test_object_acl_GET(self): local_app = swift3.filter_factory({})(FakeAppObject()) req = Request.blank('/bucket/object?acl', environ={'REQUEST_METHOD': 'GET'}, headers={'Authorization': 'AWS test:tester:hmac'}) resp = local_app(req.environ, local_app.app.do_start_response) self._check_acl('test:tester', resp)
def test_bucket_GET_max_keys(self): class FakeApp(object): def __call__(self, env, start_response): self.query_string = env["QUERY_STRING"] start_response("200 OK", []) return "[]" fake_app = FakeApp() local_app = swift3.filter_factory({})(fake_app) bucket_name = "junk" req = Request.blank( "/%s" % bucket_name, environ={"REQUEST_METHOD": "GET", "QUERY_STRING": "max-keys=5"}, headers={"Authorization": "AWS test:tester:hmac"}, ) resp = local_app(req.environ, lambda *args: None) dom = xml.dom.minidom.parseString("".join(resp)) self.assertEquals(dom.getElementsByTagName("MaxKeys")[0].childNodes[0].nodeValue, "5") args = dict(cgi.parse_qsl(fake_app.query_string)) self.assert_(args["limit"] == "6") req = Request.blank( "/%s" % bucket_name, environ={"REQUEST_METHOD": "GET", "QUERY_STRING": "max-keys=5000"}, headers={"Authorization": "AWS test:tester:hmac"}, ) resp = local_app(req.environ, lambda *args: None) dom = xml.dom.minidom.parseString("".join(resp)) self.assertEquals(dom.getElementsByTagName("MaxKeys")[0].childNodes[0].nodeValue, "1000") args = dict(cgi.parse_qsl(fake_app.query_string)) self.assertEquals(args["limit"], "1001")
def test_bucket_GET(self): local_app = swift3.filter_factory({})(FakeAppBucket()) bucket_name = "junk" req = Request.blank( "/%s" % bucket_name, environ={"REQUEST_METHOD": "GET"}, headers={"Authorization": "AWS test:tester:hmac"} ) resp = local_app(req.environ, local_app.app.do_start_response) self.assertEquals(local_app.app.response_args[0].split()[0], "200") dom = xml.dom.minidom.parseString("".join(resp)) self.assertEquals(dom.firstChild.nodeName, "ListBucketResult") name = dom.getElementsByTagName("Name")[0].childNodes[0].nodeValue self.assertEquals(name, bucket_name) objects = [n for n in dom.getElementsByTagName("Contents")] names = [] for o in objects: if o.childNodes[0].nodeName == "Key": names.append(o.childNodes[0].childNodes[0].nodeValue) if o.childNodes[1].nodeName == "LastModified": self.assertTrue(o.childNodes[1].childNodes[0].nodeValue.endswith("Z")) self.assertEquals(len(names), len(FakeAppBucket().objects)) for i in FakeAppBucket().objects: self.assertTrue(i[0] in names)
def test_bucket_PUT(self): local_app = swift3.filter_factory({})(FakeAppBucket(201)) req = Request.blank('/bucket', environ={'REQUEST_METHOD': 'PUT'}, headers={'Authorization': 'AWS test:tester:hmac'}) resp = local_app(req.environ, local_app.app.do_start_response) self.assertEquals(local_app.app.response_args[0].split()[0], '200')
def test_object_acl_GET(self): local_app = swift3.filter_factory({})(FakeAppObject()) req = Request.blank( "/bucket/object?acl", environ={"REQUEST_METHOD": "GET"}, headers={"Authorization": "AWS test:tester:hmac"} ) resp = local_app(req.environ, local_app.app.do_start_response) self._check_acl("test:tester", resp)
def test_bucket_GET(self): local_app = swift3.filter_factory({})(FakeAppBucket()) bucket_name = 'junk' req = Request.blank('/%s' % bucket_name, environ={'REQUEST_METHOD': 'GET'}, headers={'Authorization': 'AWS test:tester:hmac'}) resp = local_app(req.environ, local_app.app.do_start_response) self.assertEquals(local_app.app.response_args[0].split()[0], '200') dom = xml.dom.minidom.parseString("".join(resp)) self.assertEquals(dom.firstChild.nodeName, 'ListBucketResult') name = dom.getElementsByTagName('Name')[0].childNodes[0].nodeValue self.assertEquals(name, bucket_name) objects = [n for n in dom.getElementsByTagName('Contents')] names = [] for o in objects: if o.childNodes[0].nodeName == 'Key': names.append(o.childNodes[0].childNodes[0].nodeValue) if o.childNodes[1].nodeName == 'LastModified': self.assertTrue( o.childNodes[1].childNodes[0].nodeValue.endswith('Z')) self.assertEquals(len(names), len(FakeAppBucket().objects)) for i in FakeAppBucket().objects: self.assertTrue(i[0] in names)
def test_object_DELETE(self): local_app = swift3.filter_factory({})(FakeAppObject(204)) req = Request.blank('/bucket/object', environ={'REQUEST_METHOD': 'DELETE'}, headers={'Authorization': 'AWS test:tester:hmac'}) resp = local_app(req.environ, local_app.app.do_start_response) self.assertEquals(local_app.app.response_args[0].split()[0], '204')
def test_bucket_GET_passthroughs(self): class FakeApp(object): def __call__(self, env, start_response): self.query_string = env['QUERY_STRING'] start_response('200 OK', []) return '[]' fake_app = FakeApp() local_app = swift3.filter_factory({})(fake_app) bucket_name = 'junk' req = Request.blank('/%s' % bucket_name, environ={'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'delimiter=a&marker=b&prefix=c'}, headers={'Authorization': 'AWS test:tester:hmac'}) resp = local_app(req.environ, lambda *args: None) dom = xml.dom.minidom.parseString("".join(resp)) self.assertEquals(dom.getElementsByTagName('Prefix')[0]. childNodes[0].nodeValue, 'c') self.assertEquals(dom.getElementsByTagName('Marker')[0]. childNodes[0].nodeValue, 'b') self.assertEquals(dom.getElementsByTagName('Delimiter')[0]. childNodes[0].nodeValue, 'a') args = dict(cgi.parse_qsl(fake_app.query_string)) self.assertEquals(args['delimiter'], 'a') self.assertEquals(args['marker'], 'b') self.assertEquals(args['prefix'], 'c')
def test_bucket_GET_passthroughs(self): class FakeApp(object): def __call__(self, env, start_response): self.query_string = env['QUERY_STRING'] start_response('200 OK', []) return '[]' fake_app = FakeApp() local_app = swift3.filter_factory({})(fake_app) bucket_name = 'junk' req = Request.blank('/%s' % bucket_name, environ={'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'delimiter=a&marker=b&prefix=c'}, headers={'Authorization': 'AWS test:tester:hmac'}) resp = local_app(req.environ, lambda *args: None) dom = xml.dom.minidom.parseString("".join(resp)) self.assertEquals(dom.getElementsByTagName('Prefix')[0]. childNodes[0].nodeValue, 'c') self.assertEquals(dom.getElementsByTagName('Marker')[0]. childNodes[0].nodeValue, 'b') self.assertEquals(dom.getElementsByTagName('Delimiter')[0]. childNodes[0].nodeValue, 'a') args = dict(cgi.parse_qsl(fake_app.query_string)) self.assertEquals(args['delimiter'], 'a') self.assertEquals(args['marker'], 'b') self.assertEquals(args['prefix'], 'c')
def _test_method_error(self, cl, method, path, status, headers={}): local_app = swift3.filter_factory({})(cl(status)) headers.update({"Authorization": "AWS test:tester:hmac"}) req = Request.blank(path, environ={"REQUEST_METHOD": method}, headers=headers) resp = local_app(req.environ, start_response) dom = xml.dom.minidom.parseString("".join(resp)) self.assertEquals(dom.firstChild.nodeName, "Error") return dom.getElementsByTagName("Code")[0].childNodes[0].nodeValue
def test_object_GET_with_versionId(self): local_app = swift3.filter_factory({})(FakeAppObject()) req = Request.blank('/bucket/object?versionId=123456789.123456', environ={'REQUEST_METHOD': 'GET'}, headers={'Authorization': 'AWS test:hmac'}) local_app(req.environ, local_app.app.do_start_response) self.assertEqual(local_app.app.env[0]["PATH_INFO"], '/v1/test/bucket_versioned/object$123456789.123456$1')
def _test_method_error(self, cl, method, path, status): local_app = swift3.filter_factory({})(cl(status)) req = Request.blank(path, environ={'REQUEST_METHOD': method}, headers={'Authorization': 'AWS test:tester:hmac'}) resp = local_app(req.environ, start_response) dom = xml.dom.minidom.parseString("".join(resp)) self.assertEquals(dom.firstChild.nodeName, 'Error') return dom.getElementsByTagName('Code')[0].childNodes[0].nodeValue
def test_bucket_versioning_GET(self): local_app = swift3.filter_factory({})(FakeAppBucket()) bucket_name = 'junk' req = Request.blank('/%s?versioning' % bucket_name, environ={'REQUEST_METHOD': 'GET'}, headers={'Authorization': 'AWS test:tester:hmac'}) resp = local_app(req.environ, local_app.app.do_start_response) dom = xml.dom.minidom.parseString("".join(resp)) self.assertEquals(dom.firstChild.nodeName, 'VersioningConfiguration')
def test_bucket_PUT_acl_to_existing_container(self): local_app = swift3.filter_factory({})(FakeAppBucket(204)) req = Request.blank('/bucket?acl', environ={'REQUEST_METHOD': 'PUT'}, headers={ 'Authorization': 'AWS test:tester:hmac', 'X-Amz-Acl': 'public-read'}) resp = local_app(req.environ, local_app.app.do_start_response) self.assertEquals(local_app.app.response_args[0].split()[0], '200')
def _test_method_error(self, cl, method, path, status, headers={}): local_app = swift3.filter_factory({})(cl(status)) headers.update({'Authorization': 'AWS test:tester:hmac'}) req = Request.blank(path, environ={'REQUEST_METHOD': method}, headers=headers) resp = local_app(req.environ, start_response) dom = xml.dom.minidom.parseString("".join(resp)) self.assertEquals(dom.firstChild.nodeName, 'Error') return dom.getElementsByTagName('Code')[0].childNodes[0].nodeValue
def test_bucket_versioning_GET(self): local_app = swift3.filter_factory({})(FakeAppBucket()) bucket_name = 'junk' req = Request.blank('/%s?versioning' % bucket_name, environ={'REQUEST_METHOD': 'GET'}, headers={'Authorization': 'AWS test:tester:hmac'}) resp = local_app(req.environ, local_app.app.do_start_response) dom = xml.dom.minidom.parseString("".join(resp)) self.assertEquals(dom.firstChild.nodeName, 'VersioningConfiguration')
def test_object_DELETE_no_need_versions_file(self): app = Mock(wraps=FakeAppObject(204)) local_app = swift3.filter_factory({})(app) req = Request.blank('/bucket/meta/foo/bar', environ={'REQUEST_METHOD': 'DELETE'}, headers={'Authorization': 'AWS test:tester:hmac'}) local_app(req.environ, local_app.app.do_start_response) self.assertEquals(app.call_count, 1) self.assertEquals(app.call_args_list[0][0][0]['REQUEST_METHOD'], 'DELETE')
def test_bucket_acl_GET(self): local_app = swift3.filter_factory({})(FakeAppBucket()) bucket_name = "junk" req = Request.blank( "/%s?acl" % bucket_name, environ={"REQUEST_METHOD": "GET"}, headers={"Authorization": "AWS test:tester:hmac"}, ) resp = local_app(req.environ, local_app.app.do_start_response) self._check_acl("test:tester", resp)
def test_bucket_PUT_acl_to_existing_container(self): local_app = swift3.filter_factory({})(FakeAppBucket(204)) req = Request.blank('/bucket?acl', environ={'REQUEST_METHOD': 'PUT'}, headers={ 'Authorization': 'AWS test:tester:hmac', 'X-Amz-Acl': 'public-read' }) resp = local_app(req.environ, local_app.app.do_start_response) self.assertEquals(local_app.app.response_args[0].split()[0], '200')
def test_bucket_versioning_GET(self): local_app = swift3.filter_factory({})(FakeAppBucket()) bucket_name = "junk" req = Request.blank( "/%s?versioning" % bucket_name, environ={"REQUEST_METHOD": "GET"}, headers={"Authorization": "AWS test:tester:hmac"}, ) resp = local_app(req.environ, local_app.app.do_start_response) dom = xml.dom.minidom.parseString("".join(resp)) self.assertEquals(dom.firstChild.nodeName, "VersioningConfiguration")
def test_object_with_url_encoded_characters(self): fake_app_object = FakeAppObject() local_app = swift3.filter_factory({})(fake_app_object) req = Request.blank('/bucket_name/some name', headers={'Authorization': 'AWS test:hmac'}) # PATH_INFO contains path unquoted self.assertEquals(req.environ['PATH_INFO'], '/bucket_name/some name') local_app(req.environ, start_response) # Checking PATH_INFO is setted ok in ObjectController, still unquoted self.assertEquals(fake_app_object.env['PATH_INFO'], '/v1/test/bucket_name/some name')
def test_object_PUT_no_need_versions_file(self): app = Mock(wraps=FakeAppObject(201)) local_app = swift3.filter_factory({})(app) req = Request.blank('/bucket/meta/foo/bar', environ={'REQUEST_METHOD': 'PUT'}, headers={'Authorization': 'AWS test:hmac'}) req.date = datetime.now() req.content_type = 'text/plain' local_app(req.environ, local_app.app.do_start_response) self.assertEquals(app.call_count, 1) self.assertEquals(app.call_args_list[0][0][0]['REQUEST_METHOD'], 'PUT')
def test_bucket_PUT_versioned(self): app = Mock(wraps=FakeAppBucket(201)) local_app = swift3.filter_factory({})(app) req = Request.blank('/bucket', environ={'REQUEST_METHOD': 'PUT'}, headers={'Authorization': 'AWS test:hmac'}) local_app(req.environ, local_app.app.do_start_response) self.assertEquals(app.call_count, 2) self.assertEquals(app.call_args_list[0][0][0]['PATH_INFO'], '/v1/test/bucket') self.assertEquals(app.call_args_list[1][0][0]['PATH_INFO'], '/v1/test/bucket_versioned')
def test_path_info_encode(self): local_app = swift3.filter_factory({})(FakeAppObject()) bucket_name = 'b%75cket' object_name = 'ob%6aect:1' req = Request.blank('/%s/%s' % (bucket_name, object_name), environ={'REQUEST_METHOD': 'GET'}, headers={'Authorization': 'AWS test:tester:hmac'}) local_app(req.environ, start_response) raw_path_info = "/v1/test:tester/%s/%s" % (bucket_name, object_name) path_info = req.environ['PATH_INFO'] self.assertEquals(path_info, unquote(raw_path_info)) self.assertEquals(req.path, quote(path_info))
def test_object_GET_Range(self): local_app = swift3.filter_factory({})(FakeAppObject()) req = Request.blank('/bucket/object', environ={'REQUEST_METHOD': 'GET'}, headers={'Authorization': 'AWS test:tester:hmac', 'Range': 'bytes=0-3'}) resp = local_app(req.environ, local_app.app.do_start_response) self.assertEquals(local_app.app.response_args[0].split()[0], '206') headers = dict(local_app.app.response_args[1]) self.assertTrue('Content-Range' in headers) self.assertTrue(headers['Content-Range'].startswith('bytes 0-3'))
def test_object_GET_Range(self): local_app = swift3.filter_factory({})(FakeAppObject()) req = Request.blank( "/bucket/object", environ={"REQUEST_METHOD": "GET"}, headers={"Authorization": "AWS test:tester:hmac", "Range": "bytes=0-3"}, ) resp = local_app(req.environ, local_app.app.do_start_response) self.assertEquals(local_app.app.response_args[0].split()[0], "206") headers = dict((k.lower(), v) for k, v in local_app.app.response_args[1]) self.assertTrue("content-range" in headers) self.assertTrue(headers["content-range"].startswith("bytes 0-3"))
def test_object_GET_Range(self): local_app = swift3.filter_factory({})(FakeAppObject()) req = Request.blank('/bucket/object', environ={'REQUEST_METHOD': 'GET'}, headers={'Authorization': 'AWS test:tester:hmac', 'Range': 'bytes=0-3'}) local_app(req.environ, local_app.app.do_start_response) self.assertEquals(local_app.app.response_args[0].split()[0], '206') headers = dict((k.lower(), v) for k, v in local_app.app.response_args[1]) self.assertTrue('content-range' in headers) self.assertTrue(headers['content-range'].startswith('bytes 0-3'))
def test_object_PUT_copy_from_with_versionId(self): local_app = swift3.filter_factory({})(FakeAppObject(201)) req = Request.blank('/bucket/object', environ={'REQUEST_METHOD': 'PUT', 'HTTP_X_AMZ_COPY_SOURCE': '/bucket/foo?versionId=123456789.123456'}, headers={'Authorization': 'AWS test:hmac'}) resp = local_app(req.environ, local_app.app.do_start_response) dom = xml.dom.minidom.parseString("".join(resp)) self.assertEquals(dom.firstChild.nodeName, 'CopyObjectResult') self.assertEqual(local_app.app.env[0]["HTTP_X_COPY_FROM"], '/bucket_versioned/foo$123456789.123456$1')
def test_signed_urls(self): class FakeApp(object): def __call__(self, env, start_response): self.req = Request(env) start_response('200 OK', []) return [] app = FakeApp() local_app = swift3.filter_factory({})(app) req = Request.blank('/bucket/object?Signature=X&Expires=Y&' 'AWSAccessKeyId=Z', environ={'REQUEST_METHOD': 'GET'}) req.headers['Date'] = datetime.utcnow() req.content_type = 'text/plain' resp = local_app(req.environ, lambda *args: None) self.assertEquals(req.headers['Authorization'], 'AWS Z:X') self.assertEquals(req.headers['Date'], 'Y')
def test_object_PUT(self): local_app = swift3.filter_factory({})(FakeAppObject(201)) req = Request.blank('/bucket/object', environ={'REQUEST_METHOD': 'PUT'}, headers={'Authorization': 'AWS test:tester:hmac', 'x-amz-storage-class': 'REDUCED_REDUNDANCY', 'Content-MD5': 'Gyz1NfJ3Mcl0NDZFo5hTKA=='}) req.date = datetime.now() req.content_type = 'text/plain' resp = local_app(req.environ, local_app.app.do_start_response) self.assertEquals(local_app.app.response_args[0].split()[0], '200') headers = dict((k.lower(), v) for k, v in local_app.app.response_args[1]) self.assertEquals(headers['etag'], "\"%s\"" % local_app.app.response_headers['etag'])
def test_object_multi_DELETE(self): local_app = swift3.filter_factory({})(FakeAppBucket()) body = '<?xml version="1.0" encoding="UTF-8"?> \ <Delete>\ <Object>\ <Key>Key1</Key>\ </Object>\ <Object>\ <Key>Key2</Key>\ </Object>\ </Delete>' req = Request.blank('/bucket?delete', environ={'REQUEST_METHOD': 'POST'}, headers={'Authorization': 'AWS test:tester:hmac'}, body=body) req.date = datetime.now() req.content_type = 'text/plain' local_app(req.environ, local_app.app.do_start_response) self.assertEquals(local_app.app.response_args[0].split()[0], '200')
def test_signed_urls(self): class FakeApp(object): def __call__(self, env, start_response): self.req = Request(env) start_response('200 OK', []) return [] app = FakeApp() local_app = swift3.filter_factory({})(app) dt = datetime.utcnow() dt_formatted = dt.strftime("%a, %d %b %Y %H:%M:%S GMT") req = Request.blank( '/bucket/object?Signature=X&Expires=%s&AWSAccessKeyId=Z' % (urllib.quote(dt_formatted)), environ={'REQUEST_METHOD': 'GET'}) req.date = dt req.content_type = 'text/plain' resp = local_app(req.environ, lambda *args: None) self.assertEquals(app.req.headers['Authorization'], 'AWS Z:X') self.assertEquals(app.req.headers['Date'], dt_formatted)
def _test_object_GETorHEAD(self, method): local_app = swift3.filter_factory({})(FakeAppObject()) req = Request.blank('/bucket/object', environ={'REQUEST_METHOD': method}, headers={'Authorization': 'AWS test:tester:hmac'}) resp = local_app(req.environ, local_app.app.do_start_response) self.assertEquals(local_app.app.response_args[0].split()[0], '200') headers = dict(local_app.app.response_args[1]) for key, val in local_app.app.response_headers.iteritems(): if key in ('Content-Length', 'Content-Type', 'Content-Encoding', 'etag', 'last-modified'): self.assertTrue(key in headers) self.assertEquals(headers[key], val) elif key.startswith('x-object-meta-'): self.assertTrue('x-amz-meta-' + key[14:] in headers) self.assertEquals(headers['x-amz-meta-' + key[14:]], val) if method == 'GET': self.assertEquals(''.join(resp), local_app.app.object_body)
def setUp(self): self.app = FakeApp() self.swift = self.app.swift self.swift3 = filter_factory({}, **CONF)(self.app) self.swift.register('HEAD', '/v1/AUTH_test', swob.HTTPOk, {}, None) self.swift.register('HEAD', '/v1/AUTH_test/bucket', swob.HTTPNoContent, {}, None) self.swift.register('PUT', '/v1/AUTH_test/bucket', swob.HTTPCreated, {}, None) self.swift.register('POST', '/v1/AUTH_test/bucket', swob.HTTPNoContent, {}, None) self.swift.register('DELETE', '/v1/AUTH_test/bucket', swob.HTTPNoContent, {}, None) self.swift.register('GET', '/v1/AUTH_test/bucket/object', swob.HTTPOk, {'etag': 'object etag'}, "") self.swift.register('PUT', '/v1/AUTH_test/bucket/object', swob.HTTPCreated, {'etag': 'object etag'}, None) self.swift.register('DELETE', '/v1/AUTH_test/bucket/object', swob.HTTPNoContent, {}, None)
def test_service_GET(self): local_app = swift3.filter_factory({})(FakeAppService()) req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'}, headers={'Authorization': 'AWS test:tester:hmac'}) resp = local_app(req.environ, local_app.app.do_start_response) self.assertEquals(local_app.app.response_args[0].split()[0], '200') dom = xml.dom.minidom.parseString("".join(resp)) self.assertEquals(dom.firstChild.nodeName, 'ListAllMyBucketsResult') buckets = [n for n in dom.getElementsByTagName('Bucket')] listing = [n for n in buckets[0].childNodes if n.nodeName != '#text'] self.assertEquals(len(listing), 2) names = [] for b in buckets: if b.childNodes[0].nodeName == 'Name': names.append(b.childNodes[0].childNodes[0].nodeValue) self.assertEquals(len(names), len(FakeAppService().buckets)) for i in FakeAppService().buckets: self.assertTrue(i[0] in names)
def setUp(self): self.app = swift3.filter_factory({})(FakeApp())