committee 1.2.3 → 1.3.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
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: becdf8694f016697cfe01ac64b851bf45c90c64e
|
4
|
+
data.tar.gz: 88e687a7af19cf547342bacce32b5fb72212f0b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b618b8007da0078eeba04958a12e11f4fd1d87f55e631f1d2585c483a762b513ffc58e4f41e89f9b6b6f63f6ae984e425bff59070e8fba13603ef3a95295ce2
|
7
|
+
data.tar.gz: 45007433833b8e24b943662060c9f156dc951b41107859686639352b4d99a8956f9ec705d176f493583d9013dcdca5e63eba2a9c90456347404284590dfefc6c
|
@@ -2,13 +2,14 @@ module Committee::Middleware
|
|
2
2
|
class ResponseValidation < Base
|
3
3
|
def initialize(app, options={})
|
4
4
|
super
|
5
|
-
@raise
|
5
|
+
@raise = options[:raise]
|
6
|
+
@validate_errors = options[:validate_errors]
|
6
7
|
end
|
7
8
|
|
8
9
|
def handle(request)
|
9
10
|
status, headers, response = @app.call(request.env)
|
10
11
|
|
11
|
-
if link = @router.find_request_link(request)
|
12
|
+
if validate?(status) && link = @router.find_request_link(request)
|
12
13
|
full_body = ""
|
13
14
|
response.each do |chunk|
|
14
15
|
full_body << chunk
|
@@ -16,6 +17,7 @@ module Committee::Middleware
|
|
16
17
|
data = MultiJson.decode(full_body)
|
17
18
|
Committee::ResponseValidator.new(link).call(headers, data)
|
18
19
|
end
|
20
|
+
|
19
21
|
[status, headers, response]
|
20
22
|
rescue Committee::InvalidResponse
|
21
23
|
raise if @raise
|
@@ -24,5 +26,9 @@ module Committee::Middleware
|
|
24
26
|
raise Committee::InvalidResponse if @raise
|
25
27
|
render_error(500, :invalid_response, "Response wasn't valid JSON.")
|
26
28
|
end
|
29
|
+
|
30
|
+
def validate?(status)
|
31
|
+
@validate_errors || (200...300).include?(status)
|
32
|
+
end
|
27
33
|
end
|
28
34
|
end
|
@@ -20,6 +20,12 @@ describe Committee::Middleware::ResponseValidation do
|
|
20
20
|
assert_match /valid JSON/i, last_response.body
|
21
21
|
end
|
22
22
|
|
23
|
+
it "ignores a non-2xx invalid response" do
|
24
|
+
@app = new_rack_app("[]", {}, app_status: 404)
|
25
|
+
get "/apps"
|
26
|
+
assert_equal 404, last_response.status
|
27
|
+
end
|
28
|
+
|
23
29
|
it "rescues JSON errors" do
|
24
30
|
@app = new_rack_app("[{x:y}]")
|
25
31
|
get "/apps"
|
@@ -60,7 +66,7 @@ describe Committee::Middleware::ResponseValidation do
|
|
60
66
|
Rack::Builder.new {
|
61
67
|
use Committee::Middleware::ResponseValidation, options
|
62
68
|
run lambda { |_|
|
63
|
-
[200, headers, [response]]
|
69
|
+
[options.fetch(:app_status, 200), headers, [response]]
|
64
70
|
}
|
65
71
|
}
|
66
72
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: committee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandur
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-06-
|
12
|
+
date: 2014-06-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json_schema
|