Add UT for checking special chars in object name

Add special chars could help checking quote/unquote, encode/decode
problems. Those two is one of most common mistakes.

Change-Id: Ife1c0b481f08c1666d62b4fb51b7fdcdfdbf2ba6
This commit is contained in:
Kun Huang 2013-06-09 01:14:23 +08:00
parent 03c0c5d658
commit eec98c15cd
1 changed files with 48 additions and 0 deletions

View File

@ -1,3 +1,4 @@
#-*- coding:utf-8 -*-
# Copyright (c) 2010-2012 OpenStack, LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@ -394,6 +395,53 @@ class TestObjectController(unittest.TestCase):
""" Tear down for testing swift.object_server.ObjectController """
rmtree(os.path.dirname(self.testdir))
def test_REQUEST_SPECIAL_CHARS(self):
obj = 'special昆%20/%'
path = '/sda1/p/a/c/%s' % obj
body = 'SPECIAL_STRING'
# create one
timestamp = normalize_timestamp(time())
req = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'},
headers={'X-Timestamp': timestamp,
'Content-Type': 'application/x-test',})
req.body = body
resp = self.object_controller.PUT(req)
self.assertEquals(resp.status_int, 201)
# check it
timestamp = normalize_timestamp(time())
req = Request.blank(path, environ={'REQUEST_METHOD': 'GET'},
headers={'X-Timestamp': timestamp,
'Content-Type': 'application/x-test',})
resp = self.object_controller.GET(req)
self.assertEquals(resp.status_int, 200)
self.assertEquals(resp.body, body)
# update it
timestamp = normalize_timestamp(time())
req = Request.blank(path, environ={'REQUEST_METHOD': 'POST'},
headers={'X-Timestamp': timestamp,
'Content-Type': 'application/x-test',})
resp = self.object_controller.POST(req)
self.assertEquals(resp.status_int, 202)
# head it
timestamp = normalize_timestamp(time())
req = Request.blank(path, environ={'REQUEST_METHOD': 'HEAD'},
headers={'X-Timestamp': timestamp,
'Content-Type': 'application/x-test',})
resp = self.object_controller.HEAD(req)
self.assertEquals(resp.status_int, 200)
#delete it
timestamp = normalize_timestamp(time())
req = Request.blank(path, environ={'REQUEST_METHOD': 'DELETE'},
headers={'X-Timestamp': timestamp,
'Content-Type': 'application/x-test',})
resp = self.object_controller.DELETE(req)
self.assertEquals(resp.status_int, 204)
def test_POST_update_meta(self):
""" Test swift.object_server.ObjectController.POST """
original_headers = self.object_controller.allowed_headers