agile-proxy 0.1.10 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/bin/agile_proxy +1 -1
- data/config.yml +1 -1
- data/lib/agile_proxy/api/request_specs.rb +1 -1
- data/lib/agile_proxy/handlers/stub_handler.rb +15 -2
- data/lib/agile_proxy/model/request_spec.rb +1 -1
- data/lib/agile_proxy/version.rb +1 -1
- data/spec/integration/helpers/request_spec_helper.rb +1 -0
- data/spec/unit/agile_proxy/api/request_specs_spec.rb +1 -1
- data/spec/unit/agile_proxy/handlers/stub_handler_spec.rb +8 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74ae4ece459f7aec91a77ac5daefe1b1978de480
|
4
|
+
data.tar.gz: 1b1e68ecff0556340c41281a1f24faa3a6b75202
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e604574ae397091d8909ad20981f4d4a03dac2fbc28c7885fb588a071234f6b6ab5be27aef4750158f0857d522742cac69add078f09dc4c783b7e647460152bc
|
7
|
+
data.tar.gz: af0e99b04466f2c5120f552f8fa78e4753eae7273552fc4ca2d0a41cd8e5fd49e6c1f1686db4370c4b9989acb974d20d052228eeda12177c2089883292cab911
|
data/Gemfile.lock
CHANGED
data/bin/agile_proxy
CHANGED
@@ -31,7 +31,7 @@ module AgileProxy
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def environment
|
34
|
-
ENV['AGILE_PROXY_ENV'] || Dir.pwd == File.expand_path('..', File.dirname(__FILE__)) ? 'development' : 'production'
|
34
|
+
ENV['AGILE_PROXY_ENV'] || (Dir.pwd == File.expand_path('..', File.dirname(__FILE__)) ? 'development' : 'production')
|
35
35
|
end
|
36
36
|
end
|
37
37
|
package_name 'Http Flexible Proxy'
|
data/config.yml
CHANGED
@@ -47,6 +47,13 @@ module AgileProxy
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def add_to_router(request, headers, body, route_set)
|
50
|
+
# This needs a bit of explaining as the router did not quite behave as expected.
|
51
|
+
# This proc calls route definition methods such as get, post etc.. with the path and handler
|
52
|
+
# the handler being an inline proc.
|
53
|
+
# But, we also pass a constraints handler
|
54
|
+
# After constraints are handled though, the 'action_dispatch.request.parameters' are deleted
|
55
|
+
# from the env, so our handler preserves them in agile_proxy.parameters.
|
56
|
+
# A bit weird, but it works reliably.
|
50
57
|
proc do |spec|
|
51
58
|
path = URI.parse(spec.url).path
|
52
59
|
path = '/' if path == ''
|
@@ -55,10 +62,16 @@ module AgileProxy
|
|
55
62
|
route_spec = {
|
56
63
|
path => proc do |router_env|
|
57
64
|
AgileProxy.log(:info, "agile-proxy: STUB #{method} for '#{request.url}'")
|
58
|
-
spec.call(router_env['
|
65
|
+
spec.call(router_env['agile_proxy.parameters'], headers, body)
|
59
66
|
end
|
60
67
|
}
|
61
|
-
route_spec[:constraints] =
|
68
|
+
route_spec[:constraints] = ->(request) {
|
69
|
+
ret_value = spec.conditions_json.all? do |k, v|
|
70
|
+
request.params.key?(k) && request.params[k] == v
|
71
|
+
end
|
72
|
+
request.env['agile_proxy.parameters'] = request.env['action_dispatch.request.parameters']
|
73
|
+
ret_value
|
74
|
+
}
|
62
75
|
route_set.send method, route_spec
|
63
76
|
end
|
64
77
|
end
|
@@ -29,7 +29,7 @@ module AgileProxy
|
|
29
29
|
# This method returns a JSON decoded version of this as a HASH
|
30
30
|
# @return [Hash] decoded conditions
|
31
31
|
def conditions_json
|
32
|
-
ActiveSupport::JSON.decode(conditions)
|
32
|
+
ActiveSupport::JSON.decode(conditions).with_indifferent_access
|
33
33
|
end
|
34
34
|
# This method's output is a 'rack' response, but its input is not.
|
35
35
|
# When the router has determined that this request spec is the one that is going to be sent to the client,
|
data/lib/agile_proxy/version.rb
CHANGED
@@ -43,6 +43,7 @@ module AgileProxy
|
|
43
43
|
create_request_spec url: "#{url}/api/forums/:forum_id/:post_id", http_method: 'DELETE', response: { content_type: 'application/json', content: '{"deleted": true}' }
|
44
44
|
create_request_spec url: "#{url}/api/forums/:forum_id/:post_id", conditions: '{"post_id": "special"}', response: { content_type: 'text/html', content: '<html><body><h1>Sorted By: {{sort}}</h1><h2>{{forum_id}}</h2><h3>{{post_id}}</h3><p>This is a special response</p></body></html>', is_template: true }
|
45
45
|
create_request_spec url: "#{url}/api/forums/:forum_id/:post_id", conditions: '{"post_id": "special", "sort": "eversospecial"}', response: { content_type: 'text/html', content: '<html><body><h1>Sorted By: {{sort}}</h1><h2>{{forum_id}}</h2><h3>{{post_id}}</h3><p>This is an ever so special response</p></body></html>', is_template: true }
|
46
|
+
create_request_spec url: "#{url}/api/forums/:forum_id", http_method: 'POST',response: { content_type: 'text/html', content: '<html><body><h1></h1><h2>WRONG RESULT</h2><h3>{{forum_id}}</h3><p>This is an incorrect result probably because the conditions are being ignored ?</p></body></html>'}
|
46
47
|
create_request_spec url: "#{url}/api/forums/:forum_id", http_method: 'POST', conditions: '{"posted_var":"special_value"}', response: { content_type: 'text/html', content: '<html><body><h1></h1><h2>{{posted_var}}</h2><h3>{{forum_id}}</h3><p>This should get data from the POSTed data</p></body></html>', is_template: true }
|
47
48
|
create_request_spec url: "#{url}/api/forums/:forum_id/posts", response: { content_type: 'application/json', content: JSON.pretty_generate(posts: [
|
48
49
|
{ forum_id: '{{forum_id}}', subject: 'My first post' },
|
@@ -144,7 +144,7 @@ describe AgileProxy::Api::RequestSpecs, api_test: true do
|
|
144
144
|
end
|
145
145
|
describe 'DELETE /users/1/applications/1/request_specs' do
|
146
146
|
before :each do
|
147
|
-
expect(request_spec_assoc_class).to receive(:
|
147
|
+
expect(request_spec_assoc_class).to receive(:destroy_all)
|
148
148
|
end
|
149
149
|
it 'Should delete all request specs for the users application' do
|
150
150
|
delete '/v1/users/1/applications/1/request_specs'
|
@@ -31,18 +31,18 @@ describe AgileProxy::StubHandler do
|
|
31
31
|
|
32
32
|
describe '#handle_request' do
|
33
33
|
it 'returns 404 if the request is not stubbed' do
|
34
|
-
stub = double('stub', http_method: 'GET', url: 'http://example.test:8080/index',
|
34
|
+
stub = double('stub', http_method: 'GET', url: 'http://example.test:8080/index', conditions_json: {}, call: [404, {}, 'Not found'])
|
35
35
|
expect(request_spec_class).to receive(:where).and_return double('association', all: [stub])
|
36
36
|
expect(handler.call(to_rack_env(url: 'http://example.test:8080/index'))).to eql [404, {}, 'Not found']
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'returns a response hash if the request is stubbed' do
|
40
|
-
stub = double('stub', http_method: 'GET', url: 'http://example.test:8080/index',
|
40
|
+
stub = double('stub', http_method: 'GET', url: 'http://example.test:8080/index', conditions_json: {}, call: [200, { 'Content-Type' => 'application/json' }, 'Some content'])
|
41
41
|
expect(request_spec_class).to receive(:where).and_return double('association', all: [stub])
|
42
42
|
expect(handler.call(request.env)).to eql([200, { 'Content-Type' => 'application/json' }, 'Some content'])
|
43
43
|
end
|
44
44
|
it 'Passes on the correct parameters to the stub call method' do
|
45
|
-
stub = double('stub', http_method: 'GET', url: 'http://example.test:8080/index',
|
45
|
+
stub = double('stub', http_method: 'GET', url: 'http://example.test:8080/index', conditions_json: {})
|
46
46
|
expect(request_spec_class).to receive(:where).and_return double('association', all: [stub])
|
47
47
|
body = request.body.read
|
48
48
|
request.body.rewind
|
@@ -52,7 +52,7 @@ describe AgileProxy::StubHandler do
|
|
52
52
|
end
|
53
53
|
describe 'Routing patterns' do
|
54
54
|
describe 'With a simple GET match on the root of a domain' do
|
55
|
-
let(:request_stub) { double 'stub', url: 'http://example.com', http_method: 'GET',
|
55
|
+
let(:request_stub) { double 'stub', url: 'http://example.com', http_method: 'GET', conditions_json: {} }
|
56
56
|
before :each do
|
57
57
|
allow(request_spec_class).to receive(:where).with('url LIKE ?', 'http://example.com%').and_return double('association', all: [request_stub])
|
58
58
|
allow(request_spec_class).to receive(:where).with('url LIKE ?', 'http://subdomain.example.com%').and_return double('association', all: [])
|
@@ -67,7 +67,7 @@ describe AgileProxy::StubHandler do
|
|
67
67
|
|
68
68
|
end
|
69
69
|
describe 'With a simple GET match inside a domain' do
|
70
|
-
let(:request_stub) { double 'stub for simple get inside a domain', url: 'http://example.com/index', http_method: 'GET',
|
70
|
+
let(:request_stub) { double 'stub for simple get inside a domain', url: 'http://example.com/index', http_method: 'GET', conditions_json: {} }
|
71
71
|
before :each do
|
72
72
|
allow(request_spec_class).to receive(:where).with('url LIKE ?', 'http://example.com%').and_return double('association', all: [request_stub])
|
73
73
|
allow(request_spec_class).to receive(:where).with('url LIKE ?', 'http://subdomain.example.com%').and_return double('association', all: [])
|
@@ -83,7 +83,7 @@ describe AgileProxy::StubHandler do
|
|
83
83
|
|
84
84
|
end
|
85
85
|
describe 'With a simple POST match on the root of a domain' do
|
86
|
-
let(:request_stub) { double 'stub', url: 'http://example.com', http_method: 'POST',
|
86
|
+
let(:request_stub) { double 'stub', url: 'http://example.com', http_method: 'POST', conditions_json: {} }
|
87
87
|
before :each do
|
88
88
|
allow(request_spec_class).to receive(:where).with('url LIKE ?', 'http://example.com%').and_return double('association', all: [request_stub])
|
89
89
|
allow(request_spec_class).to receive(:where).with('url LIKE ?', 'http://subdomain.example.com%').and_return double('association', all: [])
|
@@ -98,7 +98,7 @@ describe AgileProxy::StubHandler do
|
|
98
98
|
|
99
99
|
end
|
100
100
|
describe 'With a more complex route with conditions inside a domain' do
|
101
|
-
let(:request_stub) { double 'stub for complex route inside a domain', url: 'http://example.com/users/:user_id/index', http_method: 'GET',
|
101
|
+
let(:request_stub) { double 'stub for complex route inside a domain', url: 'http://example.com/users/:user_id/index', http_method: 'GET', conditions_json: { user_id: '1' } }
|
102
102
|
before :each do
|
103
103
|
allow(request_spec_class).to receive(:where).with('url LIKE ?', 'http://example.com%').and_return double('association', all: [request_stub])
|
104
104
|
expect(request_stub).to receive(:call).and_return([200, {}, ''])
|
@@ -112,7 +112,7 @@ describe AgileProxy::StubHandler do
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
describe 'With a more complex route with conditions including query params inside a domain' do
|
115
|
-
let(:request_stub) { double 'stub for complex route inside a domain', url: 'http://example.com/users/:user_id/index', http_method: 'GET',
|
115
|
+
let(:request_stub) { double 'stub for complex route inside a domain', url: 'http://example.com/users/:user_id/index', http_method: 'GET', conditions_json: { user_id: '1', extra_1: 'extra_1', extra_2: 'extra_2' } }
|
116
116
|
before :each do
|
117
117
|
allow(request_spec_class).to receive(:where).with('url LIKE ?', 'http://example.com%').and_return double('association', all: [request_stub])
|
118
118
|
allow(request_stub).to receive(:call).and_return([200, {}, ''])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: agile-proxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gary Taylor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|