示例#1
0
    def test_with_idbroker(self):
        try:
            finish = conf.AWS_ACCOUNTS.set_for_testing(
                {})  # Set empty to test when no configs are set
            with patch('aws.client.conf_idbroker.get_conf') as get_conf:
                with patch('aws.client.Client.get_s3_connection'):
                    with patch('aws.client.IDBroker.get_cab') as get_cab:
                        get_conf.return_value = {
                            'fs.s3a.ext.cab.address': 'address'
                        }
                        get_cab.return_value = {
                            'Credentials': {
                                'AccessKeyId': 'AccessKeyId',
                                'Expiration': 0
                            }
                        }
                        provider = get_credential_provider()
                        assert_equal(
                            provider.get_credentials().get('AccessKeyId'),
                            'AccessKeyId')
                        client1 = get_client('default', 'HUE')
                        client2 = get_client('default', 'HUE')
                        assert_not_equal(
                            client1, client2
                        )  # Test that with Expiration 0 clients not equal

                        get_cab.return_value = {
                            'Credentials': {
                                'AccessKeyId':
                                'AccessKeyId',
                                'Expiration':
                                int(current_ms_from_utc()) + 10 * 1000
                            }
                        }
                        client3 = get_client('default', 'HUE')
                        client4 = get_client('default', 'HUE')
                        client5 = get_client('default', 'test')
                        assert_equal(
                            client3, client4
                        )  # Test that with 10 sec expiration, clients equal
                        assert_not_equal(
                            client4, client5
                        )  # Test different user have different clients
        finally:
            finish()
            clear_cache()
示例#2
0
def config_validator(user):
  res = []
  from aws.client import get_client # Circular dependecy
  if is_enabled():
    try:
      conn = get_client('default')._s3_connection
      conn.get_canonical_user_id()
    except Exception as e:
      LOG.exception('AWS failed configuration check.')
      res.append(('aws', _t('Failed to connect to S3, check your AWS credentials.')))

  return res
示例#3
0
    def test_with_credentials(self):
        try:
            finish = conf.AWS_ACCOUNTS.set_for_testing({
                'default': {
                    'access_key_id': 'access_key_id',
                    'secret_access_key': 'secret_access_key'
                }
            })
            with patch('aws.client.conf_idbroker.get_conf') as get_conf:
                with patch('aws.client.Client.get_s3_connection'):
                    get_conf.return_value = {}
                    client1 = get_client('default')
                    client2 = get_client('default', 'test')

                    provider = get_credential_provider()
                    assert_equal(
                        provider.get_credentials().get('AccessKeyId'),
                        conf.AWS_ACCOUNTS['default'].ACCESS_KEY_ID.get())
                    assert_equal(
                        client1, client2
                    )  # Should be the same as no support for user based client with credentials & no Expiration
        finally:
            finish()
            clear_cache()