예제 #1
0
 def test_returns_digests_in_range(self):
     s3_client = self.driver.session.create_client('s3')
     keys = [
         self._fake_key(format_date(START_DATE - timedelta(days=1))),
         self._fake_key(format_date(START_DATE + timedelta(days=1))),
         self._fake_key(format_date(START_DATE + timedelta(days=2))),
         self._fake_key(format_date(START_DATE + timedelta(days=3))),
         self._fake_key(format_date(END_DATE + timedelta(hours=1))),
         self._fake_key(format_date(END_DATE + timedelta(days=1)))
     ]
     # Create a key that looks similar but for a different trail.
     bad_name = keys[3].replace('foo', 'baz')
     # Create a key that looks similar but is from a different trail source
     # region (e.g., CloudTrail-Digest/us-west-2).
     bad_region = keys[3].replace('CloudTrail-Digest/us-east-1',
                                  'CloudTrail-Digest/us-west-2')
     bad_region = bad_region.replace('CloudTrail-Digest_us-east-1',
                                     'CloudTrail-Digest_us-west-2')
     self.parsed_responses = [{
         "Contents": [
             {
                 "Key": keys[0]
             },  # skip (date <)
             {
                 "Key": keys[1]
             },
             {
                 "Key": keys[2]
             },
             {
                 "Key": 'foo/baz/bar'
             },  # skip (regex (bogus))
             {
                 "Key": bad_name
             },  # skip (regex (trail name))
             {
                 "Key": bad_region
             },  # skip (regex (source))
             {
                 "Key": keys[3]
             },
             {
                 "Key": keys[4]
             },  # hour is +1, but keep
             {
                 "Key": keys[5]
             }
         ]
     }]  # skip (date >)
     self.patch_make_request()
     provider = self._get_mock_provider(s3_client)
     digests = provider.load_digest_keys_in_range('foo', 'prefix',
                                                  START_DATE, END_DATE)
     self.assertNotIn(bad_name, digests)
     self.assertNotIn(bad_region, digests)
     self.assertEqual(keys[1], digests[0])
     self.assertEqual(keys[2], digests[1])
     self.assertEqual(keys[3], digests[2])
     self.assertEqual(keys[4], digests[3])
예제 #2
0
 def test_returns_digests_in_range(self):
     s3_client = self.driver.session.create_client("s3")
     keys = [
         self._fake_key(format_date(START_DATE - timedelta(days=1))),
         self._fake_key(format_date(START_DATE + timedelta(days=1))),
         self._fake_key(format_date(START_DATE + timedelta(days=2))),
         self._fake_key(format_date(START_DATE + timedelta(days=3))),
         self._fake_key(format_date(END_DATE + timedelta(hours=1))),
         self._fake_key(format_date(END_DATE + timedelta(days=1))),
     ]
     # Create a key that looks similar but for a different trail.
     bad_name = keys[3].replace("foo", "baz")
     # Create a key that looks similar but is from a different trail source
     # region (e.g., CloudTrail-Digest/us-west-2).
     bad_region = keys[3].replace("CloudTrail-Digest/us-east-1", "CloudTrail-Digest/us-west-2")
     bad_region = bad_region.replace("CloudTrail-Digest_us-east-1", "CloudTrail-Digest_us-west-2")
     self.parsed_responses = [
         {
             "Contents": [
                 {"Key": keys[0]},  # skip (date <)
                 {"Key": keys[1]},
                 {"Key": keys[2]},
                 {"Key": "foo/baz/bar"},  # skip (regex (bogus))
                 {"Key": bad_name},  # skip (regex (trail name))
                 {"Key": bad_region},  # skip (regex (source))
                 {"Key": keys[3]},
                 {"Key": keys[4]},  # hour is +1, but keep
                 {"Key": keys[5]},
             ]
         }
     ]  # skip (date >)
     self.patch_make_request()
     provider = self._get_mock_provider(s3_client)
     digests = provider.load_digest_keys_in_range("foo", "prefix", START_DATE, END_DATE)
     self.assertNotIn(bad_name, digests)
     self.assertNotIn(bad_region, digests)
     self.assertEqual(keys[1], digests[0])
     self.assertEqual(keys[2], digests[1])
     self.assertEqual(keys[3], digests[2])
     self.assertEqual(keys[4], digests[3])
예제 #3
0
 def test_formats_dates(self):
     date = datetime(2015, 8, 21, tzinfo=tz.tzutc())
     self.assertEqual("20150821T000000Z", format_date(date))
예제 #4
0
 def test_formats_dates(self):
     date = datetime(2015, 8, 21, tzinfo=tz.tzutc())
     self.assertEqual('20150821T000000Z', format_date(date))