Rework use of constraints to ease testing
Prior to this patch both mainline code and testing modules imported and used constraints directly into their own namespace, or relied on the namespace of other modules that were not the constraints module. This meant that if a unit test wanted to change a constraint for its operation, it had to know how that module was using the constraint, instead of referencing the constraint module itself. This patch unifies the use of constraints so that all constraints are referenced via the constraints module. In turn, this allows a test to leverage the re-loadable nature of the constraints in the constraints module. It addition, a number of functional tests where using the default values for constraints, instead of the configured value discovered in a test.conf or in an existing swift.conf. This patch removes those direct references in favor of the load_constraint() method from the test/functional/tests.py module. Change-Id: Ia5313d653c667dd9ca800786de59b59334c34eaa
This commit is contained in:
parent
95dcc99a5f
commit
07fcf50c3a
@ -29,8 +29,8 @@ from swift.common.request_helpers import get_param, get_listing_content_type, \
|
||||
from swift.common.utils import get_logger, hash_path, public, \
|
||||
normalize_timestamp, storage_directory, config_true_value, \
|
||||
json, timing_stats, replication
|
||||
from swift.common.constraints import ACCOUNT_LISTING_LIMIT, \
|
||||
check_mount, check_float, check_utf8
|
||||
from swift.common.constraints import check_mount, check_float, check_utf8
|
||||
from swift.common import constraints
|
||||
from swift.common.db_replicator import ReplicatorRpc
|
||||
from swift.common.swob import HTTPAccepted, HTTPBadRequest, \
|
||||
HTTPCreated, HTTPForbidden, HTTPInternalServerError, \
|
||||
@ -195,14 +195,15 @@ class AccountController(object):
|
||||
if delimiter and (len(delimiter) > 1 or ord(delimiter) > 254):
|
||||
# delimiters can be made more flexible later
|
||||
return HTTPPreconditionFailed(body='Bad delimiter')
|
||||
limit = ACCOUNT_LISTING_LIMIT
|
||||
limit = constraints.ACCOUNT_LISTING_LIMIT
|
||||
given_limit = get_param(req, 'limit')
|
||||
if given_limit and given_limit.isdigit():
|
||||
limit = int(given_limit)
|
||||
if limit > ACCOUNT_LISTING_LIMIT:
|
||||
return HTTPPreconditionFailed(request=req,
|
||||
body='Maximum limit is %d' %
|
||||
ACCOUNT_LISTING_LIMIT)
|
||||
if limit > constraints.ACCOUNT_LISTING_LIMIT:
|
||||
return HTTPPreconditionFailed(
|
||||
request=req,
|
||||
body='Maximum limit is %d' %
|
||||
constraints.ACCOUNT_LISTING_LIMIT)
|
||||
marker = get_param(req, 'marker', '')
|
||||
end_marker = get_param(req, 'end_marker')
|
||||
out_content_type = get_listing_content_type(req)
|
||||
|
@ -18,7 +18,7 @@ import urllib
|
||||
from urllib import unquote
|
||||
from ConfigParser import ConfigParser, NoSectionError, NoOptionError
|
||||
|
||||
from swift.common.utils import ismount, split_path, SWIFT_CONF_FILE
|
||||
from swift.common import utils
|
||||
from swift.common.swob import HTTPBadRequest, HTTPLengthRequired, \
|
||||
HTTPRequestEntityTooLarge, HTTPPreconditionFailed
|
||||
|
||||
@ -62,13 +62,16 @@ def reload_constraints():
|
||||
SWIFT_CONSTRAINTS_LOADED = False
|
||||
OVERRIDE_CONSTRAINTS = {}
|
||||
constraints_conf = ConfigParser()
|
||||
if constraints_conf.read(SWIFT_CONF_FILE):
|
||||
if constraints_conf.read(utils.SWIFT_CONF_FILE):
|
||||
SWIFT_CONSTRAINTS_LOADED = True
|
||||
for name in DEFAULT_CONSTRAINTS:
|
||||
try:
|
||||
value = int(constraints_conf.get('swift-constraints', name))
|
||||
except (NoSectionError, NoOptionError):
|
||||
except NoOptionError:
|
||||
pass
|
||||
except NoSectionError:
|
||||
# We are never going to find the section for another option
|
||||
break
|
||||
else:
|
||||
OVERRIDE_CONSTRAINTS[name] = value
|
||||
for name, default in DEFAULT_CONSTRAINTS.items():
|
||||
@ -185,7 +188,7 @@ def check_mount(root, drive):
|
||||
if not (urllib.quote_plus(drive) == drive):
|
||||
return False
|
||||
path = os.path.join(root, drive)
|
||||
return ismount(path)
|
||||
return utils.ismount(path)
|
||||
|
||||
|
||||
def check_float(string):
|
||||
@ -240,7 +243,7 @@ def check_copy_from_header(req):
|
||||
if not src_header.startswith('/'):
|
||||
src_header = '/' + src_header
|
||||
try:
|
||||
return split_path(src_header, 2, 2, True)
|
||||
return utils.split_path(src_header, 2, 2, True)
|
||||
except ValueError:
|
||||
raise HTTPPreconditionFailed(
|
||||
request=req,
|
||||
|
@ -24,13 +24,8 @@ from swift.common.swob import Request, HTTPBadGateway, \
|
||||
HTTPPreconditionFailed, HTTPRequestEntityTooLarge, HTTPNotAcceptable, \
|
||||
HTTPLengthRequired, HTTPException, HTTPServerError, wsgify
|
||||
from swift.common.utils import json, get_logger, register_swift_info
|
||||
from swift.common.constraints import check_utf8, MAX_FILE_SIZE
|
||||
from swift.common import constraints
|
||||
from swift.common.http import HTTP_UNAUTHORIZED, HTTP_NOT_FOUND, HTTP_CONFLICT
|
||||
from swift.common.constraints import MAX_OBJECT_NAME_LENGTH, \
|
||||
MAX_CONTAINER_NAME_LENGTH
|
||||
|
||||
|
||||
MAX_PATH_LENGTH = MAX_OBJECT_NAME_LENGTH + MAX_CONTAINER_NAME_LENGTH + 2
|
||||
|
||||
|
||||
class CreateContainerError(Exception):
|
||||
@ -198,6 +193,8 @@ class Bulk(object):
|
||||
self.yield_frequency = yield_frequency
|
||||
self.retry_count = retry_count
|
||||
self.retry_interval = retry_interval
|
||||
self.max_path_length = constraints.MAX_OBJECT_NAME_LENGTH \
|
||||
+ constraints.MAX_CONTAINER_NAME_LENGTH + 2
|
||||
|
||||
def create_container(self, req, container_path):
|
||||
"""
|
||||
@ -248,7 +245,7 @@ class Bulk(object):
|
||||
objs_to_delete.append(
|
||||
{'name': unquote(obj_to_delete)})
|
||||
else:
|
||||
data = req.body_file.read(MAX_PATH_LENGTH)
|
||||
data = req.body_file.read(self.max_path_length)
|
||||
if data:
|
||||
line += data
|
||||
else:
|
||||
@ -261,7 +258,7 @@ class Bulk(object):
|
||||
raise HTTPRequestEntityTooLarge(
|
||||
'Maximum Bulk Deletes: %d per request' %
|
||||
self.max_deletes_per_request)
|
||||
if len(line) > MAX_PATH_LENGTH * 2:
|
||||
if len(line) > self.max_path_length * 2:
|
||||
raise HTTPBadRequest('Invalid File Name')
|
||||
return objs_to_delete
|
||||
|
||||
@ -327,7 +324,7 @@ class Bulk(object):
|
||||
continue
|
||||
delete_path = '/'.join(['', vrs, account,
|
||||
obj_name.lstrip('/')])
|
||||
if not check_utf8(delete_path):
|
||||
if not constraints.check_utf8(delete_path):
|
||||
failed_files.append([quote(obj_name),
|
||||
HTTPPreconditionFailed().status])
|
||||
continue
|
||||
@ -423,14 +420,14 @@ class Bulk(object):
|
||||
destination = '/'.join(
|
||||
['', vrs, account, obj_path])
|
||||
container = obj_path.split('/', 1)[0]
|
||||
if not check_utf8(destination):
|
||||
if not constraints.check_utf8(destination):
|
||||
failed_files.append(
|
||||
[quote(obj_path[:MAX_PATH_LENGTH]),
|
||||
[quote(obj_path[:self.max_path_length]),
|
||||
HTTPPreconditionFailed().status])
|
||||
continue
|
||||
if tar_info.size > MAX_FILE_SIZE:
|
||||
if tar_info.size > constraints.MAX_FILE_SIZE:
|
||||
failed_files.append([
|
||||
quote(obj_path[:MAX_PATH_LENGTH]),
|
||||
quote(obj_path[:self.max_path_length]),
|
||||
HTTPRequestEntityTooLarge().status])
|
||||
continue
|
||||
container_failure = None
|
||||
@ -447,13 +444,13 @@ class Bulk(object):
|
||||
# the object PUT to this container still may
|
||||
# succeed if acls are set
|
||||
container_failure = [
|
||||
quote(cont_path[:MAX_PATH_LENGTH]),
|
||||
quote(cont_path[:self.max_path_length]),
|
||||
err.status]
|
||||
if err.status_int == HTTP_UNAUTHORIZED:
|
||||
raise HTTPUnauthorized(request=req)
|
||||
except ValueError:
|
||||
failed_files.append([
|
||||
quote(obj_path[:MAX_PATH_LENGTH]),
|
||||
quote(obj_path[:self.max_path_length]),
|
||||
HTTPBadRequest().status])
|
||||
continue
|
||||
|
||||
@ -476,13 +473,14 @@ class Bulk(object):
|
||||
failed_files.append(container_failure)
|
||||
if resp.status_int == HTTP_UNAUTHORIZED:
|
||||
failed_files.append([
|
||||
quote(obj_path[:MAX_PATH_LENGTH]),
|
||||
quote(obj_path[:self.max_path_length]),
|
||||
HTTPUnauthorized().status])
|
||||
raise HTTPUnauthorized(request=req)
|
||||
if resp.status_int // 100 == 5:
|
||||
failed_response_type = HTTPBadGateway
|
||||
failed_files.append([
|
||||
quote(obj_path[:MAX_PATH_LENGTH]), resp.status])
|
||||
quote(obj_path[:self.max_path_length]),
|
||||
resp.status])
|
||||
|
||||
if failed_files:
|
||||
resp_dict['Response Status'] = failed_response_type().status
|
||||
|
@ -16,7 +16,7 @@
|
||||
import os
|
||||
from ConfigParser import ConfigParser, NoSectionError, NoOptionError
|
||||
from hashlib import md5
|
||||
from swift.common.constraints import CONTAINER_LISTING_LIMIT
|
||||
from swift.common import constraints
|
||||
from swift.common.exceptions import ListingIterError
|
||||
from swift.common.http import is_success
|
||||
from swift.common.swob import Request, Response, \
|
||||
@ -94,7 +94,7 @@ class GetContext(WSGIContext):
|
||||
first_byte = max(first_byte - seg_length, -1)
|
||||
last_byte = max(last_byte - seg_length, -1)
|
||||
|
||||
if len(segments) < CONTAINER_LISTING_LIMIT:
|
||||
if len(segments) < constraints.CONTAINER_LISTING_LIMIT:
|
||||
# a short page means that we're done with the listing
|
||||
break
|
||||
elif last_byte < 0:
|
||||
@ -127,7 +127,8 @@ class GetContext(WSGIContext):
|
||||
req, version, account, container, obj_prefix)
|
||||
if error_response:
|
||||
return error_response
|
||||
have_complete_listing = len(segments) < CONTAINER_LISTING_LIMIT
|
||||
have_complete_listing = len(segments) < \
|
||||
constraints.CONTAINER_LISTING_LIMIT
|
||||
|
||||
first_byte = last_byte = None
|
||||
content_length = None
|
||||
|
@ -78,7 +78,7 @@ from swift.common.swob import Request
|
||||
from swift.common.utils import (get_logger, get_remote_client,
|
||||
get_valid_utf8_str, config_true_value,
|
||||
InputProxy, list_from_csv)
|
||||
from swift.common.constraints import MAX_HEADER_SIZE
|
||||
from swift.common import constraints
|
||||
|
||||
QUOTE_SAFE = '/:'
|
||||
|
||||
@ -118,8 +118,8 @@ class ProxyLoggingMiddleware(object):
|
||||
self.access_logger = logger or get_logger(access_log_conf,
|
||||
log_route='proxy-access')
|
||||
self.access_logger.set_statsd_prefix('proxy-server')
|
||||
self.reveal_sensitive_prefix = int(conf.get('reveal_sensitive_prefix',
|
||||
MAX_HEADER_SIZE))
|
||||
self.reveal_sensitive_prefix = int(
|
||||
conf.get('reveal_sensitive_prefix', constraints.MAX_HEADER_SIZE))
|
||||
|
||||
def method_from_req(self, req):
|
||||
return req.environ.get('swift.orig_req_method', req.method)
|
||||
|
@ -32,8 +32,8 @@ from swift.common.utils import get_logger, hash_path, public, \
|
||||
normalize_timestamp, storage_directory, validate_sync_to, \
|
||||
config_true_value, json, timing_stats, replication, \
|
||||
override_bytes_from_content_type
|
||||
from swift.common.constraints import CONTAINER_LISTING_LIMIT, \
|
||||
check_mount, check_float, check_utf8
|
||||
from swift.common.constraints import check_mount, check_float, check_utf8
|
||||
from swift.common import constraints
|
||||
from swift.common.bufferedhttp import http_connect
|
||||
from swift.common.exceptions import ConnectionTimeout
|
||||
from swift.common.db_replicator import ReplicatorRpc
|
||||
@ -362,14 +362,15 @@ class ContainerController(object):
|
||||
return HTTPPreconditionFailed(body='Bad delimiter')
|
||||
marker = get_param(req, 'marker', '')
|
||||
end_marker = get_param(req, 'end_marker')
|
||||
limit = CONTAINER_LISTING_LIMIT
|
||||
limit = constraints.CONTAINER_LISTING_LIMIT
|
||||
given_limit = get_param(req, 'limit')
|
||||
if given_limit and given_limit.isdigit():
|
||||
limit = int(given_limit)
|
||||
if limit > CONTAINER_LISTING_LIMIT:
|
||||
if limit > constraints.CONTAINER_LISTING_LIMIT:
|
||||
return HTTPPreconditionFailed(
|
||||
request=req,
|
||||
body='Maximum limit is %d' % CONTAINER_LISTING_LIMIT)
|
||||
body='Maximum limit is %d'
|
||||
% constraints.CONTAINER_LISTING_LIMIT)
|
||||
out_content_type = get_listing_content_type(req)
|
||||
if self.mount_check and not check_mount(self.root, drive):
|
||||
return HTTPInsufficientStorage(drive=drive, request=req)
|
||||
|
@ -20,7 +20,8 @@ from swift.account.utils import account_listing_response
|
||||
from swift.common.request_helpers import get_listing_content_type
|
||||
from swift.common.middleware.acl import parse_acl, format_acl
|
||||
from swift.common.utils import public
|
||||
from swift.common.constraints import check_metadata, MAX_ACCOUNT_NAME_LENGTH
|
||||
from swift.common.constraints import check_metadata
|
||||
from swift.common import constraints
|
||||
from swift.common.http import HTTP_NOT_FOUND, HTTP_GONE
|
||||
from swift.proxy.controllers.base import Controller, clear_info_cache
|
||||
from swift.common.swob import HTTPBadRequest, HTTPMethodNotAllowed
|
||||
@ -50,10 +51,11 @@ class AccountController(Controller):
|
||||
|
||||
def GETorHEAD(self, req):
|
||||
"""Handler for HTTP GET/HEAD requests."""
|
||||
if len(self.account_name) > MAX_ACCOUNT_NAME_LENGTH:
|
||||
if len(self.account_name) > constraints.MAX_ACCOUNT_NAME_LENGTH:
|
||||
resp = HTTPBadRequest(request=req)
|
||||
resp.body = 'Account name length of %d longer than %d' % \
|
||||
(len(self.account_name), MAX_ACCOUNT_NAME_LENGTH)
|
||||
(len(self.account_name),
|
||||
constraints.MAX_ACCOUNT_NAME_LENGTH)
|
||||
return resp
|
||||
|
||||
partition, nodes = self.app.account_ring.get_nodes(self.account_name)
|
||||
@ -83,10 +85,11 @@ class AccountController(Controller):
|
||||
error_response = check_metadata(req, 'account')
|
||||
if error_response:
|
||||
return error_response
|
||||
if len(self.account_name) > MAX_ACCOUNT_NAME_LENGTH:
|
||||
if len(self.account_name) > constraints.MAX_ACCOUNT_NAME_LENGTH:
|
||||
resp = HTTPBadRequest(request=req)
|
||||
resp.body = 'Account name length of %d longer than %d' % \
|
||||
(len(self.account_name), MAX_ACCOUNT_NAME_LENGTH)
|
||||
(len(self.account_name),
|
||||
constraints.MAX_ACCOUNT_NAME_LENGTH)
|
||||
return resp
|
||||
account_partition, accounts = \
|
||||
self.app.account_ring.get_nodes(self.account_name)
|
||||
@ -101,10 +104,11 @@ class AccountController(Controller):
|
||||
@public
|
||||
def POST(self, req):
|
||||
"""HTTP POST request handler."""
|
||||
if len(self.account_name) > MAX_ACCOUNT_NAME_LENGTH:
|
||||
if len(self.account_name) > constraints.MAX_ACCOUNT_NAME_LENGTH:
|
||||
resp = HTTPBadRequest(request=req)
|
||||
resp.body = 'Account name length of %d longer than %d' % \
|
||||
(len(self.account_name), MAX_ACCOUNT_NAME_LENGTH)
|
||||
(len(self.account_name),
|
||||
constraints.MAX_ACCOUNT_NAME_LENGTH)
|
||||
return resp
|
||||
error_response = check_metadata(req, 'account')
|
||||
if error_response:
|
||||
|
@ -18,7 +18,8 @@ from urllib import unquote
|
||||
import time
|
||||
|
||||
from swift.common.utils import public, csv_append, normalize_timestamp
|
||||
from swift.common.constraints import check_metadata, MAX_CONTAINER_NAME_LENGTH
|
||||
from swift.common.constraints import check_metadata
|
||||
from swift.common import constraints
|
||||
from swift.common.http import HTTP_ACCEPTED
|
||||
from swift.proxy.controllers.base import Controller, delay_denial, \
|
||||
cors_validation, clear_info_cache
|
||||
@ -103,10 +104,11 @@ class ContainerController(Controller):
|
||||
if not req.environ.get('swift_owner'):
|
||||
for key in self.app.swift_owner_headers:
|
||||
req.headers.pop(key, None)
|
||||
if len(self.container_name) > MAX_CONTAINER_NAME_LENGTH:
|
||||
if len(self.container_name) > constraints.MAX_CONTAINER_NAME_LENGTH:
|
||||
resp = HTTPBadRequest(request=req)
|
||||
resp.body = 'Container name length of %d longer than %d' % \
|
||||
(len(self.container_name), MAX_CONTAINER_NAME_LENGTH)
|
||||
(len(self.container_name),
|
||||
constraints.MAX_CONTAINER_NAME_LENGTH)
|
||||
return resp
|
||||
account_partition, accounts, container_count = \
|
||||
self.account_info(self.account_name, req)
|
||||
|
@ -40,7 +40,8 @@ from swift.common.utils import ContextPool, normalize_timestamp, \
|
||||
quorum_size, GreenAsyncPile, normalize_delete_at_timestamp
|
||||
from swift.common.bufferedhttp import http_connect
|
||||
from swift.common.constraints import check_metadata, check_object_creation, \
|
||||
MAX_FILE_SIZE, check_copy_from_header
|
||||
check_copy_from_header
|
||||
from swift.common import constraints
|
||||
from swift.common.exceptions import ChunkReadTimeout, \
|
||||
ChunkWriteTimeout, ConnectionTimeout, ListingIterNotFound, \
|
||||
ListingIterNotAuthorized, ListingIterError
|
||||
@ -468,7 +469,7 @@ class ObjectController(Controller):
|
||||
except AttributeError as e:
|
||||
return HTTPNotImplemented(request=req, content_type='text/plain',
|
||||
body=str(e))
|
||||
if ml is not None and ml > MAX_FILE_SIZE:
|
||||
if ml is not None and ml > constraints.MAX_FILE_SIZE:
|
||||
return HTTPRequestEntityTooLarge(request=req)
|
||||
if 'x-delete-after' in req.headers:
|
||||
try:
|
||||
@ -599,7 +600,7 @@ class ObjectController(Controller):
|
||||
# CONTAINER_LISTING_LIMIT segments in a segmented object. In
|
||||
# this case, we're going to refuse to do the server-side copy.
|
||||
return HTTPRequestEntityTooLarge(request=req)
|
||||
if sink_req.content_length > MAX_FILE_SIZE:
|
||||
if sink_req.content_length > constraints.MAX_FILE_SIZE:
|
||||
return HTTPRequestEntityTooLarge(request=req)
|
||||
sink_req.etag = source_resp.etag
|
||||
# we no longer need the X-Copy-From header
|
||||
@ -695,7 +696,7 @@ class ObjectController(Controller):
|
||||
conn.queue.put('0\r\n\r\n')
|
||||
break
|
||||
bytes_transferred += len(chunk)
|
||||
if bytes_transferred > MAX_FILE_SIZE:
|
||||
if bytes_transferred > constraints.MAX_FILE_SIZE:
|
||||
return HTTPRequestEntityTooLarge(request=req)
|
||||
for conn in list(conns):
|
||||
if not conn.failed:
|
||||
|
@ -21,8 +21,6 @@ from uuid import uuid4
|
||||
from nose import SkipTest
|
||||
from string import letters
|
||||
|
||||
from swift.common.constraints import MAX_META_COUNT, MAX_META_NAME_LENGTH, \
|
||||
MAX_META_OVERALL_SIZE, MAX_META_VALUE_LENGTH
|
||||
from swift.common.middleware.acl import format_acl
|
||||
from swift_testing import (check_response, retry, skip, skip2, skip3,
|
||||
web_front_end, requires_acls)
|
||||
@ -32,6 +30,12 @@ from test.functional.tests import load_constraint
|
||||
|
||||
class TestAccount(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.max_meta_count = load_constraint('max_meta_count')
|
||||
self.max_meta_name_length = load_constraint('max_meta_name_length')
|
||||
self.max_meta_overall_size = load_constraint('max_meta_overall_size')
|
||||
self.max_meta_value_length = load_constraint('max_meta_value_length')
|
||||
|
||||
def test_metadata(self):
|
||||
if skip:
|
||||
raise SkipTest
|
||||
@ -714,54 +718,59 @@ class TestAccount(unittest.TestCase):
|
||||
return check_response(conn)
|
||||
|
||||
resp = retry(post,
|
||||
{'X-Account-Meta-' + ('k' * MAX_META_NAME_LENGTH): 'v'})
|
||||
{'X-Account-Meta-' + (
|
||||
'k' * self.max_meta_name_length): 'v'})
|
||||
resp.read()
|
||||
self.assertEqual(resp.status, 204)
|
||||
resp = retry(
|
||||
post,
|
||||
{'X-Account-Meta-' + ('k' * (MAX_META_NAME_LENGTH + 1)): 'v'})
|
||||
{'X-Account-Meta-' + ('k' * (
|
||||
self.max_meta_name_length + 1)): 'v'})
|
||||
resp.read()
|
||||
self.assertEqual(resp.status, 400)
|
||||
|
||||
resp = retry(post,
|
||||
{'X-Account-Meta-Too-Long': 'k' * MAX_META_VALUE_LENGTH})
|
||||
{'X-Account-Meta-Too-Long': (
|
||||
'k' * self.max_meta_value_length)})
|
||||
resp.read()
|
||||
self.assertEqual(resp.status, 204)
|
||||
resp = retry(
|
||||
post,
|
||||
{'X-Account-Meta-Too-Long': 'k' * (MAX_META_VALUE_LENGTH + 1)})
|
||||
{'X-Account-Meta-Too-Long': 'k' * (
|
||||
self.max_meta_value_length + 1)})
|
||||
resp.read()
|
||||
self.assertEqual(resp.status, 400)
|
||||
|
||||
headers = {}
|
||||
for x in xrange(MAX_META_COUNT):
|
||||
for x in xrange(self.max_meta_count):
|
||||
headers['X-Account-Meta-%d' % x] = 'v'
|
||||
resp = retry(post, headers)
|
||||
resp.read()
|
||||
self.assertEqual(resp.status, 204)
|
||||
headers = {}
|
||||
for x in xrange(MAX_META_COUNT + 1):
|
||||
for x in xrange(self.max_meta_count + 1):
|
||||
headers['X-Account-Meta-%d' % x] = 'v'
|
||||
resp = retry(post, headers)
|
||||
resp.read()
|
||||
self.assertEqual(resp.status, 400)
|
||||
|
||||
headers = {}
|
||||
header_value = 'k' * MAX_META_VALUE_LENGTH
|
||||
header_value = 'k' * self.max_meta_value_length
|
||||
size = 0
|
||||
x = 0
|
||||
while size < MAX_META_OVERALL_SIZE - 4 - MAX_META_VALUE_LENGTH:
|
||||
size += 4 + MAX_META_VALUE_LENGTH
|
||||
while size < (self.max_meta_overall_size - 4
|
||||
- self.max_meta_value_length):
|
||||
size += 4 + self.max_meta_value_length
|
||||
headers['X-Account-Meta-%04d' % x] = header_value
|
||||
x += 1
|
||||
if MAX_META_OVERALL_SIZE - size > 1:
|
||||
if self.max_meta_overall_size - size > 1:
|
||||
headers['X-Account-Meta-k'] = \
|
||||
'v' * (MAX_META_OVERALL_SIZE - size - 1)
|
||||
'v' * (self.max_meta_overall_size - size - 1)
|
||||
resp = retry(post, headers)
|
||||
resp.read()
|
||||
self.assertEqual(resp.status, 204)
|
||||
headers['X-Account-Meta-k'] = \
|
||||
'v' * (MAX_META_OVERALL_SIZE - size)
|
||||
'v' * (self.max_meta_overall_size - size)
|
||||
resp = retry(post, headers)
|
||||
resp.read()
|
||||
self.assertEqual(resp.status, 400)
|
||||
|
@ -20,12 +20,11 @@ import unittest
|
||||
from nose import SkipTest
|
||||
from uuid import uuid4
|
||||
|
||||
from swift.common.constraints import MAX_META_COUNT, MAX_META_NAME_LENGTH, \
|
||||
MAX_META_OVERALL_SIZE, MAX_META_VALUE_LENGTH
|
||||
|
||||
from swift_testing import check_response, retry, skip, skip2, skip3, \
|
||||
swift_test_perm, web_front_end, requires_acls, swift_test_user
|
||||
|
||||
from tests import load_constraint
|
||||
|
||||
|
||||
class TestContainer(unittest.TestCase):
|
||||
|
||||
@ -43,6 +42,11 @@ class TestContainer(unittest.TestCase):
|
||||
resp.read()
|
||||
self.assertEqual(resp.status, 201)
|
||||
|
||||
self.max_meta_count = load_constraint('max_meta_count')
|
||||
self.max_meta_name_length = load_constraint('max_meta_name_length')
|
||||
self.max_meta_overall_size = load_constraint('max_meta_overall_size')
|
||||
self.max_meta_value_length = load_constraint('max_meta_value_length')
|
||||
|
||||
def tearDown(self):
|
||||
if skip:
|
||||
raise SkipTest
|
||||
@ -266,7 +270,7 @@ class TestContainer(unittest.TestCase):
|
||||
name = uuid4().hex
|
||||
resp = retry(
|
||||
put, name,
|
||||
{'X-Container-Meta-' + ('k' * MAX_META_NAME_LENGTH): 'v'})
|
||||
{'X-Container-Meta-' + ('k' * self.max_meta_name_length): 'v'})
|
||||
resp.read()
|
||||
self.assertEqual(resp.status, 201)
|
||||
resp = retry(delete, name)
|
||||
@ -275,7 +279,8 @@ class TestContainer(unittest.TestCase):
|
||||
name = uuid4().hex
|
||||
resp = retry(
|
||||
put, name,
|
||||
{'X-Container-Meta-' + ('k' * (MAX_META_NAME_LENGTH + 1)): 'v'})
|
||||
{'X-Container-Meta-' + (
|
||||
'k' * (self.max_meta_name_length + 1)): 'v'})
|
||||
resp.read()
|
||||
self.assertEqual(resp.status, 400)
|
||||
resp = retry(delete, name)
|
||||
@ -285,7 +290,7 @@ class TestContainer(unittest.TestCase):
|
||||
name = uuid4().hex
|
||||
resp = retry(
|
||||
put, name,
|
||||
{'X-Container-Meta-Too-Long': 'k' * MAX_META_VALUE_LENGTH})
|
||||
{'X-Container-Meta-Too-Long': 'k' * self.max_meta_value_length})
|
||||
resp.read()
|
||||
self.assertEqual(resp.status, 201)
|
||||
resp = retry(delete, name)
|
||||
@ -294,7 +299,8 @@ class TestContainer(unittest.TestCase):
|
||||
name = uuid4().hex
|
||||
resp = retry(
|
||||
put, name,
|
||||
{'X-Container-Meta-Too-Long': 'k' * (MAX_META_VALUE_LENGTH + 1)})
|
||||
{'X-Container-Meta-Too-Long': 'k' * (
|
||||
self.max_meta_value_length + 1)})
|
||||
resp.read()
|
||||
self.assertEqual(resp.status, 400)
|
||||
resp = retry(delete, name)
|
||||
@ -303,7 +309,7 @@ class TestContainer(unittest.TestCase):
|
||||
|
||||
name = uuid4().hex
|
||||
headers = {}
|
||||
for x in xrange(MAX_META_COUNT):
|
||||
for x in xrange(self.max_meta_count):
|
||||
headers['X-Container-Meta-%d' % x] = 'v'
|
||||
resp = retry(put, name, headers)
|
||||
resp.read()
|
||||
@ -313,7 +319,7 @@ class TestContainer(unittest.TestCase):
|
||||
self.assertEqual(resp.status, 204)
|
||||
name = uuid4().hex
|
||||
headers = {}
|
||||
for x in xrange(MAX_META_COUNT + 1):
|
||||
for x in xrange(self.max_meta_count + 1):
|
||||
headers['X-Container-Meta-%d' % x] = 'v'
|
||||
resp = retry(put, name, headers)
|
||||
resp.read()
|
||||
@ -324,16 +330,17 @@ class TestContainer(unittest.TestCase):
|
||||
|
||||
name = uuid4().hex
|
||||
headers = {}
|
||||
header_value = 'k' * MAX_META_VALUE_LENGTH
|
||||
header_value = 'k' * self.max_meta_value_length
|
||||
size = 0
|
||||
x = 0
|
||||
while size < MAX_META_OVERALL_SIZE - 4 - MAX_META_VALUE_LENGTH:
|
||||
size += 4 + MAX_META_VALUE_LENGTH
|
||||
while size < (self.max_meta_overall_size - 4
|
||||
- self.max_meta_value_length):
|
||||
size += 4 + self.max_meta_value_length
|
||||
headers['X-Container-Meta-%04d' % x] = header_value
|
||||
x += 1
|
||||
if MAX_META_OVERALL_SIZE - size > 1:
|
||||
if self.max_meta_overall_size - size > 1:
|
||||
headers['X-Container-Meta-k'] = \
|
||||
'v' * (MAX_META_OVERALL_SIZE - size - 1)
|
||||
'v' * (self.max_meta_overall_size - size - 1)
|
||||
resp = retry(put, name, headers)
|
||||
resp.read()
|
||||
self.assertEqual(resp.status, 201)
|
||||
@ -342,7 +349,7 @@ class TestContainer(unittest.TestCase):
|
||||
self.assertEqual(resp.status, 204)
|
||||
name = uuid4().hex
|
||||
headers['X-Container-Meta-k'] = \
|
||||
'v' * (MAX_META_OVERALL_SIZE - size)
|
||||
'v' * (self.max_meta_overall_size - size)
|
||||
resp = retry(put, name, headers)
|
||||
resp.read()
|
||||
self.assertEqual(resp.status, 400)
|
||||
@ -362,55 +369,58 @@ class TestContainer(unittest.TestCase):
|
||||
|
||||
resp = retry(
|
||||
post,
|
||||
{'X-Container-Meta-' + ('k' * MAX_META_NAME_LENGTH): 'v'})
|
||||
{'X-Container-Meta-' + ('k' * self.max_meta_name_length): 'v'})
|
||||
resp.read()
|
||||
self.assertEqual(resp.status, 204)
|
||||
resp = retry(
|
||||
post,
|
||||
{'X-Container-Meta-' + ('k' * (MAX_META_NAME_LENGTH + 1)): 'v'})
|
||||
{'X-Container-Meta-' + (
|
||||
'k' * (self.max_meta_name_length + 1)): 'v'})
|
||||
resp.read()
|
||||
self.assertEqual(resp.status, 400)
|
||||
|
||||
resp = retry(
|
||||
post,
|
||||
{'X-Container-Meta-Too-Long': 'k' * MAX_META_VALUE_LENGTH})
|
||||
{'X-Container-Meta-Too-Long': 'k' * self.max_meta_value_length})
|
||||
resp.read()
|
||||
self.assertEqual(resp.status, 204)
|
||||
resp = retry(
|
||||
post,
|
||||
{'X-Container-Meta-Too-Long': 'k' * (MAX_META_VALUE_LENGTH + 1)})
|
||||
{'X-Container-Meta-Too-Long': 'k' * (
|
||||
self.max_meta_value_length + 1)})
|
||||
resp.read()
|
||||
self.assertEqual(resp.status, 400)
|
||||
|
||||
headers = {}
|
||||
for x in xrange(MAX_META_COUNT):
|
||||
for x in xrange(self.max_meta_count):
|
||||
headers['X-Container-Meta-%d' % x] = 'v'
|
||||
resp = retry(post, headers)
|
||||
resp.read()
|
||||
self.assertEqual(resp.status, 204)
|
||||
headers = {}
|
||||
for x in xrange(MAX_META_COUNT + 1):
|
||||
for x in xrange(self.max_meta_count + 1):
|
||||
headers['X-Container-Meta-%d' % x] = 'v'
|
||||
resp = retry(post, headers)
|
||||
resp.read()
|
||||
self.assertEqual(resp.status, 400)
|
||||
|
||||
headers = {}
|
||||
header_value = 'k' * MAX_META_VALUE_LENGTH
|
||||
header_value = 'k' * self.max_meta_value_length
|
||||
size = 0
|
||||
x = 0
|
||||
while size < MAX_META_OVERALL_SIZE - 4 - MAX_META_VALUE_LENGTH:
|
||||
size += 4 + MAX_META_VALUE_LENGTH
|
||||
while size < (self.max_meta_overall_size - 4
|
||||
- self.max_meta_value_length):
|
||||
size += 4 + self.max_meta_value_length
|
||||
headers['X-Container-Meta-%04d' % x] = header_value
|
||||
x += 1
|
||||
if MAX_META_OVERALL_SIZE - size > 1:
|
||||
if self.max_meta_overall_size - size > 1:
|
||||
headers['X-Container-Meta-k'] = \
|
||||
'v' * (MAX_META_OVERALL_SIZE - size - 1)
|
||||
'v' * (self.max_meta_overall_size - size - 1)
|
||||
resp = retry(post, headers)
|
||||
resp.read()
|
||||
self.assertEqual(resp.status, 204)
|
||||
headers['X-Container-Meta-k'] = \
|
||||
'v' * (MAX_META_OVERALL_SIZE - size)
|
||||
'v' * (self.max_meta_overall_size - size)
|
||||
resp = retry(post, headers)
|
||||
resp.read()
|
||||
self.assertEqual(resp.status, 400)
|
||||
|
@ -26,7 +26,8 @@ import simplejson
|
||||
import xml.dom.minidom
|
||||
|
||||
from swift.common.swob import Request
|
||||
from swift.account.server import AccountController, ACCOUNT_LISTING_LIMIT
|
||||
from swift.common import constraints
|
||||
from swift.account.server import AccountController
|
||||
from swift.common.utils import normalize_timestamp, replication, public
|
||||
from swift.common.request_helpers import get_sys_meta_prefix
|
||||
|
||||
@ -660,7 +661,7 @@ class TestAccountController(unittest.TestCase):
|
||||
|
||||
def test_GET_over_limit(self):
|
||||
req = Request.blank(
|
||||
'/sda1/p/a?limit=%d' % (ACCOUNT_LISTING_LIMIT + 1),
|
||||
'/sda1/p/a?limit=%d' % (constraints.ACCOUNT_LISTING_LIMIT + 1),
|
||||
environ={'REQUEST_METHOD': 'GET'})
|
||||
resp = req.get_response(self.controller)
|
||||
self.assertEqual(resp.status_int, 412)
|
||||
|
@ -25,11 +25,10 @@ from tempfile import mkdtemp
|
||||
from StringIO import StringIO
|
||||
from eventlet import sleep
|
||||
from mock import patch, call
|
||||
from swift.common import utils
|
||||
from swift.common import utils, constraints
|
||||
from swift.common.middleware import bulk
|
||||
from swift.common.swob import Request, Response, HTTPException
|
||||
from swift.common.http import HTTP_NOT_FOUND, HTTP_UNAUTHORIZED
|
||||
from swift.common.utils import json
|
||||
|
||||
|
||||
class FakeApp(object):
|
||||
@ -187,7 +186,7 @@ class TestUntar(unittest.TestCase):
|
||||
os.path.join(self.testdir, 'tar_works.tar' + extension))
|
||||
req.headers['transfer-encoding'] = 'chunked'
|
||||
resp_body = self.handle_extract_and_iter(req, compress_format)
|
||||
resp_data = json.loads(resp_body)
|
||||
resp_data = utils.json.loads(resp_body)
|
||||
self.assertEquals(resp_data['Number Files Created'], 6)
|
||||
|
||||
# test out xml
|
||||
@ -320,7 +319,7 @@ class TestUntar(unittest.TestCase):
|
||||
'tar_fails.tar'))
|
||||
req.headers['transfer-encoding'] = 'chunked'
|
||||
resp_body = self.handle_extract_and_iter(req, '')
|
||||
resp_data = json.loads(resp_body)
|
||||
resp_data = utils.json.loads(resp_body)
|
||||
self.assertEquals(resp_data['Number Files Created'], 4)
|
||||
|
||||
def test_extract_tar_fail_cont_401(self):
|
||||
@ -332,7 +331,7 @@ class TestUntar(unittest.TestCase):
|
||||
req.headers['transfer-encoding'] = 'chunked'
|
||||
resp_body = self.handle_extract_and_iter(req, '')
|
||||
self.assertEquals(self.app.calls, 1)
|
||||
resp_data = json.loads(resp_body)
|
||||
resp_data = utils.json.loads(resp_body)
|
||||
self.assertEquals(resp_data['Response Status'], '401 Unauthorized')
|
||||
self.assertEquals(resp_data['Errors'], [])
|
||||
|
||||
@ -345,7 +344,7 @@ class TestUntar(unittest.TestCase):
|
||||
req.headers['transfer-encoding'] = 'chunked'
|
||||
resp_body = self.handle_extract_and_iter(req, '')
|
||||
self.assertEquals(self.app.calls, 2)
|
||||
resp_data = json.loads(resp_body)
|
||||
resp_data = utils.json.loads(resp_body)
|
||||
self.assertEquals(resp_data['Response Status'], '401 Unauthorized')
|
||||
self.assertEquals(
|
||||
resp_data['Errors'],
|
||||
@ -360,7 +359,7 @@ class TestUntar(unittest.TestCase):
|
||||
req.headers['transfer-encoding'] = 'chunked'
|
||||
resp_body = self.handle_extract_and_iter(req, '')
|
||||
self.assertEquals(self.app.calls, 6)
|
||||
resp_data = json.loads(resp_body)
|
||||
resp_data = utils.json.loads(resp_body)
|
||||
self.assertEquals(resp_data['Number Files Created'], 4)
|
||||
self.assertEquals(
|
||||
resp_data['Errors'],
|
||||
@ -375,7 +374,7 @@ class TestUntar(unittest.TestCase):
|
||||
req.headers['transfer-encoding'] = 'chunked'
|
||||
resp_body = self.handle_extract_and_iter(req, 'gz')
|
||||
self.assertEquals(self.app.calls, 0)
|
||||
resp_data = json.loads(resp_body)
|
||||
resp_data = utils.json.loads(resp_body)
|
||||
self.assertEquals(resp_data['Response Status'], '400 Bad Request')
|
||||
self.assertEquals(
|
||||
resp_data['Response Body'].lower(),
|
||||
@ -392,13 +391,13 @@ class TestUntar(unittest.TestCase):
|
||||
req.headers['transfer-encoding'] = 'chunked'
|
||||
resp_body = self.handle_extract_and_iter(req, '')
|
||||
self.assertEquals(self.app.calls, 5)
|
||||
resp_data = json.loads(resp_body)
|
||||
resp_data = utils.json.loads(resp_body)
|
||||
self.assertEquals(resp_data['Number Files Created'], 3)
|
||||
self.assertEquals(
|
||||
resp_data['Errors'],
|
||||
[['cont/base_fails1/' + ('f' * 101), '400 Bad Request']])
|
||||
|
||||
@patch.object(bulk, 'MAX_FILE_SIZE', 4)
|
||||
@patch.object(constraints, 'MAX_FILE_SIZE', 4)
|
||||
def test_extract_tar_fail_max_file_size(self):
|
||||
tar = self.build_tar()
|
||||
dir_tree = [{'test': [{'sub_dir1': ['sub1_file1']}]}]
|
||||
@ -415,7 +414,7 @@ class TestUntar(unittest.TestCase):
|
||||
os.path.join(self.testdir, 'tar_works.tar'))
|
||||
req.headers['transfer-encoding'] = 'chunked'
|
||||
resp_body = self.handle_extract_and_iter(req, '')
|
||||
resp_data = json.loads(resp_body)
|
||||
resp_data = utils.json.loads(resp_body)
|
||||
self.assertEquals(
|
||||
resp_data['Errors'],
|
||||
[['cont' + self.testdir + '/test/sub_dir1/sub1_file1',
|
||||
@ -435,7 +434,7 @@ class TestUntar(unittest.TestCase):
|
||||
req.headers['transfer-encoding'] = 'chunked'
|
||||
resp_body = self.handle_extract_and_iter(req, '')
|
||||
self.assertEquals(self.app.calls, 5)
|
||||
resp_data = json.loads(resp_body)
|
||||
resp_data = utils.json.loads(resp_body)
|
||||
self.assertEquals(resp_data['Response Status'], '400 Bad Request')
|
||||
self.assertEquals(
|
||||
resp_data['Response Body'],
|
||||
@ -453,7 +452,7 @@ class TestUntar(unittest.TestCase):
|
||||
'tar_fails.tar'))
|
||||
req.headers['transfer-encoding'] = 'chunked'
|
||||
resp_body = self.handle_extract_and_iter(req, '')
|
||||
resp_data = json.loads(resp_body)
|
||||
resp_data = utils.json.loads(resp_body)
|
||||
self.assertEquals(self.app.calls, 5)
|
||||
self.assertEquals(len(resp_data['Errors']), 5)
|
||||
|
||||
@ -470,7 +469,7 @@ class TestUntar(unittest.TestCase):
|
||||
|
||||
with patch.object(self.bulk, 'create_container', bad_create):
|
||||
resp_body = self.handle_extract_and_iter(req, '')
|
||||
resp_data = json.loads(resp_body)
|
||||
resp_data = utils.json.loads(resp_body)
|
||||
self.assertEquals(self.app.calls, 0)
|
||||
self.assertEquals(len(resp_data['Errors']), 5)
|
||||
self.assertEquals(
|
||||
@ -488,7 +487,7 @@ class TestUntar(unittest.TestCase):
|
||||
'tar_fails.tar'))
|
||||
req.headers['transfer-encoding'] = 'chunked'
|
||||
resp_body = self.handle_extract_and_iter(req, '')
|
||||
resp_data = json.loads(resp_body)
|
||||
resp_data = utils.json.loads(resp_body)
|
||||
self.assertEquals(self.app.calls, 4)
|
||||
self.assertEquals(resp_data['Number Files Created'], 2)
|
||||
self.assertEquals(resp_data['Response Status'], '400 Bad Request')
|
||||
@ -537,7 +536,7 @@ class TestDelete(unittest.TestCase):
|
||||
self.app.delete_paths, ['/delete_works/AUTH_Acc/c/file_a',
|
||||
'/delete_works/AUTH_Acc/c/file_d'])
|
||||
self.assertEquals(self.app.calls, 2)
|
||||
resp_data = json.loads(resp_body)
|
||||
resp_data = utils.json.loads(resp_body)
|
||||
self.assertEquals(resp_data['Response Status'], '400 Bad Request')
|
||||
self.assertEquals(resp_data['Number Deleted'], 2)
|
||||
self.assertEquals(resp_data['Number Not Found'], 1)
|
||||
@ -553,7 +552,7 @@ class TestDelete(unittest.TestCase):
|
||||
self.app.delete_paths,
|
||||
['/delete_works/AUTH_Acc/c/f', '/delete_works/AUTH_Acc/c/f404'])
|
||||
self.assertEquals(self.app.calls, 2)
|
||||
resp_data = json.loads(resp_body)
|
||||
resp_data = utils.json.loads(resp_body)
|
||||
self.assertEquals(resp_data['Number Deleted'], 1)
|
||||
self.assertEquals(resp_data['Number Not Found'], 1)
|
||||
|
||||
@ -566,7 +565,7 @@ class TestDelete(unittest.TestCase):
|
||||
self.app.delete_paths,
|
||||
['/delete_works/AUTH_Acc/c/f', '/delete_works/AUTH_Acc/c/f404'])
|
||||
self.assertEquals(self.app.calls, 2)
|
||||
resp_data = json.loads(resp_body)
|
||||
resp_data = utils.json.loads(resp_body)
|
||||
self.assertEquals(resp_data['Number Deleted'], 1)
|
||||
self.assertEquals(resp_data['Number Not Found'], 1)
|
||||
|
||||
@ -580,7 +579,7 @@ class TestDelete(unittest.TestCase):
|
||||
req.method = 'POST'
|
||||
req.environ['wsgi.input'] = StringIO('/c/f\n/c/f404')
|
||||
resp_body = self.handle_delete_and_iter(req)
|
||||
resp_data = json.loads(resp_body)
|
||||
resp_data = utils.json.loads(resp_body)
|
||||
self.assertEquals(resp_data['Response Status'], '406 Not Acceptable')
|
||||
|
||||
def test_bulk_delete_call_and_content_type(self):
|
||||
@ -604,7 +603,7 @@ class TestDelete(unittest.TestCase):
|
||||
results = self.bulk.get_objs_to_delete(req)
|
||||
self.assertEquals(results, [{'name': '1 '}, {'name': '2'}])
|
||||
|
||||
with patch.object(bulk, 'MAX_PATH_LENGTH', 2):
|
||||
with patch.object(self.bulk, 'max_path_length', 2):
|
||||
results = []
|
||||
req.environ['wsgi.input'] = StringIO('1\n2\n3')
|
||||
results = self.bulk.get_objs_to_delete(req)
|
||||
@ -612,7 +611,7 @@ class TestDelete(unittest.TestCase):
|
||||
[{'name': '1'}, {'name': '2'}, {'name': '3'}])
|
||||
|
||||
with patch.object(self.bulk, 'max_deletes_per_request', 9):
|
||||
with patch.object(bulk, 'MAX_PATH_LENGTH', 1):
|
||||
with patch.object(self.bulk, 'max_path_length', 1):
|
||||
req_body = '\n'.join([str(i) for i in xrange(10)])
|
||||
req = Request.blank('/delete_works/AUTH_Acc', body=req_body)
|
||||
self.assertRaises(
|
||||
@ -630,7 +629,7 @@ class TestDelete(unittest.TestCase):
|
||||
'/delete_works/AUTH_Acc/c/f404',
|
||||
'/delete_works/AUTH_Acc/c/%25'])
|
||||
self.assertEquals(self.app.calls, 3)
|
||||
resp_data = json.loads(resp_body)
|
||||
resp_data = utils.json.loads(resp_body)
|
||||
self.assertEquals(resp_data['Number Deleted'], 2)
|
||||
self.assertEquals(resp_data['Number Not Found'], 1)
|
||||
|
||||
@ -657,7 +656,7 @@ class TestDelete(unittest.TestCase):
|
||||
'/delete_works/AUTH_Acc/c/ objbadutf8'])
|
||||
|
||||
self.assertEquals(self.app.calls, 2)
|
||||
resp_data = json.loads(resp_body)
|
||||
resp_data = utils.json.loads(resp_body)
|
||||
self.assertEquals(resp_data['Number Deleted'], 1)
|
||||
self.assertEquals(len(resp_data['Errors']), 2)
|
||||
self.assertEquals(
|
||||
@ -681,7 +680,7 @@ class TestDelete(unittest.TestCase):
|
||||
req.method = 'POST'
|
||||
resp_body = self.handle_delete_and_iter(req)
|
||||
self.assertEquals(self.app.calls, 2)
|
||||
resp_data = json.loads(resp_body)
|
||||
resp_data = utils.json.loads(resp_body)
|
||||
self.assertEquals(resp_data['Errors'], [['/c/f', '401 Unauthorized']])
|
||||
self.assertEquals(resp_data['Response Status'], '400 Bad Request')
|
||||
self.assertEquals(resp_data['Number Deleted'], 1)
|
||||
@ -691,7 +690,7 @@ class TestDelete(unittest.TestCase):
|
||||
headers={'Accept': 'application/json'})
|
||||
req.method = 'POST'
|
||||
resp_body = self.handle_delete_and_iter(req)
|
||||
resp_data = json.loads(resp_body)
|
||||
resp_data = utils.json.loads(resp_body)
|
||||
self.assertEquals(
|
||||
resp_data['Errors'],
|
||||
[['/c/f', '500 Internal Error'], ['c/f2', '500 Internal Error']])
|
||||
@ -710,7 +709,7 @@ class TestDelete(unittest.TestCase):
|
||||
new=mock.MagicMock(wraps=sleep,
|
||||
return_value=None)) as mock_sleep:
|
||||
resp_body = self.handle_delete_and_iter(req)
|
||||
resp_data = json.loads(resp_body)
|
||||
resp_data = utils.json.loads(resp_body)
|
||||
self.assertEquals(resp_data['Number Deleted'], 0)
|
||||
self.assertEquals(resp_data['Errors'], [['c', '409 Conflict']])
|
||||
self.assertEquals(resp_data['Response Status'], '400 Bad Request')
|
||||
@ -725,7 +724,7 @@ class TestDelete(unittest.TestCase):
|
||||
new=mock.MagicMock(wraps=sleep,
|
||||
return_value=None)) as mock_sleep:
|
||||
resp_body = self.handle_delete_and_iter(req)
|
||||
resp_data = json.loads(resp_body)
|
||||
resp_data = utils.json.loads(resp_body)
|
||||
self.assertEquals(resp_data['Number Deleted'], 0)
|
||||
self.assertEquals(resp_data['Errors'], [['c', '409 Conflict']])
|
||||
self.assertEquals(resp_data['Response Status'], '400 Bad Request')
|
||||
@ -744,7 +743,7 @@ class TestDelete(unittest.TestCase):
|
||||
new=mock.MagicMock(wraps=sleep,
|
||||
return_value=None)) as mock_sleep:
|
||||
resp_body = self.handle_delete_and_iter(req)
|
||||
resp_data = json.loads(resp_body)
|
||||
resp_data = utils.json.loads(resp_body)
|
||||
self.assertEquals(resp_data['Number Deleted'], 1)
|
||||
self.assertEquals(resp_data['Errors'], [])
|
||||
self.assertEquals(resp_data['Response Status'], '200 OK')
|
||||
@ -756,18 +755,18 @@ class TestDelete(unittest.TestCase):
|
||||
req = Request.blank('/delete_works/AUTH_Acc',
|
||||
headers={'Accept': 'application/json'})
|
||||
req.method = 'POST'
|
||||
bad_file = 'c/' + ('1' * bulk.MAX_PATH_LENGTH)
|
||||
bad_file = 'c/' + ('1' * self.bulk.max_path_length)
|
||||
data = '/c/f\n' + bad_file + '\n/c/f'
|
||||
req.environ['wsgi.input'] = StringIO(data)
|
||||
req.headers['Transfer-Encoding'] = 'chunked'
|
||||
resp_body = self.handle_delete_and_iter(req)
|
||||
resp_data = json.loads(resp_body)
|
||||
resp_data = utils.json.loads(resp_body)
|
||||
self.assertEquals(resp_data['Number Deleted'], 2)
|
||||
self.assertEquals(resp_data['Errors'], [[bad_file, '400 Bad Request']])
|
||||
self.assertEquals(resp_data['Response Status'], '400 Bad Request')
|
||||
|
||||
def test_bulk_delete_bad_file_over_twice_max_length(self):
|
||||
body = '/c/f\nc/' + ('123456' * bulk.MAX_PATH_LENGTH) + '\n'
|
||||
body = '/c/f\nc/' + ('123456' * self.bulk.max_path_length) + '\n'
|
||||
req = Request.blank('/delete_works/AUTH_Acc', body=body)
|
||||
req.method = 'POST'
|
||||
resp_body = self.handle_delete_and_iter(req)
|
||||
@ -780,7 +779,7 @@ class TestDelete(unittest.TestCase):
|
||||
with patch.object(self.bulk, 'max_failed_deletes', 2):
|
||||
resp_body = self.handle_delete_and_iter(req)
|
||||
self.assertEquals(self.app.calls, 2)
|
||||
resp_data = json.loads(resp_body)
|
||||
resp_data = utils.json.loads(resp_body)
|
||||
self.assertEquals(resp_data['Response Status'], '400 Bad Request')
|
||||
self.assertEquals(resp_data['Response Body'],
|
||||
'Max delete failures exceeded')
|
||||
|
@ -26,7 +26,7 @@ from swift.common.middleware import dlo
|
||||
from test.unit.common.middleware.helpers import FakeSwift
|
||||
from textwrap import dedent
|
||||
|
||||
LIMIT = 'swift.common.middleware.dlo.CONTAINER_LISTING_LIMIT'
|
||||
LIMIT = 'swift.common.constraints.CONTAINER_LISTING_LIMIT'
|
||||
|
||||
|
||||
def md5hex(s):
|
||||
|
@ -20,11 +20,10 @@ from posix import stat_result, statvfs_result
|
||||
import os
|
||||
import mock
|
||||
|
||||
import swift.common.constraints
|
||||
from swift import __version__ as swiftver
|
||||
from swift.common.swob import Request
|
||||
from swift.common.middleware import recon
|
||||
from swift.common.utils import json
|
||||
from swift.common import utils
|
||||
|
||||
|
||||
def fake_check_mount(a, b):
|
||||
@ -188,10 +187,10 @@ class TestReconSuccess(TestCase):
|
||||
self.mockos = MockOS()
|
||||
self.fakecache = FakeFromCache()
|
||||
self.real_listdir = os.listdir
|
||||
self.real_ismount = swift.common.constraints.ismount
|
||||
self.real_ismount = utils.ismount
|
||||
self.real_statvfs = os.statvfs
|
||||
os.listdir = self.mockos.fake_listdir
|
||||
swift.common.constraints.ismount = self.mockos.fake_ismount
|
||||
utils.ismount = self.mockos.fake_ismount
|
||||
os.statvfs = self.mockos.fake_statvfs
|
||||
self.real_from_cache = self.app._from_recon_cache
|
||||
self.app._from_recon_cache = self.fakecache.fake_from_recon_cache
|
||||
@ -199,7 +198,7 @@ class TestReconSuccess(TestCase):
|
||||
|
||||
def tearDown(self):
|
||||
os.listdir = self.real_listdir
|
||||
swift.common.constraints.ismount = self.real_ismount
|
||||
utils.ismount = self.real_ismount
|
||||
os.statvfs = self.real_statvfs
|
||||
del self.mockos
|
||||
self.app._from_recon_cache = self.real_from_cache
|
||||
@ -739,7 +738,7 @@ class TestReconMiddleware(unittest.TestCase):
|
||||
req = Request.blank('/recon/version',
|
||||
environ={'REQUEST_METHOD': 'GET'})
|
||||
resp = self.app(req.environ, start_response)
|
||||
self.assertEquals(resp, [json.dumps({'version': swiftver})])
|
||||
self.assertEquals(resp, [utils.json.dumps({'version': swiftver})])
|
||||
|
||||
def test_recon_get_load(self):
|
||||
get_load_resp = ['{"loadtest": "1"}']
|
||||
|
@ -23,7 +23,7 @@ from test.unit import MockTrue
|
||||
from swift.common.swob import HTTPBadRequest, Request, HTTPException
|
||||
from swift.common.http import HTTP_REQUEST_ENTITY_TOO_LARGE, \
|
||||
HTTP_BAD_REQUEST, HTTP_LENGTH_REQUIRED
|
||||
from swift.common import constraints
|
||||
from swift.common import constraints, utils
|
||||
|
||||
|
||||
class TestConstraints(unittest.TestCase):
|
||||
@ -169,7 +169,7 @@ class TestConstraints(unittest.TestCase):
|
||||
|
||||
def test_check_mount(self):
|
||||
self.assertFalse(constraints.check_mount('', ''))
|
||||
with mock.patch("swift.common.constraints.ismount", MockTrue()):
|
||||
with mock.patch("swift.common.utils.ismount", MockTrue()):
|
||||
self.assertTrue(constraints.check_mount('/srv', '1'))
|
||||
self.assertTrue(constraints.check_mount('/srv', 'foo-bar'))
|
||||
self.assertTrue(constraints.check_mount(
|
||||
@ -280,8 +280,7 @@ class TestConstraintsConfig(unittest.TestCase):
|
||||
for key in constraints.DEFAULT_CONSTRAINTS:
|
||||
f.write('%s = 1\n' % key)
|
||||
f.flush()
|
||||
with mock.patch.object(constraints, 'SWIFT_CONF_FILE',
|
||||
f.name):
|
||||
with mock.patch.object(utils, 'SWIFT_CONF_FILE', f.name):
|
||||
constraints.reload_constraints()
|
||||
for key in constraints.DEFAULT_CONSTRAINTS:
|
||||
# module level attrs should all be 1
|
||||
@ -305,15 +304,13 @@ class TestConstraintsConfig(unittest.TestCase):
|
||||
for key in constraints.DEFAULT_CONSTRAINTS:
|
||||
f.write('%s = 1\n' % key)
|
||||
f.flush()
|
||||
with mock.patch.object(constraints, 'SWIFT_CONF_FILE',
|
||||
f.name):
|
||||
with mock.patch.object(utils, 'SWIFT_CONF_FILE', f.name):
|
||||
constraints.reload_constraints()
|
||||
self.assertTrue(constraints.SWIFT_CONSTRAINTS_LOADED)
|
||||
self.assertEquals(sorted(constraints.DEFAULT_CONSTRAINTS.keys()),
|
||||
sorted(constraints.OVERRIDE_CONSTRAINTS.keys()))
|
||||
# file is now deleted...
|
||||
with mock.patch.object(constraints, 'SWIFT_CONF_FILE',
|
||||
f.name):
|
||||
with mock.patch.object(utils, 'SWIFT_CONF_FILE', f.name):
|
||||
constraints.reload_constraints()
|
||||
# no constraints have been loaded from non-existant swift.conf
|
||||
self.assertFalse(constraints.SWIFT_CONSTRAINTS_LOADED)
|
||||
|
@ -30,6 +30,7 @@ import simplejson
|
||||
from swift.common.swob import Request, HeaderKeyDict
|
||||
import swift.container
|
||||
from swift.container import server as container_server
|
||||
from swift.common import constraints
|
||||
from swift.common.utils import (normalize_timestamp, mkdirs, public,
|
||||
replication, lock_parent_directory)
|
||||
from test.unit import fake_http_connect
|
||||
@ -1017,7 +1018,7 @@ class TestContainerController(unittest.TestCase):
|
||||
def test_GET_over_limit(self):
|
||||
req = Request.blank(
|
||||
'/sda1/p/a/c?limit=%d' %
|
||||
(container_server.CONTAINER_LISTING_LIMIT + 1),
|
||||
(constraints.CONTAINER_LISTING_LIMIT + 1),
|
||||
environ={'REQUEST_METHOD': 'GET'})
|
||||
resp = req.get_response(self.controller)
|
||||
self.assertEquals(resp.status_int, 412)
|
||||
|
@ -20,7 +20,7 @@ from swift.common.swob import Request, Response
|
||||
from swift.common.middleware.acl import format_acl
|
||||
from swift.proxy import server as proxy_server
|
||||
from swift.proxy.controllers.base import headers_to_account_info
|
||||
from swift.common.constraints import MAX_ACCOUNT_NAME_LENGTH as MAX_ANAME_LEN
|
||||
from swift.common import constraints
|
||||
from test.unit import fake_http_connect, FakeRing, FakeMemcache
|
||||
from swift.common.request_helpers import get_sys_meta_prefix
|
||||
import swift.proxy.controllers.base
|
||||
@ -79,7 +79,8 @@ class TestAccountController(unittest.TestCase):
|
||||
self.assertEquals(410, resp.status_int)
|
||||
|
||||
def test_long_acct_names(self):
|
||||
long_acct_name = '%sLongAccountName' % ('Very' * (MAX_ANAME_LEN // 4))
|
||||
long_acct_name = '%sLongAccountName' % (
|
||||
'Very' * (constraints.MAX_ACCOUNT_NAME_LENGTH // 4))
|
||||
controller = proxy_server.AccountController(self.app, long_acct_name)
|
||||
|
||||
req = Request.blank('/v1/%s' % long_acct_name)
|
||||
|
@ -43,11 +43,7 @@ from swift.common import ring
|
||||
from swift.common.middleware import proxy_logging
|
||||
from swift.common.middleware.acl import parse_acl, format_acl
|
||||
from swift.common.exceptions import ChunkReadTimeout
|
||||
from swift.common.constraints import MAX_META_NAME_LENGTH, \
|
||||
MAX_META_VALUE_LENGTH, MAX_META_COUNT, MAX_META_OVERALL_SIZE, \
|
||||
MAX_FILE_SIZE, MAX_ACCOUNT_NAME_LENGTH, MAX_CONTAINER_NAME_LENGTH, \
|
||||
ACCOUNT_LISTING_LIMIT, CONTAINER_LISTING_LIMIT, MAX_OBJECT_NAME_LENGTH
|
||||
from swift.common import utils
|
||||
from swift.common import utils, constraints
|
||||
from swift.common.utils import mkdirs, normalize_timestamp, NullLogger
|
||||
from swift.common.wsgi import monkey_patch_mimetools
|
||||
from swift.proxy.controllers import base as proxy_base
|
||||
@ -1009,8 +1005,7 @@ class TestObjectController(unittest.TestCase):
|
||||
self.assertEqual(headers[:len(exp)], exp)
|
||||
|
||||
def test_PUT_message_length_too_large(self):
|
||||
swift.proxy.controllers.obj.MAX_FILE_SIZE = 10
|
||||
try:
|
||||
with mock.patch('swift.common.constraints.MAX_FILE_SIZE', 10):
|
||||
prolis = _test_sockets[0]
|
||||
sock = connect_tcp(('localhost', prolis.getsockname()[1]))
|
||||
fd = sock.makefile()
|
||||
@ -1025,8 +1020,6 @@ class TestObjectController(unittest.TestCase):
|
||||
headers = readuntil2crlfs(fd)
|
||||
exp = 'HTTP/1.1 413'
|
||||
self.assertEqual(headers[:len(exp)], exp)
|
||||
finally:
|
||||
swift.proxy.controllers.obj.MAX_FILE_SIZE = MAX_FILE_SIZE
|
||||
|
||||
def test_PUT_last_modified(self):
|
||||
prolis = _test_sockets[0]
|
||||
@ -1223,7 +1216,7 @@ class TestObjectController(unittest.TestCase):
|
||||
controller = proxy_server.ObjectController(self.app, 'account',
|
||||
'container', 'object')
|
||||
req = Request.blank('/v1/a/c/o', {}, headers={
|
||||
'Content-Length': str(MAX_FILE_SIZE + 1),
|
||||
'Content-Length': str(constraints.MAX_FILE_SIZE + 1),
|
||||
'Content-Type': 'foo/bar'})
|
||||
self.app.update_request(req)
|
||||
res = controller.PUT(req)
|
||||
@ -1423,7 +1416,7 @@ class TestObjectController(unittest.TestCase):
|
||||
|
||||
def test_POST_meta_val_len(self):
|
||||
with save_globals():
|
||||
limit = MAX_META_VALUE_LENGTH
|
||||
limit = constraints.MAX_META_VALUE_LENGTH
|
||||
self.app.object_post_as_copy = False
|
||||
proxy_server.ObjectController(self.app, 'account',
|
||||
'container', 'object')
|
||||
@ -1446,7 +1439,7 @@ class TestObjectController(unittest.TestCase):
|
||||
|
||||
def test_POST_as_copy_meta_val_len(self):
|
||||
with save_globals():
|
||||
limit = MAX_META_VALUE_LENGTH
|
||||
limit = constraints.MAX_META_VALUE_LENGTH
|
||||
set_http_connect(200, 200, 200, 200, 200, 202, 202, 202)
|
||||
# acct cont objc objc objc obj obj obj
|
||||
req = Request.blank('/v1/a/c/o', {'REQUEST_METHOD': 'POST'},
|
||||
@ -1466,7 +1459,7 @@ class TestObjectController(unittest.TestCase):
|
||||
|
||||
def test_POST_meta_key_len(self):
|
||||
with save_globals():
|
||||
limit = MAX_META_NAME_LENGTH
|
||||
limit = constraints.MAX_META_NAME_LENGTH
|
||||
self.app.object_post_as_copy = False
|
||||
set_http_connect(200, 200, 202, 202, 202)
|
||||
# acct cont obj obj obj
|
||||
@ -1488,7 +1481,7 @@ class TestObjectController(unittest.TestCase):
|
||||
|
||||
def test_POST_as_copy_meta_key_len(self):
|
||||
with save_globals():
|
||||
limit = MAX_META_NAME_LENGTH
|
||||
limit = constraints.MAX_META_NAME_LENGTH
|
||||
set_http_connect(200, 200, 200, 200, 200, 202, 202, 202)
|
||||
# acct cont objc objc objc obj obj obj
|
||||
req = Request.blank(
|
||||
@ -1509,7 +1502,7 @@ class TestObjectController(unittest.TestCase):
|
||||
|
||||
def test_POST_meta_count(self):
|
||||
with save_globals():
|
||||
limit = MAX_META_COUNT
|
||||
limit = constraints.MAX_META_COUNT
|
||||
headers = dict(
|
||||
(('X-Object-Meta-' + str(i), 'a') for i in xrange(limit + 1)))
|
||||
headers.update({'Content-Type': 'foo/bar'})
|
||||
@ -1522,7 +1515,7 @@ class TestObjectController(unittest.TestCase):
|
||||
|
||||
def test_POST_meta_size(self):
|
||||
with save_globals():
|
||||
limit = MAX_META_OVERALL_SIZE
|
||||
limit = constraints.MAX_META_OVERALL_SIZE
|
||||
count = limit / 256 # enough to cause the limit to be reached
|
||||
headers = dict(
|
||||
(('X-Object-Meta-' + str(i), 'a' * 256)
|
||||
@ -2133,18 +2126,21 @@ class TestObjectController(unittest.TestCase):
|
||||
self.assertEquals(resp.status_int, 201)
|
||||
|
||||
set_http_connect(201, 201, 201)
|
||||
req = Request.blank('/v1/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
|
||||
headers={'Content-Length': '0',
|
||||
'X-Object-Meta-' + ('a' *
|
||||
MAX_META_NAME_LENGTH): 'v'})
|
||||
req = Request.blank(
|
||||
'/v1/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
|
||||
headers={'Content-Length': '0',
|
||||
'X-Object-Meta-' + (
|
||||
'a' * constraints.MAX_META_NAME_LENGTH): 'v'})
|
||||
self.app.update_request(req)
|
||||
resp = controller.PUT(req)
|
||||
self.assertEquals(resp.status_int, 201)
|
||||
set_http_connect(201, 201, 201)
|
||||
req = Request.blank('/v1/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
|
||||
headers={'Content-Length': '0',
|
||||
'X-Object-Meta-' + ('a' *
|
||||
(MAX_META_NAME_LENGTH + 1)): 'v'})
|
||||
req = Request.blank(
|
||||
'/v1/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
|
||||
headers={
|
||||
'Content-Length': '0',
|
||||
'X-Object-Meta-' + (
|
||||
'a' * (constraints.MAX_META_NAME_LENGTH + 1)): 'v'})
|
||||
self.app.update_request(req)
|
||||
resp = controller.PUT(req)
|
||||
self.assertEquals(resp.status_int, 400)
|
||||
@ -2153,22 +2149,23 @@ class TestObjectController(unittest.TestCase):
|
||||
req = Request.blank('/v1/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
|
||||
headers={'Content-Length': '0',
|
||||
'X-Object-Meta-Too-Long': 'a' *
|
||||
MAX_META_VALUE_LENGTH})
|
||||
constraints.MAX_META_VALUE_LENGTH})
|
||||
self.app.update_request(req)
|
||||
resp = controller.PUT(req)
|
||||
self.assertEquals(resp.status_int, 201)
|
||||
set_http_connect(201, 201, 201)
|
||||
req = Request.blank('/v1/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
|
||||
headers={'Content-Length': '0',
|
||||
'X-Object-Meta-Too-Long': 'a' *
|
||||
(MAX_META_VALUE_LENGTH + 1)})
|
||||
req = Request.blank(
|
||||
'/v1/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
|
||||
headers={'Content-Length': '0',
|
||||
'X-Object-Meta-Too-Long': 'a' *
|
||||
(constraints.MAX_META_VALUE_LENGTH + 1)})
|
||||
self.app.update_request(req)
|
||||
resp = controller.PUT(req)
|
||||
self.assertEquals(resp.status_int, 400)
|
||||
|
||||
set_http_connect(201, 201, 201)
|
||||
headers = {'Content-Length': '0'}
|
||||
for x in xrange(MAX_META_COUNT):
|
||||
for x in xrange(constraints.MAX_META_COUNT):
|
||||
headers['X-Object-Meta-%d' % x] = 'v'
|
||||
req = Request.blank('/v1/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
|
||||
headers=headers)
|
||||
@ -2177,7 +2174,7 @@ class TestObjectController(unittest.TestCase):
|
||||
self.assertEquals(resp.status_int, 201)
|
||||
set_http_connect(201, 201, 201)
|
||||
headers = {'Content-Length': '0'}
|
||||
for x in xrange(MAX_META_COUNT + 1):
|
||||
for x in xrange(constraints.MAX_META_COUNT + 1):
|
||||
headers['X-Object-Meta-%d' % x] = 'v'
|
||||
req = Request.blank('/v1/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
|
||||
headers=headers)
|
||||
@ -2187,17 +2184,17 @@ class TestObjectController(unittest.TestCase):
|
||||
|
||||
set_http_connect(201, 201, 201)
|
||||
headers = {'Content-Length': '0'}
|
||||
header_value = 'a' * MAX_META_VALUE_LENGTH
|
||||
header_value = 'a' * constraints.MAX_META_VALUE_LENGTH
|
||||
size = 0
|
||||
x = 0
|
||||
while size < MAX_META_OVERALL_SIZE - 4 - \
|
||||
MAX_META_VALUE_LENGTH:
|
||||
size += 4 + MAX_META_VALUE_LENGTH
|
||||
while size < constraints.MAX_META_OVERALL_SIZE - 4 - \
|
||||
constraints.MAX_META_VALUE_LENGTH:
|
||||
size += 4 + constraints.MAX_META_VALUE_LENGTH
|
||||
headers['X-Object-Meta-%04d' % x] = header_value
|
||||
x += 1
|
||||
if MAX_META_OVERALL_SIZE - size > 1:
|
||||
if constraints.MAX_META_OVERALL_SIZE - size > 1:
|
||||
headers['X-Object-Meta-a'] = \
|
||||
'a' * (MAX_META_OVERALL_SIZE - size - 1)
|
||||
'a' * (constraints.MAX_META_OVERALL_SIZE - size - 1)
|
||||
req = Request.blank('/v1/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
|
||||
headers=headers)
|
||||
self.app.update_request(req)
|
||||
@ -2205,7 +2202,7 @@ class TestObjectController(unittest.TestCase):
|
||||
self.assertEquals(resp.status_int, 201)
|
||||
set_http_connect(201, 201, 201)
|
||||
headers['X-Object-Meta-a'] = \
|
||||
'a' * (MAX_META_OVERALL_SIZE - size)
|
||||
'a' * (constraints.MAX_META_OVERALL_SIZE - size)
|
||||
req = Request.blank('/v1/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
|
||||
headers=headers)
|
||||
self.app.update_request(req)
|
||||
@ -2381,7 +2378,7 @@ class TestObjectController(unittest.TestCase):
|
||||
class LargeResponseBody(object):
|
||||
|
||||
def __len__(self):
|
||||
return MAX_FILE_SIZE + 1
|
||||
return constraints.MAX_FILE_SIZE + 1
|
||||
|
||||
def __getitem__(self, key):
|
||||
return ''
|
||||
@ -2515,7 +2512,7 @@ class TestObjectController(unittest.TestCase):
|
||||
class LargeResponseBody(object):
|
||||
|
||||
def __len__(self):
|
||||
return MAX_FILE_SIZE + 1
|
||||
return constraints.MAX_FILE_SIZE + 1
|
||||
|
||||
def __getitem__(self, key):
|
||||
return ''
|
||||
@ -2617,12 +2614,10 @@ class TestObjectController(unittest.TestCase):
|
||||
req.body_file = ChunkedFile(11)
|
||||
self.app.memcache.store = {}
|
||||
self.app.update_request(req)
|
||||
try:
|
||||
swift.proxy.controllers.obj.MAX_FILE_SIZE = 10
|
||||
|
||||
with mock.patch('swift.common.constraints.MAX_FILE_SIZE', 10):
|
||||
res = controller.PUT(req)
|
||||
self.assertEquals(res.status_int, 413)
|
||||
finally:
|
||||
swift.proxy.controllers.obj.MAX_FILE_SIZE = MAX_FILE_SIZE
|
||||
|
||||
def test_chunked_put_bad_version(self):
|
||||
# Check bad version
|
||||
@ -4352,7 +4347,7 @@ class TestContainerController(unittest.TestCase):
|
||||
|
||||
def test_PUT_max_container_name_length(self):
|
||||
with save_globals():
|
||||
limit = MAX_CONTAINER_NAME_LENGTH
|
||||
limit = constraints.MAX_CONTAINER_NAME_LENGTH
|
||||
controller = proxy_server.ContainerController(self.app, 'account',
|
||||
'1' * limit)
|
||||
self.assert_status_map(controller.PUT,
|
||||
@ -4586,14 +4581,15 @@ class TestContainerController(unittest.TestCase):
|
||||
set_http_connect(201, 201, 201)
|
||||
req = Request.blank('/v1/a/c', environ={'REQUEST_METHOD': method},
|
||||
headers={'X-Container-Meta-' +
|
||||
('a' * MAX_META_NAME_LENGTH): 'v'})
|
||||
('a' * constraints.MAX_META_NAME_LENGTH): 'v'})
|
||||
self.app.update_request(req)
|
||||
resp = getattr(controller, method)(req)
|
||||
self.assertEquals(resp.status_int, 201)
|
||||
set_http_connect(201, 201, 201)
|
||||
req = Request.blank('/v1/a/c', environ={'REQUEST_METHOD': method},
|
||||
headers={'X-Container-Meta-' +
|
||||
('a' * (MAX_META_NAME_LENGTH + 1)): 'v'})
|
||||
req = Request.blank(
|
||||
'/v1/a/c', environ={'REQUEST_METHOD': method},
|
||||
headers={'X-Container-Meta-' +
|
||||
('a' * (constraints.MAX_META_NAME_LENGTH + 1)): 'v'})
|
||||
self.app.update_request(req)
|
||||
resp = getattr(controller, method)(req)
|
||||
self.assertEquals(resp.status_int, 400)
|
||||
@ -4601,21 +4597,21 @@ class TestContainerController(unittest.TestCase):
|
||||
set_http_connect(201, 201, 201)
|
||||
req = Request.blank('/v1/a/c', environ={'REQUEST_METHOD': method},
|
||||
headers={'X-Container-Meta-Too-Long':
|
||||
'a' * MAX_META_VALUE_LENGTH})
|
||||
'a' * constraints.MAX_META_VALUE_LENGTH})
|
||||
self.app.update_request(req)
|
||||
resp = getattr(controller, method)(req)
|
||||
self.assertEquals(resp.status_int, 201)
|
||||
set_http_connect(201, 201, 201)
|
||||
req = Request.blank('/v1/a/c', environ={'REQUEST_METHOD': method},
|
||||
headers={'X-Container-Meta-Too-Long':
|
||||
'a' * (MAX_META_VALUE_LENGTH + 1)})
|
||||
'a' * (constraints.MAX_META_VALUE_LENGTH + 1)})
|
||||
self.app.update_request(req)
|
||||
resp = getattr(controller, method)(req)
|
||||
self.assertEquals(resp.status_int, 400)
|
||||
|
||||
set_http_connect(201, 201, 201)
|
||||
headers = {}
|
||||
for x in xrange(MAX_META_COUNT):
|
||||
for x in xrange(constraints.MAX_META_COUNT):
|
||||
headers['X-Container-Meta-%d' % x] = 'v'
|
||||
req = Request.blank('/v1/a/c', environ={'REQUEST_METHOD': method},
|
||||
headers=headers)
|
||||
@ -4624,7 +4620,7 @@ class TestContainerController(unittest.TestCase):
|
||||
self.assertEquals(resp.status_int, 201)
|
||||
set_http_connect(201, 201, 201)
|
||||
headers = {}
|
||||
for x in xrange(MAX_META_COUNT + 1):
|
||||
for x in xrange(constraints.MAX_META_COUNT + 1):
|
||||
headers['X-Container-Meta-%d' % x] = 'v'
|
||||
req = Request.blank('/v1/a/c', environ={'REQUEST_METHOD': method},
|
||||
headers=headers)
|
||||
@ -4634,16 +4630,17 @@ class TestContainerController(unittest.TestCase):
|
||||
|
||||
set_http_connect(201, 201, 201)
|
||||
headers = {}
|
||||
header_value = 'a' * MAX_META_VALUE_LENGTH
|
||||
header_value = 'a' * constraints.MAX_META_VALUE_LENGTH
|
||||
size = 0
|
||||
x = 0
|
||||
while size < MAX_META_OVERALL_SIZE - 4 - MAX_META_VALUE_LENGTH:
|
||||
size += 4 + MAX_META_VALUE_LENGTH
|
||||
while size < (constraints.MAX_META_OVERALL_SIZE - 4
|
||||
- constraints.MAX_META_VALUE_LENGTH):
|
||||
size += 4 + constraints.MAX_META_VALUE_LENGTH
|
||||
headers['X-Container-Meta-%04d' % x] = header_value
|
||||
x += 1
|
||||
if MAX_META_OVERALL_SIZE - size > 1:
|
||||
if constraints.MAX_META_OVERALL_SIZE - size > 1:
|
||||
headers['X-Container-Meta-a'] = \
|
||||
'a' * (MAX_META_OVERALL_SIZE - size - 1)
|
||||
'a' * (constraints.MAX_META_OVERALL_SIZE - size - 1)
|
||||
req = Request.blank('/v1/a/c', environ={'REQUEST_METHOD': method},
|
||||
headers=headers)
|
||||
self.app.update_request(req)
|
||||
@ -4651,7 +4648,7 @@ class TestContainerController(unittest.TestCase):
|
||||
self.assertEquals(resp.status_int, 201)
|
||||
set_http_connect(201, 201, 201)
|
||||
headers['X-Container-Meta-a'] = \
|
||||
'a' * (MAX_META_OVERALL_SIZE - size)
|
||||
'a' * (constraints.MAX_META_OVERALL_SIZE - size)
|
||||
req = Request.blank('/v1/a/c', environ={'REQUEST_METHOD': method},
|
||||
headers=headers)
|
||||
self.app.update_request(req)
|
||||
@ -5357,7 +5354,7 @@ class TestAccountController(unittest.TestCase):
|
||||
def test_PUT_max_account_name_length(self):
|
||||
with save_globals():
|
||||
self.app.allow_account_management = True
|
||||
limit = MAX_ACCOUNT_NAME_LENGTH
|
||||
limit = constraints.MAX_ACCOUNT_NAME_LENGTH
|
||||
controller = proxy_server.AccountController(self.app, '1' * limit)
|
||||
self.assert_status_map(controller.PUT, (201, 201, 201), 201)
|
||||
controller = proxy_server.AccountController(
|
||||
@ -5432,14 +5429,15 @@ class TestAccountController(unittest.TestCase):
|
||||
set_http_connect(201, 201, 201)
|
||||
req = Request.blank('/v1/a/c', environ={'REQUEST_METHOD': method},
|
||||
headers={'X-Account-Meta-' +
|
||||
('a' * MAX_META_NAME_LENGTH): 'v'})
|
||||
('a' * constraints.MAX_META_NAME_LENGTH): 'v'})
|
||||
self.app.update_request(req)
|
||||
resp = getattr(controller, method)(req)
|
||||
self.assertEquals(resp.status_int, 201)
|
||||
set_http_connect(201, 201, 201)
|
||||
req = Request.blank('/v1/a/c', environ={'REQUEST_METHOD': method},
|
||||
headers={'X-Account-Meta-' +
|
||||
('a' * (MAX_META_NAME_LENGTH + 1)): 'v'})
|
||||
req = Request.blank(
|
||||
'/v1/a/c', environ={'REQUEST_METHOD': method},
|
||||
headers={'X-Account-Meta-' +
|
||||
('a' * (constraints.MAX_META_NAME_LENGTH + 1)): 'v'})
|
||||
self.app.update_request(req)
|
||||
resp = getattr(controller, method)(req)
|
||||
self.assertEquals(resp.status_int, 400)
|
||||
@ -5447,21 +5445,21 @@ class TestAccountController(unittest.TestCase):
|
||||
set_http_connect(201, 201, 201)
|
||||
req = Request.blank('/v1/a/c', environ={'REQUEST_METHOD': method},
|
||||
headers={'X-Account-Meta-Too-Long':
|
||||
'a' * MAX_META_VALUE_LENGTH})
|
||||
'a' * constraints.MAX_META_VALUE_LENGTH})
|
||||
self.app.update_request(req)
|
||||
resp = getattr(controller, method)(req)
|
||||
self.assertEquals(resp.status_int, 201)
|
||||
set_http_connect(201, 201, 201)
|
||||
req = Request.blank('/v1/a/c', environ={'REQUEST_METHOD': method},
|
||||
headers={'X-Account-Meta-Too-Long':
|
||||
'a' * (MAX_META_VALUE_LENGTH + 1)})
|
||||
'a' * (constraints.MAX_META_VALUE_LENGTH + 1)})
|
||||
self.app.update_request(req)
|
||||
resp = getattr(controller, method)(req)
|
||||
self.assertEquals(resp.status_int, 400)
|
||||
|
||||
set_http_connect(201, 201, 201)
|
||||
headers = {}
|
||||
for x in xrange(MAX_META_COUNT):
|
||||
for x in xrange(constraints.MAX_META_COUNT):
|
||||
headers['X-Account-Meta-%d' % x] = 'v'
|
||||
req = Request.blank('/v1/a/c', environ={'REQUEST_METHOD': method},
|
||||
headers=headers)
|
||||
@ -5470,7 +5468,7 @@ class TestAccountController(unittest.TestCase):
|
||||
self.assertEquals(resp.status_int, 201)
|
||||
set_http_connect(201, 201, 201)
|
||||
headers = {}
|
||||
for x in xrange(MAX_META_COUNT + 1):
|
||||
for x in xrange(constraints.MAX_META_COUNT + 1):
|
||||
headers['X-Account-Meta-%d' % x] = 'v'
|
||||
req = Request.blank('/v1/a/c', environ={'REQUEST_METHOD': method},
|
||||
headers=headers)
|
||||
@ -5480,16 +5478,17 @@ class TestAccountController(unittest.TestCase):
|
||||
|
||||
set_http_connect(201, 201, 201)
|
||||
headers = {}
|
||||
header_value = 'a' * MAX_META_VALUE_LENGTH
|
||||
header_value = 'a' * constraints.MAX_META_VALUE_LENGTH
|
||||
size = 0
|
||||
x = 0
|
||||
while size < MAX_META_OVERALL_SIZE - 4 - MAX_META_VALUE_LENGTH:
|
||||
size += 4 + MAX_META_VALUE_LENGTH
|
||||
while size < (constraints.MAX_META_OVERALL_SIZE - 4
|
||||
- constraints.MAX_META_VALUE_LENGTH):
|
||||
size += 4 + constraints.MAX_META_VALUE_LENGTH
|
||||
headers['X-Account-Meta-%04d' % x] = header_value
|
||||
x += 1
|
||||
if MAX_META_OVERALL_SIZE - size > 1:
|
||||
if constraints.MAX_META_OVERALL_SIZE - size > 1:
|
||||
headers['X-Account-Meta-a'] = \
|
||||
'a' * (MAX_META_OVERALL_SIZE - size - 1)
|
||||
'a' * (constraints.MAX_META_OVERALL_SIZE - size - 1)
|
||||
req = Request.blank('/v1/a/c', environ={'REQUEST_METHOD': method},
|
||||
headers=headers)
|
||||
self.app.update_request(req)
|
||||
@ -5497,7 +5496,7 @@ class TestAccountController(unittest.TestCase):
|
||||
self.assertEquals(resp.status_int, 201)
|
||||
set_http_connect(201, 201, 201)
|
||||
headers['X-Account-Meta-a'] = \
|
||||
'a' * (MAX_META_OVERALL_SIZE - size)
|
||||
'a' * (constraints.MAX_META_OVERALL_SIZE - size)
|
||||
req = Request.blank('/v1/a/c', environ={'REQUEST_METHOD': method},
|
||||
headers=headers)
|
||||
self.app.update_request(req)
|
||||
@ -5897,18 +5896,22 @@ class TestSwiftInfo(unittest.TestCase):
|
||||
|
||||
si = utils.get_swift_info()['swift']
|
||||
self.assertTrue('version' in si)
|
||||
self.assertEqual(si['max_file_size'], MAX_FILE_SIZE)
|
||||
self.assertEqual(si['max_meta_name_length'], MAX_META_NAME_LENGTH)
|
||||
self.assertEqual(si['max_meta_value_length'], MAX_META_VALUE_LENGTH)
|
||||
self.assertEqual(si['max_meta_count'], MAX_META_COUNT)
|
||||
self.assertEqual(si['account_listing_limit'], ACCOUNT_LISTING_LIMIT)
|
||||
self.assertEqual(si['max_file_size'], constraints.MAX_FILE_SIZE)
|
||||
self.assertEqual(si['max_meta_name_length'],
|
||||
constraints.MAX_META_NAME_LENGTH)
|
||||
self.assertEqual(si['max_meta_value_length'],
|
||||
constraints.MAX_META_VALUE_LENGTH)
|
||||
self.assertEqual(si['max_meta_count'], constraints.MAX_META_COUNT)
|
||||
self.assertEqual(si['account_listing_limit'],
|
||||
constraints.ACCOUNT_LISTING_LIMIT)
|
||||
self.assertEqual(si['container_listing_limit'],
|
||||
CONTAINER_LISTING_LIMIT)
|
||||
constraints.CONTAINER_LISTING_LIMIT)
|
||||
self.assertEqual(si['max_account_name_length'],
|
||||
MAX_ACCOUNT_NAME_LENGTH)
|
||||
constraints.MAX_ACCOUNT_NAME_LENGTH)
|
||||
self.assertEqual(si['max_container_name_length'],
|
||||
MAX_CONTAINER_NAME_LENGTH)
|
||||
self.assertEqual(si['max_object_name_length'], MAX_OBJECT_NAME_LENGTH)
|
||||
constraints.MAX_CONTAINER_NAME_LENGTH)
|
||||
self.assertEqual(si['max_object_name_length'],
|
||||
constraints.MAX_OBJECT_NAME_LENGTH)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
x
Reference in New Issue
Block a user