Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/unit/customizations/emr/test_get_service_principal.py
1569 views
1
# Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License"). You
4
# may not use this file except in compliance with the License. A copy of
5
# the License is located at
6
#
7
# http://aws.amazon.com/apache2.0/
8
#
9
# or in the "license" file accompanying this file. This file is
10
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
# ANY KIND, either express or implied. See the License for the specific
12
# language governing permissions and limitations under the License.
13
14
from awscli.testutils import unittest
15
from awscli.customizations.emr.createdefaultroles import get_service_principal
16
from awscli.customizations.emr.exceptions import \
17
ResolveServicePrincipalError
18
19
20
class TestEmrConfig(unittest.TestCase):
21
ec2_service = "ec2"
22
ec2_service_principal = "ec2.amazonaws.com"
23
emr_service = "elasticmapreduce"
24
endpoint1 = "https://ap-southeast-1.elasticmapreduce.abc/"
25
endpoint2 = "https://elasticmapreduce.abcd.def.ghi"
26
endpoint3 = "https://garbage.nothing.com"
27
expected_result1 = "elasticmapreduce.abc"
28
expected_result2 = "elasticmapreduce.def.ghi"
29
30
def test_get_emr_service_principal(self):
31
msg = "Generated Service Principal does not match the expected" + \
32
"Service Principal"
33
34
result1 = get_service_principal(self.emr_service, self.endpoint1)
35
self.assertEqual(result1, self.expected_result1, msg)
36
37
result2 = get_service_principal(self.emr_service, self.endpoint2)
38
self.assertEqual(result2, self.expected_result2, msg)
39
40
self.assertRaises(ResolveServicePrincipalError,
41
get_service_principal, self.emr_service,
42
self.endpoint3)
43
44
def test_get_ec2_service_principal(self):
45
self.assertEqual(get_service_principal(self.ec2_service, self.endpoint1), self.ec2_service_principal)
46
self.assertEqual(get_service_principal(self.ec2_service, self.endpoint2), self.ec2_service_principal)
47
self.assertEqual(get_service_principal(self.ec2_service, self.endpoint3), self.ec2_service_principal)
48
49
50
if __name__ == "__main__":
51
unittest.main()
52
53