tshield 0.13.2.0 → 0.13.3.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 +2 -0
- data/lib/tshield/configuration.rb +5 -0
- data/lib/tshield/controllers/requests.rb +8 -1
- data/lib/tshield/version.rb +1 -1
- data/spec/tshield/configuration_spec.rb +33 -5
- data/spec/tshield/controllers/requests_spec.rb +92 -0
- data/spec/tshield/fixtures/config/tshield-with-send-content-type-header.yml +18 -0
- data/spec/tshield/fixtures/config/tshield-with-send-content-type-header_as_false.yml +18 -0
- metadata +14 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff8ebc5fc00636cb1f4a14e64c431db07fc5b018
|
4
|
+
data.tar.gz: 2a3931e85a3869b2f39b19512352117bf664c750
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d6affb50388b0f3e39b13806c5079c19f708a9d62f6bff8b89f70c21ec02ff19b33e9f635b6aee9398525bea000bfbd6efa1aed3f3de1f5b5279c6a0c2761d7
|
7
|
+
data.tar.gz: 7c3646904d2f38a5f4d608b9f76e3355c26e311eb2ac2518d09eb5e4a139bdddc506a41ce0078b395dddf551c775e7b654a00a15e8de9734ac97033772de90d3
|
data/README.md
CHANGED
@@ -192,6 +192,7 @@ domains:
|
|
192
192
|
headers:
|
193
193
|
HTTP_AUTHORIZATION: Authorization
|
194
194
|
HTTP_COOKIE: Cookie
|
195
|
+
send_header_content_type: true
|
195
196
|
not_save_headers:
|
196
197
|
- transfer-encoding
|
197
198
|
cache_request: <<value>>
|
@@ -235,6 +236,7 @@ domains:
|
|
235
236
|
* Define Base URI of service
|
236
237
|
* **name**: Name to identify the domain in the generated files
|
237
238
|
* **headers**: github-issue #17
|
239
|
+
* **send_header_content_type**: Boolean domain config to send header 'Content-Type' when requesting this domain
|
238
240
|
* **not_save_headers**: List of headers that should be ignored in generated file
|
239
241
|
* **skip_query_params**: List of query params that should be ignored in generated file
|
240
242
|
* **cache_request**: <<some_description>>
|
@@ -100,6 +100,11 @@ module TShield
|
|
100
100
|
domains[domain]['not_save_headers'] || []
|
101
101
|
end
|
102
102
|
|
103
|
+
def send_header_content_type(domain)
|
104
|
+
return domains[domain]['send_header_content_type'] != false if domains[domain]
|
105
|
+
true
|
106
|
+
end
|
107
|
+
|
103
108
|
def read_session_path
|
104
109
|
session_path || '/sessions'
|
105
110
|
end
|
@@ -57,6 +57,8 @@ module TShield
|
|
57
57
|
ip: request.ip
|
58
58
|
}
|
59
59
|
|
60
|
+
treat_headers_by_domain(options, path)
|
61
|
+
|
60
62
|
if %w[POST PUT PATCH].include? method
|
61
63
|
result = request.body.read.encode('UTF-8',
|
62
64
|
invalid: :replace,
|
@@ -74,7 +76,7 @@ module TShield
|
|
74
76
|
configuration.get_excluded_headers(domain(path)).include?(key)
|
75
77
|
end
|
76
78
|
end
|
77
|
-
|
79
|
+
|
78
80
|
logger.info(
|
79
81
|
"original=#{api_response.original} method=#{method} path=#{path} "\
|
80
82
|
"content-type=#{request_content_type} "\
|
@@ -94,6 +96,11 @@ module TShield
|
|
94
96
|
end
|
95
97
|
end
|
96
98
|
|
99
|
+
def treat_headers_by_domain(options, path)
|
100
|
+
@send_header_content_type = configuration.send_header_content_type(domain(path))
|
101
|
+
options[:headers].delete('Content-Type') unless @send_header_content_type
|
102
|
+
end
|
103
|
+
|
97
104
|
def configuration
|
98
105
|
@configuration ||= TShield::Configuration.singleton
|
99
106
|
end
|
data/lib/tshield/version.rb
CHANGED
@@ -108,14 +108,42 @@ describe TShield::Configuration do
|
|
108
108
|
|
109
109
|
context 'on config exists without grpc entry' do
|
110
110
|
before :each do
|
111
|
-
|
112
|
-
|
113
|
-
.and_return('spec/tshield/fixtures/config/tshield-without-grpc.yml')
|
114
|
-
allow(TShield::Options).to receive(:instance).and_return(options_instance)
|
115
|
-
@configuration = TShield::Configuration.singleton
|
111
|
+
@configuration = generate_configuration_from_file('spec/tshield/fixtures/config/tshield-without-grpc.yml')
|
112
|
+
TShield::Configuration.clear
|
116
113
|
end
|
117
114
|
it 'should set default value for port' do
|
118
115
|
expect(@configuration.grpc).to eql('port' => 5678, 'proto_dir' => 'proto', 'services' => {})
|
119
116
|
end
|
120
117
|
end
|
118
|
+
|
119
|
+
context 'on config property request.domains.domain.send_header_content_type does not exists' do
|
120
|
+
before :each do
|
121
|
+
@configuration = generate_configuration_from_file('spec/tshield/fixtures/config/tshield-without-grpc.yml')
|
122
|
+
TShield::Configuration.clear
|
123
|
+
end
|
124
|
+
it 'should return send_header_content_type as true when property is not set' do
|
125
|
+
expect(@configuration.send_header_content_type('example.org')).to be true
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context 'on config property request.domains.domain.send_header_content_type does exists' do
|
130
|
+
before :each do
|
131
|
+
TShield::Configuration.clear
|
132
|
+
end
|
133
|
+
it 'should return send_header_content_type as true when property is true' do
|
134
|
+
@configuration = generate_configuration_from_file('spec/tshield/fixtures/config/tshield-with-send-content-type-header.yml')
|
135
|
+
expect(@configuration.send_header_content_type('example.org')).to be true
|
136
|
+
end
|
137
|
+
it 'should return send_header_content_type as false when property is false' do
|
138
|
+
@configuration = generate_configuration_from_file('spec/tshield/fixtures/config/tshield-with-send-content-type-header_as_false.yml')
|
139
|
+
expect(@configuration.send_header_content_type('example.org')).to be false
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def generate_configuration_from_file(file)
|
145
|
+
options_instance = double
|
146
|
+
allow(options_instance).to receive(:configuration_file).and_return(file)
|
147
|
+
allow(TShield::Options).to receive(:instance).and_return(options_instance)
|
148
|
+
TShield::Configuration.singleton
|
121
149
|
end
|
@@ -58,3 +58,95 @@ describe TShield::Controllers::Requests do
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
61
|
+
|
62
|
+
describe TShield::Controllers::Requests do
|
63
|
+
before :each do
|
64
|
+
@configuration = double
|
65
|
+
allow(TShield::Configuration)
|
66
|
+
.to receive(:singleton).and_return(@configuration)
|
67
|
+
allow(@configuration).to receive(:get_before_filters).and_return([])
|
68
|
+
allow(@configuration).to receive(:not_save_headers).and_return([])
|
69
|
+
allow(@configuration).to receive(:get_after_filters).and_return([])
|
70
|
+
allow(@configuration).to receive(:get_headers).and_return([])
|
71
|
+
allow(@configuration).to receive(:request).and_return('timeout' => 10)
|
72
|
+
allow(@configuration).to receive(:get_name).and_return('example.org')
|
73
|
+
allow(@configuration).to receive(:get_domain_for).and_return('example.org')
|
74
|
+
allow(@configuration).to receive(:get_delay).and_return(0)
|
75
|
+
|
76
|
+
|
77
|
+
allow(TShield::Options).to receive_message_chain(:instance, :break?)
|
78
|
+
@mock_logger = double
|
79
|
+
@controller = MockController.new(@mock_logger)
|
80
|
+
end
|
81
|
+
context 'when send_header_content_type is false for a single domain' do
|
82
|
+
it 'should remove application/json header when making a request' do
|
83
|
+
params = { 'captures' => ['/'] }
|
84
|
+
request = double
|
85
|
+
matcher = double
|
86
|
+
matched_response = double
|
87
|
+
|
88
|
+
allow(@configuration).to receive(:send_header_content_type).and_return(false)
|
89
|
+
allow(request).to receive(:request_method).and_return('GET')
|
90
|
+
allow(request).to receive(:content_type).and_return('application/json')
|
91
|
+
allow(request).to receive(:ip).and_return('0.0.0.0')
|
92
|
+
allow(request).to receive(:env).and_return('QUERY_STRING' => 'a=b')
|
93
|
+
allow(TShield::RequestMatching).to receive(:new).and_return(matcher)
|
94
|
+
allow(matcher).to receive(:match_request).and_return(nil)
|
95
|
+
allow(TShield::RequestVCR).to receive(:new).and_return(matcher)
|
96
|
+
allow(matcher).to receive(:vcr_response).and_return(matched_response)
|
97
|
+
allow(matched_response).to receive(:original).and_return(false)
|
98
|
+
allow(matched_response).to receive(:status).and_return(200)
|
99
|
+
allow(matched_response).to receive(:headers).and_return({})
|
100
|
+
allow(matched_response).to receive(:body).and_return('')
|
101
|
+
allow(@mock_logger).to receive(:info)
|
102
|
+
|
103
|
+
expect(TShield::RequestVCR).to receive(:new).with("/",{
|
104
|
+
call: 0,
|
105
|
+
headers: {},
|
106
|
+
ip: "0.0.0.0",
|
107
|
+
method: "GET",
|
108
|
+
raw_query: "a=b",
|
109
|
+
secondary_sessions: nil,
|
110
|
+
session: nil
|
111
|
+
})
|
112
|
+
@controller.treat(params, request, nil)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'when send_header_content_type is true for a single domain' do
|
117
|
+
it 'should NOT remove application/json header when making a request' do
|
118
|
+
params = { 'captures' => ['/'] }
|
119
|
+
request = double
|
120
|
+
matcher = double
|
121
|
+
matched_response = double
|
122
|
+
|
123
|
+
allow(@configuration).to receive(:send_header_content_type).and_return(true)
|
124
|
+
allow(request).to receive(:request_method).and_return('GET')
|
125
|
+
allow(request).to receive(:content_type).and_return('application/json')
|
126
|
+
allow(request).to receive(:ip).and_return('0.0.0.0')
|
127
|
+
allow(request).to receive(:env).and_return('QUERY_STRING' => 'a=b')
|
128
|
+
allow(TShield::RequestMatching).to receive(:new).and_return(matcher)
|
129
|
+
allow(matcher).to receive(:match_request).and_return(nil)
|
130
|
+
allow(TShield::RequestVCR).to receive(:new).and_return(matcher)
|
131
|
+
allow(matcher).to receive(:vcr_response).and_return(matched_response)
|
132
|
+
allow(matched_response).to receive(:original).and_return(false)
|
133
|
+
allow(matched_response).to receive(:status).and_return(200)
|
134
|
+
allow(matched_response).to receive(:headers).and_return({})
|
135
|
+
allow(matched_response).to receive(:body).and_return('')
|
136
|
+
allow(@mock_logger).to receive(:info)
|
137
|
+
|
138
|
+
expect(TShield::RequestVCR).to receive(:new).with("/",{
|
139
|
+
call: 0,
|
140
|
+
headers: {'Content-Type' => 'application/json'},
|
141
|
+
ip: "0.0.0.0",
|
142
|
+
method: "GET",
|
143
|
+
raw_query: "a=b",
|
144
|
+
secondary_sessions: nil,
|
145
|
+
session: nil
|
146
|
+
})
|
147
|
+
|
148
|
+
|
149
|
+
@controller.treat(params, request, nil)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
---
|
2
|
+
request:
|
3
|
+
timeout: 0
|
4
|
+
domains:
|
5
|
+
'example.org':
|
6
|
+
name: 'example.org'
|
7
|
+
send_header_content_type: true
|
8
|
+
filters:
|
9
|
+
- 'ExampleFilter'
|
10
|
+
paths:
|
11
|
+
- '/api/one'
|
12
|
+
- '/api/two'
|
13
|
+
skip_query_params:
|
14
|
+
- 'a'
|
15
|
+
'example.com':
|
16
|
+
name: 'example.com'
|
17
|
+
paths:
|
18
|
+
- '/api/three'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
---
|
2
|
+
request:
|
3
|
+
timeout: 0
|
4
|
+
domains:
|
5
|
+
'example.org':
|
6
|
+
name: 'example.org'
|
7
|
+
send_header_content_type: false
|
8
|
+
filters:
|
9
|
+
- 'ExampleFilter'
|
10
|
+
paths:
|
11
|
+
- '/api/one'
|
12
|
+
- '/api/two'
|
13
|
+
skip_query_params:
|
14
|
+
- 'a'
|
15
|
+
'example.com':
|
16
|
+
name: 'example.com'
|
17
|
+
paths:
|
18
|
+
- '/api/three'
|
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.3.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: 2021-
|
12
|
+
date: 2021-02-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: grpc
|
@@ -430,6 +430,8 @@ files:
|
|
430
430
|
- spec/tshield/after_filter_spec.rb
|
431
431
|
- spec/tshield/configuration_spec.rb
|
432
432
|
- spec/tshield/controllers/requests_spec.rb
|
433
|
+
- spec/tshield/fixtures/config/tshield-with-send-content-type-header.yml
|
434
|
+
- spec/tshield/fixtures/config/tshield-with-send-content-type-header_as_false.yml
|
433
435
|
- spec/tshield/fixtures/config/tshield-without-grpc.yml
|
434
436
|
- spec/tshield/fixtures/config/tshield.yml
|
435
437
|
- spec/tshield/fixtures/filters/example_filter.rb
|
@@ -467,16 +469,18 @@ specification_version: 4
|
|
467
469
|
summary: Proxy for mocks API responses
|
468
470
|
test_files:
|
469
471
|
- spec/spec_helper.rb
|
472
|
+
- spec/tshield/sessions_spec.rb
|
473
|
+
- spec/tshield/configuration_spec.rb
|
474
|
+
- spec/tshield/controllers/requests_spec.rb
|
470
475
|
- spec/tshield/fixtures/matching/example.json
|
471
|
-
- spec/tshield/fixtures/
|
476
|
+
- spec/tshield/fixtures/proto/test_services_pb.rb
|
477
|
+
- spec/tshield/fixtures/config/tshield-with-send-content-type-header.yml
|
478
|
+
- spec/tshield/fixtures/config/tshield-with-send-content-type-header_as_false.yml
|
472
479
|
- spec/tshield/fixtures/config/tshield.yml
|
480
|
+
- spec/tshield/fixtures/config/tshield-without-grpc.yml
|
473
481
|
- spec/tshield/fixtures/filters/example_filter.rb
|
474
|
-
- spec/tshield/fixtures/proto/test_services_pb.rb
|
475
|
-
- spec/tshield/options_spec.rb
|
476
|
-
- spec/tshield/configuration_spec.rb
|
477
|
-
- spec/tshield/sessions_spec.rb
|
478
|
-
- spec/tshield/request_matching_spec.rb
|
479
|
-
- spec/tshield/controllers/requests_spec.rb
|
480
482
|
- spec/tshield/grpc_spec.rb
|
481
|
-
- spec/tshield/request_vcr_spec.rb
|
482
483
|
- spec/tshield/after_filter_spec.rb
|
484
|
+
- spec/tshield/request_vcr_spec.rb
|
485
|
+
- spec/tshield/request_matching_spec.rb
|
486
|
+
- spec/tshield/options_spec.rb
|