Esempio n. 1
0
def test_parse_error_response_ssl(demisto_client_configure, mocker):
    """
    Given
        - An empty (no given input path) Uploader object
        - An API exception raised by SSL failure

    When
        - Parsing error response

    Then
        - Ensure a error message is parsed successfully
        - Verify SSL error message printed as expected
    """
    mocker.patch("builtins.print")
    file_type = "playbook"
    file_name = "SomePlaybookName.yml"
    api_exception = ApiException(reason="[SSL: CERTIFICATE_VERIFY_FAILED]")
    uploader = Uploader(input="", insecure=False, verbose=False)
    uploader._parse_error_response(error=api_exception, file_type=file_type, file_name=file_name)
    upload_failed_message = u"{}{}{}".format(
        LOG_COLORS.RED, f"\nUpload {file_type}: {file_name} failed:", LOG_COLORS.NATIVE
    )
    api_exception_message = u'{}{}{}'.format(
        LOG_COLORS.RED,
        "[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate.\n"
        "Try running the command with --insecure flag.",
        LOG_COLORS.NATIVE
    )
    # verify exactly 2 calls to print_error
    assert len(print.call_args_list) == 2
    assert print.call_args_list[0][0][0] == upload_failed_message
    assert print.call_args_list[1][0][0] == api_exception_message
Esempio n. 2
0
def test_parse_error_response_connection(demisto_client_configure, mocker):
    """
    Given
        - An empty (no given input path) Uploader object
        - An API exception raised by connection failure

    When
        - Parsing error response

    Then
        - Ensure a error message is parsed successfully
        - Verify connection error message printed as expected
    """
    mocker.patch("builtins.print")
    file_type = "widget"
    file_name = "SomeWidgetName.json"
    api_exception = ApiException(reason="Failed to establish a new connection:")
    uploader = Uploader(input="", insecure=False, verbose=False)
    uploader._parse_error_response(error=api_exception, file_type=file_type, file_name=file_name)
    upload_failed_message = u"{}{}{}".format(
        LOG_COLORS.RED, f"\nUpload {file_type}: {file_name} failed:", LOG_COLORS.NATIVE
    )
    api_exception_message = u'{}{}{}'.format(
        LOG_COLORS.RED,
        "Failed to establish a new connection: Connection refused.\n"
        "Try checking your BASE url configuration.",
        LOG_COLORS.NATIVE
    )
    # verify exactly 2 calls to print_error
    assert len(print.call_args_list) == 2
    assert print.call_args_list[0][0][0] == upload_failed_message
    assert print.call_args_list[1][0][0] == api_exception_message
Esempio n. 3
0
def test_parse_error_response_forbidden(demisto_client_configure, mocker):
    """
    Given
        - An empty (no given input path) Uploader object
        - An API exception raised by forbidden failure

    When
        - Parsing error response

    Then
        - Ensure a error message is parsed successfully
        - Verify forbidden error message printed as expected
    """
    mocker.patch("builtins.print")
    file_type = "incident field"
    file_name = "SomeIncidentFieldName.json"
    api_exception = ApiException(reason="Forbidden", )
    api_exception.body = json.dumps({"status": 403, "error": "Error message"})
    uploader = Uploader(input="", insecure=False, verbose=False)
    uploader._parse_error_response(error=api_exception,
                                   file_type=file_type,
                                   file_name=file_name)
    upload_failed_message = u"{}{}{}".format(
        LOG_COLORS.RED, f"\nUpload {file_type}: {file_name} failed:",
        LOG_COLORS.NATIVE)
    api_exception_message = u'{}{}{}'.format(
        LOG_COLORS.RED,
        "Error message\nTry checking your API key configuration.",
        LOG_COLORS.NATIVE)
    # verify exactly 2 calls to print_error
    assert len(print.call_args_list) == 2
    assert print.call_args_list[0][0][0] == upload_failed_message
    assert print.call_args_list[1][0][0] == api_exception_message