Example #1
0
 def test_initializer(self):
     """Test AWSAccountAlias initializer."""
     arn = 'roleArn'
     schema = 'acct10001'
     accessor = AWSAccountAlias(arn, schema)
     self.assertEqual(accessor._role_arn, arn)
     self.assertEqual(accessor._schema, schema)
Example #2
0
    def test_update_account_via_orgs(self, mock_get_alias,
                                     mock_get_account_names):
        """Test update alias with org api response."""
        alias = 'hccm-alias'
        mock_get_alias.return_value = (self.account_id, alias)
        member_account_id = '1234598760'
        member_account_name = 'hccm-member'
        account_names = [{
            'id': self.account_id,
            'name': alias
        }, {
            'id': member_account_id,
            'name': member_account_name
        }]
        mock_get_account_names.return_value = account_names
        role_arn = 'arn:aws:iam::{}:role/CostManagement'.format(
            self.account_id)
        accessor = AWSAccountAlias(role_arn, 'acct10001')
        accessor.update_account_alias()

        db_access = AccountAliasAccessor(self.account_id, 'acct10001')
        self.assertEqual(db_access._obj.account_id, self.account_id)
        self.assertEqual(db_access._obj.account_alias, alias)

        member_db_access = AccountAliasAccessor(member_account_id, 'acct10001')
        self.assertEqual(member_db_access._obj.account_id, member_account_id)
        self.assertEqual(member_db_access._obj.account_alias,
                         member_account_name)
Example #3
0
    def test_update_account_via_orgs(self, mock_get_alias,
                                     mock_get_account_names):
        """Test update alias with org api response."""
        alias = "hccm-alias"
        mock_get_alias.return_value = (self.account_id, alias)
        member_account_id = "1234598760"
        member_account_name = "hccm-member"
        account_names = [
            {
                "id": self.account_id,
                "name": alias
            },
            {
                "id": member_account_id,
                "name": member_account_name
            },
        ]
        mock_get_account_names.return_value = account_names
        role_arn = f"arn:aws:iam::{self.account_id}:role/CostManagement"
        accessor = AWSAccountAlias(role_arn, "acct10001")
        accessor.update_account_alias()

        db_access = AccountAliasAccessor(self.account_id, "acct10001")
        self.assertEqual(db_access._obj.account_id, self.account_id)
        self.assertEqual(db_access._obj.account_alias, alias)

        member_db_access = AccountAliasAccessor(member_account_id, "acct10001")
        self.assertEqual(member_db_access._obj.account_id, member_account_id)
        self.assertEqual(member_db_access._obj.account_alias,
                         member_account_name)
Example #4
0
    def test_update_account_alias_no_alias(self, mock_get_alias, mock_get_account_names):
        """Test updating alias when none is set."""
        mock_get_alias.return_value = (self.account_id, None)
        role_arn = 'arn:aws:iam::{}:role/CostManagement'.format(self.account_id)
        accessor = AWSAccountAlias(role_arn, 'acct10001')
        accessor.update_account_alias()

        db_access = AccountAliasAccessor(self.account_id, 'acct10001')
        self.assertEqual(db_access._obj.account_id, self.account_id)
        self.assertIsNone(db_access._obj.account_alias)
Example #5
0
    def _set_labler(self):
        """
        Create the account labeler object.

        Args:
            None

        Returns:
            (Object) : Some object that implements update_account_alias()

        """
        if self.provider_type == Provider.PROVIDER_AWS:
            return AWSAccountAlias(role_arn=self.auth, schema_name=self.schema)
        return None
    def test_update_account_alias_with_alias(self, mock_get_alias):
        """Test updating alias."""
        alias = 'hccm-alias'
        mock_get_alias.return_value = (self.account_id, alias)
        role_arn = 'arn:aws:iam::{}:role/CostManagement'.format(self.account_id)
        accessor = AWSAccountAlias(role_arn, 'acct10001')
        accessor.update_account_alias()

        db_access = AccountAliasAccessor(self.account_id, 'acct10001')
        self.assertEqual(db_access._obj.account_id, self.account_id)
        self.assertEqual(db_access._obj.account_alias, alias)

        mock_get_alias.return_value = (self.account_id, None)
        accessor.update_account_alias()
        db_access = AccountAliasAccessor(self.account_id, 'acct10001')
        self.assertIsNone(db_access._obj.account_alias)
Example #7
0
    def test_update_account_alias_with_alias(self, mock_get_alias,
                                             mock_get_account_names):
        """Test updating alias."""
        alias = "hccm-alias"
        mock_get_alias.return_value = (self.account_id, alias)
        role_arn = f"arn:aws:iam::{self.account_id}:role/CostManagement"
        accessor = AWSAccountAlias(role_arn, "acct10001")
        accessor.update_account_alias()

        db_access = AccountAliasAccessor(self.account_id, "acct10001")
        self.assertEqual(db_access._obj.account_id, self.account_id)
        self.assertEqual(db_access._obj.account_alias, alias)

        mock_get_alias.return_value = (self.account_id, None)
        accessor.update_account_alias()
        db_access = AccountAliasAccessor(self.account_id, "acct10001")
        self.assertIsNone(db_access._obj.account_alias)