Example #1
0
def test_read_auth_profile_invalid_json_payload_raises_exception(mocker):
    import json

    req_params: typing.Dict = {
        "auth_profile": "testProfile",
        "iam_access_key_id": "testAccessKey",
        "iam_secret_key": "someSecretKey",
        "iam_session_token": "someToken",
        "info": RedshiftProperty(),
    }

    req_params["info"].put("region", "us-east-1")

    mock_redshift_client: MagicMock = MagicMock()
    mock_redshift_client.describe_authentication_profiles.return_value = {
        "AuthenticationProfiles": [{
            "AuthenticationProfileContent": "{{{{"
        }]
    }
    mocker.patch("boto3.client", return_value=mock_redshift_client)

    with pytest.raises(
            ProgrammingError,
            match=
            "Unable to decode the JSON content of the Redshift authentication profile"
    ):
        IamHelper.read_auth_profile(**req_params)
Example #2
0
def test_read_auth_profile_loads_json_payload(mocker):
    import json

    req_params: typing.Dict = {
        "auth_profile": "testProfile",
        "iam_access_key_id": "testAccessKey",
        "iam_secret_key": "someSecretKey",
        "iam_session_token": "someToken",
        "info": RedshiftProperty(),
    }

    req_params["info"].put("region", "us-east-1")

    mock_payload: typing.Dict[str, str] = {
        "region": "someTestRegion",
        "cluster_identifier": "someCluster"
    }

    mock_redshift_client: MagicMock = MagicMock()
    mock_redshift_client.describe_authentication_profiles.return_value = {
        "AuthenticationProfiles": [{
            "AuthenticationProfileContent":
            json.dumps(mock_payload)
        }]
    }
    mocker.patch("boto3.client", return_value=mock_redshift_client)

    result = IamHelper.read_auth_profile(**req_params)
    assert result.region == mock_payload["region"]
    assert result.cluster_identifier == mock_payload["cluster_identifier"]
Example #3
0
def test_read_auth_profile_raises_exception_if_profile_dne(mocker):
    from botocore import exceptions  # type: ignore

    req_params: typing.Dict = {
        "auth_profile": "testProfile",
        "iam_access_key_id": "testAccessKey",
        "iam_secret_key": "someSecretKey",
        "iam_session_token": "someToken",
        "info": RedshiftProperty(),
    }

    req_params["info"].put("region", "us-east-1")

    mock_redshift_client: MagicMock = MagicMock()
    mock_redshift_client.describe_authentication_profiles.side_effect = exceptions.ClientError(
        operation_name="ErrorOp", error_response=MagicMock())
    mocker.patch("boto3.client", return_value=mock_redshift_client)

    with pytest.raises(
            InterfaceError,
            match=
            "Unable to retrieve contents of Redshift authentication profile from server"
    ):
        IamHelper.read_auth_profile(**req_params)