def test_get_request_date__invalid_date(self):
     check = None
     req = requests.Request('GET', 'http://blah.com')
     req = req.prepare()
     req.headers['date'] = ''
     result = AWS4Auth.get_request_date(req)
     self.assertEqual(result, check)
 def test_get_request_date__xamzdate_only(self):
     date_str = '19000404T010101Z'
     check = datetime.date(1900, 4, 4)
     req = requests.Request('GET', 'http://blah.com')
     req = req.prepare()
     req.headers['x-amz-date'] = date_str
     result = AWS4Auth.get_request_date(req)
     self.assertEqual(result, check, date_str)
 def test_get_request_date__date_and_invalid_xamzdate(self):
     xamzdate_str = '19000404X010101Z'
     date_str = 'Sun, 05 Jan 1980 01:01:01 GMT'
     check = datetime.date(1980, 1, 5)
     req = requests.Request('GET', 'http://blah.com')
     req = req.prepare()
     req.headers['x-amz-date'] = xamzdate_str
     req.headers['date'] = date_str
     result = AWS4Auth.get_request_date(req)
     self.assertEqual(result, check)
 def test_aws4auth_add_header(self):
     req = requests.Request('GET', 'http://blah.com')
     req = req.prepare()
     if 'date' in req.headers: del req.headers['date']
     secret_key = 'dummy'
     region = 'us-east-1'
     service = 'iam'
     key = AWS4SigningKey(secret_key, region, service)
     auth = AWS4Auth('dummy', key)
     sreq = auth(req)
     self.assertIn('x-amz-date', sreq.headers)
     self.assertIsNotNone(AWS4Auth.get_request_date(sreq))
 def test_get_request_date__date_only(self):
     tests = {
         'Sun, 05 Jan 1980 01:01:01 GMT': (1980, 1, 5),
         '19000404T010101Z': (1900, 4, 4),
         'Monday, 06-Feb-85 01:01:01 EST': (2085, 2, 6),
         'Sun Jan 5 01:01:01 1980': (1980, 1, 5),
         '1985-02-06T01:01:01+01:00': (1985, 2, 6),
     }
     tests = dict([(k, datetime.date(*v)) for k, v in tests.items()])
     for date_str, check in tests.items():
         req = requests.Request('GET', 'http://blah.com')
         req = req.prepare()
         req.headers['date'] = date_str
         result = AWS4Auth.get_request_date(req)
         self.assertEqual(result, check, date_str)
 def test_get_request_date__no_headers(self):
     req = requests.Request('GET', 'http://blah.com')
     req = req.prepare()
     check = None
     result = AWS4Auth.get_request_date(req)
     self.assertEqual(result, check)