mr_muscle
mr_muscle

Reputation: 2900

Hiding sensitive data in VCR

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.

Upvotes: 2

Views: 1721

Answers (1)

fphilipe
fphilipe

Reputation: 10054

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 ', '')
}

Upvotes: 2

Related Questions