Filtering sensitive data with VCR

折月煮酒 提交于 2019-12-03 11:24:48
VCR.configure do |c|
  c.filter_sensitive_data("<SOMESITE_PASSWORD>") do
    ENV['SOMESITE_PASSWORD']
    # or $credentials['somesite']['password'] or whatever
  end
end

Essentially, you give VCR a bit of placeholder text, and then the block needs to return the real password, reading it from whatever the canonical password "repository" is.

Note that the real password is only needed the first time, when the request is recorded; on subsequent runs, it can be a fake password (as long as it's the same fake password used by the code making the request).

for rails 4+, if you are using secrets.yml you might want to do

VCR.configure do |config|
  Rails.application.secrets.each do |k,v|
    config.filter_sensitive_data("ENV[#{k}]") { v }
  end
end

now you're sure not to forget any

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!