Update pep8 config to (mostly) match upstream swift
The combination of select and ignore options doesn't do what we want, anyway. Now, we won't regress on a number of issues, like H234, H235, and E127. Also added H237 to ignore list, as we currently trip module multifile is removed in Python 3 ... in test/functional/test_object.py Change-Id: Id746552bc024e726e29105c077057e46e248a0a8 Related-Change: I41d63b9467083d7606ad18aaa398ca7738b27fae
This commit is contained in:
@@ -15,8 +15,7 @@
|
|||||||
|
|
||||||
import base64
|
import base64
|
||||||
from email.header import Header
|
from email.header import Header
|
||||||
from hashlib import sha256
|
from hashlib import sha256, md5
|
||||||
import md5
|
|
||||||
import re
|
import re
|
||||||
import six
|
import six
|
||||||
import string
|
import string
|
||||||
@@ -644,7 +643,7 @@ class Request(swob.Request):
|
|||||||
raise InvalidRequest('Missing required header for this request: '
|
raise InvalidRequest('Missing required header for this request: '
|
||||||
'Content-MD5')
|
'Content-MD5')
|
||||||
|
|
||||||
digest = md5.new(body).digest().encode('base64').strip()
|
digest = md5(body).digest().encode('base64').strip()
|
||||||
if self.environ['HTTP_CONTENT_MD5'] != digest:
|
if self.environ['HTTP_CONTENT_MD5'] != digest:
|
||||||
raise BadDigest(content_md5=self.environ['HTTP_CONTENT_MD5'])
|
raise BadDigest(content_md5=self.environ['HTTP_CONTENT_MD5'])
|
||||||
|
|
||||||
|
@@ -318,11 +318,11 @@ class TestSwift3Bucket(Swift3FunctionalTestCase):
|
|||||||
# non existed verb in the controller
|
# non existed verb in the controller
|
||||||
status, headers, body = \
|
status, headers, body = \
|
||||||
self.conn.make_request('GETPUT', 'bucket')
|
self.conn.make_request('GETPUT', 'bucket')
|
||||||
self.assertEquals(get_error_code(body), 'MethodNotAllowed')
|
self.assertEqual(get_error_code(body), 'MethodNotAllowed')
|
||||||
# the method exists in the controller but deny as MethodNotAllowed
|
# the method exists in the controller but deny as MethodNotAllowed
|
||||||
status, headers, body = \
|
status, headers, body = \
|
||||||
self.conn.make_request('_delete_segments_bucket', 'bucket')
|
self.conn.make_request('_delete_segments_bucket', 'bucket')
|
||||||
self.assertEquals(get_error_code(body), 'MethodNotAllowed')
|
self.assertEqual(get_error_code(body), 'MethodNotAllowed')
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(os.environ['AUTH'] == 'tempauth',
|
@unittest.skipIf(os.environ['AUTH'] == 'tempauth',
|
||||||
|
@@ -472,7 +472,7 @@ class TestSwift3MultiUpload(Swift3FunctionalTestCase):
|
|||||||
status, headers, body = \
|
status, headers, body = \
|
||||||
self.conn.make_request('POST', bucket, keys[0], body=xml,
|
self.conn.make_request('POST', bucket, keys[0], body=xml,
|
||||||
query=query)
|
query=query)
|
||||||
self.assertEquals(get_error_code(body), 'EntityTooSmall')
|
self.assertEqual(get_error_code(body), 'EntityTooSmall')
|
||||||
|
|
||||||
# invalid credentials
|
# invalid credentials
|
||||||
auth_error_conn = Connection(aws_secret_key='invalid')
|
auth_error_conn = Connection(aws_secret_key='invalid')
|
||||||
@@ -557,22 +557,22 @@ class TestSwift3MultiUpload(Swift3FunctionalTestCase):
|
|||||||
# Initiate Multipart Upload
|
# Initiate Multipart Upload
|
||||||
for expected_key, (status, headers, body) in \
|
for expected_key, (status, headers, body) in \
|
||||||
izip(keys, results_generator):
|
izip(keys, results_generator):
|
||||||
self.assertEquals(status, 200)
|
self.assertEqual(status, 200)
|
||||||
self.assertCommonResponseHeaders(headers)
|
self.assertCommonResponseHeaders(headers)
|
||||||
self.assertTrue('content-type' in headers)
|
self.assertTrue('content-type' in headers)
|
||||||
self.assertEquals(headers['content-type'], 'application/xml')
|
self.assertEqual(headers['content-type'], 'application/xml')
|
||||||
self.assertTrue('content-length' in headers)
|
self.assertTrue('content-length' in headers)
|
||||||
self.assertEquals(headers['content-length'], str(len(body)))
|
self.assertEqual(headers['content-length'], str(len(body)))
|
||||||
elem = fromstring(body, 'InitiateMultipartUploadResult')
|
elem = fromstring(body, 'InitiateMultipartUploadResult')
|
||||||
self.assertEquals(elem.find('Bucket').text, bucket)
|
self.assertEqual(elem.find('Bucket').text, bucket)
|
||||||
key = elem.find('Key').text
|
key = elem.find('Key').text
|
||||||
self.assertEquals(expected_key, key)
|
self.assertEqual(expected_key, key)
|
||||||
upload_id = elem.find('UploadId').text
|
upload_id = elem.find('UploadId').text
|
||||||
self.assertTrue(upload_id is not None)
|
self.assertTrue(upload_id is not None)
|
||||||
self.assertTrue((key, upload_id) not in uploads)
|
self.assertTrue((key, upload_id) not in uploads)
|
||||||
uploads.append((key, upload_id))
|
uploads.append((key, upload_id))
|
||||||
|
|
||||||
self.assertEquals(len(uploads), len(keys)) # sanity
|
self.assertEqual(len(uploads), len(keys)) # sanity
|
||||||
|
|
||||||
# Upload Part Copy Range
|
# Upload Part Copy Range
|
||||||
key, upload_id = uploads[0]
|
key, upload_id = uploads[0]
|
||||||
@@ -591,19 +591,19 @@ class TestSwift3MultiUpload(Swift3FunctionalTestCase):
|
|||||||
status, headers, body, resp_etag = \
|
status, headers, body, resp_etag = \
|
||||||
self._upload_part_copy(src_bucket, src_obj, bucket,
|
self._upload_part_copy(src_bucket, src_obj, bucket,
|
||||||
key, upload_id, 1, src_range)
|
key, upload_id, 1, src_range)
|
||||||
self.assertEquals(status, 200)
|
self.assertEqual(status, 200)
|
||||||
self.assertCommonResponseHeaders(headers)
|
self.assertCommonResponseHeaders(headers)
|
||||||
self.assertTrue('content-type' in headers)
|
self.assertTrue('content-type' in headers)
|
||||||
self.assertEquals(headers['content-type'], 'application/xml')
|
self.assertEqual(headers['content-type'], 'application/xml')
|
||||||
self.assertTrue('content-length' in headers)
|
self.assertTrue('content-length' in headers)
|
||||||
self.assertEquals(headers['content-length'], str(len(body)))
|
self.assertEqual(headers['content-length'], str(len(body)))
|
||||||
self.assertTrue('etag' not in headers)
|
self.assertTrue('etag' not in headers)
|
||||||
elem = fromstring(body, 'CopyPartResult')
|
elem = fromstring(body, 'CopyPartResult')
|
||||||
|
|
||||||
last_modified = elem.find('LastModified').text
|
last_modified = elem.find('LastModified').text
|
||||||
self.assertTrue(last_modified is not None)
|
self.assertTrue(last_modified is not None)
|
||||||
|
|
||||||
self.assertEquals(resp_etag, etag)
|
self.assertEqual(resp_etag, etag)
|
||||||
|
|
||||||
# Check last-modified timestamp
|
# Check last-modified timestamp
|
||||||
key, upload_id = uploads[0]
|
key, upload_id = uploads[0]
|
||||||
@@ -616,7 +616,7 @@ class TestSwift3MultiUpload(Swift3FunctionalTestCase):
|
|||||||
# FIXME: COPY result drops mili/microseconds but GET doesn't
|
# FIXME: COPY result drops mili/microseconds but GET doesn't
|
||||||
last_modified_gets = [p.find('LastModified').text
|
last_modified_gets = [p.find('LastModified').text
|
||||||
for p in elem.iterfind('Part')]
|
for p in elem.iterfind('Part')]
|
||||||
self.assertEquals(
|
self.assertEqual(
|
||||||
last_modified_gets[0].rsplit('.', 1)[0],
|
last_modified_gets[0].rsplit('.', 1)[0],
|
||||||
last_modified.rsplit('.', 1)[0],
|
last_modified.rsplit('.', 1)[0],
|
||||||
'%r != %r' % (last_modified_gets[0], last_modified))
|
'%r != %r' % (last_modified_gets[0], last_modified))
|
||||||
@@ -631,12 +631,12 @@ class TestSwift3MultiUpload(Swift3FunctionalTestCase):
|
|||||||
self.conn.make_request('DELETE', bucket, key, query=query)
|
self.conn.make_request('DELETE', bucket, key, query=query)
|
||||||
|
|
||||||
# sanities
|
# sanities
|
||||||
self.assertEquals(status, 204)
|
self.assertEqual(status, 204)
|
||||||
self.assertCommonResponseHeaders(headers)
|
self.assertCommonResponseHeaders(headers)
|
||||||
self.assertTrue('content-type' in headers)
|
self.assertTrue('content-type' in headers)
|
||||||
self.assertEquals(headers['content-type'], 'text/html; charset=UTF-8')
|
self.assertEqual(headers['content-type'], 'text/html; charset=UTF-8')
|
||||||
self.assertTrue('content-length' in headers)
|
self.assertTrue('content-length' in headers)
|
||||||
self.assertEquals(headers['content-length'], '0')
|
self.assertEqual(headers['content-length'], '0')
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(os.environ['AUTH'] == 'tempauth',
|
@unittest.skipIf(os.environ['AUTH'] == 'tempauth',
|
||||||
@@ -665,23 +665,23 @@ class TestSwift3MultiUploadSigV4(TestSwift3MultiUpload):
|
|||||||
# Initiate Multipart Upload
|
# Initiate Multipart Upload
|
||||||
for expected_key, (status, _, body) in \
|
for expected_key, (status, _, body) in \
|
||||||
izip(keys, results_generator):
|
izip(keys, results_generator):
|
||||||
self.assertEquals(status, 200) # sanity
|
self.assertEqual(status, 200) # sanity
|
||||||
elem = fromstring(body, 'InitiateMultipartUploadResult')
|
elem = fromstring(body, 'InitiateMultipartUploadResult')
|
||||||
key = elem.find('Key').text
|
key = elem.find('Key').text
|
||||||
self.assertEquals(expected_key, key) # sanity
|
self.assertEqual(expected_key, key) # sanity
|
||||||
upload_id = elem.find('UploadId').text
|
upload_id = elem.find('UploadId').text
|
||||||
self.assertTrue(upload_id is not None) # sanity
|
self.assertTrue(upload_id is not None) # sanity
|
||||||
self.assertTrue((key, upload_id) not in uploads)
|
self.assertTrue((key, upload_id) not in uploads)
|
||||||
uploads.append((key, upload_id))
|
uploads.append((key, upload_id))
|
||||||
|
|
||||||
self.assertEquals(len(uploads), len(keys)) # sanity
|
self.assertEqual(len(uploads), len(keys)) # sanity
|
||||||
|
|
||||||
# Upload Part
|
# Upload Part
|
||||||
key, upload_id = uploads[0]
|
key, upload_id = uploads[0]
|
||||||
content = 'a' * MIN_SEGMENT_SIZE
|
content = 'a' * MIN_SEGMENT_SIZE
|
||||||
status, headers, body = \
|
status, headers, body = \
|
||||||
self._upload_part(bucket, key, upload_id, content)
|
self._upload_part(bucket, key, upload_id, content)
|
||||||
self.assertEquals(status, 200)
|
self.assertEqual(status, 200)
|
||||||
|
|
||||||
# Complete Multipart Upload
|
# Complete Multipart Upload
|
||||||
key, upload_id = uploads[0]
|
key, upload_id = uploads[0]
|
||||||
@@ -689,24 +689,24 @@ class TestSwift3MultiUploadSigV4(TestSwift3MultiUpload):
|
|||||||
xml = self._gen_comp_xml(etags)
|
xml = self._gen_comp_xml(etags)
|
||||||
status, headers, body = \
|
status, headers, body = \
|
||||||
self._complete_multi_upload(bucket, key, upload_id, xml)
|
self._complete_multi_upload(bucket, key, upload_id, xml)
|
||||||
self.assertEquals(status, 200) # sanity
|
self.assertEqual(status, 200) # sanity
|
||||||
|
|
||||||
# GET multipart object
|
# GET multipart object
|
||||||
status, headers, body = \
|
status, headers, body = \
|
||||||
self.conn.make_request('GET', bucket, key)
|
self.conn.make_request('GET', bucket, key)
|
||||||
self.assertEquals(status, 200) # sanity
|
self.assertEqual(status, 200) # sanity
|
||||||
self.assertEquals(content, body) # sanity
|
self.assertEqual(content, body) # sanity
|
||||||
|
|
||||||
# DELETE bucket while the object existing
|
# DELETE bucket while the object existing
|
||||||
status, headers, body = \
|
status, headers, body = \
|
||||||
self.conn.make_request('DELETE', bucket)
|
self.conn.make_request('DELETE', bucket)
|
||||||
self.assertEquals(status, 409) # sanity
|
self.assertEqual(status, 409) # sanity
|
||||||
|
|
||||||
# The object must still be there.
|
# The object must still be there.
|
||||||
status, headers, body = \
|
status, headers, body = \
|
||||||
self.conn.make_request('GET', bucket, key)
|
self.conn.make_request('GET', bucket, key)
|
||||||
self.assertEquals(status, 200) # sanity
|
self.assertEqual(status, 200) # sanity
|
||||||
self.assertEquals(content, body) # sanity
|
self.assertEqual(content, body) # sanity
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@@ -31,7 +31,7 @@ class TestSwift3PresignedUrls(Swift3FunctionalTestCase):
|
|||||||
|
|
||||||
# GET Bucket (Without Object)
|
# GET Bucket (Without Object)
|
||||||
status, _junk, _junk = self.conn.make_request('PUT', bucket)
|
status, _junk, _junk = self.conn.make_request('PUT', bucket)
|
||||||
self.assertEquals(status, 200)
|
self.assertEqual(status, 200)
|
||||||
|
|
||||||
url, headers = self.conn.generate_url_and_headers('GET', bucket)
|
url, headers = self.conn.generate_url_and_headers('GET', bucket)
|
||||||
resp = requests.get(url, headers=headers)
|
resp = requests.get(url, headers=headers)
|
||||||
@@ -43,14 +43,14 @@ class TestSwift3PresignedUrls(Swift3FunctionalTestCase):
|
|||||||
str(len(resp.content)))
|
str(len(resp.content)))
|
||||||
|
|
||||||
elem = fromstring(resp.content, 'ListBucketResult')
|
elem = fromstring(resp.content, 'ListBucketResult')
|
||||||
self.assertEquals(elem.find('Name').text, bucket)
|
self.assertEqual(elem.find('Name').text, bucket)
|
||||||
self.assertEquals(elem.find('Prefix').text, None)
|
self.assertEqual(elem.find('Prefix').text, None)
|
||||||
self.assertEquals(elem.find('Marker').text, None)
|
self.assertEqual(elem.find('Marker').text, None)
|
||||||
self.assertEquals(elem.find('MaxKeys').text,
|
self.assertEqual(elem.find('MaxKeys').text,
|
||||||
str(CONF.max_bucket_listing))
|
str(CONF.max_bucket_listing))
|
||||||
self.assertEquals(elem.find('IsTruncated').text, 'false')
|
self.assertEqual(elem.find('IsTruncated').text, 'false')
|
||||||
objects = elem.findall('./Contents')
|
objects = elem.findall('./Contents')
|
||||||
self.assertEquals(list(objects), [])
|
self.assertEqual(list(objects), [])
|
||||||
|
|
||||||
# GET Bucket (With Object)
|
# GET Bucket (With Object)
|
||||||
for obj in req_objects:
|
for obj in req_objects:
|
||||||
@@ -68,14 +68,14 @@ class TestSwift3PresignedUrls(Swift3FunctionalTestCase):
|
|||||||
str(len(resp.content)))
|
str(len(resp.content)))
|
||||||
|
|
||||||
elem = fromstring(resp.content, 'ListBucketResult')
|
elem = fromstring(resp.content, 'ListBucketResult')
|
||||||
self.assertEquals(elem.find('Name').text, bucket)
|
self.assertEqual(elem.find('Name').text, bucket)
|
||||||
self.assertEquals(elem.find('Prefix').text, None)
|
self.assertEqual(elem.find('Prefix').text, None)
|
||||||
self.assertEquals(elem.find('Marker').text, None)
|
self.assertEqual(elem.find('Marker').text, None)
|
||||||
self.assertEquals(elem.find('MaxKeys').text,
|
self.assertEqual(elem.find('MaxKeys').text,
|
||||||
str(CONF.max_bucket_listing))
|
str(CONF.max_bucket_listing))
|
||||||
self.assertEquals(elem.find('IsTruncated').text, 'false')
|
self.assertEqual(elem.find('IsTruncated').text, 'false')
|
||||||
resp_objects = elem.findall('./Contents')
|
resp_objects = elem.findall('./Contents')
|
||||||
self.assertEquals(len(list(resp_objects)), 2)
|
self.assertEqual(len(list(resp_objects)), 2)
|
||||||
for o in resp_objects:
|
for o in resp_objects:
|
||||||
self.assertIn(o.find('Key').text, req_objects)
|
self.assertIn(o.find('Key').text, req_objects)
|
||||||
self.assertIsNotNone(o.find('LastModified').text)
|
self.assertIsNotNone(o.find('LastModified').text)
|
||||||
@@ -160,7 +160,7 @@ class TestSwift3PresignedUrls(Swift3FunctionalTestCase):
|
|||||||
obj = 'object'
|
obj = 'object'
|
||||||
|
|
||||||
status, _junk, _junk = self.conn.make_request('PUT', bucket)
|
status, _junk, _junk = self.conn.make_request('PUT', bucket)
|
||||||
self.assertEquals(status, 200)
|
self.assertEqual(status, 200)
|
||||||
|
|
||||||
# HEAD/missing object
|
# HEAD/missing object
|
||||||
head_url, headers = self.conn.generate_url_and_headers(
|
head_url, headers = self.conn.generate_url_and_headers(
|
||||||
@@ -173,8 +173,8 @@ class TestSwift3PresignedUrls(Swift3FunctionalTestCase):
|
|||||||
resp = requests.get(head_url)
|
resp = requests.get(head_url)
|
||||||
self.assertEqual(resp.status_code, 403,
|
self.assertEqual(resp.status_code, 403,
|
||||||
'Got %d %s' % (resp.status_code, resp.content))
|
'Got %d %s' % (resp.status_code, resp.content))
|
||||||
self.assertEquals(get_error_code(resp.content),
|
self.assertEqual(get_error_code(resp.content),
|
||||||
'SignatureDoesNotMatch')
|
'SignatureDoesNotMatch')
|
||||||
|
|
||||||
# PUT empty object
|
# PUT empty object
|
||||||
put_url, headers = self.conn.generate_url_and_headers(
|
put_url, headers = self.conn.generate_url_and_headers(
|
||||||
@@ -210,7 +210,7 @@ class TestSwift3PresignedUrls(Swift3FunctionalTestCase):
|
|||||||
|
|
||||||
# Final cleanup
|
# Final cleanup
|
||||||
status, _junk, _junk = self.conn.make_request('DELETE', bucket)
|
status, _junk, _junk = self.conn.make_request('DELETE', bucket)
|
||||||
self.assertEquals(status, 204)
|
self.assertEqual(status, 204)
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(os.environ['AUTH'] == 'tempauth',
|
@unittest.skipIf(os.environ['AUTH'] == 'tempauth',
|
||||||
|
@@ -196,7 +196,7 @@ class TestSwift3Bucket(Swift3TestCase):
|
|||||||
_, path = self.swift.calls[-1]
|
_, path = self.swift.calls[-1]
|
||||||
_, query_string = path.split('?')
|
_, query_string = path.split('?')
|
||||||
args = dict(cgi.parse_qsl(query_string))
|
args = dict(cgi.parse_qsl(query_string))
|
||||||
self.assert_(args['limit'] == '6')
|
self.assertEqual(args['limit'], '6')
|
||||||
|
|
||||||
req = Request.blank('/%s?max-keys=5000' % bucket_name,
|
req = Request.blank('/%s?max-keys=5000' % bucket_name,
|
||||||
environ={'REQUEST_METHOD': 'GET'},
|
environ={'REQUEST_METHOD': 'GET'},
|
||||||
@@ -483,7 +483,7 @@ class TestSwift3Bucket(Swift3TestCase):
|
|||||||
headers={'Authorization': 'AWS test:tester:hmac',
|
headers={'Authorization': 'AWS test:tester:hmac',
|
||||||
'Date': self.get_date_header()})
|
'Date': self.get_date_header()})
|
||||||
status, headers, body = self.call_swift3(req)
|
status, headers, body = self.call_swift3(req)
|
||||||
self.assertEquals(status.split()[0], '503')
|
self.assertEqual(status.split()[0], '503')
|
||||||
called = [(method, path) for method, path, _ in
|
called = [(method, path) for method, path, _ in
|
||||||
self.swift.calls_with_headers]
|
self.swift.calls_with_headers]
|
||||||
# Don't delete original bucket when error occured in segment container
|
# Don't delete original bucket when error occured in segment container
|
||||||
|
@@ -20,7 +20,6 @@ from datetime import datetime
|
|||||||
import hashlib
|
import hashlib
|
||||||
import base64
|
import base64
|
||||||
from urllib import unquote, quote
|
from urllib import unquote, quote
|
||||||
from md5 import md5
|
|
||||||
|
|
||||||
from swift.common import swob, utils
|
from swift.common import swob, utils
|
||||||
from swift.common.swob import Request
|
from swift.common.swob import Request
|
||||||
@@ -66,7 +65,7 @@ class TestSwift3Middleware(Swift3TestCase):
|
|||||||
headers={'Authorization': 'AWS test:tester:hmac',
|
headers={'Authorization': 'AWS test:tester:hmac',
|
||||||
'Date': self.get_date_header()})
|
'Date': self.get_date_header()})
|
||||||
status, headers, body = self.call_swift3(req)
|
status, headers, body = self.call_swift3(req)
|
||||||
self.assertEquals(self._get_error_code(body), 'MethodNotAllowed')
|
self.assertEqual(self._get_error_code(body), 'MethodNotAllowed')
|
||||||
|
|
||||||
def test_path_info_encode(self):
|
def test_path_info_encode(self):
|
||||||
bucket_name = 'b%75cket'
|
bucket_name = 'b%75cket'
|
||||||
@@ -234,7 +233,7 @@ class TestSwift3Middleware(Swift3TestCase):
|
|||||||
req.headers['Date'] = datetime.utcnow()
|
req.headers['Date'] = datetime.utcnow()
|
||||||
req.content_type = 'text/plain'
|
req.content_type = 'text/plain'
|
||||||
status, headers, body = self.call_swift3(req)
|
status, headers, body = self.call_swift3(req)
|
||||||
self.assertEquals(self._get_error_code(body), 'AccessDenied')
|
self.assertEqual(self._get_error_code(body), 'AccessDenied')
|
||||||
|
|
||||||
def test_signed_urls_v4(self):
|
def test_signed_urls_v4(self):
|
||||||
req = Request.blank(
|
req = Request.blank(
|
||||||
@@ -250,9 +249,9 @@ class TestSwift3Middleware(Swift3TestCase):
|
|||||||
environ={'REQUEST_METHOD': 'GET'})
|
environ={'REQUEST_METHOD': 'GET'})
|
||||||
req.content_type = 'text/plain'
|
req.content_type = 'text/plain'
|
||||||
status, headers, body = self.call_swift3(req)
|
status, headers, body = self.call_swift3(req)
|
||||||
self.assertEquals(status.split()[0], '200', body)
|
self.assertEqual(status.split()[0], '200', body)
|
||||||
for _, _, headers in self.swift.calls_with_headers:
|
for _, _, headers in self.swift.calls_with_headers:
|
||||||
self.assertEquals('AWS test:tester:X', headers['Authorization'])
|
self.assertEqual('AWS test:tester:X', headers['Authorization'])
|
||||||
self.assertIn('X-Auth-Token', headers)
|
self.assertIn('X-Auth-Token', headers)
|
||||||
|
|
||||||
def test_signed_urls_v4_missing_x_amz_date(self):
|
def test_signed_urls_v4_missing_x_amz_date(self):
|
||||||
@@ -265,7 +264,7 @@ class TestSwift3Middleware(Swift3TestCase):
|
|||||||
environ={'REQUEST_METHOD': 'GET'})
|
environ={'REQUEST_METHOD': 'GET'})
|
||||||
req.content_type = 'text/plain'
|
req.content_type = 'text/plain'
|
||||||
status, headers, body = self.call_swift3(req)
|
status, headers, body = self.call_swift3(req)
|
||||||
self.assertEquals(self._get_error_code(body), 'AccessDenied')
|
self.assertEqual(self._get_error_code(body), 'AccessDenied')
|
||||||
|
|
||||||
def test_signed_urls_v4_invalid_algorithm(self):
|
def test_signed_urls_v4_invalid_algorithm(self):
|
||||||
req = Request.blank('/bucket/object'
|
req = Request.blank('/bucket/object'
|
||||||
@@ -279,7 +278,7 @@ class TestSwift3Middleware(Swift3TestCase):
|
|||||||
environ={'REQUEST_METHOD': 'GET'})
|
environ={'REQUEST_METHOD': 'GET'})
|
||||||
req.content_type = 'text/plain'
|
req.content_type = 'text/plain'
|
||||||
status, headers, body = self.call_swift3(req)
|
status, headers, body = self.call_swift3(req)
|
||||||
self.assertEquals(self._get_error_code(body), 'InvalidArgument')
|
self.assertEqual(self._get_error_code(body), 'InvalidArgument')
|
||||||
|
|
||||||
def test_signed_urls_v4_missing_signed_headers(self):
|
def test_signed_urls_v4_missing_signed_headers(self):
|
||||||
req = Request.blank('/bucket/object'
|
req = Request.blank('/bucket/object'
|
||||||
@@ -292,8 +291,8 @@ class TestSwift3Middleware(Swift3TestCase):
|
|||||||
environ={'REQUEST_METHOD': 'GET'})
|
environ={'REQUEST_METHOD': 'GET'})
|
||||||
req.content_type = 'text/plain'
|
req.content_type = 'text/plain'
|
||||||
status, headers, body = self.call_swift3(req)
|
status, headers, body = self.call_swift3(req)
|
||||||
self.assertEquals(self._get_error_code(body),
|
self.assertEqual(self._get_error_code(body),
|
||||||
'AuthorizationHeaderMalformed')
|
'AuthorizationHeaderMalformed')
|
||||||
|
|
||||||
def test_signed_urls_v4_invalid_credentials(self):
|
def test_signed_urls_v4_invalid_credentials(self):
|
||||||
req = Request.blank('/bucket/object'
|
req = Request.blank('/bucket/object'
|
||||||
@@ -307,7 +306,7 @@ class TestSwift3Middleware(Swift3TestCase):
|
|||||||
environ={'REQUEST_METHOD': 'GET'})
|
environ={'REQUEST_METHOD': 'GET'})
|
||||||
req.content_type = 'text/plain'
|
req.content_type = 'text/plain'
|
||||||
status, headers, body = self.call_swift3(req)
|
status, headers, body = self.call_swift3(req)
|
||||||
self.assertEquals(self._get_error_code(body), 'AccessDenied')
|
self.assertEqual(self._get_error_code(body), 'AccessDenied')
|
||||||
|
|
||||||
def test_signed_urls_v4_missing_signature(self):
|
def test_signed_urls_v4_missing_signature(self):
|
||||||
req = Request.blank('/bucket/object'
|
req = Request.blank('/bucket/object'
|
||||||
@@ -320,7 +319,7 @@ class TestSwift3Middleware(Swift3TestCase):
|
|||||||
environ={'REQUEST_METHOD': 'GET'})
|
environ={'REQUEST_METHOD': 'GET'})
|
||||||
req.content_type = 'text/plain'
|
req.content_type = 'text/plain'
|
||||||
status, headers, body = self.call_swift3(req)
|
status, headers, body = self.call_swift3(req)
|
||||||
self.assertEquals(self._get_error_code(body), 'AccessDenied')
|
self.assertEqual(self._get_error_code(body), 'AccessDenied')
|
||||||
|
|
||||||
def test_bucket_virtual_hosted_style(self):
|
def test_bucket_virtual_hosted_style(self):
|
||||||
req = Request.blank('/',
|
req = Request.blank('/',
|
||||||
@@ -380,7 +379,7 @@ class TestSwift3Middleware(Swift3TestCase):
|
|||||||
self.assertEqual(self._get_error_code(body), 'InvalidDigest')
|
self.assertEqual(self._get_error_code(body), 'InvalidDigest')
|
||||||
|
|
||||||
def test_object_create_bad_md5_too_short(self):
|
def test_object_create_bad_md5_too_short(self):
|
||||||
too_short_digest = md5('hey').hexdigest()[:-1]
|
too_short_digest = hashlib.md5('hey').hexdigest()[:-1]
|
||||||
md5_str = too_short_digest.encode('base64').strip()
|
md5_str = too_short_digest.encode('base64').strip()
|
||||||
req = Request.blank(
|
req = Request.blank(
|
||||||
'/bucket/object',
|
'/bucket/object',
|
||||||
@@ -392,7 +391,7 @@ class TestSwift3Middleware(Swift3TestCase):
|
|||||||
self.assertEqual(self._get_error_code(body), 'InvalidDigest')
|
self.assertEqual(self._get_error_code(body), 'InvalidDigest')
|
||||||
|
|
||||||
def test_object_create_bad_md5_too_long(self):
|
def test_object_create_bad_md5_too_long(self):
|
||||||
too_long_digest = md5('hey').hexdigest() + 'suffix'
|
too_long_digest = hashlib.md5('hey').hexdigest() + 'suffix'
|
||||||
md5_str = too_long_digest.encode('base64').strip()
|
md5_str = too_long_digest.encode('base64').strip()
|
||||||
req = Request.blank(
|
req = Request.blank(
|
||||||
'/bucket/object',
|
'/bucket/object',
|
||||||
@@ -579,9 +578,9 @@ class TestSwift3Middleware(Swift3TestCase):
|
|||||||
req = Request.blank('/bucket/object', environ=environ, headers=headers)
|
req = Request.blank('/bucket/object', environ=environ, headers=headers)
|
||||||
req.content_type = 'text/plain'
|
req.content_type = 'text/plain'
|
||||||
status, headers, body = self.call_swift3(req)
|
status, headers, body = self.call_swift3(req)
|
||||||
self.assertEquals(status.split()[0], '200', body)
|
self.assertEqual(status.split()[0], '200', body)
|
||||||
for _, _, headers in self.swift.calls_with_headers:
|
for _, _, headers in self.swift.calls_with_headers:
|
||||||
self.assertEquals('AWS test:tester:X', headers['Authorization'])
|
self.assertEqual('AWS test:tester:X', headers['Authorization'])
|
||||||
self.assertIn('X-Auth-Token', headers)
|
self.assertIn('X-Auth-Token', headers)
|
||||||
|
|
||||||
def test_signature_v4_no_date(self):
|
def test_signature_v4_no_date(self):
|
||||||
@@ -597,8 +596,8 @@ class TestSwift3Middleware(Swift3TestCase):
|
|||||||
req = Request.blank('/bucket/object', environ=environ, headers=headers)
|
req = Request.blank('/bucket/object', environ=environ, headers=headers)
|
||||||
req.content_type = 'text/plain'
|
req.content_type = 'text/plain'
|
||||||
status, headers, body = self.call_swift3(req)
|
status, headers, body = self.call_swift3(req)
|
||||||
self.assertEquals(status.split()[0], '403')
|
self.assertEqual(status.split()[0], '403')
|
||||||
self.assertEquals(self._get_error_code(body), 'AccessDenied')
|
self.assertEqual(self._get_error_code(body), 'AccessDenied')
|
||||||
|
|
||||||
def test_signature_v4_no_payload(self):
|
def test_signature_v4_no_payload(self):
|
||||||
environ = {
|
environ = {
|
||||||
@@ -613,9 +612,9 @@ class TestSwift3Middleware(Swift3TestCase):
|
|||||||
req = Request.blank('/bucket/object', environ=environ, headers=headers)
|
req = Request.blank('/bucket/object', environ=environ, headers=headers)
|
||||||
req.content_type = 'text/plain'
|
req.content_type = 'text/plain'
|
||||||
status, headers, body = self.call_swift3(req)
|
status, headers, body = self.call_swift3(req)
|
||||||
self.assertEquals(status.split()[0], '400')
|
self.assertEqual(status.split()[0], '400')
|
||||||
self.assertEquals(self._get_error_code(body), 'InvalidRequest')
|
self.assertEqual(self._get_error_code(body), 'InvalidRequest')
|
||||||
self.assertEquals(
|
self.assertEqual(
|
||||||
self._get_error_message(body),
|
self._get_error_message(body),
|
||||||
'Missing required header for this request: x-amz-content-sha256')
|
'Missing required header for this request: x-amz-content-sha256')
|
||||||
|
|
||||||
@@ -631,8 +630,8 @@ class TestSwift3Middleware(Swift3TestCase):
|
|||||||
headers=headers)
|
headers=headers)
|
||||||
req.content_type = 'text/plain'
|
req.content_type = 'text/plain'
|
||||||
status, headers, body = self.call_swift3(req)
|
status, headers, body = self.call_swift3(req)
|
||||||
self.assertEquals(self._get_error_code(body), error)
|
self.assertEqual(self._get_error_code(body), error)
|
||||||
self.assertEquals(self._get_error_message(body), msg)
|
self.assertEqual(self._get_error_message(body), msg)
|
||||||
|
|
||||||
auth_str = ('AWS4-HMAC-SHA256 '
|
auth_str = ('AWS4-HMAC-SHA256 '
|
||||||
'SignedHeaders=host;x-amz-date,'
|
'SignedHeaders=host;x-amz-date,'
|
||||||
@@ -676,7 +675,7 @@ class TestSwift3Middleware(Swift3TestCase):
|
|||||||
def verify(hash_val, path, environ):
|
def verify(hash_val, path, environ):
|
||||||
s = canonical_string(path, environ)
|
s = canonical_string(path, environ)
|
||||||
s = s.split('\n')[3]
|
s = s.split('\n')[3]
|
||||||
self.assertEquals(hash_val, s)
|
self.assertEqual(hash_val, s)
|
||||||
|
|
||||||
# all next data got from aws4_testsuite from Amazon
|
# all next data got from aws4_testsuite from Amazon
|
||||||
# http://docs.aws.amazon.com/general/latest/gr/samples
|
# http://docs.aws.amazon.com/general/latest/gr/samples
|
||||||
@@ -812,7 +811,7 @@ class TestSwift3Middleware(Swift3TestCase):
|
|||||||
status, headers, body = self.call_swift3(req)
|
status, headers, body = self.call_swift3(req)
|
||||||
# FIXME: should this failed as 400 or pass via query auth?
|
# FIXME: should this failed as 400 or pass via query auth?
|
||||||
# for now, 403 forbbiden for safety
|
# for now, 403 forbbiden for safety
|
||||||
self.assertEquals(status.split()[0], '403', body)
|
self.assertEqual(status.split()[0], '403', body)
|
||||||
|
|
||||||
# But if we are missing Signature in query param
|
# But if we are missing Signature in query param
|
||||||
req = Request.blank('/bucket/object'
|
req = Request.blank('/bucket/object'
|
||||||
@@ -823,7 +822,7 @@ class TestSwift3Middleware(Swift3TestCase):
|
|||||||
headers=headers)
|
headers=headers)
|
||||||
req.content_type = 'text/plain'
|
req.content_type = 'text/plain'
|
||||||
status, headers, body = self.call_swift3(req)
|
status, headers, body = self.call_swift3(req)
|
||||||
self.assertEquals(status.split()[0], '403', body)
|
self.assertEqual(status.split()[0], '403', body)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@@ -644,10 +644,10 @@ class TestSwift3MultiUpload(Swift3TestCase):
|
|||||||
body=xml)
|
body=xml)
|
||||||
status, headers, body = self.call_swift3(req)
|
status, headers, body = self.call_swift3(req)
|
||||||
fromstring(body, 'CompleteMultipartUploadResult')
|
fromstring(body, 'CompleteMultipartUploadResult')
|
||||||
self.assertEquals(status.split()[0], '200')
|
self.assertEqual(status.split()[0], '200')
|
||||||
|
|
||||||
_, _, headers = self.swift.calls_with_headers[-2]
|
_, _, headers = self.swift.calls_with_headers[-2]
|
||||||
self.assertEquals(headers.get('X-Object-Meta-Foo'), 'bar')
|
self.assertEqual(headers.get('X-Object-Meta-Foo'), 'bar')
|
||||||
|
|
||||||
def test_object_multipart_upload_complete_segment_too_small(self):
|
def test_object_multipart_upload_complete_segment_too_small(self):
|
||||||
msgs = [
|
msgs = [
|
||||||
@@ -671,8 +671,8 @@ class TestSwift3MultiUpload(Swift3TestCase):
|
|||||||
self.swift.register('PUT', '/v1/AUTH_test/bucket/object',
|
self.swift.register('PUT', '/v1/AUTH_test/bucket/object',
|
||||||
swob.HTTPBadRequest, {}, msg)
|
swob.HTTPBadRequest, {}, msg)
|
||||||
status, headers, body = self.call_swift3(req)
|
status, headers, body = self.call_swift3(req)
|
||||||
self.assertEquals(status.split()[0], '400')
|
self.assertEqual(status.split()[0], '400')
|
||||||
self.assertEquals(self._get_error_code(body), 'EntityTooSmall')
|
self.assertEqual(self._get_error_code(body), 'EntityTooSmall')
|
||||||
|
|
||||||
def test_object_multipart_upload_complete_single_zero_length_segment(self):
|
def test_object_multipart_upload_complete_single_zero_length_segment(self):
|
||||||
segment_bucket = '/v1/AUTH_test/empty-bucket+segments'
|
segment_bucket = '/v1/AUTH_test/empty-bucket+segments'
|
||||||
@@ -713,7 +713,7 @@ class TestSwift3MultiUpload(Swift3TestCase):
|
|||||||
body=xml)
|
body=xml)
|
||||||
status, headers, body = self.call_swift3(req)
|
status, headers, body = self.call_swift3(req)
|
||||||
fromstring(body, 'CompleteMultipartUploadResult')
|
fromstring(body, 'CompleteMultipartUploadResult')
|
||||||
self.assertEquals(status.split()[0], '200')
|
self.assertEqual(status.split()[0], '200')
|
||||||
|
|
||||||
self.assertEqual(self.swift.calls, [
|
self.assertEqual(self.swift.calls, [
|
||||||
('HEAD', '/v1/AUTH_test/empty-bucket'),
|
('HEAD', '/v1/AUTH_test/empty-bucket'),
|
||||||
@@ -726,8 +726,8 @@ class TestSwift3MultiUpload(Swift3TestCase):
|
|||||||
('DELETE', '/v1/AUTH_test/empty-bucket+segments/object/X'),
|
('DELETE', '/v1/AUTH_test/empty-bucket+segments/object/X'),
|
||||||
])
|
])
|
||||||
_, _, put_headers = self.swift.calls_with_headers[-3]
|
_, _, put_headers = self.swift.calls_with_headers[-3]
|
||||||
self.assertEquals(put_headers.get('X-Object-Meta-Foo'), 'bar')
|
self.assertEqual(put_headers.get('X-Object-Meta-Foo'), 'bar')
|
||||||
self.assertEquals(put_headers.get('Content-Type'), 'baz/quux')
|
self.assertEqual(put_headers.get('Content-Type'), 'baz/quux')
|
||||||
|
|
||||||
def test_object_multipart_upload_complete_double_zero_length_segment(self):
|
def test_object_multipart_upload_complete_double_zero_length_segment(self):
|
||||||
segment_bucket = '/v1/AUTH_test/empty-bucket+segments'
|
segment_bucket = '/v1/AUTH_test/empty-bucket+segments'
|
||||||
@@ -769,8 +769,8 @@ class TestSwift3MultiUpload(Swift3TestCase):
|
|||||||
'Date': self.get_date_header(), },
|
'Date': self.get_date_header(), },
|
||||||
body=xml)
|
body=xml)
|
||||||
status, headers, body = self.call_swift3(req)
|
status, headers, body = self.call_swift3(req)
|
||||||
self.assertEquals(self._get_error_code(body), 'EntityTooSmall')
|
self.assertEqual(self._get_error_code(body), 'EntityTooSmall')
|
||||||
self.assertEquals(status.split()[0], '400')
|
self.assertEqual(status.split()[0], '400')
|
||||||
|
|
||||||
self.assertEqual(self.swift.calls, [
|
self.assertEqual(self.swift.calls, [
|
||||||
('HEAD', '/v1/AUTH_test/empty-bucket'),
|
('HEAD', '/v1/AUTH_test/empty-bucket'),
|
||||||
@@ -1480,11 +1480,11 @@ class TestSwift3MultiUpload(Swift3TestCase):
|
|||||||
status, header, body = self._test_copy_for_s3acl(
|
status, header, body = self._test_copy_for_s3acl(
|
||||||
account, src_headers={'Content-Length': '10'}, put_header=header)
|
account, src_headers={'Content-Length': '10'}, put_header=header)
|
||||||
|
|
||||||
self.assertEquals(status.split()[0], '400')
|
self.assertEqual(status.split()[0], '400')
|
||||||
self.assertIn('Range specified is not valid for '
|
self.assertIn('Range specified is not valid for '
|
||||||
'source object of size: 10', body)
|
'source object of size: 10', body)
|
||||||
|
|
||||||
self.assertEquals([
|
self.assertEqual([
|
||||||
('HEAD', '/v1/AUTH_test/bucket'),
|
('HEAD', '/v1/AUTH_test/bucket'),
|
||||||
('HEAD', '/v1/AUTH_test/bucket+segments/object/X'),
|
('HEAD', '/v1/AUTH_test/bucket+segments/object/X'),
|
||||||
('HEAD', '/v1/AUTH_test/src_bucket/src_obj'),
|
('HEAD', '/v1/AUTH_test/src_bucket/src_obj'),
|
||||||
@@ -1497,13 +1497,13 @@ class TestSwift3MultiUpload(Swift3TestCase):
|
|||||||
status, header, body = \
|
status, header, body = \
|
||||||
self._test_copy_for_s3acl(account, put_header=header)
|
self._test_copy_for_s3acl(account, put_header=header)
|
||||||
|
|
||||||
self.assertEquals(status.split()[0], '400', body)
|
self.assertEqual(status.split()[0], '400', body)
|
||||||
|
|
||||||
header = {'X-Amz-Copy-Source-Range': 'asdf'}
|
header = {'X-Amz-Copy-Source-Range': 'asdf'}
|
||||||
status, header, body = \
|
status, header, body = \
|
||||||
self._test_copy_for_s3acl(account, put_header=header)
|
self._test_copy_for_s3acl(account, put_header=header)
|
||||||
|
|
||||||
self.assertEquals(status.split()[0], '400', body)
|
self.assertEqual(status.split()[0], '400', body)
|
||||||
|
|
||||||
def test_upload_part_copy_range(self):
|
def test_upload_part_copy_range(self):
|
||||||
account = 'test:tester'
|
account = 'test:tester'
|
||||||
@@ -1512,17 +1512,17 @@ class TestSwift3MultiUpload(Swift3TestCase):
|
|||||||
status, header, body = self._test_copy_for_s3acl(
|
status, header, body = self._test_copy_for_s3acl(
|
||||||
account, src_headers={'Content-Length': '20'}, put_header=header)
|
account, src_headers={'Content-Length': '20'}, put_header=header)
|
||||||
|
|
||||||
self.assertEquals(status.split()[0], '200', body)
|
self.assertEqual(status.split()[0], '200', body)
|
||||||
|
|
||||||
self.assertEquals([
|
self.assertEqual([
|
||||||
('HEAD', '/v1/AUTH_test/bucket'),
|
('HEAD', '/v1/AUTH_test/bucket'),
|
||||||
('HEAD', '/v1/AUTH_test/bucket+segments/object/X'),
|
('HEAD', '/v1/AUTH_test/bucket+segments/object/X'),
|
||||||
('HEAD', '/v1/AUTH_test/src_bucket/src_obj'),
|
('HEAD', '/v1/AUTH_test/src_bucket/src_obj'),
|
||||||
('PUT', '/v1/AUTH_test/bucket+segments/object/X/1'),
|
('PUT', '/v1/AUTH_test/bucket+segments/object/X/1'),
|
||||||
], self.swift.calls)
|
], self.swift.calls)
|
||||||
put_headers = self.swift.calls_with_headers[-1][2]
|
put_headers = self.swift.calls_with_headers[-1][2]
|
||||||
self.assertEquals('bytes=0-9', put_headers['Range'])
|
self.assertEqual('bytes=0-9', put_headers['Range'])
|
||||||
self.assertEquals('/src_bucket/src_obj', put_headers['X-Copy-From'])
|
self.assertEqual('/src_bucket/src_obj', put_headers['X-Copy-From'])
|
||||||
|
|
||||||
|
|
||||||
class TestSwift3MultiUploadNonUTC(TestSwift3MultiUpload):
|
class TestSwift3MultiUploadNonUTC(TestSwift3MultiUpload):
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
hacking
|
hacking>=0.11.0,<0.12 # Apache-2.0
|
||||||
sphinx
|
sphinx
|
||||||
nose
|
nose
|
||||||
openstack.nose_plugin
|
openstack.nose_plugin
|
||||||
|
15
tox.ini
15
tox.ini
@@ -61,7 +61,18 @@ setenv = VIRTUAL_ENV={envdir}
|
|||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
# follow the same style guidelines with swift
|
# follow the same style guidelines with swift
|
||||||
ignore = H
|
# F812: list comprehension redefines ...
|
||||||
select = F,E,W,H102,H103,H501,H903,H231
|
# H101: Use TODO(NAME)
|
||||||
|
# H202: assertRaises Exception too broad
|
||||||
|
# H233: Python 3.x incompatible use of print operator
|
||||||
|
# H237: module ... is removed in Python 3
|
||||||
|
# H301: one import per line
|
||||||
|
# H306: imports not in alphabetical order (time, os)
|
||||||
|
# H401: docstring should not start with a space
|
||||||
|
# H403: multi line docstrings should end on a new line
|
||||||
|
# H404: multi line docstring should start without a leading new line
|
||||||
|
# H405: multi line docstring summary not separated with an empty line
|
||||||
|
# H501: Do not use self.__dict__ for string formatting
|
||||||
|
ignore = F812,H101,H202,H233,H237,H301,H306,H401,H403,H404,H405,H501
|
||||||
exclude = .venv,.git,.tox,dist,doc,*egg,build
|
exclude = .venv,.git,.tox,dist,doc,*egg,build
|
||||||
show-source = True
|
show-source = True
|
||||||
|
Reference in New Issue
Block a user