def test_fails_when_digest_metadata_is_missing(self):
     key = MockDigestProvider([]).get_key_at_position(1)
     self.parsed_responses = [
         {
             'LocationConstraint': ''
         },
         {
             'Contents': [{
                 'Key': key
             }]
         },
         {
             'Body': six.BytesIO(_gz_compress(self._logs[0]['_raw_value'])),
             'Metadata': {}
         },
     ]
     s3_client_provider = S3ClientProvider(self.driver.session, 'us-east-1')
     digest_provider = DigestProvider(s3_client_provider, TEST_ACCOUNT_ID,
                                      'foo', 'us-east-1')
     key_provider = Mock()
     key_provider.get_public_keys.return_value = {
         'a': {
             'Value': VALID_TEST_KEY
         }
     }
     _setup_mock_traverser(self._mock_traverser, key_provider,
                           digest_provider, Mock())
     stdout, stderr, rc = self.run_cmd(
         ("cloudtrail validate-logs --trail-arn %s --start-time %s "
          "--region us-east-1") % (TEST_TRAIL_ARN, START_TIME_ARG), 1)
     self.assertIn(
         'Digest file\ts3://1/%s\tINVALID: signature verification failed' %
         key, stderr)
Exemplo n.º 2
0
 def test_removes_cli_error_events(self):
     # We should also remove the error handler for S3.
     # This can be removed once the client switchover is done.
     session = mock.Mock()
     s3_client = mock.Mock()
     session.create_client.return_value = s3_client
     s3_client.get_bucket_location.return_value = {'LocationConstraint': ''}
     provider = S3ClientProvider(session)
     client = provider.get_client('foo')
Exemplo n.º 3
0
 def test_caches_previously_loaded_clients(self):
     session = Mock()
     s3_client = Mock()
     session.create_client.return_value = s3_client
     s3_client.get_bucket_location.return_value = {'LocationConstraint': ''}
     provider = S3ClientProvider(session)
     client = provider.get_client('foo')
     self.assertEqual(1, session.create_client.call_count)
     self.assertEqual(client, provider.get_client('foo'))
     self.assertEqual(1, session.create_client.call_count)
Exemplo n.º 4
0
 def test_removes_cli_error_events(self):
     # We should also remove the error handler for S3.
     # This can be removed once the client switchover is done.
     session = Mock()
     s3_client = Mock()
     session.create_client.return_value = s3_client
     s3_client.get_bucket_location.return_value = {'LocationConstraint': ''}
     provider = S3ClientProvider(session)
     client = provider.get_client('foo')
     client.meta.events.unregister.assert_called_with(
         'after-call', unique_id='awscli-error-handler')
Exemplo n.º 5
0
 def test_creates_clients_for_buckets_in_us_east_1(self):
     session = Mock()
     s3_client = Mock()
     session.create_client.return_value = s3_client
     s3_client.get_bucket_location.return_value = {'LocationConstraint': ''}
     provider = S3ClientProvider(session)
     created_client = provider.get_client('foo')
     self.assertEqual(s3_client, created_client)
     create_client_calls = session.create_client.call_args_list
     self.assertEqual(create_client_calls, [call('s3', 'us-east-1')])
     self.assertEqual(1, s3_client.get_bucket_location.call_count)