tshield 0.11.7.0 → 0.11.8.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 +45 -44
- data/lib/tshield.rb +1 -0
- data/lib/tshield/matching/filters.rb +7 -1
- data/lib/tshield/request_matching.rb +5 -0
- data/lib/tshield/version.rb +1 -1
- data/spec/tshield/fixtures/matching/example.json +18 -0
- data/spec/tshield/request_matching_spec.rb +37 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2f5af220b6e8aed08b79c006af7975d48416a651c24345b30d20ac7db67e5ca
|
4
|
+
data.tar.gz: a1cc446bac420e431ec099b027c624e33bb5bcd8291605bdd6876d5aaa04b0b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4bcbfd8ce65cac9dfb6db41879f9237b6aa26b865b5fb9fee27423ea2352a81d5bf713812b2699d5656df933f2bfe96546ad5cd767b0177cf41226dfc7e2539
|
7
|
+
data.tar.gz: 18b671f8d124aa3237051ed9e516054ddb466510a192107c9016cdba8e11111d770e1603e788daa13218ec8f02dac13d73b14e6a4da7c19463805b0c9431758c
|
data/README.md
CHANGED
@@ -10,22 +10,22 @@ TShield
|
|
10
10
|
## API mocks for development and testing
|
11
11
|
TShield is an open source proxy for mocks API responses.
|
12
12
|
|
13
|
-
*
|
14
|
-
*
|
15
|
-
*
|
16
|
-
*
|
17
|
-
*
|
13
|
+
* REST
|
14
|
+
* SOAP
|
15
|
+
* Session manager to separate multiple scenarios (success, error, sucess variation, ...)
|
16
|
+
* Lightweight
|
17
|
+
* MIT license
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
*
|
22
|
-
*
|
23
|
-
*
|
24
|
-
*
|
25
|
-
*
|
26
|
-
*
|
27
|
-
*
|
28
|
-
*
|
19
|
+
## Table of Contents
|
20
|
+
|
21
|
+
* [Basic Usage](#basic-usage)
|
22
|
+
* [Config options for Pattern Matching](#config-options-for-pattern-matching)
|
23
|
+
* [Config options for VCR](#config-options-for-vcr)
|
24
|
+
* [Manage Sessions](#manage-sessions)
|
25
|
+
* [Custom controllers](#custom-controllers)
|
26
|
+
* [Features](#features)
|
27
|
+
* [Examples](#examples)
|
28
|
+
* [Contributing](#contributing)
|
29
29
|
|
30
30
|
## Basic Usage
|
31
31
|
### Install
|
@@ -42,8 +42,8 @@ Default port is `4567`
|
|
42
42
|
|
43
43
|
#### Command Line Options
|
44
44
|
|
45
|
-
*
|
46
|
-
*
|
45
|
+
* **-port**: Overwrite default port (4567)
|
46
|
+
* **-help**: Show all command line options
|
47
47
|
|
48
48
|
#### Config example
|
49
49
|
|
@@ -75,37 +75,38 @@ All files should be in `matching` directory.
|
|
75
75
|
Each file should be a valid JSON array of objects and each object must contain
|
76
76
|
at least the following attributes:
|
77
77
|
|
78
|
-
*
|
79
|
-
*
|
80
|
-
*
|
78
|
+
* **method**: a http method.
|
79
|
+
* **path**: url path. This attribute accept regex, see example in [regex.json](https://github.com/diegorubin/tshield/blob/master/component_tests/matching/examples/regex.json)
|
80
|
+
* **response**: object with response data. Into session can be used an array of objects to return different responses like vcr mode. See example: [multiples_response.json](https://github.com/diegorubin/tshield/blob/master/component_tests/matching/examples/multiple_response.json). External file can be used as body content, see example in [file.json](https://github.com/diegorubin/tshield/blob/master/component_tests/matching/examples/file.json).
|
81
81
|
|
82
82
|
Response must be contain the following attributes:
|
83
83
|
|
84
|
-
*
|
85
|
-
|
86
|
-
*
|
87
|
-
*
|
84
|
+
* **headers**: key value object with expected headers to match. In the evaluation process
|
85
|
+
this stub will be returned if all headers are in request.
|
86
|
+
* **status**: integer used http status respose.
|
87
|
+
* **body**: content to be returned.
|
88
88
|
|
89
89
|
Optional request attributes:
|
90
90
|
|
91
|
-
*
|
92
|
-
|
93
|
-
*
|
91
|
+
* **headers**: key value object with expected headers to match. In the evaluation process
|
92
|
+
this stub will be returned if all headers are in request.
|
93
|
+
* **query**: works like headers but use query params.
|
94
94
|
|
95
|
-
|
95
|
+
**Important**: If VCR config conflicts with Matching config Matching will be
|
96
96
|
used. Matching config have priority.
|
97
97
|
|
98
98
|
### Session Configuration
|
99
99
|
|
100
100
|
To register stub into a session create an object with following attributes:
|
101
101
|
|
102
|
-
*
|
103
|
-
*
|
102
|
+
* **session**: name of session.
|
103
|
+
* **stubs**: an array with objects described above.
|
104
104
|
|
105
105
|
### Example of matching configuration
|
106
106
|
|
107
107
|
```json
|
108
|
-
[
|
108
|
+
[
|
109
|
+
{
|
109
110
|
"method": "GET",
|
110
111
|
"path": "/matching/example",
|
111
112
|
"query": {
|
@@ -205,19 +206,19 @@ domains:
|
|
205
206
|
- /users
|
206
207
|
```
|
207
208
|
**request**
|
208
|
-
*
|
209
|
-
*
|
209
|
+
* **timeout**: wait time for real service in seconds
|
210
|
+
* **verify_ssl**: ignores invalid ssl if false
|
210
211
|
|
211
212
|
**domain**
|
212
|
-
*
|
213
|
-
*
|
214
|
-
*
|
215
|
-
*
|
216
|
-
*
|
217
|
-
*
|
218
|
-
*
|
219
|
-
*
|
220
|
-
*
|
213
|
+
* Define Base URI of service
|
214
|
+
* **name**: Name to identify the domain in the generated files
|
215
|
+
* **headers**: github-issue #17
|
216
|
+
* **not_save_headers**: List of headers that should be ignored in generated file
|
217
|
+
* **skip_query_params**: List of query params that should be ignored in generated file
|
218
|
+
* **cache_request**: <<some_description>>
|
219
|
+
* **filters**: Implementation of before or after filters used in domain requests
|
220
|
+
* **excluded_headers**: <<some_description>>
|
221
|
+
* **paths**: Paths list of all services that will be called. Used to filter what domain will "receive the request"
|
221
222
|
|
222
223
|
## Manage Sessions
|
223
224
|
|
@@ -282,8 +283,8 @@ This features files are used as base for the component tests.
|
|
282
283
|
#### Basic example for a client app requesting an API
|
283
284
|
[examples/client-api-nodejs](examples/client-api-nodejs)
|
284
285
|
|
285
|
-
#### Basic example for component/acceptance test
|
286
|
-
|
286
|
+
#### Basic example for component/acceptance test using tshield sessions
|
287
|
+
[examples/component-test](examples/component-test)
|
287
288
|
|
288
289
|
## Contributing
|
289
290
|
[Hacking or Contributing to TShield](CONTRIBUTING.md)
|
data/lib/tshield.rb
CHANGED
@@ -23,8 +23,14 @@ module TShield
|
|
23
23
|
stubs.select { |stub| Filters.include_query(stub['query'], @options[:raw_query] || '') }
|
24
24
|
end
|
25
25
|
|
26
|
+
def filter_by_path(stubs)
|
27
|
+
stubs.each do |key, value|
|
28
|
+
return value if @path =~ /^#{key}$/
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
26
32
|
def filter_stubs(stubs)
|
27
|
-
result = filter_by_query(filter_by_headers(filter_by_method(stubs
|
33
|
+
result = filter_by_query(filter_by_headers(filter_by_method(filter_by_path(stubs))))
|
28
34
|
result[0]['response'] unless result.empty?
|
29
35
|
end
|
30
36
|
|
@@ -87,9 +87,14 @@ module TShield
|
|
87
87
|
|
88
88
|
def read_body(content)
|
89
89
|
return content.to_json if content.is_a? Hash
|
90
|
+
return read_file_content(content) if content =~ %r{^FILE://}
|
90
91
|
|
91
92
|
content
|
92
93
|
end
|
94
|
+
|
95
|
+
def read_file_content(content)
|
96
|
+
File.open(File.join('matching', content.gsub('FILE://', '')), 'r').read
|
97
|
+
end
|
93
98
|
end
|
94
99
|
end
|
95
100
|
end
|
data/lib/tshield/version.rb
CHANGED
@@ -53,6 +53,24 @@
|
|
53
53
|
"body": "post content"
|
54
54
|
}
|
55
55
|
},
|
56
|
+
{
|
57
|
+
"method": "GET",
|
58
|
+
"path": "/matching/file.txt",
|
59
|
+
"response": {
|
60
|
+
"status": 200,
|
61
|
+
"headers": {},
|
62
|
+
"body": "FILE://body.json"
|
63
|
+
}
|
64
|
+
},
|
65
|
+
{
|
66
|
+
"method": "GET",
|
67
|
+
"path": "/matching/regex/\\d+",
|
68
|
+
"response": {
|
69
|
+
"status": 200,
|
70
|
+
"headers": {},
|
71
|
+
"body": "stub with regex"
|
72
|
+
}
|
73
|
+
},
|
56
74
|
{
|
57
75
|
"method": "GET",
|
58
76
|
"path": "/matching/twice",
|
@@ -160,6 +160,43 @@ describe TShield::RequestMatching do
|
|
160
160
|
expect(response.status).to eql(200)
|
161
161
|
end
|
162
162
|
end
|
163
|
+
context 'on match have file reference' do
|
164
|
+
before :each do
|
165
|
+
request_matching = TShield::RequestMatching
|
166
|
+
.new('/matching/file.txt',
|
167
|
+
method: 'GET')
|
168
|
+
|
169
|
+
file_content_double = double
|
170
|
+
allow(File).to receive(:join).with('matching', 'body.json')
|
171
|
+
.and_return('matching/body.json')
|
172
|
+
allow(File).to receive(:open).with('matching/body.json', 'r')
|
173
|
+
.and_return(file_content_double)
|
174
|
+
|
175
|
+
allow(file_content_double).to receive(:read).and_return("line1\nline2")
|
176
|
+
|
177
|
+
@response = request_matching.match_request
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'should return content of file' do
|
181
|
+
expect(@response.body).to eql("line1\nline2")
|
182
|
+
expect(@response.headers).to eql({})
|
183
|
+
expect(@response.status).to eql(200)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
context 'on match with regex' do
|
187
|
+
before :each do
|
188
|
+
@response = request_matching = TShield::RequestMatching
|
189
|
+
.new('/matching/regex/1234',
|
190
|
+
method: 'GET').match_request
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'should return content of file' do
|
194
|
+
expect(@response.body).to eql('stub with regex')
|
195
|
+
expect(@response.headers).to eql({})
|
196
|
+
expect(@response.status).to eql(200)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
163
200
|
context 'on not match' do
|
164
201
|
before :each do
|
165
202
|
@request_matching = TShield::RequestMatching.new('/')
|
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.11.
|
4
|
+
version: 0.11.8.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: 2019-09-
|
12
|
+
date: 2019-09-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: byebug
|