From c354db215861713b817418064182e2e3c8e94922 Mon Sep 17 00:00:00 2001 From: gholt Date: Mon, 15 Apr 2013 22:12:23 +0000 Subject: [PATCH] Expirer now quotes names when deleting Change-Id: I5c615c6f32967510f09b783b1ba7089119f1d8bd --- swift/obj/expirer.py | 4 +++- test/unit/obj/test_expirer.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/swift/obj/expirer.py b/swift/obj/expirer.py index 85bc29b5d7..023b3a27b6 100644 --- a/swift/obj/expirer.py +++ b/swift/obj/expirer.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import urllib from random import random from time import time from os.path import join @@ -162,6 +163,7 @@ class ObjectExpirer(Daemon): :param timestamp: The timestamp the X-Delete-At value must match to perform the actual delete. """ - self.swift.make_request('DELETE', '/v1/%s' % actual_obj.lstrip('/'), + path = '/v1/' + urllib.quote(actual_obj.lstrip('/')) + self.swift.make_request('DELETE', path, {'X-If-Delete-At': str(timestamp)}, (2, HTTP_NOT_FOUND, HTTP_PRECONDITION_FAILED)) diff --git a/test/unit/obj/test_expirer.py b/test/unit/obj/test_expirer.py index 55d5708606..92154b32db 100644 --- a/test/unit/obj/test_expirer.py +++ b/test/unit/obj/test_expirer.py @@ -13,10 +13,13 @@ # See the License for the specific language governing permissions and # limitations under the License. +import urllib from time import time from unittest import main, TestCase from test.unit import FakeLogger +import mock + from swift.common import internal_client from swift.obj import expirer @@ -512,5 +515,16 @@ class TestObjectExpirer(TestCase): pass self.assertEquals(503, exc.resp.status_int) + def test_delete_actual_object_quotes(self): + name = 'this name should get quoted' + timestamp = '1366063156.863045' + x = expirer.ObjectExpirer({}) + x.swift.make_request = mock.MagicMock() + x.delete_actual_object(name, timestamp) + x.swift.make_request.assert_called_once() + self.assertEquals(x.swift.make_request.call_args[0][1], + '/v1/' + urllib.quote(name)) + + if __name__ == '__main__': main()