kiwicom / pytest-recording

A pytest plugin that allows recording network interactions via VCR.py
MIT License
425 stars 34 forks source link

Filter sensitive data from response/how to use `before_record_response`? #94

Closed ghost closed 1 year ago

ghost commented 2 years ago

One of my cassettes makes a call to an authorization endpoint and therefore has sensitive data (access_token, etc) in the response body. Is there a way to filter the sensitive data from the response body, similar to the before_record_response function in vcr.py? I tried calling that function from my code but it didn't work: @pytest.mark.vcr(before_record_response=lambda r: None).

psdon commented 1 year ago

Use vcr_config

@pytest.fixture(scope="module")
def vcr_config():
    return {
        "filter_headers": [
            "Authorization"
        ]
    }
Stranger6667 commented 1 year ago

Indeed, the vcr_config fixture should be used for this purpose

akaihola commented 1 year ago

Indeed, the vcr_config fixture should be used for this purpose

The before_record_response option in vcr_config? How and why would it behave differently than when passed to the decorator?