25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/etna/spec/vcr.rb', line 25
def setup_base_vcr(spec_helper_dir, server: nil, application: nil)
VCR.configure do |c|
c.hook_into :webmock
c.cassette_serializers
c.cassette_library_dir = ::File.join(spec_helper_dir, 'fixtures', 'cassettes')
c.allow_http_connections_when_no_cassette = true
c.register_request_matcher :verify_uri_route do |request_1, request_2|
next true if server.nil? || application.nil?
route_match = request_1.uri =~ /https:\/\/#{application.dev_route}(.*)/
if route_match && route_match[1]
def request_1.request_method
method.to_s.upcase
end
def request_1.path
URI(uri).path
end
!!server.find_route(request_1)
else
true
end
end
c.register_request_matcher :try_uri do |request_1, request_2|
clean_query(request_1.uri) == clean_query(request_2.uri)
end
c.register_request_matcher :try_body do |request_1, request_2|
if request_1.['Content-Type'].first =~ /application\/json/
if request_2.['Content-Type'].first =~ /application\/json/
request_1_json = begin
JSON.parse(request_1.body) rescue 'not-json'
end
request_2_json = begin
JSON.parse(request_2.body) rescue 'not-json'
end
clean_query(request_1_json) == clean_query(request_2_json)
else
false
end
else
request_1.body == request_2.body
end
end
if File.exists?('log')
c.debug_logger = File.open('log/vcr_debug.log', 'w')
end
c.default_cassette_options = {
serialize_with: :compressed,
record: if ENV['IS_CI'] == '1'
:none
else
ENV['RERECORD'] ? :all : :once
end,
match_requests_on: [:method, :try_uri, :try_body, :verify_uri_route]
}
c.filter_sensitive_data('<AUTHORIZATION>') do |interaction|
interaction.request.['Authorization'].first
end
c.before_record do |interaction|
key = prepare_vcr_secret
if interaction.response.body && !interaction.response.body.empty?
cipher = OpenSSL::Cipher.new("AES-256-CBC")
iv = cipher.random_iv
cipher.encrypt
cipher.key = key
cipher.iv = iv
encrypted = cipher.update(interaction.response.body)
encrypted << cipher.final
interaction.response.body = [iv, encrypted].pack('mm')
end
end
c.before_playback do |interaction|
key = prepare_vcr_secret
if interaction.response.body && !interaction.response.body.empty?
iv, encrypted = interaction.response.body.unpack('mm')
cipher = OpenSSL::Cipher.new("AES-256-CBC")
cipher.decrypt
cipher.key = key
cipher.iv = iv
plain = cipher.update(encrypted)
plain << cipher.final
interaction.response.body = plain
end
end
end
require 'multipartable'
def Multipartable.secure_boundary
"--THIS-IS-STABLE-FOR-TESTING"
end
end
|