pinch_hitter 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.ruby-version +1 -1
- data/.travis.yml +7 -3
- data/Changelog +33 -29
- data/features/replay.feature +11 -0
- data/features/step_definitions/replay_steps.rb +16 -7
- data/features/step_definitions/response_steps.rb +1 -1
- data/features/step_definitions/verify_requests_steps.rb +3 -3
- data/lib/pinch_hitter/message/message_store.rb +1 -1
- data/lib/pinch_hitter/service/endpoint_handlers.rb +4 -0
- data/lib/pinch_hitter/service/replay_ws.rb +14 -8
- data/lib/pinch_hitter/service/runner.rb +1 -1
- data/lib/pinch_hitter/version.rb +1 -1
- data/test/message_assertions.rb +1 -1
- data/test/test_pinch_hitter.rb +1 -0
- data/test/test_service.rb +8 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 45eba7bb747442209e486b0747ad30254f8d40b6c56b6e580f209462bdff2db6
|
4
|
+
data.tar.gz: ac50532874df051f1f66787550261b26c3ed6ef38f28ad5ba180fc074c5ba8c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07b7050e60f69ab498294084f174343986f2acbef493c6b102ad7cf7c7121c3d56cc80e6e0b1e2e2ffb374f983ac95c01838f3a15aaec9b0e0bba14a2a107916
|
7
|
+
data.tar.gz: 9e8c48398060dea6ad6b1373295246775d74fbc7bb87ddc654ede2f8b0853465774f647e798e79b319c2cdbdb6daf71f8b523ee71b07aff332fee4c987804569
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.
|
1
|
+
ruby-2.7.0
|
data/.travis.yml
CHANGED
data/Changelog
CHANGED
@@ -1,43 +1,47 @@
|
|
1
|
-
===
|
2
|
-
|
1
|
+
=== release 0.7.0 / 2020-02-16
|
2
|
+
* Disable request security (#16) - Thanks @nwallace!
|
3
|
+
* Return 404 for exhausted/unconfigured endpoints (#14) - Thanks @nwallace!
|
3
4
|
|
4
|
-
===
|
5
|
-
|
5
|
+
=== release 0.6.0 / 2016-06-14
|
6
|
+
* removed references to 1.9.2 which has long been eol'd. - thanks @garyjohnson!
|
7
|
+
* remove dependency on nokogiri
|
6
8
|
|
7
|
-
=== Release 0.
|
8
|
-
Add ability to
|
9
|
+
=== Release 0.5.6 / 2016-03-19
|
10
|
+
* Add ability to disable cache control (useful for IE testing)
|
11
|
+
* Allow client to register a module that will hydrate the response object.
|
12
|
+
* Break apart recording and responding to better support full response payloads
|
9
13
|
|
10
|
-
=== Release 0.
|
11
|
-
*
|
12
|
-
* Support PUT, PATCH, DELETE
|
14
|
+
=== Release 0.5.5 / 2015-11-5
|
15
|
+
* Allow Cross-Origin requests
|
13
16
|
|
14
|
-
=== Release 0.5 /
|
15
|
-
*
|
17
|
+
=== Release 0.5.4 / 2015-11-5
|
18
|
+
* Add require for Net::HTTP as some rubies can't resolve it properly - Thanks
|
19
|
+
@kumichou!
|
20
|
+
* Convert JSON back to JSON after applying overrides - Thanks Tim Conner!
|
16
21
|
|
17
|
-
=== Release 0.5.
|
18
|
-
*
|
22
|
+
=== Release 0.5.3 / 2015-8-14
|
23
|
+
* Add ability to silence the sintatra/webrick output and keep it out of the
|
24
|
+
test logs.
|
19
25
|
|
20
26
|
=== Release 0.5.2 / 2014-8-8
|
21
27
|
* Fix edge case where storing simple messages would fail without a messages
|
22
28
|
directory. Thanks to Dan Parks and Nathan Wallace for pointing it out!
|
23
29
|
|
24
|
-
=== Release 0.5.
|
25
|
-
*
|
26
|
-
test logs.
|
30
|
+
=== Release 0.5.1 / 2014-7-3
|
31
|
+
* Travis revealed some test issues with newer gems. Thanks Travis CI!
|
27
32
|
|
28
|
-
=== Release 0.5
|
29
|
-
*
|
30
|
-
@kumichou!
|
31
|
-
* Convert JSON back to JSON after applying overrides - Thanks Tim Conner!
|
33
|
+
=== Release 0.5 / 2014-7-3
|
34
|
+
* Fix issue where priming large messages would cause a 500
|
32
35
|
|
33
|
-
=== Release 0.
|
34
|
-
*
|
36
|
+
=== Release 0.4 / 2014-3-3
|
37
|
+
* Add ability to retrieve requests made by the application
|
38
|
+
* Support PUT, PATCH, DELETE
|
35
39
|
|
36
|
-
=== Release 0.
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
+
=== Release 0.3 / 2013-3-22
|
41
|
+
Add ability to register modules for custom message handling
|
42
|
+
|
43
|
+
=== Release 0.2 / 2013-1-27
|
44
|
+
Switch json to do overrides by key rather than path (like xml)
|
40
45
|
|
41
|
-
=== Release 0.
|
42
|
-
|
43
|
-
* Remove dependency on nokogiri
|
46
|
+
=== Release 0.1 / 2013-1-20
|
47
|
+
Initial release of the gem
|
data/features/replay.feature
CHANGED
@@ -40,3 +40,14 @@ Feature: Test WS replay
|
|
40
40
|
Given I have a car reservation I want to delete
|
41
41
|
When I delete a car reservation
|
42
42
|
Then I should see a car reservation cancellation
|
43
|
+
|
44
|
+
Scenario: Unconfigured routes respond with Page Not Found
|
45
|
+
When I make a reservation for a car rental I never set up
|
46
|
+
Then I see that the car reservation was not found
|
47
|
+
|
48
|
+
Scenario: Exhausted routes respond with Page Not Found
|
49
|
+
Given I want a car rental
|
50
|
+
When I make a reservation
|
51
|
+
Then I see a car reservation
|
52
|
+
When I make a reservation again
|
53
|
+
Then I see that the car reservation was not found
|
@@ -6,12 +6,16 @@ Given /^I want a car rental$/ do
|
|
6
6
|
mock.prime '/car_rental', :car_rental
|
7
7
|
end
|
8
8
|
|
9
|
-
When /^I make a reservation
|
9
|
+
When /^I make a reservation(?: again)?$/ do
|
10
10
|
@response = app.post '/car_rental', '{"reservation": "yes"}'
|
11
11
|
end
|
12
12
|
|
13
|
+
When /^I make a reservation for a car rental I never set up$/ do
|
14
|
+
@response = app.post '/car_rental_bogus', '{"reservation": "yes"}'
|
15
|
+
end
|
16
|
+
|
13
17
|
Then /^I see a car reservation$/ do
|
14
|
-
@response.body.to_s.
|
18
|
+
expect(@response.body.to_s).to eq messages.load(:car_rental).squish
|
15
19
|
end
|
16
20
|
|
17
21
|
Given /^I want a car rental with a "(.*?)" of "(.*?)"$/ do |tag, text|
|
@@ -19,7 +23,12 @@ Given /^I want a car rental with a "(.*?)" of "(.*?)"$/ do |tag, text|
|
|
19
23
|
end
|
20
24
|
|
21
25
|
Then /^I see a car reservation with a "(.*?)" of "(.*?)"$/ do |tag, text|
|
22
|
-
@response.body.to_s.
|
26
|
+
expect(@response.body.to_s).to eq messages.load(:car_rental, { tag => text }).squish
|
27
|
+
end
|
28
|
+
|
29
|
+
Then /^I see that the car reservation was not found$/ do
|
30
|
+
expect(@response.code).to eq "404"
|
31
|
+
expect(@response.body).to eq ""
|
23
32
|
end
|
24
33
|
|
25
34
|
Given /^I want to lookup a definition$/ do
|
@@ -31,7 +40,7 @@ When /^I query the glossary$/ do
|
|
31
40
|
end
|
32
41
|
|
33
42
|
Then /^I see a definition$/ do
|
34
|
-
@response.body.to_s.
|
43
|
+
expect(@response.body.to_s).to eq messages.load(:glossary).squish
|
35
44
|
end
|
36
45
|
|
37
46
|
Given /^I want to lookup a definition with a "(.*?)" of "(.*?)"$/ do |key, value|
|
@@ -39,7 +48,7 @@ Given /^I want to lookup a definition with a "(.*?)" of "(.*?)"$/ do |key, value
|
|
39
48
|
end
|
40
49
|
|
41
50
|
Then /^I see a definition with a "(.*?)" of "(.*?)"$/ do |key, value|
|
42
|
-
@response.body.to_s.
|
51
|
+
expect(@response.body.to_s).to eq messages.load(:glossary, { key => value }).squish
|
43
52
|
end
|
44
53
|
|
45
54
|
Given(/^I want to do some fancy processing$/) do
|
@@ -51,7 +60,7 @@ When(/^I query my service with (.*?)$/) do |request|
|
|
51
60
|
end
|
52
61
|
|
53
62
|
Then(/^I see (.*?) in the service response$/) do |response|
|
54
|
-
@response.body.to_s.
|
63
|
+
expect(@response.body.to_s).to eq "<response>#{response}</response>"
|
55
64
|
end
|
56
65
|
|
57
66
|
Given(/^I have a car reservation I want to delete$/) do
|
@@ -63,5 +72,5 @@ When(/^I delete a car reservation$/) do
|
|
63
72
|
end
|
64
73
|
|
65
74
|
Then(/^I should see a car reservation cancellation$/) do
|
66
|
-
@response.body.to_s.
|
75
|
+
expect( @response.body.to_s).to eq messages.load(:cancelled_reservation).squish
|
67
76
|
end
|
@@ -9,7 +9,7 @@ When /^I make (\d+) posts$/ do |number|
|
|
9
9
|
end
|
10
10
|
|
11
11
|
Then /^the service has received (\d+) posts(?:s?)$/ do |number|
|
12
|
-
mock.request_log('/test_post').count.
|
12
|
+
expect(mock.request_log('/test_post').count).to eq number.to_i
|
13
13
|
end
|
14
14
|
|
15
15
|
When /^I do a (.*?) on "(.*?)"$/ do |method, endpoint|
|
@@ -17,12 +17,12 @@ When /^I do a (.*?) on "(.*?)"$/ do |method, endpoint|
|
|
17
17
|
end
|
18
18
|
|
19
19
|
Then(/^the service has recieved a request on "(.*?)"$/) do |endpoint|
|
20
|
-
mock.request_log(endpoint).count.
|
20
|
+
expect(mock.request_log(endpoint).count).to be > 0
|
21
21
|
end
|
22
22
|
|
23
23
|
When /^the headers for the request on "(.*?)" should contain:$/ do |endpoint, table|
|
24
24
|
headers = mock.request_log(endpoint).first.headers
|
25
25
|
table.rows_hash.each do |key, value|
|
26
|
-
headers[key].
|
26
|
+
expect(headers[key]).to eq value
|
27
27
|
end
|
28
28
|
end
|
@@ -21,6 +21,7 @@ module PinchHitter::Service
|
|
21
21
|
mime_type :xml, "text/xml"
|
22
22
|
mime_type :json, "application/json"
|
23
23
|
disable :no_cache
|
24
|
+
disable :protection
|
24
25
|
end
|
25
26
|
|
26
27
|
|
@@ -40,17 +41,17 @@ module PinchHitter::Service
|
|
40
41
|
end
|
41
42
|
|
42
43
|
post '/store' do
|
43
|
-
store
|
44
|
+
store params["endpoint"], request.body.read
|
44
45
|
status 200
|
45
46
|
end
|
46
47
|
|
47
48
|
post '/register_module' do
|
48
|
-
register_module
|
49
|
+
register_module params["endpoint"], request.body.read
|
49
50
|
status 200
|
50
51
|
end
|
51
52
|
|
52
53
|
get '/received_requests' do
|
53
|
-
requests request["endpoint"]
|
54
|
+
requests request.params["endpoint"]
|
54
55
|
end
|
55
56
|
|
56
57
|
post '/respond' do
|
@@ -86,12 +87,17 @@ module PinchHitter::Service
|
|
86
87
|
endpoint = normalize(endpoint)
|
87
88
|
body, request = wrap(request)
|
88
89
|
@@recorder.record(endpoint, request)
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
90
|
+
if @@handlers.handler_for?(endpoint)
|
91
|
+
message = @@handlers.respond_to(endpoint, body, request, response)
|
92
|
+
if message
|
93
|
+
content_type determine_content_type message
|
94
|
+
message
|
95
|
+
else
|
96
|
+
status 404
|
97
|
+
end
|
98
|
+
else
|
99
|
+
status 404
|
93
100
|
end
|
94
|
-
message
|
95
101
|
end
|
96
102
|
|
97
103
|
def register_module(endpoint='/', mod='')
|
@@ -18,7 +18,7 @@ module PinchHitter::Service::Runner
|
|
18
18
|
@app = PinchHitter::Service::ReplayWs.new
|
19
19
|
@app.settings.enable :no_cache if @no_cache
|
20
20
|
@replay_service = Thread.new do
|
21
|
-
Rack::Handler::WEBrick.run @app, service_options(host, port)
|
21
|
+
Rack::Handler::WEBrick.run @app, **service_options(host, port)
|
22
22
|
end
|
23
23
|
wait_for_replay(timeout)
|
24
24
|
end
|
data/lib/pinch_hitter/version.rb
CHANGED
data/test/message_assertions.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module MessageAssertions
|
2
2
|
def xml_message
|
3
|
-
|
3
|
+
%Q{<?xml version="1.0" encoding="UTF-8"?>
|
4
4
|
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:replay="http://www.leandog.com/replay">
|
5
5
|
<env:Body>
|
6
6
|
<replay:Response>BARK!</replay:Response>
|
data/test/test_pinch_hitter.rb
CHANGED
data/test/test_service.rb
CHANGED
@@ -37,7 +37,7 @@ class TestService < MiniTest::Test
|
|
37
37
|
post "/reset", ''
|
38
38
|
assert_equal 200, last_response.status
|
39
39
|
post "/respond", ''
|
40
|
-
assert_equal
|
40
|
+
assert_equal 404, last_response.status
|
41
41
|
assert_equal '', last_response.body
|
42
42
|
end
|
43
43
|
|
@@ -148,6 +148,13 @@ class TestService < MiniTest::Test
|
|
148
148
|
app.disable :no_cache
|
149
149
|
end
|
150
150
|
|
151
|
+
def test_cors_protections_are_off
|
152
|
+
post "/store", xml_message
|
153
|
+
post "/respond", ''
|
154
|
+
|
155
|
+
assert_nil last_response["X-Frame-Options"]
|
156
|
+
end
|
157
|
+
|
151
158
|
def test_request_handler
|
152
159
|
post '/register_module?endpoint=stuff', Marshal.dump(TestRequestHandler)
|
153
160
|
post '/stuff', ''
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pinch_hitter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Jackson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -192,8 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
192
192
|
- !ruby/object:Gem::Version
|
193
193
|
version: '0'
|
194
194
|
requirements: []
|
195
|
-
|
196
|
-
rubygems_version: 2.5.1
|
195
|
+
rubygems_version: 3.1.2
|
197
196
|
signing_key:
|
198
197
|
specification_version: 4
|
199
198
|
summary: Test utility for mocking out external web responses
|