Skip to content

filter_sensitive_data doesn't work with dynamic query parameter substitution #1040

@jscheid

Description

@jscheid

When using filter_sensitive_data with a value extracted dynamically from a query parameter, the cassette fails to replay, apparently because VCR is comparing the URL without substitution to the sanitized one.

There's a simple workaround, but in an ideal world it wouldn't be necessary:

match_requests_on: [VCR.request_matchers.uri_without_param(:secret)]

Here is a failing test case:

diff --git a/spec/lib/vcr/configuration_spec.rb b/spec/lib/vcr/configuration_spec.rb
index 5e555e5..85701a9 100644
--- a/spec/lib/vcr/configuration_spec.rb
+++ b/spec/lib/vcr/configuration_spec.rb
@@ -158,6 +158,20 @@ RSpec.describe VCR::Configuration do
         end
       end
     end
+
+    specify 'the filter_sensitive_data option works with dynamic query parameters' do
+      VCR.configure do |c|
+        c.filter_sensitive_data('<SECRET>') do |interaction|
+          Rack::Utils.parse_query(URI(interaction.request.uri).query)['secret']
+        end
+      end
+
+      2.times do
+        VCR.use_cassette("example") do
+          ::Net::HTTP.get_response(URI("http://localhost:#{VCR::SinatraApp.port}/foo?secret=1234"))
+        end
+      end
+    end
   end
 
   [:before_record, :before_playback].each do |hook_type|

I've tried fixing this but got lost in hooks...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions