Skip to content

Instantly share code, notes, and snippets.

@raphaelfruneaux
Last active January 19, 2022 19:34
Show Gist options
  • Select an option

  • Save raphaelfruneaux/a878a2b6ad3d8d98ef98dd71ab1fa3b8 to your computer and use it in GitHub Desktop.

Select an option

Save raphaelfruneaux/a878a2b6ad3d8d98ef98dd71ab1fa3b8 to your computer and use it in GitHub Desktop.

Revisions

  1. raphaelfruneaux revised this gist Jun 21, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion vcr_replacer.py
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ def clean_sensitive_data_from_request(response):
    content = response["content"]

    if isinstance(content, str):
    content = json.loads(response["content"])
    content = json.loads(content)

    updated = False
    for field in SENSITIVE_FIELDS:
  2. raphaelfruneaux created this gist Jun 21, 2021.
    39 changes: 39 additions & 0 deletions vcr_replacer.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    import json
    import pytest

    REPLACEMENT_VALUE = "fake"

    SENSITIVE_FIELDS = (
    "client-id",
    "client-secret",
    "access_token",
    "Authorization",
    )


    def clean_sensitive_data_from_request(response):
    content = response["content"]

    if isinstance(content, str):
    content = json.loads(response["content"])

    updated = False
    for field in SENSITIVE_FIELDS:
    if field in content:
    content[field] = REPLACEMENT_VALUE
    updated = True

    if updated:
    response["content"] = json.dumps(content)

    return response



    @pytest.fixture(scope="module")
    def vcr_config():
    return {
    "filter_headers": [("authorization", REPLACEMENT_VALUE)],
    "filter_query_parameters": [("access_token", REPLACEMENT_VALUE)],
    "before_record_response": clean_sensitive_data_from_request,
    }