tshield 0.13.1.0 → 0.13.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 00416e9ccddf713260cb56ce47d99ed396a52c4f
4
- data.tar.gz: bb284f26697e5846e87c7f613adc1b7f197cbb1e
3
+ metadata.gz: 87b26d114e278df9af5848487fbe41a5783b69e9
4
+ data.tar.gz: 36fd3d713a4c30d82631d7141c83154c90659281
5
5
  SHA512:
6
- metadata.gz: 93446eabb0d14f55d8f492b360b1b89a2ff98df607289b2ec6271b78e05d4eed70407ef386ec3b3aa72cbee8bff3217729614b2004d89fb153a9d680c2a02762
7
- data.tar.gz: 69cadb4c11b0219aab6b30cbcad5ed00e9bd99cc60921554034368fa58b804d31f11a0e9bd13ecaff51d9e535601bb92d5bdf2952bb2d0bac1b98e9e0e5bd660
6
+ metadata.gz: 5bd5f43cc13647026b199ad55ab149b842d6bbedae8dcfccb9a345dcc99abb72c132641ede6cd80bff36bd7e5e9123deb8dde882c4573b2d441a8c9c3e430df9
7
+ data.tar.gz: 956d0f30dcf1c57ba98e3488deb0d8d80367c8c5ffa6c5b6c383eed282bf17f679463df5403e93ba17033ca1dcb8bfc69afe3deeff778a44b9431b47089c7f47
data/README.md CHANGED
@@ -3,7 +3,7 @@ TShield
3
3
 
4
4
  [![Build Status](https://travis-ci.org/diegorubin/tshield.svg)](https://travis-ci.org/diegorubin/tshield)
5
5
  [![Coverage Status](https://coveralls.io/repos/github/diegorubin/tshield/badge.svg?branch=master)](https://coveralls.io/github/diegorubin/tshield?branch=master)
6
- [![SourceLevel](https://app.sourcelevel.io/github/diegorubin/tshield.svg)](https://app.sourcelevel.io/github/diegorubin/tshield)
6
+ [![SourceLevel](https://app.sourcelevel.io/github/diegorubin/-/tshield.svg)](https://app.sourcelevel.io/github/diegorubin/-/tshield)
7
7
  [![Join the chat at https://gitter.im/diegorubin/tshield](https://badges.gitter.im/diegorubin/tshield.svg)](https://gitter.im/diegorubin/tshield?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
8
8
  [![Gem Version](https://badge.fury.io/rb/tshield.svg)](https://badge.fury.io/rb/tshield)
9
9
  ![TShield Publish](https://github.com/diegorubin/tshield/workflows/TShield%20Publish/badge.svg)
@@ -78,12 +78,31 @@ module TShield
78
78
  @method ||= @options[:method].downcase
79
79
  end
80
80
 
81
+ def apply_set_cookie_header_values(raw_response, headers = {})
82
+
83
+ headers_clone = headers.clone
84
+
85
+ field = raw_response.get_fields('Set-Cookie')
86
+
87
+ if !field.nil? && !field.empty?
88
+ cookies_values = []
89
+ field.each { |value| cookies_values.push(value) }
90
+ headers_clone['Set-Cookie'] = cookies_values
91
+ end
92
+
93
+ headers_clone
94
+ end
95
+
81
96
  def save(raw_response)
82
97
  headers = {}
98
+
83
99
  raw_response.headers.each do |k, v|
100
+ next if k == 'set-cookie'
84
101
  headers[k] = v unless configuration.not_save_headers(domain).include? k
85
102
  end
86
103
 
104
+ headers = apply_set_cookie_header_values(raw_response, headers)
105
+
87
106
  content = {
88
107
  body: raw_response.body,
89
108
  status: raw_response.code,
@@ -29,9 +29,9 @@ module TShield
29
29
 
30
30
  options '*' do
31
31
  response.headers['Allow'] = 'GET, PUT, POST, DELETE, OPTIONS'
32
- response.headers['Access-Control-Allow-Headers'] = 'Authorization, Content-Type,
33
- Accept, X-User-Email, X-Auth-Token'
32
+ response.headers['Access-Control-Allow-Headers'] = '*'
34
33
  response.headers['Access-Control-Allow-Origin'] = '*'
34
+ response.headers['Access-Control-Allow-Methods'] = '*'
35
35
  200
36
36
  end
37
37
 
@@ -5,7 +5,7 @@ module TShield
5
5
  class Version
6
6
  MAJOR = 0
7
7
  MINOR = 13
8
- PATCH = 1
8
+ PATCH = 2
9
9
  PRE = 0
10
10
 
11
11
  class << self
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: false
2
2
 
3
- require 'coveralls'
4
- Coveralls.wear!
3
+ if ENV['COVERALLS_REPO_TOKEN']
4
+ require 'coveralls'
5
+ Coveralls.wear!
6
+ end
5
7
 
6
8
  require 'bundler/setup'
7
9
  Bundler.setup
@@ -10,6 +10,7 @@ describe TShield::RequestVCR do
10
10
  allow(TShield::Configuration)
11
11
  .to receive(:singleton).and_return(@configuration)
12
12
  allow(@configuration).to receive(:get_before_filters).and_return([])
13
+ allow(@configuration).to receive(:not_save_headers).and_return([])
13
14
  allow(@configuration).to receive(:get_after_filters).and_return([])
14
15
  allow(@configuration).to receive(:request).and_return('timeout' => 10)
15
16
  allow(@configuration).to receive(:get_domain_for).and_return('example.org')
@@ -35,6 +36,24 @@ describe TShield::RequestVCR do
35
36
  TShield::RequestVCR.new '/', method: 'GET'
36
37
  end
37
38
 
39
+ it 'should write response headers as multiple occcurences when has more than one with same key' do
40
+ allow_any_instance_of(TShield::RequestVCR).to receive(:exists)
41
+ .and_return(false)
42
+ allow_any_instance_of(TShield::RequestVCR).to receive(:destiny)
43
+ allow(HTTParty).to receive(:send).and_return(RawResponseCookiesMultipleValues.new)
44
+
45
+ write_spy = double
46
+ allow(File).to receive(:open).and_return(write_spy)
47
+
48
+ expect(write_spy).to receive(:write).ordered.with('this is the body')
49
+ expect(write_spy).to receive(:write)
50
+ .ordered
51
+ .with("{\n \"status\": 200,\n \"headers\": {\n \"Set-Cookie\": [\n \"FirstCookie=An Value\",\n \"SecondCookie=An Value\"\n ]\n }\n}")
52
+ allow(write_spy).to receive(:close)
53
+
54
+ TShield::RequestVCR.new '/', method: 'GET'
55
+ end
56
+
38
57
  describe 'and query params exists in list to skip' do
39
58
  before :each do
40
59
  allow(@configuration).to receive(:get_name).and_return('example.org')
@@ -144,8 +163,33 @@ describe TShield::RequestVCR do
144
163
  'this is the body'
145
164
  end
146
165
 
166
+ def get_fields(field = "")
167
+ []
168
+ end
169
+
147
170
  def code
148
171
  200
149
172
  end
150
173
  end
174
+
175
+ class RawResponseCookiesMultipleValues
176
+ def headers
177
+ {'Set-Cookie' => ['FirstCookie=An Value', 'SecondCookie=An Value']}
178
+ end
179
+
180
+ def body
181
+ 'this is the body'
182
+ end
183
+
184
+ def get_fields(field = "")
185
+ self.headers[filed] unless self.headers.key?(field)
186
+ end
187
+
188
+ def code
189
+ 200
190
+ end
191
+ end
192
+
151
193
  end
194
+
195
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tshield
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.1.0
4
+ version: 0.13.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diego Rubin
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-12-10 00:00:00.000000000 Z
12
+ date: 2021-01-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: grpc
@@ -466,17 +466,17 @@ signing_key:
466
466
  specification_version: 4
467
467
  summary: Proxy for mocks API responses
468
468
  test_files:
469
+ - spec/spec_helper.rb
469
470
  - spec/tshield/fixtures/matching/example.json
470
- - spec/tshield/fixtures/config/tshield.yml
471
471
  - spec/tshield/fixtures/config/tshield-without-grpc.yml
472
+ - spec/tshield/fixtures/config/tshield.yml
472
473
  - spec/tshield/fixtures/filters/example_filter.rb
473
474
  - spec/tshield/fixtures/proto/test_services_pb.rb
475
+ - spec/tshield/options_spec.rb
474
476
  - spec/tshield/configuration_spec.rb
475
477
  - spec/tshield/sessions_spec.rb
476
- - spec/tshield/request_vcr_spec.rb
477
- - spec/tshield/options_spec.rb
478
- - spec/tshield/after_filter_spec.rb
479
478
  - spec/tshield/request_matching_spec.rb
480
479
  - spec/tshield/controllers/requests_spec.rb
481
480
  - spec/tshield/grpc_spec.rb
482
- - spec/spec_helper.rb
481
+ - spec/tshield/request_vcr_spec.rb
482
+ - spec/tshield/after_filter_spec.rb