parroty / exvcr

HTTP request/response recording library for elixir, inspired by VCR.
MIT License
720 stars 131 forks source link

Sensitive information isn't filtered for HTTP request made in Task #148

Closed A-Legg closed 4 years ago

A-Legg commented 4 years ago

Environment

Actual behavior

While recording http requests that are made outside of the test process, spawned tasks in this case, the call to ExVCR.Config.filter_sensitive_data/2 is not filtering out the sensitive data in the cassette.

Example test that has a request made in a task during the call to Vehicles.spawn_task_to_update_info/1:

    test "updates the price validation via a task" do
      use_cassette "price_validation_validate_vehicle_successful_task", [ignore_localhost: true, match_requests_on: [:query, :request_body]] do
        ExVCR.Config.filter_sensitive_data(API_KEY, "PACEHOLDER")
        ExVCR.Config.filter_request_headers("Authorization")
        ExVCR.Config.filter_request_options("basic_auth")
        ExVCR.Config.cassette_library_dir("fixtures/cassettes")

        vehicle = insert(:vehicle)
        Vehicles.spawn_task_to_update_info(vehicle)
      end
    end

The information is successfully filtered in all other cassettes.

Expected behavior

All sensitive data is filtered out of the cassette regardless of which process the request originated.

Odaeus commented 4 years ago

I have this problem as well but didn't realise it was due to the requests being made in a different process until I read your issue! Thanks for pointing that out.

After some digging I found a commit that added an undocumented option to persist the settings globally. If you set enable_global_settings: true in the ExVCR config, it will now apply the filters.

Personally, I think this should probably default to true as this problem is quite confusing and I would imagine having the filters applied globally is the expected behaviour.

A-Legg commented 4 years ago

@Odaeus My apologies for the delayed response, things have been super busy. Awesome find, thanks so much for taking the time!