def test_registered_defaults(self): name_check.filter_factory({})(FakeApp()) swift_info = utils.get_swift_info() self.assertTrue('name_check' in swift_info) self.assertTrue( isinstance(swift_info['name_check'].get('maximum_length'), numbers.Integral)) self.assertTrue( isinstance(swift_info['name_check'].get('forbidden_chars'), str)) self.assertTrue( isinstance(swift_info['name_check'].get('forbidden_regexp'), str))
def test_registered_configured_options(self): conf = {'maximum_length': 512, 'forbidden_chars': '\'\"`', 'forbidden_regexp': "/\./|/\.\./|/\.$"} name_check.filter_factory(conf)(FakeApp()) swift_info = utils.get_swift_info() self.assertTrue('name_check' in swift_info) self.assertEqual(swift_info['name_check'].get('maximum_length'), 512) self.assertEqual(set(swift_info['name_check'].get('forbidden_chars')), set('\'\"`')) self.assertEqual(swift_info['name_check'].get('forbidden_regexp'), "/\./|/\.\./|/\.$")
def test_registered_defaults(self): name_check.filter_factory({})(FakeApp()) swift_info = utils.get_swift_info() self.assertTrue('name_check' in swift_info) self.assertTrue(isinstance( swift_info['name_check'].get('maximum_length'), numbers.Integral)) self.assertTrue(isinstance( swift_info['name_check'].get('forbidden_chars'), str)) self.assertTrue(isinstance( swift_info['name_check'].get('forbidden_regexp'), str))
def setUp(self): self.conf = { 'maximum_length': MAX_LENGTH, 'forbidden_chars': FORBIDDEN_CHARS, 'forbidden_regexp': FORBIDDEN_REGEXP } self.test_check = name_check.filter_factory(self.conf)(FakeApp())
def test_maximum_length_from_config(self): # test invalid length app = name_check.filter_factory({'maximum_length': "500"})(FakeApp()) path = '/V1.0/a/c/' + 'o' * (500 - 9) resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'} ).get_response(app) self.assertEqual( resp.body, ("Object/Container/Account name longer than the allowed " "maximum 500")) self.assertEqual(resp.status_int, 400) # test valid length path = '/V1.0/a/c/' + 'o' * (500 - 10) resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'} ).get_response(app) self.assertEqual(resp.status_int, 200) self.assertEqual(resp.body, 'OK')
def setUp(self): self.conf = {'maximum_length': MAX_LENGTH, 'forbidden_chars': FORBIDDEN_CHARS, 'forbidden_regexp': FORBIDDEN_REGEXP} self.test_check = name_check.filter_factory(self.conf)(FakeApp())