diff --git a/swift/common/constraints.py b/swift/common/constraints.py index a1dc3c9848..f661a6989d 100644 --- a/swift/common/constraints.py +++ b/swift/common/constraints.py @@ -302,9 +302,9 @@ def valid_timestamp(request): def check_delete_headers(request): """ - Validate if 'x-delete' headers are have correct values - values should be positive integers and correspond to - a time in the future. + Check that 'x-delete-after' and 'x-delete-at' headers have valid values. + Values should be positive integers and correspond to a time greater than or + equal to the request timestamp. :param request: the swob request object @@ -319,13 +319,13 @@ def check_delete_headers(request): raise HTTPBadRequest(request=request, content_type='text/plain', body='Non-integer X-Delete-After') - actual_del_time = now + x_delete_after - if actual_del_time < now: + actual_del_time = utils.normalize_delete_at_timestamp( + now + x_delete_after) + if int(actual_del_time) < now: raise HTTPBadRequest(request=request, content_type='text/plain', body='X-Delete-After in past') - request.headers['x-delete-at'] = utils.normalize_delete_at_timestamp( - actual_del_time) + request.headers['x-delete-at'] = actual_del_time del request.headers['x-delete-after'] if 'x-delete-at' in request.headers: diff --git a/test/unit/common/test_constraints.py b/test/unit/common/test_constraints.py index 05ad8240f5..b55ec6bdc9 100644 --- a/test/unit/common/test_constraints.py +++ b/test/unit/common/test_constraints.py @@ -283,6 +283,14 @@ class TestConstraints(unittest.TestCase): self.assertEqual(cm.exception.status_int, HTTP_BAD_REQUEST) self.assertIn('X-Delete-After in past', cm.exception.body) + headers = {'X-Delete-After': '0', + 'X-Timestamp': str(time.time())} + with self.assertRaises(HTTPException) as cm: + constraints.check_delete_headers( + Request.blank('/', headers=headers)) + self.assertEqual(cm.exception.status_int, HTTP_BAD_REQUEST) + self.assertIn('X-Delete-After in past', cm.exception.body) + # X-Delete-At delete_at = str(int(ts + 100)) headers = {'X-Delete-At': delete_at,