Top Level Namespace
Defined Under Namespace
Modules: Enum, Etna, StrongConfirmation, WithEtnaClients, WithLogger
Classes: DirectedGraph, EnvironmentScoped, EtnaApp, String
Constant Summary
collapse
- WithEtnaClientsByEnvironment =
EnvironmentScoped.new do
include WithEtnaClients
end
Instance Method Summary
collapse
Instance Method Details
#prepare_vcr_secret ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/etna/spec/vcr.rb', line 113
def prepare_vcr_secret
secret = ENV["CI_SECRET"]
if (secret.nil? || secret.empty?) && ENV['IS_CI'] != '1'
current_example = RSpec.current_example
RSpec::Core::Pending.mark_pending! current_example, 'CI_SECRET must be set to run this test'
raise "CI_SECRET must be set to run this test"
end
digest = Digest::SHA256.new
digest.update(secret)
digest.digest
end
|
#setup_base_vcr(spec_helper_dir, server: nil, application: nil) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
|
# File 'lib/etna/spec/vcr.rb', line 7
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_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
request_1_json == request_2_json
else
false
end
else
request_1.body == request_2.body
end
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, :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
|