def test_get_caller_identity_arn_from_a_execution_role(boto_session): sess = Session(boto_session) arn = 'arn:aws:sts::369233609183:assumed-role/AmazonSageMaker-ExecutionRole-20171129T072388/SageMaker' sess.boto_session.client('sts').get_caller_identity.return_value = {'Arn': arn} sess.boto_session.client('iam').get_role.return_value = {'Role': {'Arn': arn}} actual = sess.get_caller_identity_arn() assert actual == 'arn:aws:iam::369233609183:role/service-role/AmazonSageMaker-ExecutionRole-20171129T072388'
def test_get_caller_identity_arn_from_an_user(boto_session): sess = Session(boto_session) arn = 'arn:aws:iam::369233609183:user/mia' sess.boto_session.client('sts').get_caller_identity.return_value = {'Arn': arn} sess.boto_session.client('iam').get_role.return_value = {'Role': {'Arn': arn}} actual = sess.get_caller_identity_arn() assert actual == 'arn:aws:iam::369233609183:user/mia'
def test_get_caller_identity_arn_from_a_role(boto_session): sess = Session(boto_session) arn = 'arn:aws:sts::369233609183:assumed-role/SageMakerRole/6d009ef3-5306-49d5-8efc-78db644d8122' sess.boto_session.client('sts').get_caller_identity.return_value = {'Arn': arn} expected_role = 'arn:aws:iam::369233609183:role/SageMakerRole' sess.boto_session.client('iam').get_role.return_value = {'Role': {'Arn': expected_role}} actual = sess.get_caller_identity_arn() assert actual == expected_role
def test_get_caller_identity_arn_from_an_user_without_permissions(boto_session): sess = Session(boto_session) arn = 'arn:aws:iam::369233609183:user/mia' sess.boto_session.client('sts').get_caller_identity.return_value = {'Arn': arn} sess.boto_session.client('iam').get_role.side_effect = ClientError({}, {}) with patch('logging.Logger.warning') as mock_logger: actual = sess.get_caller_identity_arn() assert actual == 'arn:aws:iam::369233609183:user/mia' mock_logger.assert_called_once()
def test_get_caller_identity_arn_from_role_with_path(boto_session): sess = Session(boto_session) arn_prefix = 'arn:aws:iam::369233609183:role' role_name = 'name' sess.boto_session.client('sts').get_caller_identity.return_value = {'Arn': '/'.join([arn_prefix, role_name])} role_path = 'path' role_with_path = '/'.join([arn_prefix, role_path, role_name]) sess.boto_session.client('iam').get_role.return_value = {'Role': {'Arn': role_with_path}} actual = sess.get_caller_identity_arn() assert actual == role_with_path
def test_get_caller_identity_arn_from_a_execution_role(boto_session): sess = Session(boto_session) arn = 'arn:aws:sts::369233609183:assumed-role/AmazonSageMaker-ExecutionRole-20171129T072388/SageMaker' sess.boto_session.client('sts').get_caller_identity.return_value = { 'Arn': arn } sess.boto_session.client('iam').get_role.return_value = { 'Role': { 'Arn': arn } } actual = sess.get_caller_identity_arn() assert actual == 'arn:aws:iam::369233609183:role/service-role/AmazonSageMaker-ExecutionRole-20171129T072388'
def test_get_caller_identity_arn_from_an_user(boto_session): sess = Session(boto_session) arn = 'arn:aws:iam::369233609183:user/mia' sess.boto_session.client('sts').get_caller_identity.return_value = { 'Arn': arn } sess.boto_session.client('iam').get_role.return_value = { 'Role': { 'Arn': arn } } actual = sess.get_caller_identity_arn() assert actual == 'arn:aws:iam::369233609183:user/mia'
def test_get_caller_identity_arn_from_a_role(boto_session): sess = Session(boto_session) arn = 'arn:aws:sts::369233609183:assumed-role/SageMakerRole/6d009ef3-5306-49d5-8efc-78db644d8122' sess.boto_session.client('sts').get_caller_identity.return_value = { 'Arn': arn } expected_role = 'arn:aws:iam::369233609183:role/SageMakerRole' sess.boto_session.client('iam').get_role.return_value = { 'Role': { 'Arn': expected_role } } actual = sess.get_caller_identity_arn() assert actual == expected_role
def test_get_caller_identity_arn_from_a_execution_role(boto_session): sess = Session(boto_session) arn = "arn:aws:sts::369233609183:assumed-role/AmazonSageMaker-ExecutionRole-20171129T072388/SageMaker" sess.boto_session.client("sts").get_caller_identity.return_value = { "Arn": arn } sess.boto_session.client("iam").get_role.return_value = { "Role": { "Arn": arn } } actual = sess.get_caller_identity_arn() assert ( actual == "arn:aws:iam::369233609183:role/service-role/AmazonSageMaker-ExecutionRole-20171129T072388" )
def test_get_caller_identity_arn_from_role_with_path(boto_session): sess = Session(boto_session) arn_prefix = 'arn:aws:iam::369233609183:role' role_name = 'name' sess.boto_session.client('sts').get_caller_identity.return_value = { 'Arn': '/'.join([arn_prefix, role_name]) } role_path = 'path' role_with_path = '/'.join([arn_prefix, role_path, role_name]) sess.boto_session.client('iam').get_role.return_value = { 'Role': { 'Arn': role_with_path } } actual = sess.get_caller_identity_arn() assert actual == role_with_path
def test_get_caller_identity_arn_from_role_with_path(boto_session): sess = Session(boto_session) arn_prefix = "arn:aws:iam::369233609183:role" role_name = "name" sess.boto_session.client("sts").get_caller_identity.return_value = { "Arn": "/".join([arn_prefix, role_name]) } role_path = "path" role_with_path = "/".join([arn_prefix, role_path, role_name]) sess.boto_session.client("iam").get_role.return_value = { "Role": { "Arn": role_with_path } } actual = sess.get_caller_identity_arn() assert actual == role_with_path
def test_get_caller_identity_arn_from_a_role(boto_session): sess = Session(boto_session) arn = ( "arn:aws:sts::369233609183:assumed-role/SageMakerRole/6d009ef3-5306-49d5-8efc-78db644d8122" ) sess.boto_session.client("sts").get_caller_identity.return_value = { "Arn": arn } expected_role = "arn:aws:iam::369233609183:role/SageMakerRole" sess.boto_session.client("iam").get_role.return_value = { "Role": { "Arn": expected_role } } actual = sess.get_caller_identity_arn() assert actual == expected_role