Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test not published to Report Portal when docstring or parameter contains \0 #382

Closed
AlexLitvino opened this issue Nov 20, 2024 · 5 comments
Labels

Comments

@AlexLitvino
Copy link

Result for test is not published to Report Portal when \0 is contained in:

  • docstring
  • value for parameterization

Steps to Reproduce
Run the following tests with publishing result to Report Portal:

def test_with_slash_zero_in_docstring():
    """This test verifies publishing \0 to Report Portal"""
    pass

import pytest

@pytest.mark.parametrize('param', ['1\0',])
def test_with_param_with_slash_zero(param):
    pass

Expected behavior
Test result is published to Report Portal (test launch is created with test items inside).

Actual behavior
Test launch is created but they are empty, doesn't contain any tests.

Sniffing packets with WireShark, the following Start root(suite) item requests were sent for the 1st and the 2nd tests:
POST /api/v2/my_project/item
{"codeRef": "tests/test_example.py:test_with_slash_zero_in_docstring", "description": "This test verifies publishing \u0000 to Report Portal", "hasStats": true, "name": "tests/test_example.py::test_with_slash_zero_in_docstring", "retry": false, "retryOf": null, "startTime": "1732110741030", "testCaseId": "tests/test_example.py:test_with_slash_zero_in_docstring", "type": "STEP", "launchUuid": "b354fc52-5f18-4120-a864-3d531bab7077", "attributes": [], "parameters": null}

POST /api/v2/my_project/item
{"codeRef": "tests/test_example.py:test_with_param_with_slash_zero", "description": null, "hasStats": true, "name": "tests/test_example.py::test_with_param_with_slash_zero[1\x00]", "retry": false, "retryOf": null, "startTime": "1732111412360", "testCaseId": "tests/test_example.py:test_with_param_with_slash_zero[1\u0000]", "type": "STEP", "launchUuid": "4fd5a4cd-522e-495b-b356-1b6b00f35d36", "attributes": [], "parameters": [{"key": "param", "value": "1\u0000"}]}:

Package versions
pytest 8.3.2
pytest-reportportal 5.4.5
reportportal-client 5.5.9

Note that if \0 is placed at the end of docstring line, result is published to Report Portal, though request contains \u000:
"description": "This test verifies publishing \u0000"

Also general issue here might be not escaping back slash. For example for test

def test_with_docstring_with_slash_n():
    """Test to verify publishing with new line

    Precondition
    - Create file

    Action
    - Write string 'A\nB' to the file

    Result
    - File contains string 'A\nB'
    """
    pass

We get results as on image below. Not sure if it is should be separate issue.
TestResultWithNewLine
And because of usage expandtabs in trim_docstring function of pytest_reportportal we got 8 whitespaces instead of \t.

@HardNorth HardNorth added invalid and removed bug labels Dec 2, 2024
@HardNorth
Copy link
Member

@AlexLitvino \0 is not a text character, it is strictly binary one. So strictly, that many libraries use it to check if data is binary or text. And RP wasn't supposed to work with binary data. Also in general we do not modify data on client side, except some special cases, so it's your responsibility to sanitize it.

@AlexLitvino
Copy link
Author

@HardNorth , regarding \0 in docstrings I agree with you that it could be updated from our side.
But passing string with \0 in parameter value doesn't belong to docstrings, it's rather test data, so shouldn't it be fixed?

@pytest.mark.parametrize('param', ['1\0',])
def test_with_param_with_slash_zero(param):
    pass

I used such workaround for it, but it's not so obviously:

@pytest.mark.parametrize('param', ['test line with slash 0', 'another test line'])
def test_with_param_with_slash_zero(param):
    if param == 'test line with slash 0':
        param = '1\0'

@HardNorth
Copy link
Member

@AlexLitvino OK, I can add escaping of this symbol, but only this one.

@HardNorth HardNorth reopened this Dec 4, 2024
@HardNorth
Copy link
Member

@AlexLitvino
Copy link
Author

@HardNorth , thank you. Checked, everything ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants