diff --git a/tests/integration/test_aiohttp.py b/tests/integration/test_aiohttp.py index 0835c34..49cf993 100644 --- a/tests/integration/test_aiohttp.py +++ b/tests/integration/test_aiohttp.py @@ -440,3 +440,19 @@ def test_not_allow_redirects(tmpdir, mockbin): assert response.url.path == "/redirect/308/5" assert response.status == 308 assert cassette.play_count == 1 + + +def test_filter_query_parameters(tmpdir, httpbin): + url = httpbin + "?password=secret" + path = str(tmpdir.join("query_param_filter.yaml")) + + with vcr.use_cassette(path, filter_query_parameters=["password"]) as cassette: + get(url) + + assert "password" not in cassette.requests[0].url + assert "secret" not in cassette.requests[0].url + + with open(path) as f: + cassette_content = f.read() + assert "password" not in cassette_content + assert "secret" not in cassette_content diff --git a/tests/integration/test_filter.py b/tests/integration/test_filter.py index a6910f1..19d2f69 100644 --- a/tests/integration/test_filter.py +++ b/tests/integration/test_filter.py @@ -45,13 +45,18 @@ def test_filter_basic_auth(tmpdir, httpbin): def test_filter_querystring(tmpdir, httpbin): - url = httpbin.url + "/?foo=bar" + url = httpbin.url + "/?password=secret" cass_file = str(tmpdir.join("filter_qs.yaml")) - with vcr.use_cassette(cass_file, filter_query_parameters=["foo"]): + with vcr.use_cassette(cass_file, filter_query_parameters=["password"]): urlopen(url) - with vcr.use_cassette(cass_file, filter_query_parameters=["foo"]) as cass: + with vcr.use_cassette(cass_file, filter_query_parameters=["password"]) as cass: urlopen(url) - assert "foo" not in cass.requests[0].url + assert "password" not in cass.requests[0].url + assert "secret" not in cass.requests[0].url + with open(cass_file) as f: + cassette_content = f.read() + assert "password" not in cassette_content + assert "secret" not in cassette_content def test_filter_post_data(tmpdir, httpbin): diff --git a/vcr/stubs/aiohttp_stubs.py b/vcr/stubs/aiohttp_stubs.py index 7b8ddc9..50faf22 100644 --- a/vcr/stubs/aiohttp_stubs.py +++ b/vcr/stubs/aiohttp_stubs.py @@ -66,7 +66,7 @@ def build_response(vcr_request, vcr_response, history): headers=_deserialize_headers(vcr_request.headers), real_url=URL(vcr_request.url), ) - response = MockClientResponse(vcr_request.method, URL(vcr_response.get("url")), request_info=request_info) + response = MockClientResponse(vcr_request.method, URL(vcr_request.url), request_info=request_info) response.status = vcr_response["status"]["code"] response._body = vcr_response["body"].get("string", b"") response.reason = vcr_response["status"]["message"] @@ -163,7 +163,6 @@ async def record_response(cassette, vcr_request, response): "status": {"code": response.status, "message": response.reason}, "headers": _serialize_headers(response.headers), "body": body, - "url": str(response.url), } cassette.append(vcr_request, vcr_response)