diff --git a/test/unit/common/middleware/s3api/__init__.py b/test/unit/common/middleware/s3api/__init__.py index 4ec20255c2..bc2f64301f 100644 --- a/test/unit/common/middleware/s3api/__init__.py +++ b/test/unit/common/middleware/s3api/__init__.py @@ -199,9 +199,10 @@ class S3ApiTestCase(unittest.TestCase): # email.utils.formatdate returns utc timestamp in default return email.utils.formatdate(time.time() + skew) - def get_v4_amz_date_header(self, when=None): - if when is None: - when = datetime.utcnow() + def get_v4_amz_date_header(self, offset=None): + when = datetime.utcnow() + if offset is not None: + when += offset return when.strftime('%Y%m%dT%H%M%SZ') def call_app(self, req, app=None, expect_exception=False): diff --git a/test/unit/common/middleware/s3api/test_s3request.py b/test/unit/common/middleware/s3api/test_s3request.py index 7391b35f82..ac2e1cc738 100644 --- a/test/unit/common/middleware/s3api/test_s3request.py +++ b/test/unit/common/middleware/s3api/test_s3request.py @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from datetime import datetime, timedelta +from datetime import timedelta import hashlib from mock import patch, MagicMock import unittest @@ -470,12 +470,12 @@ class TestRequest(S3ApiTestCase): # near-past X-Amz-Date headers date_header = {'X-Amz-Date': self.get_v4_amz_date_header( - datetime.utcnow() - timedelta(minutes=10) + timedelta(minutes=-10) )} self._test_request_timestamp_sigv4(date_header) date_header = {'X-Amz-Date': self.get_v4_amz_date_header( - datetime.utcnow() - timedelta(minutes=10) + timedelta(minutes=-10) )} with self.assertRaises(RequestTimeTooSkewed) as cm, \ patch.object(self.s3api.conf, 'allowable_clock_skew', 300): @@ -483,19 +483,19 @@ class TestRequest(S3ApiTestCase): # near-future X-Amz-Date headers date_header = {'X-Amz-Date': self.get_v4_amz_date_header( - datetime.utcnow() + timedelta(minutes=10) + timedelta(minutes=10) )} self._test_request_timestamp_sigv4(date_header) date_header = {'X-Amz-Date': self.get_v4_amz_date_header( - datetime.utcnow() + timedelta(minutes=10) + timedelta(minutes=10) )} with self.assertRaises(RequestTimeTooSkewed) as cm, \ patch.object(self.s3api.conf, 'allowable_clock_skew', 300): self._test_request_timestamp_sigv4(date_header) date_header = {'X-Amz-Date': self.get_v4_amz_date_header( - datetime.utcnow() + timedelta(days=1) + timedelta(days=1) )} with self.assertRaises(RequestTimeTooSkewed) as cm: self._test_request_timestamp_sigv4(date_header)