def test__1(self): ''' Make sure that append() fails when it can't decode the prefix or the path ''' # Note: '/cio\xc3a8' is wrong on purpose here self.assertEqual( utils_path.append(six.b('/cio\xc3a8'), '/foobar', False), None) self.assertEqual( utils_path.append('/foobar', six.b('/cio\xc3\xa8'), False), None)
def test__3(self): ''' Verify that append() does not allow to go above the rootdir ''' self.assertEqual(utils_path.append('/foobar', '../etc/passwd', False), None) self.assertEqual( utils_path.append('/foobar', six.b('\x2e\x2e\x2fetc\x2fpasswd'), False), None) self.assertEqual( utils_path.append('/foobar', six.b('..%2fetc%2fpasswd'), True), None)
def test__1(self): ''' Make sure that append() fails when it can't decode the prefix or the path ''' # Note: '/cio\xc3a8' is wrong on purpose here self.assertEqual( utils_path.append(six.b('/cio\xc3a8'), '/foobar', False), None ) self.assertEqual( utils_path.append('/foobar', six.b('/cio\xc3\xa8'), False), None )
def test_decode_failure(self): ''' Make sure that possibly_decode() does not decode an invalid UTF-8 string ''' self.assertEqual( utils_path.possibly_decode(six.b("\xc2b7"), 'utf-8'), None )
def test__3(self): ''' Verify that append() does not allow to go above the rootdir ''' self.assertEqual( utils_path.append('/foobar', '../etc/passwd', False), None ) self.assertEqual( utils_path.append('/foobar', six.b('\x2e\x2e\x2fetc\x2fpasswd'), False), None ) self.assertEqual( utils_path.append('/foobar', six.b('..%2fetc%2fpasswd'), True), None )
def test__2(self): ''' Make sure that depth_visit() accepts a non-ascii prefix ''' visit = { "count": 0, "expect_path": [ six.b("/foo\xc3\xa8").decode("utf-8") + "/bar", six.b("/foo\xc3\xa8").decode("utf-8") + "/bar" + "/baz", ], "expect_leaf": [False, True], } def on_visit_called(path, leaf): ''' Just an helper function ''' self.assertEqual(path, visit["expect_path"][visit["count"]]) self.assertEqual(leaf, visit["expect_leaf"][visit["count"]]) visit["count"] += 1 utils_path.depth_visit(six.b('/foo\xc3\xa8'), ['bar', 'baz'], on_visit_called)
def test__2(self): ''' Make sure that depth_visit() accepts a non-ascii prefix ''' visit = { "count": 0, "expect_path": [ six.b("/foo\xc3\xa8").decode("utf-8") + "/bar", six.b("/foo\xc3\xa8").decode("utf-8") + "/bar" + "/baz", ], "expect_leaf": [ False, True ], } def on_visit_called(path, leaf): ''' Just an helper function ''' self.assertEqual(path, visit["expect_path"][visit["count"]]) self.assertEqual(leaf, visit["expect_leaf"][visit["count"]]) visit["count"] += 1 utils_path.depth_visit(six.b('/foo\xc3\xa8'), ['bar', 'baz'], on_visit_called)
def test__3(self): ''' Make sure that depth_visit() does not accept non-ascii component ''' self.assertRaises(RuntimeError, utils_path.depth_visit, '/foo', ['bar', six.b('baz\xc3\xa8')], lambda *args: None)
def test_ascii_bytes(self): ''' Test possibly_decode() with ascii bytes input ''' self.assertEqual( utils_path.possibly_decode(six.b('abc'), 'utf-8'), six.u('abc') )
def test_nonascii_bytes(self): ''' Test possibly_decode() with unicode bytes input ''' self.assertEqual( utils_path.possibly_decode(six.b('cio\xc3\xa8'), 'utf-8'), six.u("cio\xe8") )
def test_decode_failure(self): ''' Make sure that possibly_decode() does not decode an invalid UTF-8 string ''' self.assertEqual(utils_path.possibly_decode(six.b("\xc2b7"), 'utf-8'), None)
def test_ascii_bytes(self): ''' Test possibly_decode() with ascii bytes input ''' self.assertEqual(utils_path.possibly_decode(six.b('abc'), 'utf-8'), six.u('abc'))
def test_nonascii_bytes(self): ''' Test possibly_decode() with unicode bytes input ''' self.assertEqual( utils_path.possibly_decode(six.b('cio\xc3\xa8'), 'utf-8'), six.u("cio\xe8"))