committee 1.14.0 → 1.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b93ed460e34afc046f016a0b28c53c221bb4eb5
|
4
|
+
data.tar.gz: 0670a4037229f06312799901ade0e94bf416a95e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c64af87f69eeeb24ba0b6dd0e9baa873c436d67e452dfde3c432e318d3cf583ec536dd1faed3c136ce1e4d0a2b90aac17083b861492ce0ed518d24ea2ede4f36
|
7
|
+
data.tar.gz: 9fcc322cc7e10fa8299fc0025dada82a5222c3546988737ed344f06d9e809ccf1c6a010a193d1e49378ba3c2767b0e340652793bcd8f22edf0d7c2590795a96e
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Committee::Middleware
|
2
2
|
class ResponseValidation < Base
|
3
|
-
|
3
|
+
attr_reader :validate_errors
|
4
|
+
|
5
|
+
def initialize(app, options = {})
|
4
6
|
super
|
5
7
|
@validate_errors = options[:validate_errors]
|
6
8
|
end
|
@@ -14,7 +16,7 @@ module Committee::Middleware
|
|
14
16
|
full_body << chunk
|
15
17
|
end
|
16
18
|
data = JSON.parse(full_body)
|
17
|
-
Committee::ResponseValidator.new(link).call(status, headers, data)
|
19
|
+
Committee::ResponseValidator.new(link, validate_errors: validate_errors).call(status, headers, data)
|
18
20
|
end
|
19
21
|
|
20
22
|
[status, headers, response]
|
@@ -27,7 +29,7 @@ module Committee::Middleware
|
|
27
29
|
end
|
28
30
|
|
29
31
|
def validate?(status)
|
30
|
-
Committee::ResponseValidator.validate?(status)
|
32
|
+
Committee::ResponseValidator.validate?(status, validate_errors: validate_errors)
|
31
33
|
end
|
32
34
|
end
|
33
35
|
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
module Committee
|
2
2
|
class ResponseValidator
|
3
|
-
|
3
|
+
attr_reader :validate_errors
|
4
|
+
|
5
|
+
def initialize(link, options = {})
|
4
6
|
@link = link
|
7
|
+
@validate_errors = options[:validate_errors]
|
5
8
|
|
6
9
|
# we should eventually move off of validating against parent schema too
|
7
10
|
# ... this is a Herokuism and not in the specification
|
@@ -9,8 +12,10 @@ module Committee
|
|
9
12
|
@validator = JsonSchema::Validator.new(schema)
|
10
13
|
end
|
11
14
|
|
12
|
-
def self.validate?(status)
|
13
|
-
|
15
|
+
def self.validate?(status, options = {})
|
16
|
+
validate_errors = options[:validate_errors]
|
17
|
+
|
18
|
+
status != 204 and validate_errors || (200...300).include?(status)
|
14
19
|
end
|
15
20
|
|
16
21
|
def call(status, headers, data)
|
@@ -32,7 +37,7 @@ module Committee
|
|
32
37
|
return if data == nil
|
33
38
|
end
|
34
39
|
|
35
|
-
if self.class.validate?(status) && !@validator.validate(data)
|
40
|
+
if self.class.validate?(status, validate_errors: validate_errors) && !@validator.validate(data)
|
36
41
|
errors = JsonSchema::SchemaError.aggregate(@validator.errors).join("\n")
|
37
42
|
raise InvalidResponse, "Invalid response.\n\n#{errors}"
|
38
43
|
end
|
@@ -26,6 +26,14 @@ describe Committee::Middleware::ResponseValidation do
|
|
26
26
|
assert_equal 404, last_response.status
|
27
27
|
end
|
28
28
|
|
29
|
+
it "optionally validates non-2xx invalid responses" do
|
30
|
+
@app = new_rack_app("", {}, {app_status: 404, validate_errors: true})
|
31
|
+
|
32
|
+
get "/apps"
|
33
|
+
assert_equal 500, last_response.status
|
34
|
+
assert_match /valid JSON/i, last_response.body
|
35
|
+
end
|
36
|
+
|
29
37
|
it "passes through a 204 (no content) response" do
|
30
38
|
@app = new_rack_app("", {}, app_status: 204)
|
31
39
|
get "/apps"
|
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.14.
|
4
|
+
version: 1.14.1
|
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: 2016-
|
12
|
+
date: 2016-05-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json_schema
|
@@ -156,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
156
|
version: '0'
|
157
157
|
requirements: []
|
158
158
|
rubyforge_project:
|
159
|
-
rubygems_version: 2.
|
159
|
+
rubygems_version: 2.5.1
|
160
160
|
signing_key:
|
161
161
|
specification_version: 4
|
162
162
|
summary: A collection of Rack middleware to support JSON Schema.
|