2016-04-26 34 views
0

根據我在讀什麼在這裏:https://relishapp.com/vcr/vcr/v/1-11-3/docs/configuration/filter-sensitive-data過濾用VCR敏感數據後,重新運行規範失敗,壞的URI錯誤

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

這有悖於以上段落來自文檔。我究竟做錯了什麼?

在此先感謝您的幫助。

路易絲

回答

0

filter_sensitive_data是兩種方法的包裝:before_recordbefore_playback。我可以用這些方法來查找和替換用戶名和密碼在互動 - 寫入YAML文件之前,先和播放卡帶回來的時候重新運行測試之前的第二位。

此鏈接:https://groups.google.com/forum/#!searchin/vcr-ruby/sensitive/vcr-ruby/uSm8HDBiWYw/OWIJk2_krVMJ,特別是從邁倫馬斯頓的評論,提供了一個大致的輪廓,我再修改,以適應我的特定API調用。