2

In a recorded cassette from VCR gem I've got:

http_interactions:
- request:
    method: get
    uri: https://nme_site/rest/api/2/search?.a_lot_of_data
    body:
      encoding: US-ASCII
      string: ''
    headers:
      Accept:
      - application/json
      Accept-Encoding:
      - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
      User-Agent:
      - Ruby
      Authorization:
      - Basic ZGV345646543653

How to hide Authorization: - Basic ZGV345646543653 ?

I was trying to:

config.filter_sensitive_data('<AUTH>') { 'http_interactions.request.Authorization' } but it won't worked.

mr_muscle
  • 2,536
  • 18
  • 61

1 Answers1

2

Based on the docs on #filter_sensitive_data, this should do it:

config.filter_sensitive_data('<AUTH>') { |interaction|
  interaction.request.headers['Authorization']
}

This will replace Basic ZGV345646543653 with <AUTH>.

If you only want to replace ZGV345646543653 so the header reads Basic <AUTH>, then you'd need this:

config.filter_sensitive_data('<AUTH>') { |interaction|
  interaction.request.headers['Authorization'].sub('Basic ', '')
}
fphilipe
  • 9,739
  • 1
  • 40
  • 52
  • 2
    unfortunately it doesn't work, still received those values – mr_muscle Feb 26 '20 at 16:03
  • 2
    `interaction.request.headers['Authorization']` returns an `Array`, not `String`, so you need to do `interaction.request.headers['Authorization'][0]`. – Kris May 17 '22 at 15:54