예제 #1
0
 def test_cost_usage_source_is_reachable_no_bucket_exists(
         self, mock_get_sts_access, mock_check_s3_access):
     """Verify that the cost usage source is authenticated and created."""
     provider_interface = AWSProvider()
     with self.assertRaises(ValidationError):
         provider_interface.cost_usage_source_is_reachable(
             'iam_arn', 'bucket_name')
예제 #2
0
    def test_invalid_roleARN(self):
        """Test _get_sts_access with an invalid RoleARN."""
        iam_arn = 'toosmall'
        bucket_name = 'my_s3_bucket'

        provider_interface = AWSProvider()
        with self.assertRaises(ValidationError):
            provider_interface.cost_usage_source_is_reachable(iam_arn, bucket_name)
예제 #3
0
    def test_provider_s3_fail(self, check_s3_access):
        """Test creating a provider with AWS s3 bucket doesn't exist."""
        check_s3_access.return_value = False
        iam_arn = 'arn:aws:s3:::my_s3_bucket'
        bucket_name = 'my_s3_bucket'

        provider_interface = AWSProvider()
        with self.assertRaises(ValidationError):
            provider_interface.cost_usage_source_is_reachable(iam_arn, bucket_name)
예제 #4
0
    def test_provider_sts_fail(self, get_sts_access):
        """Test creating a provider with AWS STS failure."""
        get_sts_access.return_value = (None, None, None)
        iam_arn = 'arn:aws:s3:::my_s3_bucket'
        bucket_name = 'my_s3_bucket'

        provider_interface = AWSProvider()
        with self.assertRaises(ValidationError):
            provider_interface.cost_usage_source_is_reachable(iam_arn, bucket_name)
예제 #5
0
    def test_no_credential_error(self):
        """Test attempting STS access where no credentials are found."""
        with patch.object(SigV4Auth, 'add_auth', side_effect=NoCredentialsError):
            iam_arn = 'arn:aws:s3:::my_s3_bucket'
            bucket_name = 'my_s3_bucket'

            provider_interface = AWSProvider()
            with self.assertRaises(ValidationError):
                provider_interface.cost_usage_source_is_reachable(iam_arn, bucket_name)
예제 #6
0
 def test_cost_usage_source_is_reachable_no_topics(
         self, mock_get_sts_access, mock_check_s3_access,
         mock_check_cost_report_access, mock_get_configured_sns_topics):
     """Verify that the cost usage source is authenticated and created."""
     provider_interface = AWSProvider()
     try:
         provider_interface.cost_usage_source_is_reachable(
             'iam_arn', 'bucket_name')
     except Exception:
         self.fail('Unexpected Error')
예제 #7
0
    def test_provider_org_fail(self, check_org_access, check_cost_report_access, check_s3_access):
        """Test creating a provider with AWS org access failure."""
        iam_arn = 'arn:aws:s3:::my_s3_bucket'
        bucket_name = 'my_s3_bucket'
        access_key_id, secret_access_key, session_token = _get_sts_access(
            iam_arn)
        s3_resource = boto3.resource(
            's3',
            aws_access_key_id=access_key_id,
            aws_secret_access_key=secret_access_key,
            aws_session_token=session_token,
        )
        s3_resource.create_bucket(Bucket=bucket_name)

        provider_interface = AWSProvider()
        try:
            provider_interface.cost_usage_source_is_reachable(iam_arn, bucket_name)
        except Exception:
            self.fail('Unexpected error thrown')
예제 #8
0
    def test_cost_usage_source_is_reachable(self, check_org_access, check_cost_report_access):
        """Verify that the cost usage source is authenticated and created."""
        check_org_access.return_value = True
        check_cost_report_access.return_value = True

        iam_arn = 'arn:aws:s3:::my_s3_bucket'
        bucket_name = 'my_s3_bucket'
        access_key_id, secret_access_key, session_token = _get_sts_access(
            iam_arn)
        s3_resource = boto3.resource(
            's3',
            aws_access_key_id=access_key_id,
            aws_secret_access_key=secret_access_key,
            aws_session_token=session_token,
        )
        s3_resource.create_bucket(Bucket=bucket_name)

        provider_interface = AWSProvider()

        try:
            provider_interface.cost_usage_source_is_reachable(iam_arn, bucket_name)
        except Exception:
            self.fail('Unexpected Error')
예제 #9
0
    def _create_service(self, service_name):
        """
        Create the provider service object.

        This will establish what service (AWS, etc) ProviderAccessor should use
        when interacting with Koku core.

        Args:
            service_name (String): Provider Type

        Returns:
            (Object) : Some object that is a child of ProviderInterface

        """
        if service_name == 'AWS':
            return AWSProvider()
예제 #10
0
    def test_provider_cur_fail(self, check_cost_report_access):
        """Test creating a provider with AWS cost report access failure."""
        check_cost_report_access.return_value = False
        iam_arn = 'arn:aws:s3:::my_s3_bucket'
        bucket_name = 'my_s3_bucket'

        provider_interface = AWSProvider()
        with self.assertRaises(ValidationError):
            provider_interface.cost_usage_source_is_reachable(iam_arn, bucket_name)

        access_key_id, secret_access_key, session_token = _get_sts_access(
            iam_arn)
        s3_resource = boto3.resource(
            's3',
            aws_access_key_id=access_key_id,
            aws_secret_access_key=secret_access_key,
            aws_session_token=session_token,
        )
        s3_resource.create_bucket(Bucket=bucket_name)

        provider_interface = AWSProvider()
        with self.assertRaises(ValidationError):
            provider_interface.cost_usage_source_is_reachable(iam_arn, bucket_name)
예제 #11
0
 def test_get_name(self):
     """Get name of provider."""
     provider = AWSProvider()
     self.assertEqual(provider.name(), 'AWS')
예제 #12
0
 def test_cost_usage_source_is_reachable_no_arn(self):
     """Verify that the cost usage source is authenticated and created."""
     provider_interface = AWSProvider()
     with self.assertRaises(ValidationError):
         provider_interface.cost_usage_source_is_reachable(
             None, 'bucket_name')
예제 #13
0
 def test_get_name_aws(self):
     """Get name of aws service provider."""
     provider = AWSProvider()
     interface = ProviderAccessor(provider.name())
     self.assertEqual(provider.name(), interface.service_name())