Пример #1
0
def split_and_validate_path(request, minsegs=1, maxsegs=None, rest_with_last=False):
    """
    Utility function to split and validate the request path.

    :returns: result of split_path if everything's okay
    :raises: HTTPBadRequest if something's not okay
    """
    try:
        segs = split_path(unquote(request.path), minsegs, maxsegs, rest_with_last)
        validate_device_partition(segs[0], segs[1])
        return segs
    except ValueError as err:
        raise HTTPBadRequest(body=str(err), request=request, content_type="text/plain")
Пример #2
0
def split_and_validate_path(request,
                            minsegs=1,
                            maxsegs=None,
                            rest_with_last=False):
    """
    Utility function to split and validate the request path.

    :returns: result of split_path if everything's okay
    :raises: HTTPBadRequest if something's not okay
    """
    try:
        segs = split_path(unquote(request.path), minsegs, maxsegs,
                          rest_with_last)
        validate_device_partition(segs[0], segs[1])
        return segs
    except ValueError as err:
        raise HTTPBadRequest(body=str(err),
                             request=request,
                             content_type='text/plain')
Пример #3
0
 def test_validate_device_partition(self):
     # Test swift.common.ondisk.validate_device_partition
     ondisk.validate_device_partition('foo', 'bar')
     self.assertRaises(ValueError,
                       ondisk.validate_device_partition, '', '')
     self.assertRaises(ValueError,
                       ondisk.validate_device_partition, '', 'foo')
     self.assertRaises(ValueError,
                       ondisk.validate_device_partition, 'foo', '')
     self.assertRaises(ValueError,
                       ondisk.validate_device_partition, 'foo/bar', 'foo')
     self.assertRaises(ValueError,
                       ondisk.validate_device_partition, 'foo', 'foo/bar')
     self.assertRaises(ValueError,
                       ondisk.validate_device_partition, '.', 'foo')
     self.assertRaises(ValueError,
                       ondisk.validate_device_partition, '..', 'foo')
     self.assertRaises(ValueError,
                       ondisk.validate_device_partition, 'foo', '.')
     self.assertRaises(ValueError,
                       ondisk.validate_device_partition, 'foo', '..')
     try:
         ondisk.validate_device_partition('o\nn e', 'foo')
     except ValueError as err:
         self.assertEquals(str(err), 'Invalid device: o%0An%20e')
     try:
         ondisk.validate_device_partition('foo', 'o\nn e')
     except ValueError as err:
         self.assertEquals(str(err), 'Invalid partition: o%0An%20e')