def test_bucket_GET_max_keys(self): bucket_name = 'junk' req = Request.blank('/%s?max-keys=5' % bucket_name, environ={'REQUEST_METHOD': 'GET'}, headers={ 'Authorization': 'OSS test:tester:hmac', 'Date': self.get_date_header() }) status, headers, body = self.call_oss2swift(req) elem = fromstring(body, 'ListBucketResult') self.assertEqual(elem.find('./MaxKeys').text, '5') _, path = self.swift.calls[-1] _, query_string = path.split('?') args = dict(cgi.parse_qsl(query_string)) self.assertEqual(args['limit'], '6') req = Request.blank('/%s?max-keys=5000' % bucket_name, environ={'REQUEST_METHOD': 'GET'}, headers={ 'Authorization': 'OSS test:tester:hmac', 'Date': self.get_date_header() }) status, headers, body = self.call_oss2swift(req) elem = fromstring(body, 'ListBucketResult') self.assertEqual(elem.find('./MaxKeys').text, '5000') _, path = self.swift.calls[-1] _, query_string = path.split('?') args = dict(cgi.parse_qsl(query_string)) self.assertEqual(args['limit'], '1001')
def test_service(self): # GET Service(without bucket) status, headers, body = self.conn.make_request('GET') self.assertEqual(status, 200) self.assertCommonResponseHeaders(headers) self.assertTrue(headers['Content-Type'] is not None) # TODO; requires consideration # self.assertEqual(headers['transfer-encoding'], 'chunked') elem = fromstring(body, 'ListAllMyBucketsResult') buckets = elem.findall('./Buckets/Bucket') self.assertEqual(list(buckets), []) owner = elem.find('Owner') self.assertEqual(self.conn.user_id, owner.find('ID').text) self.assertEqual(self.conn.user_id, owner.find('DisplayName').text) # GET Service(with Bucket) req_buckets = ('bucket', 'bucket2') for bucket in req_buckets: self.conn.make_request('PUT', bucket) status, headers, body = self.conn.make_request('GET') self.assertEqual(status, 200) elem = fromstring(body, 'ListAllMyBucketsResult') resp_buckets = elem.findall('./Buckets/Bucket') self.assertEqual(len(list(resp_buckets)), 2) for b in resp_buckets: self.assertTrue(b.find('Name').text in req_buckets) self.assertTrue(b.find('CreationDate') is not None)
def test_delete_multi_objects_with_quiet(self): bucket = 'bucket' put_objects = ['obj'] query = {'delete': ''} # with Quiet true quiet = 'true' self._prepare_test_delete_multi_objects(bucket, put_objects) xml = self._gen_multi_delete_xml(put_objects, quiet) content_md5 = calculate_md5(xml) status, headers, body = \ self.conn.make_request('POST', bucket,body=xml, headers={'Content-MD5': content_md5}, query=query) self.assertEqual(status, 200) elem = fromstring(body, 'DeleteResult') resp_objects = elem.findall('Deleted') self.assertEqual(len(resp_objects), 0) # with Quiet false quiet = 'false' self._prepare_test_delete_multi_objects(bucket, put_objects) xml = self._gen_multi_delete_xml(put_objects, quiet) content_md5 = calculate_md5(xml) status, headers, body = \ self.conn.make_request('POST', bucket,body=xml, headers={'Content-MD5': content_md5}, query=query) self.assertEqual(status, 200) elem = fromstring(body, 'DeleteResult') resp_objects = elem.findall('Deleted') self.assertEqual(len(resp_objects), 1)
def test_service_GET_with_blind_resource(self): buckets = (('apple', 1, 200), ('orange', 3, 430), ('apple+segment', 1, 200)) expected = buckets[:-1] bucket_list = create_bucket_list_json(buckets) self.swift.register('GET', '/v1/AUTH_test', swob.HTTPOk, {}, bucket_list) req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'}, headers={ 'Authorization': 'OSS test:tester:hmac', 'Date': self.get_date_header() }) status, headers, body = self.call_oss2swift(req) self.assertEqual(status.split()[0], '200') elem = fromstring(body, 'ListAllMyBucketsResult') all_buckets = elem.find('./Buckets') buckets = all_buckets.iterchildren('Bucket') listing = list(list(buckets)[0]) self.assertEqual(len(listing), 5) names = [] for b in all_buckets.iterchildren('Bucket'): names.append(b.find('./Name').text) self.assertEqual(len(names), len(expected)) for i in expected: self.assertTrue(i[0] in names)
def swift_acl_translate(acl, group='', user='', xml=False): """ Takes an OSS style ACL and returns a list of header/value pairs that implement that ACL in Swift, or "NotImplemented" if there isn't a way to do that yet. """ swift_acl = {} swift_acl['public-read'] = [['X-Container-Read', '.r:*,.rlistings']] # Swift does not support public write: swift_acl['public-read-write'] = [['X-Container-Write', '.r:*'], ['X-Container-Read', '.r:*,.rlistings']] # TODO: if there's a way to get group and user, this should work for # private: # swift_acl['private'] = \ # [['HTTP_X_CONTAINER_WRITE', group + ':' + user], \ # ['HTTP_X_CONTAINER_READ', group + ':' + user]] swift_acl['private'] = [['X-Container-Write', ' '], ['X-Container-Read', ' ']] if xml: # We are working with XML and need to parse it try: elem = fromstring(acl, 'AccessControlPolicy') except (XMLSyntaxError, DocumentInvalid): raise MalformedACLError() acl = 'unknown' acl = elem.find('./AccessControlList/Grant').text if acl not in swift_acl: raise ACLError() return swift_acl[acl]
def PUT(self, req): """ Handle PUT Bucket Referer request """ xml = req.xml(MAX_PUT_BUCKET_REFERER_SIZE) if xml: # check referer try: elem = fromstring(xml, 'RefererConfiguration') allow_empyt_referer=elem.find('AllowEmptyReferer').text if allow_empyt_referer not in ['true','false']: raise InvalidArgument() referer_list=elem.find('RefererList') swift_referers=[] for referer in referer_list.findall('Referer'): swift_referers.append(referer.text) if len(swift_referers)==0 : req.headers['X-Container-Read']=' ' else: req.headers['X-Container-Read'] = '.r:'+','.join(get_real_url(swift_referers)) except (XMLSyntaxError, DocumentInvalid): raise MalformedXML() except Exception as e: exc_type, exc_value, exc_traceback = sys.exc_info() LOGGER.error(e) raise exc_type, exc_value, exc_traceback resp = req.get_response(self.app) resp.status = HTTP_OK return resp
def PUT(self, req): """ Handle PUT Bucket request """ location = "" xml = req.xml(MAX_PUT_BUCKET_BODY_SIZE) if xml: # check location try: elem = fromstring(xml, 'CreateBucketConfiguration') location = elem.find('./LocationConstraint').text except (XMLSyntaxError, DocumentInvalid): raise MalformedXML() except Exception as e: exc_type, exc_value, exc_traceback = sys.exc_info() LOGGER.error(e) raise exc_type, exc_value, exc_traceback if location not in CONF.location: # Oss2swift cannot support multiple regions currently. raise InvalidLocationConstraint() if location is None or location == "": location = choice(CONF.location) req.headers['X-Container-Meta-Location'] = location # req.headers['X-Container-Meta-Location'] = location req.headers['X-Container-Meta-Create'] = time.time() resp = req.get_response(self.app) resp.status = HTTP_OK resp.location = '/' + location return resp
def test_object_multi_DELETE_quiet(self): self.swift.register('DELETE', '/v1/AUTH_test/bucket/Key1', swob.HTTPNoContent, {}, None) self.swift.register('DELETE', '/v1/AUTH_test/bucket/Key2', swob.HTTPNotFound, {}, None) elem = Element('Delete') SubElement(elem, 'Quiet').text = 'true' for key in ['Key1', 'Key2']: obj = SubElement(elem, 'Object') SubElement(obj, 'Key').text = key body = tostring(elem, use_ossns=False) content_md5 = md5(body).digest().encode('base64').strip() req = Request.blank('/bucket?delete', environ={'REQUEST_METHOD': 'POST'}, headers={ 'Authorization': 'OSS test:tester:hmac', 'Date': self.get_date_header(), 'Content-MD5': content_md5 }, body=body) status, headers, body = self.call_oss2swift(req) self.assertEqual(status.split()[0], '200') elem = fromstring(body) self.assertEqual(len(elem.findall('Deleted')), 0)
def test_upload_part_error(self): bucket = 'bucket' self.conn.make_request('PUT', bucket) query = {'uploads': ''} key = 'obj' status, headers, body = \ self.conn.make_request('POST', bucket, key, query=query) elem = fromstring(body, 'InitiateMultipartUploadResult') upload_id = elem.find('UploadId').text query = {'partNumber': '1', 'uploadId': upload_id} auth_error_conn = Connection(oss_secret_key='invalid') status, headers, body = \ auth_error_conn.make_request('PUT', bucket, key, query=query) self.assertEqual(get_error_code(body), 'SignatureDoesNotMatch') status, headers, body = \ self.conn.make_request('PUT', 'nothing', key, query=query) self.assertEqual(get_error_code(body), 'NoSuchBucket') query = {'partNumber': '1', 'uploadId': 'nothing'} status, headers, body = \ self.conn.make_request('PUT', bucket, key, query=query) self.assertEqual(get_error_code(body), 'NoSuchUpload') query = {'partNumber': '0', 'uploadId': upload_id} status, headers, body = \ self.conn.make_request('PUT', bucket, key, query=query) self.assertEqual(get_error_code(body), 'InvalidArgument') err_msg = 'Part number must be an integer between 1 and' self.assertTrue(err_msg in get_error_msg(body))
def test_bucket_GET(self): bucket_name = 'junk' req = Request.blank('/%s' % bucket_name, environ={'REQUEST_METHOD': 'GET'}, headers={ 'Authorization': 'OSS test:tester:hmac', 'Date': self.get_date_header() }) status, headers, body = self.call_oss2swift(req) self.assertEqual(status.split()[0], '200') elem = fromstring(body, 'ListBucketResult') name = elem.find('./Name').text self.assertEqual(name, bucket_name) objects = elem.iterchildren('Contents') names = [] for o in objects: names.append(o.find('./Key').text) self.assertEqual('2011-01-05T02:19:14.000Z', o.find('./LastModified').text) self.assertEqual('"0"', o.find('./ETag').text) self.assertEqual('Normal', o.find('./Type').text) self.assertEqual(len(names), len(self.objects)) for i in self.objects: self.assertTrue(i[0] in names)
def test_abort_multi_upload_error(self): bucket = 'bucket' self.conn.make_request('PUT', bucket) obj = 'obj' query = {'uploads': ''} status, headers, body = \ self.conn.make_request('POST', bucket, obj, query=query) elem = fromstring(body, 'InitiateMultipartUploadResult') upload_id = elem.find('UploadId').text self._upload_part(bucket, obj, upload_id) query = {'uploadId': upload_id} auth_error_conn = Connection(oss_secret_key='invalid') status, headers, body = \ auth_error_conn.make_request('DELETE', bucket, obj, query=query) self.assertEqual(get_error_code(body), 'SignatureDoesNotMatch') status, headers, body = \ self.conn.make_request('DELETE', 'nothing', obj, query=query) self.assertEqual(get_error_code(body), 'NoSuchBucket') query = {'uploadId': 'nothing'} status, headers, body = \ self.conn.make_request('DELETE', bucket, obj, query=query) self.assertEqual(get_error_code(body), 'NoSuchUpload')
def test_get_bucket_with_prefix(self): bucket = 'bucket' req_objects = ('object', 'object2', 'subdir/object', 'subdir2/object', 'dir/subdir/object') self._prepare_test_get_bucket(bucket, req_objects) prefix = 'object' query = {'prefix': prefix} expect_objects = ('object', 'object2') status, headers, body = \ self.conn.make_request('GET', bucket, query=query) self.assertEqual(status, 200) elem = fromstring(body, 'ListBucketResult') self.assertEqual(elem.find('Prefix').text, prefix) resp_objects = elem.findall('./Contents') self.assertEqual(len(list(resp_objects)), len(expect_objects)) for i, o in enumerate(resp_objects): self.assertEqual(o.find('Key').text, expect_objects[i]) self.assertTrue(o.find('LastModified').text is not None) self.assertRegexpMatches( o.find('LastModified').text, r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$') self.assertTrue(o.find('ETag').text is not None) self.assertTrue(o.find('Size').text is not None) self.assertEqual(o.find('StorageClass').text, 'STANDARD') self.assertTrue(o.find('Owner/ID').text, self.conn.user_id) self.assertTrue( o.find('Owner/DisplayName').text, self.conn.user_id)
def PUT(self, req): """ Handle PUT Bucket website request """ xml = req.xml(MAX_PUT_BUCKET_WEBSITE_SIZE) if xml: try: elem = fromstring(xml, 'WebsiteConfiguration') index = elem.find('IndexDocument') sufix = index.find('Suffix').text if elem.find('ErrorDocument') is not None: error_doc = elem.find('ErrorDocument') key = error_doc.find('Key').text # resp = req.get_response(self.app, obj=sufix,method='GET') # if resp.status_int==HTTP_NOT_FOUND: # raise NoSuchKey(sufix) req.headers['X-Container-Meta-Web-Index'] = str(sufix) req.headers['X-Container-Meta-Web-Error'] = str(key) req.headers['X-Container-Meta-Web-Listings'] = 'true' req.headers['X-Container-Meta-Web-Listings-CSS'] = '*.css' req.headers['X-Container-Read'] = '.r:*' except (XMLSyntaxError, DocumentInvalid): raise MalformedXML() except Exception as e: exc_type, exc_value, exc_traceback = sys.exc_info() LOGGER.error(e) raise exc_type, exc_value, exc_traceback resp = req.get_response(self.app) resp.status = HTTP_OK return resp
def test_acl(self): self.conn.make_request('PUT', self.bucket, self.obj) query = {'acl': ''} # PUT Bucket ACL headers = {'x-oss-acl': 'public-read'} status, headers, body = \ self.conn.make_request('PUT', self.bucket, headers=headers, query=query) self.assertEqual(status, 200) self.assertCommonResponseHeaders(headers) self.assertEqual(headers['Content-Length'], '0') # GET Bucket ACL status, headers, body = \ self.conn.make_request('GET', self.bucket, query=query) self.assertEqual(status, 200) self.assertCommonResponseHeaders(headers) # TODO: Fix the response that last-modified must be in the response. # self.assertTrue(headers['last-modified'] is not None) self.assertEqual(headers['Content-Length'], str(len(body))) self.assertTrue(headers['Content-Type'] is not None) elem = fromstring(body, 'AccessControlPolicy') owner = elem.find('Owner') self.assertEqual(owner.find('ID').text, self.conn.user_id) self.assertEqual(owner.find('DisplayName').text, self.conn.user_id) acl = elem.find('AccessControlList') self.assertTrue(acl.find('Grant') is not None) # GET Object ACL status, headers, body = \ self.conn.make_request('GET', self.bucket, self.obj, query=query) self.assertEqual(status, 200) self.assertCommonResponseHeaders(headers) # TODO: Fix the response that last-modified must be in the response. # self.assertTrue(headers['last-modified'] is not None) self.assertEqual(headers['Content-Length'], str(len(body))) self.assertTrue(headers['Content-Type'] is not None) elem = fromstring(body, 'AccessControlPolicy') owner = elem.find('Owner') self.assertEqual(owner.find('ID').text, self.conn.user_id) self.assertEqual(owner.find('DisplayName').text, self.conn.user_id) acl = elem.find('AccessControlList') self.assertTrue(acl.find('Grant') is not None)
def test_object_location(self): req = Request.blank('/bucket?location', environ={'REQUEST_METHOD': 'GET'}, headers={'Authorization': 'OSS test:tester:hmac', 'Date': self.get_date_header()}) status, headers, body = self.call_oss2swift(req) self.assertEqual(status.split()[0], '200') elem = fromstring(body, 'LocationConstraint') location = elem.text self.assertEqual(location, None)
def test_object_multi_DELETE_without_permission(self): status, headers, body = self._test_object_multi_DELETE('test:other') self.assertEqual(status.split()[0], '200') elem = fromstring(body) errors = elem.findall('Error') self.assertEqual(len(errors), 2) for e in errors: self.assertTrue(e.find('Key').text in self.keys) self.assertEqual(e.find('Code').text, 'AccessDenied') self.assertEqual(e.find('Message').text, 'Access Denied.')
def test_bucket_logging_GET(self): req = Request.blank('/bucket?logging', environ={'REQUEST_METHOD': 'GET'}, headers={ 'Authorization': 'OSS test:tester:hmac', 'Date': self.get_date_header() }) status, headers, body = self.call_oss2swift(req) xml = fromstring(body, 'BucketLoggingStatus') self.assertEqual(xml.keys(), []) self.assertEqual(status.split()[0], '200')
def test_object_PUT_copy_self(self): status, headers, body = \ self._test_object_PUT_copy_self(swob.HTTPOk) self.assertEqual(status.split()[0], '400') elem = fromstring(body, 'Error') err_msg = ("This copy request is illegal because it is trying to copy " "an object to itself without changing the object's " "metadata, storage class, website redirect location or " "encryption attributes.") self.assertEqual(elem.find('Code').text, 'InvalidRequest') self.assertEqual(elem.find('Message').text, err_msg)
def test_get_bucket_with_encoding_type(self): bucket = 'bucket' put_objects = ('object', 'object2') self._prepare_test_get_bucket(bucket, put_objects) encoding_type = 'url' query = {'encoding-type': encoding_type} status, headers, body = \ self.conn.make_request('GET', bucket, query=query) self.assertEqual(status, 200) elem = fromstring(body, 'ListBucketResult') self.assertEqual(elem.find('EncodingType').text, encoding_type)
def test_unsupported_method(self): req = Request.blank('/bucket?acl', environ={'REQUEST_METHOD': 'POST'}, headers={ 'Authorization': 'OSS test:tester:hmac', 'Date': self.get_date_header() }) status, headers, body = self.call_oss2swift(req) elem = fromstring(body, 'Error') self.assertEqual(elem.find('./Code').text, 'MethodNotAllowed') self.assertEqual(elem.find('./Method').text, 'POST') self.assertEqual(elem.find('./ResourceType').text, 'ACL')
def test_delete_bucket_multi_upload_object_exisiting(self): bucket = 'bucket' keys = ['obj1'] uploads = [] results_generator = self._initiate_multi_uploads_result_generator( bucket, keys) # Initiate Multipart Upload for expected_key, (status, _, body) in \ izip(keys, results_generator): self.assertEqual(status, 200) # sanity elem = fromstring(body, 'InitiateMultipartUploadResult') key = elem.find('Key').text self.assertEqual(expected_key, key) # sanity upload_id = elem.find('UploadId').text self.assertTrue(upload_id is not None) # sanity self.assertTrue((key, upload_id) not in uploads) uploads.append((key, upload_id)) self.assertEqual(len(uploads), len(keys)) # sanity # Upload Part key, upload_id = uploads[0] content = 'a' * MIN_SEGMENT_SIZE status, headers, body = \ self._upload_part(bucket, key, upload_id, content) self.assertEqual(status, 200) # Complete Multipart Upload key, upload_id = uploads[0] etags = [md5(content).hexdigest()] xml = self._gen_comp_xml(etags) status, headers, body = \ self._complete_multi_upload(bucket, key, upload_id, xml) self.assertEqual(status, 200) # sanity # GET multipart object status, headers, body = \ self.conn.make_request('GET', bucket, key) self.assertEqual(status, 200) # sanity self.assertEqual(content, body) # sanity # DELETE bucket while the object existing status, headers, body = \ self.conn.make_request('DELETE', bucket) self.assertEqual(status, 409) # sanity # The object must still be there. status, headers, body = \ self.conn.make_request('GET', bucket, key) self.assertEqual(status, 200) # sanity self.assertEqual(content, body) # sanity
def test_bucket_GET_is_truncated(self): bucket_name = 'junk' req = Request.blank('/%s?max-keys=5' % bucket_name, environ={'REQUEST_METHOD': 'GET'}, headers={ 'Authorization': 'OSS test:tester:hmac', 'Date': self.get_date_header() }) status, headers, body = self.call_oss2swift(req) elem = fromstring(body, 'ListBucketResult') self.assertEqual(elem.find('./IsTruncated').text, 'false') req = Request.blank('/%s?max-keys=4' % bucket_name, environ={'REQUEST_METHOD': 'GET'}, headers={ 'Authorization': 'OSS test:tester:hmac', 'Date': self.get_date_header() }) status, headers, body = self.call_oss2swift(req) elem = fromstring(body, 'ListBucketResult') self.assertEqual(elem.find('./IsTruncated').text, 'true')
def test_bucket_GET_subdir_with_delimiter_max_keys(self): bucket_name = 'junk-subdir' req = Request.blank('/%s?delimiter=a&max-keys=1' % bucket_name, environ={'REQUEST_METHOD': 'GET'}, headers={ 'Authorization': 'OSS test:tester:hmac', 'Date': self.get_date_header() }) status, headers, body = self.call_oss2swift(req) self.assertEqual(status.split()[0], '200') elem = fromstring(body, 'ListBucketResult') self.assertEqual(elem.find('./NextMarker').text, 'rose') self.assertEqual(elem.find('./MaxKeys').text, '1') self.assertEqual(elem.find('./IsTruncated').text, 'true')
def test_upload_part_copy_error(self): src_bucket = 'src' src_obj = 'src' self.conn.make_request('PUT', src_bucket) self.conn.make_request('PUT', src_bucket, src_obj) src_path = '%s/%s' % (src_bucket, src_obj) bucket = 'bucket' self.conn.make_request('PUT', bucket) key = 'obj' query = {'uploads': ''} status, headers, body = \ self.conn.make_request('POST', bucket, key, query=query) elem = fromstring(body, 'InitiateMultipartUploadResult') upload_id = elem.find('UploadId').text query = {'partNumber': '1', 'uploadId': upload_id} auth_error_conn = Connection(oss_secret_key='invalid') status, headers, body = \ auth_error_conn.make_request('PUT', bucket, key, headers={ 'X-Oss-Copy-Source': src_path }, query=query) self.assertEqual(get_error_code(body), 'SignatureDoesNotMatch') status, headers, body = \ self.conn.make_request('PUT', 'nothing', key, headers={'X-Oss-Copy-Source': src_path}, query=query) self.assertEqual(get_error_code(body), 'NoSuchBucket') query = {'partNumber': '1', 'uploadId': 'nothing'} status, headers, body = \ self.conn.make_request('PUT', bucket, key, headers={'X-Oss-Copy-Source': src_path}, query=query) self.assertEqual(get_error_code(body), 'NoSuchUpload') src_path = '%s/%s' % (src_bucket, 'nothing') query = {'partNumber': '1', 'uploadId': upload_id} status, headers, body = \ self.conn.make_request('PUT', bucket, key, headers={'X-Oss-Copy-Source': src_path}, query=query) self.assertEqual(get_error_code(body), 'NoSuchKey')
def test_service_GET_without_bucket(self): bucket_list = [] for var in range(0, 10): bucket = 'bucket%s' % var self.swift.register('HEAD', '/v1/AUTH_test/%s' % bucket, swob.HTTPNotFound, {}, None) bucket_list.append((bucket, var, 300 + var)) status, headers, body = \ self._test_service_GET_for_check_bucket_owner(bucket_list) self.assertEqual(status.split()[0], '200') elem = fromstring(body, 'ListAllMyBucketsResult') resp_buckets = elem.find('./Buckets') buckets = resp_buckets.iterchildren('Bucket') self.assertEqual(len(list(buckets)), 0)
def test_object_PUT_copy_self_metadata_replace(self): date_header = self.get_date_header() timestamp = mktime(date_header) last_modified = OssTimestamp(timestamp).ossxmlformat header = {'x-oss-metadata-directive': 'REPLACE', 'Date': date_header} status, headers, body = self._test_object_PUT_copy_self( swob.HTTPOk, header, timestamp=timestamp) self.assertEqual(status.split()[0], '200') self.assertEqual(headers['Content-Type'], 'application/xml') self.assertTrue(headers.get('etag') is None) elem = fromstring(body, 'CopyObjectResult') self.assertEqual(elem.find('LastModified').text, last_modified) self.assertEqual(elem.find('ETag').text, '"%s"' % self.etag) _, _, headers = self.swift.calls_with_headers[-1] self.assertEqual(headers['X-Copy-From'], '/bucket/object') self.assertEqual(headers['Content-Length'], '0')
def test_bucket_GET_subdir(self): bucket_name = 'junk-subdir' req = Request.blank('/%s' % bucket_name, environ={'REQUEST_METHOD': 'GET'}, headers={ 'Authorization': 'OSS test:tester:hmac', 'Date': self.get_date_header() }) status, headers, body = self.call_oss2swift(req) self.assertEqual(status.split()[0], '200') elem = fromstring(body, 'ListBucketResult') name = elem.find('./Name').text self.assertEqual(name, bucket_name) prefixes = elem.findall('CommonPrefixes') self.assertEqual(len(prefixes), len(self.prefixes)) for p in prefixes: self.assertTrue(p.find('./Prefix').text in self.prefixes)
def test_bucket_GET_passthroughs(self): bucket_name = 'junk' req = Request.blank('/%s?delimiter=a&marker=b&prefix=c' % bucket_name, environ={'REQUEST_METHOD': 'GET'}, headers={ 'Authorization': 'OSS test:tester:hmac', 'Date': self.get_date_header() }) status, headers, body = self.call_oss2swift(req) elem = fromstring(body, 'ListBucketResult') self.assertEqual(elem.find('./Prefix').text, 'c') self.assertEqual(elem.find('./Marker').text, 'b') self.assertEqual(elem.find('./Delimiter').text, 'a') _, path = self.swift.calls[-1] _, query_string = path.split('?') args = dict(cgi.parse_qsl(query_string)) self.assertEqual(args['delimiter'], 'a') self.assertEqual(args['marker'], 'b') self.assertEqual(args['prefix'], 'c')
def test_object_PUT_copy_no_slash(self): date_header = self.get_date_header() timestamp = mktime(date_header) last_modified = OssTimestamp(timestamp).ossxmlformat # Some clients (like Boto) don't include the leading slash; # OSS seems to tolerate this so we should, too status, headers, body = self._test_object_PUT_copy( swob.HTTPOk, src_path='some/source', put_header={'Date': date_header}, timestamp=timestamp) self.assertEqual(status.split()[0], '200') self.assertEqual(headers['Content-Type'], 'application/xml') self.assertTrue(headers.get('etag') is None) self.assertTrue(headers.get('x-oss-meta-something') is None) elem = fromstring(body, 'CopyObjectResult') self.assertEqual(elem.find('LastModified').text, last_modified) self.assertEqual(elem.find('ETag').text, '"%s"' % self.etag) _, _, headers = self.swift.calls_with_headers[-1] self.assertEqual(headers['X-Copy-From'], '/some/source') self.assertEqual(headers['Content-Length'], '0')
def test_service_GET_without_owner_bucket(self): bucket_list = [] for var in range(0, 10): user_id = 'test:other' bucket = 'bucket%s' % var owner = Owner(user_id, user_id) headers = encode_acl('container', ACL(owner, [])) self.swift.register('HEAD', '/v1/AUTH_test/%s' % bucket, swob.HTTPNoContent, headers, None) bucket_list.append((bucket, var, 300 + var)) status, headers, body = \ self._test_service_GET_for_check_bucket_owner(bucket_list) self.assertEqual(status.split()[0], '200') elem = fromstring(body, 'ListAllMyBucketsResult') resp_buckets = elem.find('./Buckets') buckets = resp_buckets.iterchildren('Bucket') self.assertEqual(len(list(buckets)), 0)