How to use get_role_policy method in localstack

Best Python code snippet using localstack_python

LAMBDA_ROLE_ALLOWED_ON_LOGGING_test.py

Source:LAMBDA_ROLE_ALLOWED_ON_LOGGING_test.py Github

copy

Full Screen

1#2# This file made available under CC0 1.0 Universal (https://creativecommons.org/publicdomain/zero/1.0/legalcode)3#4# Created with the Rule Development Kit: https://github.com/awslabs/aws-config-rdk5# Can be used stand-alone or with the Rule Compliance Engine: https://github.com/awslabs/aws-config-engine-for-compliance-as-code6#7import sys8import json9import unittest10try:11 from unittest.mock import MagicMock12except ImportError:13 from mock import MagicMock14CONFIG_CLIENT_MOCK = MagicMock()15IAM_CLIENT_MOCK = MagicMock()16STS_CLIENT_MOCK = MagicMock()17class Boto3Mock():18 def client(self, client_name, *args, **kwargs):19 if client_name == 'config':20 return CONFIG_CLIENT_MOCK21 elif client_name == 'iam':22 return IAM_CLIENT_MOCK23 if client_name == 'sts':24 return STS_CLIENT_MOCK25 else:26 raise Exception("Attempting to create an unknown client")27sys.modules['boto3'] = Boto3Mock()28rule = __import__('LAMBDA_ROLE_ALLOWED_ON_LOGGING')29def assert_successful_evaluation(testClass, response, resp_expected):30 testClass.assertEquals(response[0]['ComplianceType'], resp_expected)31def assert_customer_error_response(testClass, response, customerErrorCode=None, customerErrorMessage=None):32 if customerErrorCode:33 testClass.assertEqual(customerErrorCode, response['customerErrorCode'])34 if customerErrorMessage:35 testClass.assertEqual(customerErrorMessage, response['customerErrorMessage'])36 testClass.assertTrue(response['customerErrorCode'])37 testClass.assertTrue(response['customerErrorMessage'])38 if "internalErrorMessage" in response:39 testClass.assertTrue(response['internalErrorMessage'])40 if "internalErrorDetails" in response:41 testClass.assertTrue(response['internalErrorDetails'])42def build_invoking_event(item_status='OK'):43 invoking_event = {44 "configurationItemDiff":"SomeDifference",45 "notificationCreationTime":"SomeTime",46 "messageType":"SomeType",47 "recordVersion":"SomeVersion",48 "configurationItem":49 { 50 "relationships":[{"resourceName":"some_role"}],51 "configurationItemCaptureTime": "2018-05-11T17:53:48.872Z",52 "configurationItemStatus": item_status,53 "configurationStateId": "1526061228872",54 "arn": "arn:aws:lambda:us-east-1:823362693882:function:test-function",55 "resourceType": "AWS::Lambda::Function",56 "resourceId": "test-function",57 "resourceName": "test-function",58 "configuration": {59 "functionName": "test-function",60 "functionArn": "arn:aws:lambda:us-east-1:823362693882:function:test-function",61 "role": "some-role-arn"62 }63 }64 }65 return json.dumps(invoking_event)66def build_lambda_event(ruleParameters='{}', invokingEvent=build_invoking_event()):67 return({68 "invokingEvent" : invokingEvent,69 "ruleParameters" : ruleParameters,70 "resultToken" : "TESTMODE",71 "eventLeftScope" : False,72 "executionRoleArn" : "arn:aws:iam::123456789012:role/service-role/config-role",73 "configRuleArn" : "arn:aws:config:us-east-1:123456789012:config-rule/config-rule-8fngan",74 "configRuleName" : "LAMBDA_ROLE_ALLOWED_ON_LOGGING",75 "configRuleId" : "config-rule-8fngan",76 "accountId" : "SampleID"77 })78def gen_statement(action="*", resource="*", effect="Allow"):79 return {80 "Action": action,81 "Resource": resource,82 "Effect": effect83 }84 85def gen_statement_list(statement=gen_statement(), statement2=False, statement3=False):86 statement_list = []87 statement_list.append(statement)88 if statement2:89 statement_list.append(statement2)90 if statement3:91 statement_list.append(statement3)92 return statement_list93def gen_policy_api(type="inline", statement_list=gen_statement_list()):94 if type == "inline":95 return {96 "RoleName": "AdminLambda",97 "PolicyDocument": {98 "Version": "2012-10-17",99 "Statement": statement_list100 }101 }102 if type == "list_attached":103 return {104 "AttachedPolicies": [105 {106 "PolicyName": "some-policy-name",107 "PolicyArn": "some-policy-arn"108 }109 ]110 }111 if type == "get_policy": 112 return {113 "Policy": {114 "PolicyName": "some-policy-name",115 "Arn": "some-policy-arn",116 "DefaultVersionId": "some-version-id" 117 }118 }119 if type == "get_policy_version":120 return {121 "PolicyVersion": {122 "Document": {123 "Statement": statement_list124 }125 }126 }127class TestScenario1DeletedRole(unittest.TestCase):128 def test_NOT_APPLICABLE_lambda_function_deleted(self):129 invokEvent = build_invoking_event("ResourceDeleted")130 lambdaEvent = build_lambda_event(invokingEvent=invokEvent)131 response = rule.lambda_handler(lambdaEvent, {})132 resp_expected = "NOT_APPLICABLE"133 assert_successful_evaluation(self, response, resp_expected)134class TestScenario2AWSManagedRole(unittest.TestCase):135 def test_COMPLIANT_AWSLambdaBasicExecution_attached_on_role(self):136 list_attached_role_pl = {137 "AttachedPolicies": [138 {139 "PolicyName": "AWSLambdaBasicExecutionRole-11389b43-d62e-4847-a0af-a967a8e02578",140 "PolicyArn": "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"141 }142 ]143 }144 IAM_CLIENT_MOCK.list_attached_role_policies = MagicMock(return_value=list_attached_role_pl)145 lambdaEvent = build_lambda_event()146 response = rule.lambda_handler(lambdaEvent, {})147 resp_expected = "COMPLIANT"148 assert_successful_evaluation(self, response, resp_expected)149class TestScenario3NoPolicyOnRole(unittest.TestCase):150 def test_NON_COMPLIANT_no_policy_attached_on_role_case(self):151 list_attached_role_pl = {"AttachedPolicies": []}152 IAM_CLIENT_MOCK.list_attached_role_policies = MagicMock(return_value=list_attached_role_pl)153 lambdaEvent = build_lambda_event()154 response = rule.lambda_handler(lambdaEvent, {})155 resp_expected = "NON_COMPLIANT"156 assert_successful_evaluation(self, response, resp_expected)157 158class TestScenario4ActionStar(unittest.TestCase):159 def test_COMPLIANT_action_star_allow_string_inline(self):160 get_pl = gen_policy_api()161 list_attached_role_pl = {"AttachedPolicies": []}162 IAM_CLIENT_MOCK.list_attached_role_policies = MagicMock(return_value=list_attached_role_pl)163 IAM_CLIENT_MOCK.list_role_policies = MagicMock(return_value={"PolicyNames": ["some-inline-name-policy"]})164 IAM_CLIENT_MOCK.get_role_policy = MagicMock(return_value=get_pl)165 lambdaEvent = build_lambda_event()166 response = rule.lambda_handler(lambdaEvent, {})167 resp_expected = "COMPLIANT"168 assert_successful_evaluation(self, response, resp_expected)169 def test_COMPLIANT_action_star_allow_list_inline(self):170 get_pl = gen_policy_api(statement_list=gen_statement_list(gen_statement(action=["some-action","*"])))171 list_attached_role_pl = {"AttachedPolicies": []}172 IAM_CLIENT_MOCK.list_attached_role_policies = MagicMock(return_value=list_attached_role_pl)173 IAM_CLIENT_MOCK.list_role_policies = MagicMock(return_value={"PolicyNames": ["some-inline-name-policy"]})174 IAM_CLIENT_MOCK.get_role_policy = MagicMock(return_value=get_pl)175 lambdaEvent = build_lambda_event()176 response = rule.lambda_handler(lambdaEvent, {})177 resp_expected = "COMPLIANT"178 assert_successful_evaluation(self, response, resp_expected)179 180 def test_NON_COMPLIANT_action_star_deny_inline(self):181 get_pl = gen_policy_api(statement_list=gen_statement_list(gen_statement(effect="Deny")))182 list_attached_role_pl = {"AttachedPolicies": []}183 IAM_CLIENT_MOCK.list_attached_role_policies = MagicMock(return_value=list_attached_role_pl)184 IAM_CLIENT_MOCK.list_role_policies = MagicMock(return_value={"PolicyNames": ["some-inline-name-policy"]})185 IAM_CLIENT_MOCK.get_role_policy = MagicMock(return_value=get_pl)186 lambdaEvent = build_lambda_event()187 response = rule.lambda_handler(lambdaEvent, {})188 resp_expected = "NON_COMPLIANT"189 assert_successful_evaluation(self, response, resp_expected)190 def test_NON_COMPLIANT_action_star_other_resource_string_inline(self):191 get_pl = gen_policy_api(statement_list=gen_statement_list(gen_statement(resource="something_else")))192 list_attached_role_pl = {"AttachedPolicies": []}193 IAM_CLIENT_MOCK.list_attached_role_policies = MagicMock(return_value=list_attached_role_pl)194 IAM_CLIENT_MOCK.list_role_policies = MagicMock(return_value={"PolicyNames": ["some-inline-name-policy"]})195 IAM_CLIENT_MOCK.get_role_policy = MagicMock(return_value=get_pl)196 lambdaEvent = build_lambda_event()197 response = rule.lambda_handler(lambdaEvent, {})198 resp_expected = "NON_COMPLIANT"199 assert_successful_evaluation(self, response, resp_expected)200 def test_COMPLIANT_action_star_resource_list_inline(self):201 get_pl = gen_policy_api(statement_list=gen_statement_list(gen_statement(resource=["something_else","*"])))202 list_attached_role_pl = {"AttachedPolicies": []}203 IAM_CLIENT_MOCK.list_attached_role_policies = MagicMock(return_value=list_attached_role_pl)204 IAM_CLIENT_MOCK.list_role_policies = MagicMock(return_value={"PolicyNames": ["some-inline-name-policy"]})205 IAM_CLIENT_MOCK.get_role_policy = MagicMock(return_value=get_pl)206 lambdaEvent = build_lambda_event()207 response = rule.lambda_handler(lambdaEvent, {})208 resp_expected = "COMPLIANT"209 assert_successful_evaluation(self, response, resp_expected)210 211 def test_COMPLIANT_action_star_allow_managed(self):212 list_attached_role_pl = gen_policy_api(type="list_attached")213 get_pl = gen_policy_api(type="get_policy")214 get_pl_version = gen_policy_api(type="get_policy_version")215 IAM_CLIENT_MOCK.list_attached_role_policies = MagicMock(return_value=list_attached_role_pl)216 IAM_CLIENT_MOCK.get_policy = MagicMock(return_value=get_pl)217 IAM_CLIENT_MOCK.get_policy_version = MagicMock(return_value=get_pl_version)218 IAM_CLIENT_MOCK.list_role_policies = MagicMock(return_value={"PolicyNames": []})219 lambdaEvent = build_lambda_event()220 response = rule.lambda_handler(lambdaEvent, {})221 resp_expected = "COMPLIANT"222 assert_successful_evaluation(self, response, resp_expected)223 def test_NON_COMPLIANT_action_star_deny_managed(self):224 list_attached_role_pl = gen_policy_api(type="list_attached")225 get_pl = gen_policy_api(type="get_policy")226 get_pl_version = gen_policy_api(type="get_policy_version",statement_list=gen_statement_list(gen_statement(effect="Deny")))227 IAM_CLIENT_MOCK.list_attached_role_policies = MagicMock(return_value=list_attached_role_pl)228 IAM_CLIENT_MOCK.get_policy = MagicMock(return_value=get_pl)229 IAM_CLIENT_MOCK.get_policy_version = MagicMock(return_value=get_pl_version)230 IAM_CLIENT_MOCK.list_role_policies = MagicMock(return_value={"PolicyNames": []})231 lambdaEvent = build_lambda_event()232 response = rule.lambda_handler(lambdaEvent, {})233 resp_expected = "NON_COMPLIANT"234 assert_successful_evaluation(self, response, resp_expected)235 def test_COMPLIANT_action_star_resource_ok_managed(self):236 list_attached_role_pl = gen_policy_api(type="list_attached")237 get_pl = gen_policy_api(type="get_policy")238 get_pl_version = gen_policy_api(type="get_policy_version",statement_list=gen_statement_list(gen_statement(resource="arn:aws:logs:*")))239 IAM_CLIENT_MOCK.list_attached_role_policies = MagicMock(return_value=list_attached_role_pl)240 IAM_CLIENT_MOCK.get_policy = MagicMock(return_value=get_pl)241 IAM_CLIENT_MOCK.get_policy_version = MagicMock(return_value=get_pl_version)242 IAM_CLIENT_MOCK.list_role_policies = MagicMock(return_value={"PolicyNames": []})243 lambdaEvent = build_lambda_event()244 response = rule.lambda_handler(lambdaEvent, {})245 resp_expected = "COMPLIANT"246 assert_successful_evaluation(self, response, resp_expected)247class TestScenario5LogStar(unittest.TestCase):248 249 def test_COMPLIANT_action_logstar_allow_string_inline(self):250 get_pl = gen_policy_api(statement_list=gen_statement_list(gen_statement(action="log:*")))251 list_attached_role_pl = {"AttachedPolicies": []}252 IAM_CLIENT_MOCK.list_attached_role_policies = MagicMock(return_value=list_attached_role_pl)253 IAM_CLIENT_MOCK.list_role_policies = MagicMock(return_value={"PolicyNames": ["some-inline-name-policy"]})254 IAM_CLIENT_MOCK.get_role_policy = MagicMock(return_value=get_pl)255 lambdaEvent = build_lambda_event()256 response = rule.lambda_handler(lambdaEvent, {})257 resp_expected = "COMPLIANT"258 assert_successful_evaluation(self, response, resp_expected)259 def test_COMPLIANT_action_logstar_allow_list_inline(self):260 get_pl = gen_policy_api(statement_list=gen_statement_list(gen_statement(action=["some-action","log:*"])))261 list_attached_role_pl = {"AttachedPolicies": []}262 IAM_CLIENT_MOCK.list_attached_role_policies = MagicMock(return_value=list_attached_role_pl)263 IAM_CLIENT_MOCK.list_role_policies = MagicMock(return_value={"PolicyNames": ["some-inline-name-policy"]})264 IAM_CLIENT_MOCK.get_role_policy = MagicMock(return_value=get_pl)265 lambdaEvent = build_lambda_event()266 response = rule.lambda_handler(lambdaEvent, {})267 resp_expected = "COMPLIANT"268 assert_successful_evaluation(self, response, resp_expected)269 270 def test_NON_COMPLIANT_action_logstar_deny_inline(self):271 get_pl = gen_policy_api(statement_list=gen_statement_list(gen_statement(action="log:*",effect="Deny")))272 list_attached_role_pl = {"AttachedPolicies": []}273 IAM_CLIENT_MOCK.list_attached_role_policies = MagicMock(return_value=list_attached_role_pl)274 IAM_CLIENT_MOCK.list_role_policies = MagicMock(return_value={"PolicyNames": ["some-inline-name-policy"]})275 IAM_CLIENT_MOCK.get_role_policy = MagicMock(return_value=get_pl)276 lambdaEvent = build_lambda_event()277 response = rule.lambda_handler(lambdaEvent, {})278 resp_expected = "NON_COMPLIANT"279 assert_successful_evaluation(self, response, resp_expected)280 def test_NON_COMPLIANT_action_logstar_other_resource_string_inline(self):281 get_pl = gen_policy_api(statement_list=gen_statement_list(gen_statement(action="log:*", resource="something_else")))282 list_attached_role_pl = {"AttachedPolicies": []}283 IAM_CLIENT_MOCK.list_attached_role_policies = MagicMock(return_value=list_attached_role_pl)284 IAM_CLIENT_MOCK.list_role_policies = MagicMock(return_value={"PolicyNames": ["some-inline-name-policy"]})285 IAM_CLIENT_MOCK.get_role_policy = MagicMock(return_value=get_pl)286 lambdaEvent = build_lambda_event()287 response = rule.lambda_handler(lambdaEvent, {})288 resp_expected = "NON_COMPLIANT"289 assert_successful_evaluation(self, response, resp_expected)290 def test_COMPLIANT_action_logstar_resource_list_inline(self):291 get_pl = gen_policy_api(statement_list=gen_statement_list(gen_statement(action="log:*", resource=["something_else","*"])))292 list_attached_role_pl = {"AttachedPolicies": []}293 IAM_CLIENT_MOCK.list_attached_role_policies = MagicMock(return_value=list_attached_role_pl)294 IAM_CLIENT_MOCK.list_role_policies = MagicMock(return_value={"PolicyNames": ["some-inline-name-policy"]})295 IAM_CLIENT_MOCK.get_role_policy = MagicMock(return_value=get_pl)296 lambdaEvent = build_lambda_event()297 response = rule.lambda_handler(lambdaEvent, {})298 resp_expected = "COMPLIANT"299 assert_successful_evaluation(self, response, resp_expected)300 301 def test_COMPLIANT_action_logstar_allow_managed(self):302 list_attached_role_pl = gen_policy_api(type="list_attached")303 get_pl = gen_policy_api(type="get_policy")304 get_pl_version = gen_policy_api(type="get_policy_version",statement_list=gen_statement_list(gen_statement(action="log:*")))305 IAM_CLIENT_MOCK.list_attached_role_policies = MagicMock(return_value=list_attached_role_pl)306 IAM_CLIENT_MOCK.get_policy = MagicMock(return_value=get_pl)307 IAM_CLIENT_MOCK.get_policy_version = MagicMock(return_value=get_pl_version)308 IAM_CLIENT_MOCK.list_role_policies = MagicMock(return_value={"PolicyNames": []})309 lambdaEvent = build_lambda_event()310 response = rule.lambda_handler(lambdaEvent, {})311 resp_expected = "COMPLIANT"312 assert_successful_evaluation(self, response, resp_expected)313 def test_NON_COMPLIANT_action_logstar_deny_managed(self):314 list_attached_role_pl = gen_policy_api(type="list_attached")315 get_pl = gen_policy_api(type="get_policy")316 get_pl_version = gen_policy_api(type="get_policy_version",statement_list=gen_statement_list(gen_statement(action="log:*",effect="Deny")))317 IAM_CLIENT_MOCK.list_attached_role_policies = MagicMock(return_value=list_attached_role_pl)318 IAM_CLIENT_MOCK.get_policy = MagicMock(return_value=get_pl)319 IAM_CLIENT_MOCK.get_policy_version = MagicMock(return_value=get_pl_version)320 IAM_CLIENT_MOCK.list_role_policies = MagicMock(return_value={"PolicyNames": []})321 lambdaEvent = build_lambda_event()322 response = rule.lambda_handler(lambdaEvent, {})323 resp_expected = "NON_COMPLIANT"324 assert_successful_evaluation(self, response, resp_expected)325 def test_COMPLIANT_action_logstar_resource_ok_managed(self):326 list_attached_role_pl = gen_policy_api(type="list_attached")327 get_pl = gen_policy_api(type="get_policy")328 get_pl_version = gen_policy_api(type="get_policy_version",statement_list=gen_statement_list(gen_statement(action="log:*",resource="arn:aws:logs:*")))329 IAM_CLIENT_MOCK.list_attached_role_policies = MagicMock(return_value=list_attached_role_pl)330 IAM_CLIENT_MOCK.get_policy = MagicMock(return_value=get_pl)331 IAM_CLIENT_MOCK.get_policy_version = MagicMock(return_value=get_pl_version)332 IAM_CLIENT_MOCK.list_role_policies = MagicMock(return_value={"PolicyNames": []})333 lambdaEvent = build_lambda_event()334 response = rule.lambda_handler(lambdaEvent, {})335 resp_expected = "COMPLIANT"336 assert_successful_evaluation(self, response, resp_expected)337 338class TestScenario6LogExactActions(unittest.TestCase):339 CreateLogGroup = gen_statement(action="logs:CreateLogGroup")340 CreateLogStream = gen_statement(action="logs:CreateLogStream")341 PutLogEvents = gen_statement(action="logs:PutLogEvents")342 PutLogEventsDeny = gen_statement(action="logs:PutLogEvents", effect="Deny")343 PutLogEventsBadResource = gen_statement(action="logs:PutLogEvents", resource="some-bad-resource")344 statement_list_all_in_one = gen_statement_list(gen_statement(action=["logs:CreateLogGroup","logs:CreateLogStream","logs:PutLogEvents"]))345 statement_list_all_in_three = gen_statement_list(CreateLogGroup, CreateLogStream, PutLogEvents)346 statement_list_all_in_three_with_deny = gen_statement_list(CreateLogGroup, CreateLogStream, PutLogEventsDeny)347 statement_list_all_in_three_with_bad_resource = gen_statement_list(CreateLogGroup, CreateLogStream, PutLogEventsBadResource)348 def test_COMPLIANT_action_logexactaction_inline(self):349 for state in [self.statement_list_all_in_one, self.statement_list_all_in_three]:350 get_pl = gen_policy_api(statement_list=state)351 list_attached_role_pl = {"AttachedPolicies": []}352 IAM_CLIENT_MOCK.list_attached_role_policies = MagicMock(return_value=list_attached_role_pl)353 IAM_CLIENT_MOCK.list_role_policies = MagicMock(return_value={"PolicyNames": ["some-inline-name-policy"]})354 IAM_CLIENT_MOCK.get_role_policy = MagicMock(return_value=get_pl)355 lambdaEvent = build_lambda_event()356 response = rule.lambda_handler(lambdaEvent, {})357 resp_expected = "COMPLIANT"358 assert_successful_evaluation(self, response, resp_expected)359 360 def test_NON_COMPLIANT_action_logexactaction_inline(self):361 for state in [self.statement_list_all_in_three_with_deny, self.statement_list_all_in_three_with_bad_resource]:362 get_pl = gen_policy_api(statement_list=state)363 list_attached_role_pl = {"AttachedPolicies": []}364 IAM_CLIENT_MOCK.list_attached_role_policies = MagicMock(return_value=list_attached_role_pl)365 IAM_CLIENT_MOCK.list_role_policies = MagicMock(return_value={"PolicyNames": ["some-inline-name-policy"]})366 IAM_CLIENT_MOCK.get_role_policy = MagicMock(return_value=get_pl)367 lambdaEvent = build_lambda_event()368 response = rule.lambda_handler(lambdaEvent, {})369 resp_expected = "NON_COMPLIANT"370 assert_successful_evaluation(self, response, resp_expected)371 372 def test_COMPLIANT_action_logexactaction_managed(self):373 for state in [self.statement_list_all_in_one, self.statement_list_all_in_three]:374 list_attached_role_pl = gen_policy_api(type="list_attached")375 get_pl = gen_policy_api(type="get_policy")376 get_pl_version = gen_policy_api(type="get_policy_version",statement_list=state)377 IAM_CLIENT_MOCK.list_attached_role_policies = MagicMock(return_value=list_attached_role_pl)378 IAM_CLIENT_MOCK.get_policy = MagicMock(return_value=get_pl)379 IAM_CLIENT_MOCK.get_policy_version = MagicMock(return_value=get_pl_version)380 IAM_CLIENT_MOCK.list_role_policies = MagicMock(return_value={"PolicyNames": []})381 lambdaEvent = build_lambda_event()382 response = rule.lambda_handler(lambdaEvent, {})383 resp_expected = "COMPLIANT"384 assert_successful_evaluation(self, response, resp_expected)385 386 def test_NOT_COMPLIANT_action_logexactaction_managed(self):387 for state in [self.statement_list_all_in_three_with_deny, self.statement_list_all_in_three_with_bad_resource]:388 list_attached_role_pl = gen_policy_api(type="list_attached")389 get_pl = gen_policy_api(type="get_policy")390 get_pl_version = gen_policy_api(type="get_policy_version",statement_list=state)391 IAM_CLIENT_MOCK.list_attached_role_policies = MagicMock(return_value=list_attached_role_pl)392 IAM_CLIENT_MOCK.get_policy = MagicMock(return_value=get_pl)393 IAM_CLIENT_MOCK.get_policy_version = MagicMock(return_value=get_pl_version)394 IAM_CLIENT_MOCK.list_role_policies = MagicMock(return_value={"PolicyNames": []})395 lambdaEvent = build_lambda_event()396 response = rule.lambda_handler(lambdaEvent, {})397 resp_expected = "NON_COMPLIANT"...

Full Screen

Full Screen

test_iam.py

Source:test_iam.py Github

copy

Full Screen

...49 )50 role = client.get_role(RoleName=role_name)51 self.assertIn("Role", role)52 self.assertEqual(role_name, role["Role"]["RoleName"])53 client.get_role_policy(54 RoleName=role_name,55 PolicyName=policy_name56 )57 def test_create_service_role_already_exists(self):58 role_name = "ecsServiceRole"59 policy_name = "AmazonEC2ContainerServiceRolePolicy"60 with mock_iam():61 client = boto3.client("iam", region_name=REGION)62 client.create_role(63 RoleName=role_name,64 AssumeRolePolicyDocument=get_ecs_assumerole_policy().to_json()65 )66 self.assertTrue(67 create_ecs_service_role(68 context=self.context,69 provider=self.provider,70 )71 )72 role = client.get_role(RoleName=role_name)73 self.assertIn("Role", role)74 self.assertEqual(role_name, role["Role"]["RoleName"])75 client.get_role_policy(76 RoleName=role_name,77 PolicyName=policy_name...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful