使用 VCR 过滤敏感数据后,重新 运行 规范因错误的 URI 错误而失败

After filtering sensitive data using VCR, re-running the spec fails with bad URI error

根据我在这里阅读的内容:https://relishapp.com/vcr/vcr/v/1-11-3/docs/configuration/filter-sensitive-data

When the interactions are replayed, the sensitive text will replace the substitution string so that the interaction will be identical to what was originally recorded.

我的 vcr_setup.rb 文件如下所示:

require 'vcr'

VCR.config do |c|
  c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
  c.stub_with :fakeweb
  c.default_cassette_options = { :record => :once }

  c.filter_sensitive_data("<DOMAIN>") do |interaction|
     interaction.request.uri.split(":")[1][2..-1]
   end

   c.filter_sensitive_data("<PASSWORD>") do |interaction|
     interaction.request.uri.split(":")[2].split("@")[0]
   end
end

interaction.request.uri 看起来像这样(替换了敏感信息):

"https://<my_secret_domain>:<my_secret_password>@services.someprovider.com:443/enterprise/composite/some_api_call"

在我 运行 我的 rspec 第一次测试后,盒式磁带正确显示:

uri: https://<DOMAIN>:<PASSWORD>@services.someprovider.com:443/enterprise/composite/some_api_call

然而,当我再次尝试 运行 测试时,出现了这个错误:

Failure/Error: VCR.use_cassette("#{provider_name}_mail_dispatcher_points_already_awarded", record: :all) do
 URI::InvalidURIError:
   bad URI(is not URI?): https://<DOMAIN>:<PASSWORD>@services.someprovider.com:443/enterprise/composite/some_api_call
 # ./spec/models/mail_dispatcher_spec.rb:130:in `block (3 levels) in <top (required)>'

这与文档中的上述段落相反。我究竟做错了什么?

在此先感谢您的帮助。

路易丝

filter_sensitive_data 是两个方法的包装器:before_recordbefore_playback。我能够使用这些方法在交互中查找和替换用户名和密码 - 第一个是在写入 YAML 文件之前,第二个是在重新 运行 测试时播放磁带之前。

link:https://groups.google.com/forum/#!searchin/vcr-ruby/sensitive/vcr-ruby/uSm8HDBiWYw/OWIJk2_krVMJ,尤其是 Myron Marston 的评论,提供了一个粗略的轮廓,然后我对其进行了修改以适应我的特定 API 调用。