From 69e940c661731c8ac3cc0cf4e874929c86dcdeb2 Mon Sep 17 00:00:00 2001 From: MotoKen Date: Wed, 20 Mar 2013 13:46:42 +0800 Subject: Accepts aws-sdk-java timestamp format The aws-sdk-java timestamp format is "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" which contains millisecond representation. However, the current implementation does not accept this kind of format. References: https://github.com/aws/aws-sdk-java/blob/master/src/main/java/com/amazonaws/auth/QueryStringSigner.java#L173 Adds ability to parse this format in ec2utils.is_ec2_timestamp_expired. Fixes bug 1156445. Change-Id: I389ff8b9c6c91b699538b889add264d66dbb8131 --- nova/tests/api/ec2/test_ec2_validate.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'nova/tests') diff --git a/nova/tests/api/ec2/test_ec2_validate.py b/nova/tests/api/ec2/test_ec2_validate.py index 24d226335..9b67d67a1 100644 --- a/nova/tests/api/ec2/test_ec2_validate.py +++ b/nova/tests/api/ec2/test_ec2_validate.py @@ -194,6 +194,25 @@ class EC2TimestampValidationTestCase(test.TestCase): expired = ec2utils.is_ec2_timestamp_expired(params) self.assertFalse(expired) + def test_validate_ec2_timestamp_ms_time_regex(self): + result = ec2utils._ms_time_regex.match('2011-04-22T11:29:49.123Z') + self.assertIsNotNone(result) + result = ec2utils._ms_time_regex.match('2011-04-22T11:29:49.123456Z') + self.assertIsNotNone(result) + result = ec2utils._ms_time_regex.match('2011-04-22T11:29:49.1234567Z') + self.assertIsNone(result) + result = ec2utils._ms_time_regex.match('2011-04-22T11:29:49.123') + self.assertIsNone(result) + result = ec2utils._ms_time_regex.match('2011-04-22T11:29:49Z') + self.assertIsNone(result) + + def test_validate_ec2_timestamp_aws_sdk_format(self): + params = {'Timestamp': '2011-04-22T11:29:49.123Z'} + expired = ec2utils.is_ec2_timestamp_expired(params) + self.assertFalse(expired) + expired = ec2utils.is_ec2_timestamp_expired(params, expires=300) + self.assertTrue(expired) + def test_validate_ec2_timestamp_invalid_format(self): params = {'Timestamp': '2011-04-22T11:29:49.000P'} expired = ec2utils.is_ec2_timestamp_expired(params) -- cgit