Path: blob/develop/tests/unit/customizations/emr/test_get_service_principal.py
1569 views
# Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.1#2# Licensed under the Apache License, Version 2.0 (the "License"). You3# may not use this file except in compliance with the License. A copy of4# the License is located at5#6# http://aws.amazon.com/apache2.0/7#8# or in the "license" file accompanying this file. This file is9# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF10# ANY KIND, either express or implied. See the License for the specific11# language governing permissions and limitations under the License.1213from awscli.testutils import unittest14from awscli.customizations.emr.createdefaultroles import get_service_principal15from awscli.customizations.emr.exceptions import \16ResolveServicePrincipalError171819class TestEmrConfig(unittest.TestCase):20ec2_service = "ec2"21ec2_service_principal = "ec2.amazonaws.com"22emr_service = "elasticmapreduce"23endpoint1 = "https://ap-southeast-1.elasticmapreduce.abc/"24endpoint2 = "https://elasticmapreduce.abcd.def.ghi"25endpoint3 = "https://garbage.nothing.com"26expected_result1 = "elasticmapreduce.abc"27expected_result2 = "elasticmapreduce.def.ghi"2829def test_get_emr_service_principal(self):30msg = "Generated Service Principal does not match the expected" + \31"Service Principal"3233result1 = get_service_principal(self.emr_service, self.endpoint1)34self.assertEqual(result1, self.expected_result1, msg)3536result2 = get_service_principal(self.emr_service, self.endpoint2)37self.assertEqual(result2, self.expected_result2, msg)3839self.assertRaises(ResolveServicePrincipalError,40get_service_principal, self.emr_service,41self.endpoint3)4243def test_get_ec2_service_principal(self):44self.assertEqual(get_service_principal(self.ec2_service, self.endpoint1), self.ec2_service_principal)45self.assertEqual(get_service_principal(self.ec2_service, self.endpoint2), self.ec2_service_principal)46self.assertEqual(get_service_principal(self.ec2_service, self.endpoint3), self.ec2_service_principal)474849if __name__ == "__main__":50unittest.main()515253