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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0c0e017cec57427c43e8e5d00fdbf6f5824a811d
4
- data.tar.gz: 4f08b9678da6946f6775d3bf61c874b081982f21
2
+ SHA256:
3
+ metadata.gz: 45eba7bb747442209e486b0747ad30254f8d40b6c56b6e580f209462bdff2db6
4
+ data.tar.gz: ac50532874df051f1f66787550261b26c3ed6ef38f28ad5ba180fc074c5ba8c5
5
5
  SHA512:
6
- metadata.gz: 3132ce9f63afd12c4a4efeb632a8d1d339aba116708f060586090108e3f2d879d1135bf2f35f89122d5c55fe287230c43f333cd1e6f60f50118166e932f5cf99
7
- data.tar.gz: b086e13074d4362d6ebd7e910818eaffcb48c9eb1370175970c3fb984f6bba0775437f321132171aa719b743a8092801cc65b5a41bb49137f5632b70ecd72310
6
+ metadata.gz: 07b7050e60f69ab498294084f174343986f2acbef493c6b102ad7cf7c7121c3d56cc80e6e0b1e2e2ffb374f983ac95c01838f3a15aaec9b0e0bba14a2a107916
7
+ data.tar.gz: 9e8c48398060dea6ad6b1373295246775d74fbc7bb87ddc654ede2f8b0853465774f647e798e79b319c2cdbdb6daf71f8b523ee71b07aff332fee4c987804569
@@ -1 +1 @@
1
- ruby-2.3.1
1
+ ruby-2.7.0
@@ -1,7 +1,11 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.9
4
- - 2.2.5
5
- - 2.3.1
3
+ - 2.1.10
4
+ - 2.2.10
5
+ - 2.3.8
6
+ - 2.4.9
7
+ - 2.5.7
8
+ - 2.6.5
9
+ - 2.7.0
6
10
  before_install:
7
11
  - gem update bundler
data/Changelog CHANGED
@@ -1,43 +1,47 @@
1
- === Release 0.1 / 2013-1-20
2
- Initial release of the gem
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
- === Release 0.2 / 2013-1-27
5
- Switch json to do overrides by key rather than path (like xml)
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.3 / 2013-3-22
8
- Add ability to register modules for custom message handling
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.4 / 2014-3-3
11
- * Add ability to retrieve requests made by the application
12
- * Support PUT, PATCH, DELETE
14
+ === Release 0.5.5 / 2015-11-5
15
+ * Allow Cross-Origin requests
13
16
 
14
- === Release 0.5 / 2014-7-3
15
- * Fix issue where priming large messages would cause a 500
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.1 / 2014-7-3
18
- * Travis revealed some test issues with newer gems. Thanks Travis CI!
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.3 / 2015-8-14
25
- * Add ability to silence the sintatra/webrick output and keep it out of the
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.4 / 2015-11-5
29
- * Add require for Net::HTTP as some rubies can't resolve it properly - Thanks
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.5.5 / 2015-11-5
34
- * Allow Cross-Origin requests
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.5.6 / 2016-03-19
37
- * Add ability to disable cache control (useful for IE testing)
38
- * Allow client to register a module that will hydrate the response object.
39
- * Break apart recording and responding to better support full response payloads
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.6.0 / 2016-06-14
42
- * Removed references to 1.9.2 which has long been EOL'd. - Thanks @garyjohnson!
43
- * Remove dependency on nokogiri
46
+ === Release 0.1 / 2013-1-20
47
+ Initial release of the gem
@@ -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$/ do
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.should == messages.load(:car_rental).squish
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.should == messages.load(:car_rental, { tag => text }).squish
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.should == messages.load(:glossary).squish
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.should == messages.load(:glossary, { key => value }).squish
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.should == "<response>#{response}</response>"
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.should == messages.load(:cancelled_reservation).squish
75
+ expect( @response.body.to_s).to eq messages.load(:cancelled_reservation).squish
67
76
  end
@@ -9,5 +9,5 @@ When(/^I make a request$/) do
9
9
  end
10
10
 
11
11
  Then(/^my response has a no\-cache,no\-store Cache\-Control header$/) do
12
- @response.header['Cache-Control'].should == 'no-cache, no-store'
12
+ expect(@response.header['Cache-Control']).to eq 'no-cache, no-store'
13
13
  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.should == number.to_i
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.should be > 0
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].should == value
26
+ expect(headers[key]).to eq value
27
27
  end
28
28
  end
@@ -3,7 +3,7 @@ require 'pinch_hitter/message/json'
3
3
  require 'pinch_hitter/message/content_type'
4
4
 
5
5
  module PinchHitter::Message
6
- class MessageStore
6
+ class MessageStore
7
7
  include Xml
8
8
  include Json
9
9
  include ContentType
@@ -26,6 +26,10 @@ module PinchHitter::Service
26
26
  handlers[endpoint] || store_handler(endpoint)
27
27
  end
28
28
 
29
+ def handler_for?(endpoint)
30
+ handlers.has_key?(endpoint)
31
+ end
32
+
29
33
  def register_module(endpoint, mod)
30
34
  handler = Object.new
31
35
  handler.extend(mod)
@@ -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 request["endpoint"], request.body.read
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 request["endpoint"], request.body.read
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
- message = @@handlers.respond_to(endpoint, body, request, response)
90
- if message.is_a? String
91
- content_type determine_content_type message
92
- puts "No message found for #{endpoint}" unless message
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
@@ -1,3 +1,3 @@
1
1
  module PinchHitter
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  module MessageAssertions
2
2
  def xml_message
3
- message = %Q{<?xml version="1.0" encoding="UTF-8"?>
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>
@@ -76,6 +76,7 @@ class TestPinchHitter < MiniTest::Test
76
76
  def test_request_headers
77
77
  session.delete '/foo'
78
78
  headers = @test.request_log('/foo').first.headers
79
+ assert headers.keys.include? 'CONTENT_TYPE'
79
80
  end
80
81
 
81
82
  def test_received_messages
@@ -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 200, last_response.status
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.6.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: 2016-06-14 00:00:00.000000000 Z
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
- rubyforge_project:
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