Best Python code snippet using localstack_python
test_password_policy.py
Source:test_password_policy.py
...36 if srv_error.status != 404:37 raise srv_error38 # Update the policy and check it back39 test_min_length = 8840 iam.update_account_password_policy(minimum_password_length=test_min_length)41 new_policy = iam.get_account_password_policy()42 new_min_length = new_policy['get_account_password_policy_response']\43 ['get_account_password_policy_result']['password_policy']\44 ['minimum_password_length']45 if test_min_length != int(new_min_length):46 raise Exception("Failed to update account password policy")47 # Delete the policy and check the correct deletion48 test_policy = ''49 iam.delete_account_password_policy()50 try:51 test_policy = iam.get_account_password_policy()52 except boto.exception.BotoServerError as srv_error:53 test_policy = None54 if srv_error.status != 404:55 raise srv_error56 if test_policy is not None:57 raise Exception("Failed to delete account password policy")58 # Restore initial account password policy59 if initial_policy:60 p = initial_policy['get_account_password_policy_response']\61 ['get_account_password_policy_result']['password_policy']62 iam.update_account_password_policy(minimum_password_length=int(p['minimum_password_length']),63 allow_users_to_change_password=bool(p['allow_users_to_change_password']),64 hard_expiry=bool(p['hard_expiry']),65 max_password_age=int(p['max_password_age']),66 password_reuse_prevention=int(p['password_reuse_prevention']),67 require_lowercase_characters=bool(p['require_lowercase_characters']),68 require_numbers=bool(p['require_numbers']),69 require_symbols=bool(p['require_symbols']),...
iam.py
Source:iam.py
...35 return dict(PasswordPolicy={})36 else:37 e.response.pop('ResponseMetadata')38 return e.response39def update_account_password_policy(region, account, dryrun=True, policy_attributes=None):40 '''41 orgcrawler -r OrganizationAccountAccessRole --service iam orgcrawler.untested_payload.iam.update_account_password_policy True42 '''43 client = boto3.client('iam', region_name=region, **account.credentials)44 '''45 print('dryrun:',dryrun)46 print('policy_attributes:',policy_attributes)47 '''48 cis_standard = {49 'MinimumPasswordLength': 8,50 'RequireSymbols': True,51 'RequireNumbers': True,52 'RequireUppercaseCharacters': True,53 'RequireLowercaseCharacters': True,54 'AllowUsersToChangePassword': True,55 'MaxPasswordAge': 180,56 'PasswordReusePrevention': 24,57 'HardExpiry': False,58 }59 if policy_attributes is None:60 policy_attributes = cis_standard61 if dryrun is True:62 current_state = get_account_password_policy(region, account)63 return dict(Dryrun={64 'CurrentPasswordPolicy': current_state.get('PasswordPolicy'),65 'ProposedPasswordPolicy': policy_attributes,66 })67 else:68 try:69 response = client.update_account_password_policy(**policy_attributes)70 return dict(HTTPStatusCode=response['ResponseMetadata']['HTTPStatusCode'])71 except ClientError as e:72 e.response.pop('ResponseMetadata')73 return e.response74def delete_account_password_policy(region, account, dryrun=True):75 '''76 orgcrawler -r OrganizationAccountAccessRole --service iam orgcrawler.untested_payload.iam.delete_account_password_policy77 '''78 client = boto3.client('iam', region_name=region, **account.credentials)79 if dryrun:80 return dict(Dryrun='No action')81 else:82 try:83 response = client.delete_account_password_policy()...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!