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 +4 -4
- data/README.md +1 -1
- data/lib/tshield/request_vcr.rb +19 -0
- data/lib/tshield/server.rb +2 -2
- data/lib/tshield/version.rb +1 -1
- data/spec/spec_helper.rb +4 -2
- data/spec/tshield/request_vcr_spec.rb +44 -0
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87b26d114e278df9af5848487fbe41a5783b69e9
|
4
|
+
data.tar.gz: 36fd3d713a4c30d82631d7141c83154c90659281
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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)
|
data/lib/tshield/request_vcr.rb
CHANGED
@@ -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,
|
data/lib/tshield/server.rb
CHANGED
@@ -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'] = '
|
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
|
|
data/lib/tshield/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -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.
|
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:
|
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/
|
481
|
+
- spec/tshield/request_vcr_spec.rb
|
482
|
+
- spec/tshield/after_filter_spec.rb
|