From 939bc37eabb9892e36f370e7b520b5caf09a8935 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Wed, 12 Jun 2024 16:08:05 +0200 Subject: [PATCH] test(vcr): automatically redact bearer tokens --- spec/support/vcr.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/support/vcr.rb b/spec/support/vcr.rb index cd86fba50..8ad4ebd34 100644 --- a/spec/support/vcr.rb +++ b/spec/support/vcr.rb @@ -4,4 +4,13 @@ VCR.configure do |c| c.cassette_library_dir = 'spec/fixtures/cassettes' c.configure_rspec_metadata! c.ignore_hosts 'test.host', 'chromedriver.storage.googleapis.com' + + c.filter_sensitive_data('redacted') do |interaction| + auth = interaction.request.headers['Authorization']&.first + next if auth.nil? + + if (match = auth.match(/^Bearer\s+([^,\s]+)/)) + match.captures.first + end + end end