1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-09 17:15:35 +00:00

Fix for #174 to prevent filters from corrupting request

This commit is contained in:
Abram Clark
2023-05-18 19:38:32 +00:00
committed by Jair Henrique
parent 0e06836908
commit 3b41f0ede3
2 changed files with 22 additions and 1 deletions

View File

@@ -142,3 +142,24 @@ def test_decompress_regular(tmpdir, httpbin):
resp = urlopen(url).read()
assert_cassette_has_one_response(cass)
assert_is_json(resp)
def test_before_record_request_corruption(tmpdir, httpbin):
"""Modifying request in before_record_request should not affect outgoing request"""
def before_record(request):
request.headers.clear()
request.body = b""
return request
req = Request(
httpbin.url + "/post",
data=urlencode({"test": "exists"}).encode(),
headers={"X-Test": "exists"},
)
cass_file = str(tmpdir.join("modified_response.yaml"))
with vcr.use_cassette(cass_file, before_record_request=before_record):
resp = json.loads(urlopen(req).read())
assert resp["headers"]["X-Test"] == "exists"
assert resp["form"]["test"] == "exists"

View File

@@ -219,7 +219,7 @@ class VCR:
filter_functions.extend(before_record_request)
def before_record_request(request):
request = copy.copy(request)
request = copy.deepcopy(request)
for function in filter_functions:
if request is None:
break