def do_test(headers, status, err_msg): req = Request.blank('/v1/a/c/o', method='PUT', headers=headers) with self.assertRaises(swob.HTTPException) as cm: symlink._check_symlink_header(req) self.assertEqual(cm.exception.status, status) self.assertEqual(cm.exception.body, err_msg)
def do_test(headers, status, err_msg): req = Request.blank('/v1/a/c/o', method='PUT', headers=headers) with self.assertRaises(swob.HTTPException) as cm: symlink._check_symlink_header(req) self.assertEqual(cm.exception.status, status) self.assertEqual(cm.exception.body, err_msg)
def test_check_symlink_header_points_to_itself(self): req = Request.blank('/v1/a/c/o', method='PUT', headers={'X-Symlink-Target': 'c/o'}) with self.assertRaises(swob.HTTPException) as cm: symlink._check_symlink_header(req) self.assertEqual(cm.exception.status, '400 Bad Request') self.assertEqual(cm.exception.body, 'Symlink cannot target itself') # Even if set account to itself, it will fail as well req = Request.blank('/v1/a/c/o', method='PUT', headers={ 'X-Symlink-Target': 'c/o', 'X-Symlink-Target-Account': 'a' }) with self.assertRaises(swob.HTTPException) as cm: symlink._check_symlink_header(req) self.assertEqual(cm.exception.status, '400 Bad Request') self.assertEqual(cm.exception.body, 'Symlink cannot target itself') # sanity, the case to another account is safe req = Request.blank('/v1/a/c/o', method='PUT', headers={ 'X-Symlink-Target': 'c/o', 'X-Symlink-Target-Account': 'a1' }) symlink._check_symlink_header(req)
def test_check_symlink_header_points_to_itself(self): req = Request.blank('/v1/a/c/o', method='PUT', headers={'X-Symlink-Target': 'c/o'}) with self.assertRaises(swob.HTTPException) as cm: symlink._check_symlink_header(req) self.assertEqual(cm.exception.status, '400 Bad Request') self.assertEqual(cm.exception.body, 'Symlink cannot target itself') # Even if set account to itself, it will fail as well req = Request.blank('/v1/a/c/o', method='PUT', headers={'X-Symlink-Target': 'c/o', 'X-Symlink-Target-Account': 'a'}) with self.assertRaises(swob.HTTPException) as cm: symlink._check_symlink_header(req) self.assertEqual(cm.exception.status, '400 Bad Request') self.assertEqual(cm.exception.body, 'Symlink cannot target itself') # sanity, the case to another account is safe req = Request.blank('/v1/a/c/o', method='PUT', headers={'X-Symlink-Target': 'c/o', 'X-Symlink-Target-Account': 'a1'}) symlink._check_symlink_header(req)
def do_test(headers): req = Request.blank('/v1/a/c/o', method='PUT', headers=headers) symlink._check_symlink_header(req)
def do_test(headers): req = Request.blank('/v1/a/c/o', method='PUT', headers=headers) symlink._check_symlink_header(req)