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_secretObject



94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/etna/spec/vcr.rb', line 94

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) ⇒ 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
# File 'lib/etna/spec/vcr.rb', line 7

def setup_base_vcr(spec_helper_dir)
  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 :try_body do |request_1, request_2|
      if request_1.headers['Content-Type'].first =~ /application\/json/
        if request_2.headers['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.debug_logger = File.open('log/vcr_debug.log', 'w')

    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]
    }

    # Filter the authorization headers of any request by replacing any occurrence of that request's
    # Authorization value with <AUTHORIZATION>
    c.filter_sensitive_data('<AUTHORIZATION>') do |interaction|
      interaction.request.headers['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