Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
auto_refresh=False,
region=None,
)
profiles = {
'role': {
'role_arn': 'myrolearn',
'source_profile': 'user',
},
'user': {
'aws_access_key_id': 'AKIA...',
'aws_secret_access_key': 'SECRET',
'mfa_serial': 'mymfaserial',
},
}
result = default_plugins.get_credentials(config, arguments, profiles)
aws_lib.get_session_token.assert_not_called()
aws_lib.assume_role.assert_called_with(
{ 'AccessKeyId': 'AKIA...', 'SecretAccessKey': 'SECRET', 'SessionToken': None, 'Region': None },
'myrolearn',
'mysessionname',
region=None,
external_id='myexternalid',
role_duration='43200',
mfa_serial='mymfaserial',
mfa_token='123123',
)
assert result == aws_lib.assume_role.return_value
auto_refresh=False,
region=None,
)
profiles = {
'role': {
'role_arn': 'myrolearn',
'source_profile': 'user',
},
'user': {
'aws_access_key_id': 'AKIA...',
'aws_secret_access_key': 'SECRET',
'mfa_serial': 'mymfaserial',
},
}
result = default_plugins.get_credentials(config, arguments, profiles)
aws_lib.get_session_token.assert_called_with(
{ 'AccessKeyId': 'AKIA...', 'SecretAccessKey': 'SECRET', 'SessionToken': None, 'Region': None },
region=None,
mfa_serial='mymfaserial',
mfa_token='123123',
ignore_cache=True,
)
assert result == aws_lib.get_session_token.return_value
auto_refresh=True,
region=None,
)
profiles = {
'role': {
'role_arn': 'myrolearn',
'source_profile': 'user',
},
'user': {
'aws_access_key_id': 'AKIA...',
'aws_secret_access_key': 'SECRET',
'mfa_serial': 'mymfaserial',
},
}
result = default_plugins.get_credentials(config, arguments, profiles)
aws_lib.get_session_token.assert_called_with(
{ 'AccessKeyId': 'AKIA...', 'SecretAccessKey': 'SECRET', 'SessionToken': None, 'Region': None },
region=None,
mfa_serial='mymfaserial',
mfa_token='123123',
ignore_cache=True,
)
aws_lib.assume_role.assert_called_with(
aws_lib.get_session_token.return_value,
'myrolearn',
'mysessionname',
region=None,
external_id='myexternalid',
role_duration=0,
)
assert result == aws_lib.assume_role.return_value
auto_refresh=True,
region=None,
)
profiles = {
'role': {
'role_arn': 'myrolearn',
'source_profile': 'user',
},
'user': {
'aws_access_key_id': 'AKIA...',
'aws_secret_access_key': 'SECRET',
'mfa_serial': 'mymfaserial',
},
}
with pytest.raises(SystemExit):
default_plugins.get_credentials(config, arguments, profiles)
safe_print.assert_called()
force_refresh=True,
auto_refresh=False,
region=None,
)
profiles = {
'role': {
'role_arn': 'myrolearn',
'source_profile': 'user',
},
'user': {
'aws_access_key_id': 'AKIA...',
'aws_secret_access_key': 'SECRET',
},
}
result = default_plugins.get_credentials(config, arguments, profiles)
aws_lib.get_session_token.assert_not_called()
aws_lib.assume_role.assert_called_with(
{ 'AccessKeyId': 'AKIA...', 'SecretAccessKey': 'SECRET', 'SessionToken': None, 'Region': None },
'myrolearn',
'mysessionname',
region=None,
external_id='myexternalid',
role_duration=0,
)
assert result == aws_lib.assume_role.return_value
force_refresh=True,
auto_refresh=False,
region=None,
)
profiles = {
'role': {
'role_arn': 'myrolearn',
'source_profile': 'user',
},
'user': {
'aws_access_key_id': 'AKIA...',
'aws_secret_access_key': 'SECRET',
},
}
result = default_plugins.get_credentials(config, arguments, profiles)
assert result == assume_role_from_cli.return_value
force_refresh=True,
auto_refresh=False,
region=None,
)
profiles = {
'role': {
'role_arn': 'myrolearn',
'source_profile': 'user',
},
'user': {
'aws_access_key_id': 'AKIA...',
'aws_secret_access_key': 'SECRET',
},
}
result = default_plugins.get_credentials(config, arguments, profiles)
aws_lib.get_session_token.assert_not_called()
aws_lib.assume_role.assert_not_called()
assert result == {
'AccessKeyId': 'AKIA...',
'SecretAccessKey': 'SECRET',
'SessionToken': None,
'Region': None,
}
auto_refresh=False,
region=None,
)
profiles = {
'role': {
'role_arn': 'myrolearn',
'source_profile': 'user',
},
'user': {
'aws_access_key_id': 'AKIA...',
'aws_secret_access_key': 'SECRET',
'mfa_serial': 'mymfaserial',
},
}
result = default_plugins.get_credentials(config, arguments, profiles)
aws_lib.get_session_token.assert_called_with(
{ 'AccessKeyId': 'AKIA...', 'SecretAccessKey': 'SECRET', 'SessionToken': None, 'Region': None },
region=None,
mfa_serial='mymfaserial',
mfa_token='123123',
ignore_cache=True,
)
aws_lib.assume_role.assert_called_with(
aws_lib.get_session_token.return_value,
'myrolearn',
'mysessionname',
region=None,
external_id='myexternalid',
role_duration=0,
)
assert result == aws_lib.assume_role.return_value