undoing new exception type

This commit is contained in:
David Goetz 2010-11-01 14:47:48 -07:00
parent 4b4a0997a4
commit 1f09bb6720
12 changed files with 64 additions and 70 deletions

View File

@ -34,7 +34,7 @@ from swift.common.utils import get_logger, get_param, hash_path, \
from swift.common.constraints import ACCOUNT_LISTING_LIMIT, \ from swift.common.constraints import ACCOUNT_LISTING_LIMIT, \
check_mount, check_float, check_utf8 check_mount, check_float, check_utf8
from swift.common.db_replicator import ReplicatorRpc from swift.common.db_replicator import ReplicatorRpc
from swift.common.exceptions import InvalidPathError
DATADIR = 'accounts' DATADIR = 'accounts'
@ -60,7 +60,7 @@ class AccountController(object):
"""Handle HTTP DELETE request.""" """Handle HTTP DELETE request."""
try: try:
drive, part, account = split_path(unquote(req.path), 3) drive, part, account = split_path(unquote(req.path), 3)
except InvalidPathError, err: except ValueError, err:
return HTTPBadRequest(body=str(err), content_type='text/plain', return HTTPBadRequest(body=str(err), content_type='text/plain',
request=req) request=req)
if self.mount_check and not check_mount(self.root, drive): if self.mount_check and not check_mount(self.root, drive):
@ -80,7 +80,7 @@ class AccountController(object):
try: try:
drive, part, account, container = split_path(unquote(req.path), drive, part, account, container = split_path(unquote(req.path),
3, 4) 3, 4)
except InvalidPathError, err: except ValueError, err:
return HTTPBadRequest(body=str(err), content_type='text/plain', return HTTPBadRequest(body=str(err), content_type='text/plain',
request=req) request=req)
if self.mount_check and not check_mount(self.root, drive): if self.mount_check and not check_mount(self.root, drive):
@ -135,7 +135,7 @@ class AccountController(object):
try: try:
drive, part, account, container = split_path(unquote(req.path), drive, part, account, container = split_path(unquote(req.path),
3, 4) 3, 4)
except InvalidPathError, err: except ValueError, err:
return HTTPBadRequest(body=str(err), content_type='text/plain', return HTTPBadRequest(body=str(err), content_type='text/plain',
request=req) request=req)
if self.mount_check and not check_mount(self.root, drive): if self.mount_check and not check_mount(self.root, drive):
@ -166,7 +166,7 @@ class AccountController(object):
"""Handle HTTP GET request.""" """Handle HTTP GET request."""
try: try:
drive, part, account = split_path(unquote(req.path), 3) drive, part, account = split_path(unquote(req.path), 3)
except InvalidPathError, err: except ValueError, err:
return HTTPBadRequest(body=str(err), content_type='text/plain', return HTTPBadRequest(body=str(err), content_type='text/plain',
request=req) request=req)
if self.mount_check and not check_mount(self.root, drive): if self.mount_check and not check_mount(self.root, drive):
@ -257,7 +257,7 @@ class AccountController(object):
""" """
try: try:
post_args = split_path(unquote(req.path), 3) post_args = split_path(unquote(req.path), 3)
except InvalidPathError, err: except ValueError, err:
return HTTPBadRequest(body=str(err), content_type='text/plain', return HTTPBadRequest(body=str(err), content_type='text/plain',
request=req) request=req)
drive, partition, hash = post_args drive, partition, hash = post_args
@ -275,7 +275,7 @@ class AccountController(object):
"""Handle HTTP POST request.""" """Handle HTTP POST request."""
try: try:
drive, part, account = split_path(unquote(req.path), 3) drive, part, account = split_path(unquote(req.path), 3)
except InvalidPathError, err: except ValueError, err:
return HTTPBadRequest(body=str(err), content_type='text/plain', return HTTPBadRequest(body=str(err), content_type='text/plain',
request=req) request=req)
if 'x-timestamp' not in req.headers or \ if 'x-timestamp' not in req.headers or \

View File

@ -30,7 +30,6 @@ from webob.exc import HTTPBadRequest, HTTPConflict, HTTPForbidden, \
from swift.common.bufferedhttp import http_connect_raw as http_connect from swift.common.bufferedhttp import http_connect_raw as http_connect
from swift.common.db import get_db_connection from swift.common.db import get_db_connection
from swift.common.utils import get_logger, split_path from swift.common.utils import get_logger, split_path
from swift.common.exceptions import InvalidPathError
class AuthController(object): class AuthController(object):
@ -416,7 +415,7 @@ YOU HAVE A FEW OPTIONS:
""" """
try: try:
_, token = split_path(request.path, minsegs=2) _, token = split_path(request.path, minsegs=2)
except InvalidPathError: except ValueError:
return HTTPBadRequest() return HTTPBadRequest()
# Retrieves (TTL, account, user, cfaccount) if valid, False otherwise # Retrieves (TTL, account, user, cfaccount) if valid, False otherwise
validation = self.validate_token(token) validation = self.validate_token(token)
@ -452,7 +451,7 @@ YOU HAVE A FEW OPTIONS:
""" """
try: try:
_, account_name, user_name = split_path(request.path, minsegs=3) _, account_name, user_name = split_path(request.path, minsegs=3)
except InvalidPathError: except ValueError:
return HTTPBadRequest() return HTTPBadRequest()
create_reseller_admin = \ create_reseller_admin = \
request.headers.get('x-auth-user-reseller-admin') == 'true' request.headers.get('x-auth-user-reseller-admin') == 'true'
@ -517,8 +516,12 @@ YOU HAVE A FEW OPTIONS:
:param request: A webob.Request instance. :param request: A webob.Request instance.
""" """
try:
pathsegs = \ pathsegs = \
split_path(request.path, minsegs=1, maxsegs=3, rest_with_last=True) split_path(request.path, minsegs=1, maxsegs=3,
rest_with_last=True)
except ValueError:
return HTTPBadRequest()
if pathsegs[0] == 'v1' and pathsegs[2] == 'auth': if pathsegs[0] == 'v1' and pathsegs[2] == 'auth':
account = pathsegs[1] account = pathsegs[1]
user = request.headers.get('x-storage-user') user = request.headers.get('x-storage-user')
@ -608,8 +611,6 @@ YOU HAVE A FEW OPTIONS:
else: else:
return HTTPBadRequest(request=env)(env, start_response) return HTTPBadRequest(request=env)(env, start_response)
response = handler(req) response = handler(req)
except InvalidPathError:
return HTTPNotFound()(env, start_response)
except: except:
self.logger.exception('ERROR Unhandled exception in ReST request') self.logger.exception('ERROR Unhandled exception in ReST request')
return HTTPServiceUnavailable(request=req)(env, start_response) return HTTPServiceUnavailable(request=req)(env, start_response)

View File

@ -52,6 +52,3 @@ class DriveNotMounted(Exception):
class LockTimeout(MessageTimeout): class LockTimeout(MessageTimeout):
pass pass
class InvalidPathError(Exception):
pass

View File

@ -21,7 +21,7 @@ from webob.exc import HTTPForbidden, HTTPUnauthorized, HTTPNotFound
from swift.common.bufferedhttp import http_connect_raw as http_connect from swift.common.bufferedhttp import http_connect_raw as http_connect
from swift.common.middleware.acl import clean_acl, parse_acl, referrer_allowed from swift.common.middleware.acl import clean_acl, parse_acl, referrer_allowed
from swift.common.utils import cache_from_env, split_path, TRUE_VALUES from swift.common.utils import cache_from_env, split_path, TRUE_VALUES
from swift.common.exceptions import InvalidPathError
class DevAuth(object): class DevAuth(object):
"""Auth Middleware that uses the dev auth server.""" """Auth Middleware that uses the dev auth server."""
@ -85,7 +85,7 @@ class DevAuth(object):
try: try:
version, rest = split_path(env.get('PATH_INFO', ''), version, rest = split_path(env.get('PATH_INFO', ''),
1, 2, True) 1, 2, True)
except InvalidPathError, err: except ValueError, err:
return HTTPNotFound()(env, start_response) return HTTPNotFound()(env, start_response)
if rest and rest.startswith(self.reseller_prefix): if rest and rest.startswith(self.reseller_prefix):
# Handle anonymous access to accounts I'm the definitive # Handle anonymous access to accounts I'm the definitive
@ -148,10 +148,11 @@ class DevAuth(object):
""" """
Returns None if the request is authorized to continue or a standard Returns None if the request is authorized to continue or a standard
WSGI response callable if not. WSGI response callable if not.
:raises: InvalidPathError (thrown by split_path) if given invalid path
""" """
try:
version, account, container, obj = split_path(req.path, 1, 4, True) version, account, container, obj = split_path(req.path, 1, 4, True)
except ValueError:
return HTTPNotFound(request=req)
if not account or not account.startswith(self.reseller_prefix): if not account or not account.startswith(self.reseller_prefix):
return self.denied_response(req) return self.denied_response(req)
user_groups = (req.remote_user or '').split(',') user_groups = (req.remote_user or '').split(',')

View File

@ -18,7 +18,7 @@ from webob.exc import HTTPNotFound
from swift.common.utils import split_path, cache_from_env, get_logger from swift.common.utils import split_path, cache_from_env, get_logger
from swift.proxy.server import get_container_memcache_key from swift.proxy.server import get_container_memcache_key
from swift.common.exceptions import InvalidPathError
class MaxSleepTimeHit(Exception): class MaxSleepTimeHit(Exception):
pass pass
@ -207,7 +207,7 @@ class RateLimitMiddleware(object):
self.memcache_client = cache_from_env(env) self.memcache_client = cache_from_env(env)
try: try:
version, account, container, obj = split_path(req.path, 1, 4, True) version, account, container, obj = split_path(req.path, 1, 4, True)
except InvalidPathError: except ValueError:
return HTTPNotFound()(env, start_response) return HTTPNotFound()(env, start_response)
ratelimit_resp = self.handle_ratelimit(req, account, container, obj) ratelimit_resp = self.handle_ratelimit(req, account, container, obj)
if ratelimit_resp is None: if ratelimit_resp is None:

View File

@ -40,8 +40,7 @@ import eventlet
from eventlet import greenio, GreenPool, sleep, Timeout, listen from eventlet import greenio, GreenPool, sleep, Timeout, listen
from eventlet.green import socket, subprocess, ssl, thread, threading from eventlet.green import socket, subprocess, ssl, thread, threading
from swift.common.exceptions import LockTimeout, MessageTimeout, \ from swift.common.exceptions import LockTimeout, MessageTimeout
InvalidPathError
# logging doesn't import patched as cleanly as one would like # logging doesn't import patched as cleanly as one would like
from logging.handlers import SysLogHandler from logging.handlers import SysLogHandler
@ -209,13 +208,12 @@ def split_path(path, minsegs=1, maxsegs=None, rest_with_last=False):
trailing data, raises ValueError. trailing data, raises ValueError.
:returns: list of segments with a length of maxsegs (non-existant :returns: list of segments with a length of maxsegs (non-existant
segments will return as None) segments will return as None)
:raises: InvalidPathError if given an invalid path :raises: ValueError if given an invalid path
""" """
if not maxsegs: if not maxsegs:
maxsegs = minsegs maxsegs = minsegs
if minsegs > maxsegs: if minsegs > maxsegs:
raise InvalidPathError('minsegs > maxsegs: %d > %d' % (minsegs, raise ValueError('minsegs > maxsegs: %d > %d' % (minsegs, maxsegs))
maxsegs))
if rest_with_last: if rest_with_last:
segs = path.split('/', maxsegs) segs = path.split('/', maxsegs)
minsegs += 1 minsegs += 1
@ -223,7 +221,7 @@ def split_path(path, minsegs=1, maxsegs=None, rest_with_last=False):
count = len(segs) count = len(segs)
if segs[0] or count < minsegs or count > maxsegs or \ if segs[0] or count < minsegs or count > maxsegs or \
'' in segs[1:minsegs]: '' in segs[1:minsegs]:
raise InvalidPathError('Invalid path: %s' % quote(path)) raise ValueError('Invalid path: %s' % quote(path))
else: else:
minsegs += 1 minsegs += 1
maxsegs += 1 maxsegs += 1
@ -231,7 +229,7 @@ def split_path(path, minsegs=1, maxsegs=None, rest_with_last=False):
count = len(segs) count = len(segs)
if segs[0] or count < minsegs or count > maxsegs + 1 or \ if segs[0] or count < minsegs or count > maxsegs + 1 or \
'' in segs[1:minsegs] or (count == maxsegs + 1 and segs[maxsegs]): '' in segs[1:minsegs] or (count == maxsegs + 1 and segs[maxsegs]):
raise InvalidPathError('Invalid path: %s' % quote(path)) raise ValueError('Invalid path: %s' % quote(path))
segs = segs[1:maxsegs] segs = segs[1:maxsegs]
segs.extend([None] * (maxsegs - 1 - len(segs))) segs.extend([None] * (maxsegs - 1 - len(segs)))
return segs return segs

View File

@ -35,7 +35,7 @@ from swift.common.utils import get_logger, get_param, hash_path, \
from swift.common.constraints import CONTAINER_LISTING_LIMIT, \ from swift.common.constraints import CONTAINER_LISTING_LIMIT, \
check_mount, check_float, check_utf8 check_mount, check_float, check_utf8
from swift.common.bufferedhttp import http_connect from swift.common.bufferedhttp import http_connect
from swift.common.exceptions import ConnectionTimeout, InvalidPathError from swift.common.exceptions import ConnectionTimeout
from swift.common.db_replicator import ReplicatorRpc from swift.common.db_replicator import ReplicatorRpc
DATADIR = 'containers' DATADIR = 'containers'
@ -130,7 +130,7 @@ class ContainerController(object):
try: try:
drive, part, account, container, obj = split_path( drive, part, account, container, obj = split_path(
unquote(req.path), 4, 5, True) unquote(req.path), 4, 5, True)
except InvalidPathError, err: except ValueError, err:
return HTTPBadRequest(body=str(err), content_type='text/plain', return HTTPBadRequest(body=str(err), content_type='text/plain',
request=req) request=req)
if 'x-timestamp' not in req.headers or \ if 'x-timestamp' not in req.headers or \
@ -166,7 +166,7 @@ class ContainerController(object):
try: try:
drive, part, account, container, obj = split_path( drive, part, account, container, obj = split_path(
unquote(req.path), 4, 5, True) unquote(req.path), 4, 5, True)
except InvalidPathError, err: except ValueError, err:
return HTTPBadRequest(body=str(err), content_type='text/plain', return HTTPBadRequest(body=str(err), content_type='text/plain',
request=req) request=req)
if 'x-timestamp' not in req.headers or \ if 'x-timestamp' not in req.headers or \
@ -212,7 +212,7 @@ class ContainerController(object):
try: try:
drive, part, account, container, obj = split_path( drive, part, account, container, obj = split_path(
unquote(req.path), 4, 5, True) unquote(req.path), 4, 5, True)
except InvalidPathError, err: except ValueError, err:
return HTTPBadRequest(body=str(err), content_type='text/plain', return HTTPBadRequest(body=str(err), content_type='text/plain',
request=req) request=req)
if self.mount_check and not check_mount(self.root, drive): if self.mount_check and not check_mount(self.root, drive):
@ -239,7 +239,7 @@ class ContainerController(object):
try: try:
drive, part, account, container, obj = split_path( drive, part, account, container, obj = split_path(
unquote(req.path), 4, 5, True) unquote(req.path), 4, 5, True)
except InvalidPathError, err: except ValueError, err:
return HTTPBadRequest(body=str(err), content_type='text/plain', return HTTPBadRequest(body=str(err), content_type='text/plain',
request=req) request=req)
if self.mount_check and not check_mount(self.root, drive): if self.mount_check and not check_mount(self.root, drive):
@ -343,7 +343,7 @@ class ContainerController(object):
""" """
try: try:
post_args = split_path(unquote(req.path), 3) post_args = split_path(unquote(req.path), 3)
except InvalidPathError, err: except ValueError, err:
return HTTPBadRequest(body=str(err), content_type='text/plain', return HTTPBadRequest(body=str(err), content_type='text/plain',
request=req) request=req)
drive, partition, hash = post_args drive, partition, hash = post_args
@ -361,7 +361,7 @@ class ContainerController(object):
"""Handle HTTP POST request.""" """Handle HTTP POST request."""
try: try:
drive, part, account, container = split_path(unquote(req.path), 4) drive, part, account, container = split_path(unquote(req.path), 4)
except InvalidPathError, err: except ValueError, err:
return HTTPBadRequest(body=str(err), content_type='text/plain', return HTTPBadRequest(body=str(err), content_type='text/plain',
request=req) request=req)
if 'x-timestamp' not in req.headers or \ if 'x-timestamp' not in req.headers or \

View File

@ -41,7 +41,7 @@ from swift.common.utils import mkdirs, normalize_timestamp, \
from swift.common.bufferedhttp import http_connect from swift.common.bufferedhttp import http_connect
from swift.common.constraints import check_object_creation, check_mount, \ from swift.common.constraints import check_object_creation, check_mount, \
check_float, check_utf8 check_float, check_utf8
from swift.common.exceptions import ConnectionTimeout, InvalidPathError from swift.common.exceptions import ConnectionTimeout
from swift.obj.replicator import get_hashes, invalidate_hash, \ from swift.obj.replicator import get_hashes, invalidate_hash, \
recalculate_hashes recalculate_hashes
@ -313,7 +313,7 @@ class ObjectController(object):
try: try:
device, partition, account, container, obj = \ device, partition, account, container, obj = \
split_path(unquote(request.path), 5, 5, True) split_path(unquote(request.path), 5, 5, True)
except InvalidPathError, err: except ValueError, err:
return HTTPBadRequest(body=str(err), request=request, return HTTPBadRequest(body=str(err), request=request,
content_type='text/plain') content_type='text/plain')
if 'x-timestamp' not in request.headers or \ if 'x-timestamp' not in request.headers or \
@ -342,7 +342,7 @@ class ObjectController(object):
try: try:
device, partition, account, container, obj = \ device, partition, account, container, obj = \
split_path(unquote(request.path), 5, 5, True) split_path(unquote(request.path), 5, 5, True)
except InvalidPathError, err: except ValueError, err:
return HTTPBadRequest(body=str(err), request=request, return HTTPBadRequest(body=str(err), request=request,
content_type='text/plain') content_type='text/plain')
if self.mount_check and not check_mount(self.devices, device): if self.mount_check and not check_mount(self.devices, device):
@ -414,7 +414,7 @@ class ObjectController(object):
try: try:
device, partition, account, container, obj = \ device, partition, account, container, obj = \
split_path(unquote(request.path), 5, 5, True) split_path(unquote(request.path), 5, 5, True)
except InvalidPathError, err: except ValueError, err:
return HTTPBadRequest(body=str(err), request=request, return HTTPBadRequest(body=str(err), request=request,
content_type='text/plain') content_type='text/plain')
if self.mount_check and not check_mount(self.devices, device): if self.mount_check and not check_mount(self.devices, device):
@ -474,7 +474,7 @@ class ObjectController(object):
try: try:
device, partition, account, container, obj = \ device, partition, account, container, obj = \
split_path(unquote(request.path), 5, 5, True) split_path(unquote(request.path), 5, 5, True)
except InvalidPathError, err: except ValueError, err:
resp = HTTPBadRequest(request=request) resp = HTTPBadRequest(request=request)
resp.content_type = 'text/plain' resp.content_type = 'text/plain'
resp.body = str(err) resp.body = str(err)
@ -502,7 +502,7 @@ class ObjectController(object):
try: try:
device, partition, account, container, obj = \ device, partition, account, container, obj = \
split_path(unquote(request.path), 5, 5, True) split_path(unquote(request.path), 5, 5, True)
except InvalidPathError, e: except ValueError, e:
return HTTPBadRequest(body=str(e), request=request, return HTTPBadRequest(body=str(e), request=request,
content_type='text/plain') content_type='text/plain')
if 'x-timestamp' not in request.headers or \ if 'x-timestamp' not in request.headers or \
@ -537,7 +537,7 @@ class ObjectController(object):
try: try:
device, partition, suffix = split_path( device, partition, suffix = split_path(
unquote(request.path), 2, 3, True) unquote(request.path), 2, 3, True)
except InvalidPathError, e: except ValueError, e:
return HTTPBadRequest(body=str(e), request=request, return HTTPBadRequest(body=str(e), request=request,
content_type='text/plain') content_type='text/plain')
if self.mount_check and not check_mount(self.devices, device): if self.mount_check and not check_mount(self.devices, device):

View File

@ -39,7 +39,7 @@ from swift.common.constraints import check_metadata, check_object_creation, \
check_utf8, MAX_ACCOUNT_NAME_LENGTH, MAX_CONTAINER_NAME_LENGTH, \ check_utf8, MAX_ACCOUNT_NAME_LENGTH, MAX_CONTAINER_NAME_LENGTH, \
MAX_FILE_SIZE MAX_FILE_SIZE
from swift.common.exceptions import ChunkReadTimeout, \ from swift.common.exceptions import ChunkReadTimeout, \
ChunkWriteTimeout, ConnectionTimeout, InvalidPathError ChunkWriteTimeout, ConnectionTimeout
def update_headers(response, headers): def update_headers(response, headers):
@ -1260,7 +1260,7 @@ class BaseApplication(object):
:param path: path from request :param path: path from request
:returns: tuple of (controller class, path dictionary) :returns: tuple of (controller class, path dictionary)
:raises: InvalidPathError (thrown by split_path) if given invalid path :raises: ValueError (thrown by split_path) id given invalid path
""" """
version, account, container, obj = split_path(path, 1, 4, True) version, account, container, obj = split_path(path, 1, 4, True)
d = dict(version=version, d = dict(version=version,
@ -1299,8 +1299,6 @@ class BaseApplication(object):
response = self.handle_request(req)(env, start_response) response = self.handle_request(req)(env, start_response)
self.posthooklogger(env, req) self.posthooklogger(env, req)
return response return response
except InvalidPathError:
HTTPNotFound()(env, start_response)
except: except:
print "EXCEPTION IN __call__: %s: %s" % \ print "EXCEPTION IN __call__: %s: %s" % \
(traceback.format_exc(), env) (traceback.format_exc(), env)
@ -1330,7 +1328,7 @@ class BaseApplication(object):
try: try:
try: try:
controller, path_parts = self.get_controller(req.path) controller, path_parts = self.get_controller(req.path)
except InvalidPathError: except ValueError:
return HTTPNotFound(request=req) return HTTPNotFound(request=req)
if not check_utf8(req.path_info): if not check_utf8(req.path_info):
return HTTPPreconditionFailed(request=req, body='Invalid UTF8') return HTTPPreconditionFailed(request=req, body='Invalid UTF8')

View File

@ -18,7 +18,6 @@ from urllib import unquote
import copy import copy
from swift.common.utils import split_path, get_logger from swift.common.utils import split_path, get_logger
from swift.common.exceptions import InvalidPathError
month_map = '_ Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split() month_map = '_ Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split()
@ -70,7 +69,7 @@ class AccessLogProcessor(object):
try: try:
(version, account, container_name, object_name) = \ (version, account, container_name, object_name) = \
split_path(request, 2, 4, True) split_path(request, 2, 4, True)
except InvalidPathError, e: except ValueError, e:
self.logger.debug( self.logger.debug(
'Invalid path: %s from data: %s' % (e, repr(raw_log))) 'Invalid path: %s from data: %s' % (e, repr(raw_log)))
return {} return {}

View File

@ -27,7 +27,6 @@ from webob import Request
from swift.auth import server as auth_server from swift.auth import server as auth_server
from swift.common.db import DatabaseConnectionError, get_db_connection from swift.common.db import DatabaseConnectionError, get_db_connection
from swift.common.utils import get_logger from swift.common.utils import get_logger
from swift.common.exceptions import InvalidPathError
class TestException(Exception): class TestException(Exception):
@ -242,8 +241,9 @@ class TestAuthServer(unittest.TestCase):
len(set(repr(a) for a in cfaccounts) - set(failed)), 2) len(set(repr(a) for a in cfaccounts) - set(failed)), 2)
def test_auth_bad_path(self): def test_auth_bad_path(self):
self.assertRaises(InvalidPathError, self.controller.handle_auth, res = self.controller.handle_auth(
Request.blank('', environ={'REQUEST_METHOD': 'GET'})) Request.blank('', environ={'REQUEST_METHOD': 'GET'}))
self.assertEquals(res.status_int, 400)
res = self.controller.handle_auth(Request.blank('/bad', res = self.controller.handle_auth(Request.blank('/bad',
environ={'REQUEST_METHOD': 'GET'})) environ={'REQUEST_METHOD': 'GET'}))
self.assertEquals(res.status_int, 400) self.assertEquals(res.status_int, 400)

View File

@ -29,7 +29,7 @@ from StringIO import StringIO
from eventlet import sleep from eventlet import sleep
from swift.common import utils from swift.common import utils
from swift.common.exceptions import InvalidPathError
class TestUtils(unittest.TestCase): class TestUtils(unittest.TestCase):
""" Tests for swift.common.utils """ """ Tests for swift.common.utils """
@ -87,36 +87,36 @@ class TestUtils(unittest.TestCase):
def test_split_path(self): def test_split_path(self):
""" Test swift.common.utils.split_account_path """ """ Test swift.common.utils.split_account_path """
self.assertRaises(InvalidPathError, utils.split_path, '') self.assertRaises(ValueError, utils.split_path, '')
self.assertRaises(InvalidPathError, utils.split_path, '/') self.assertRaises(ValueError, utils.split_path, '/')
self.assertRaises(InvalidPathError, utils.split_path, '//') self.assertRaises(ValueError, utils.split_path, '//')
self.assertEquals(utils.split_path('/a'), ['a']) self.assertEquals(utils.split_path('/a'), ['a'])
self.assertRaises(InvalidPathError, utils.split_path, '//a') self.assertRaises(ValueError, utils.split_path, '//a')
self.assertEquals(utils.split_path('/a/'), ['a']) self.assertEquals(utils.split_path('/a/'), ['a'])
self.assertRaises(InvalidPathError, utils.split_path, '/a/c') self.assertRaises(ValueError, utils.split_path, '/a/c')
self.assertRaises(InvalidPathError, utils.split_path, '//c') self.assertRaises(ValueError, utils.split_path, '//c')
self.assertRaises(InvalidPathError, utils.split_path, '/a/c/') self.assertRaises(ValueError, utils.split_path, '/a/c/')
self.assertRaises(InvalidPathError, utils.split_path, '/a//') self.assertRaises(ValueError, utils.split_path, '/a//')
self.assertRaises(InvalidPathError, utils.split_path, '/a', 2) self.assertRaises(ValueError, utils.split_path, '/a', 2)
self.assertRaises(InvalidPathError, utils.split_path, '/a', 2, 3) self.assertRaises(ValueError, utils.split_path, '/a', 2, 3)
self.assertRaises(InvalidPathError, utils.split_path, '/a', 2, 3, True) self.assertRaises(ValueError, utils.split_path, '/a', 2, 3, True)
self.assertEquals(utils.split_path('/a/c', 2), ['a', 'c']) self.assertEquals(utils.split_path('/a/c', 2), ['a', 'c'])
self.assertEquals(utils.split_path('/a/c/o', 3), ['a', 'c', 'o']) self.assertEquals(utils.split_path('/a/c/o', 3), ['a', 'c', 'o'])
self.assertRaises(InvalidPathError, utils.split_path, '/a/c/o/r', 3, 3) self.assertRaises(ValueError, utils.split_path, '/a/c/o/r', 3, 3)
self.assertEquals(utils.split_path('/a/c/o/r', 3, 3, True), self.assertEquals(utils.split_path('/a/c/o/r', 3, 3, True),
['a', 'c', 'o/r']) ['a', 'c', 'o/r'])
self.assertEquals(utils.split_path('/a/c', 2, 3, True), self.assertEquals(utils.split_path('/a/c', 2, 3, True),
['a', 'c', None]) ['a', 'c', None])
self.assertRaises(InvalidPathError, utils.split_path, '/a', 5, 4) self.assertRaises(ValueError, utils.split_path, '/a', 5, 4)
self.assertEquals(utils.split_path('/a/c/', 2), ['a', 'c']) self.assertEquals(utils.split_path('/a/c/', 2), ['a', 'c'])
self.assertEquals(utils.split_path('/a/c/', 2, 3), ['a', 'c', '']) self.assertEquals(utils.split_path('/a/c/', 2, 3), ['a', 'c', ''])
try: try:
utils.split_path('o\nn e', 2) utils.split_path('o\nn e', 2)
except InvalidPathError, err: except ValueError, err:
self.assertEquals(str(err), 'Invalid path: o%0An%20e') self.assertEquals(str(err), 'Invalid path: o%0An%20e')
try: try:
utils.split_path('o\nn e', 2, 3, True) utils.split_path('o\nn e', 2, 3, True)
except InvalidPathError, err: except ValueError, err:
self.assertEquals(str(err), 'Invalid path: o%0An%20e') self.assertEquals(str(err), 'Invalid path: o%0An%20e')
def test_NullLogger(self): def test_NullLogger(self):