예제 #1
0
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'
예제 #2
0
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'
예제 #3
0
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
예제 #4
0
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()
예제 #5
0
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
예제 #6
0
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'
예제 #7
0
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'
예제 #8
0
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
예제 #9
0
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"
    )
예제 #10
0
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
예제 #11
0
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
예제 #12
0
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