committee 3.2.0 → 3.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/committee/schema_validator/open_api_3/operation_wrapper.rb +3 -1
- data/lib/committee/schema_validator/open_api_3/response_validator.rb +0 -1
- data/test/middleware/request_validation_open_api_3_test.rb +33 -21
- data/test/middleware/response_validation_open_api_3_test.rb +3 -2
- data/test/schema_validator/open_api_3/operation_wrapper_test.rb +6 -6
- data/test/test/methods_test.rb +6 -5
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2af076998ef23743c239df64c5517e3e334422a3523f09e6f8baa4f1a9f1ef77
|
4
|
+
data.tar.gz: a5ae6eca5d34310a69e1c33ca6f11a807e19316c8fad9123521ecf835cfe091c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65e65734251a25cb3a3735081c8a3e2e6973b93d1e14b66261d3978e7dac3ea5a9081fe7a530625cf9407d3ac25bc8941d6bea064d07f546186b6a2ebd043fa6
|
7
|
+
data.tar.gz: 7dee370a2748aa7b67d1e360e86aacb204d16a5a68d18ac879ececc3633d6d92f5ad9b49ba36ac8851e1a04f2322fec2269b8926f30f061d1524bf284af90848
|
@@ -116,7 +116,9 @@ module Committee
|
|
116
116
|
content_type = headers['Content-Type'].to_s.split(";").first.to_s
|
117
117
|
|
118
118
|
# bad performance because when we coerce value, same check
|
119
|
-
|
119
|
+
schema_validator_options = build_openapi_parser_post_option(validator_option)
|
120
|
+
request_operation.validate_request_parameter(params, headers, schema_validator_options)
|
121
|
+
request_operation.validate_request_body(content_type, params, schema_validator_options)
|
120
122
|
rescue => e
|
121
123
|
raise Committee::InvalidRequest.new(e.message)
|
122
124
|
end
|
@@ -17,7 +17,6 @@ module Committee
|
|
17
17
|
def call(status, headers, response_data, strict)
|
18
18
|
return unless Committee::Middleware::ResponseValidation.validate?(status, validate_success_only)
|
19
19
|
|
20
|
-
#content_type = headers['Content-Type'].to_s.split(";").first.to_s
|
21
20
|
operation_wrapper.validate_response_params(status, headers, response_data, strict, check_header)
|
22
21
|
end
|
23
22
|
|
@@ -250,7 +250,7 @@ describe Committee::Middleware::RequestValidation do
|
|
250
250
|
post "/characters", JSON.generate(params)
|
251
251
|
assert_equal 400, last_response.status
|
252
252
|
# FIXME: when ruby 2.3 dropped, fix because ruby 2.3 return Fixnum, ruby 2.4 or later return Integer
|
253
|
-
assert_match(/
|
253
|
+
assert_match(/expected string, but received #{1.class}:/i, last_response.body)
|
254
254
|
end
|
255
255
|
|
256
256
|
it "rescues JSON errors" do
|
@@ -279,7 +279,8 @@ describe Committee::Middleware::RequestValidation do
|
|
279
279
|
header "Content-Type", "application/json"
|
280
280
|
post "/v1/characters", JSON.generate(params)
|
281
281
|
assert_equal 400, last_response.status
|
282
|
-
|
282
|
+
# FIXME: when ruby 2.3 dropped, fix because ruby 2.3 return Fixnum, ruby 2.4 or later return Integer
|
283
|
+
assert_match(/expected string, but received #{1.class}: /i, last_response.body)
|
283
284
|
end
|
284
285
|
|
285
286
|
it "ignores paths outside the prefix" do
|
@@ -321,7 +322,7 @@ describe Committee::Middleware::RequestValidation do
|
|
321
322
|
get "/validate", nil
|
322
323
|
end
|
323
324
|
|
324
|
-
assert_match(/required parameters query_string
|
325
|
+
assert_match(/missing required parameters: query_string/i, e.message)
|
325
326
|
end
|
326
327
|
|
327
328
|
it "raises error when required path parameter is invalid" do
|
@@ -332,7 +333,7 @@ describe Committee::Middleware::RequestValidation do
|
|
332
333
|
get "/coerce_path_params/#{not_an_integer}", nil
|
333
334
|
end
|
334
335
|
|
335
|
-
assert_match(/
|
336
|
+
assert_match(/expected integer, but received String: abc/i, e.message)
|
336
337
|
end
|
337
338
|
|
338
339
|
it "optionally raises an error" do
|
@@ -356,7 +357,7 @@ describe Committee::Middleware::RequestValidation do
|
|
356
357
|
get "/string_params_coercer", {"integer_1" => "1"}
|
357
358
|
|
358
359
|
assert_equal 400, last_response.status
|
359
|
-
assert_match(/
|
360
|
+
assert_match(/expected integer, but received String:/i, last_response.body)
|
360
361
|
end
|
361
362
|
|
362
363
|
it "passes through a valid request for OpenAPI3" do
|
@@ -375,7 +376,7 @@ describe Committee::Middleware::RequestValidation do
|
|
375
376
|
get "/characters?limit=foo"
|
376
377
|
|
377
378
|
assert_equal 400, last_response.status
|
378
|
-
assert_match(/foo
|
379
|
+
assert_match(/expected integer, but received String: foo/i, last_response.body)
|
379
380
|
end
|
380
381
|
|
381
382
|
it "coerce string to integer" do
|
@@ -399,21 +400,32 @@ describe Committee::Middleware::RequestValidation do
|
|
399
400
|
end
|
400
401
|
|
401
402
|
describe 'check header' do
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
403
|
+
[
|
404
|
+
{ check_header: true, description: 'valid value', value: 1, expected: { status: 200 } },
|
405
|
+
{ check_header: true, description: 'missing value', value: nil, expected: { status: 400, error: 'missing required parameters: integer' } },
|
406
|
+
{ check_header: true, description: 'invalid value', value: 'x', expected: { status: 400, error: 'expected integer, but received String: x' } },
|
407
|
+
|
408
|
+
{ check_header: false, description: 'valid value', value: 1, expected: { status: 200 } },
|
409
|
+
{ check_header: false, description: 'missing value', value: nil, expected: { status: 200 } },
|
410
|
+
{ check_header: false, description: 'invalid value', value: 'x', expected: { status: 200 } },
|
411
|
+
].each do |check_header:, description:, value:, expected:|
|
412
|
+
describe "when #{check_header}" do
|
413
|
+
%w(get post put patch delete).each do |method|
|
414
|
+
describe method do
|
415
|
+
describe description do
|
416
|
+
it (expected[:error].nil? ? 'should pass' : 'should fail') do
|
417
|
+
@app = new_rack_app(schema: open_api_3_schema, check_header: check_header)
|
418
|
+
|
419
|
+
header 'integer', value
|
420
|
+
send(method, "/header")
|
421
|
+
|
422
|
+
assert_equal expected[:status], last_response.status
|
423
|
+
assert_match(expected[:error], last_response.body) if expected[:error]
|
424
|
+
end
|
425
|
+
end
|
426
|
+
end
|
427
|
+
end
|
428
|
+
end
|
417
429
|
end
|
418
430
|
end
|
419
431
|
|
@@ -47,7 +47,7 @@ describe Committee::Middleware::ResponseValidation do
|
|
47
47
|
get "/characters"
|
48
48
|
}
|
49
49
|
|
50
|
-
assert_match(/
|
50
|
+
assert_match(/expected object, but received Array: /i, e.message)
|
51
51
|
end
|
52
52
|
|
53
53
|
it "passes through a 204 (no content) response" do
|
@@ -138,7 +138,8 @@ describe Committee::Middleware::ResponseValidation do
|
|
138
138
|
e = assert_raises(Committee::InvalidResponse) do
|
139
139
|
get "/characters"
|
140
140
|
end
|
141
|
-
|
141
|
+
|
142
|
+
assert_match(/but received String: 1/i, e.message)
|
142
143
|
end
|
143
144
|
|
144
145
|
it "detects an invalid response status code with validate_success_only=true" do
|
@@ -53,7 +53,7 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
|
|
53
53
|
}
|
54
54
|
|
55
55
|
# FIXME: when ruby 2.3 dropped, fix because ruby 2.3 return Fixnum, ruby 2.4 or later return Integer
|
56
|
-
|
56
|
+
assert_match(/expected string, but received #{1.class}: 1/i, e.message)
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'support put method' do
|
@@ -65,7 +65,7 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
|
|
65
65
|
}
|
66
66
|
|
67
67
|
# FIXME: when ruby 2.3 dropped, fix because ruby 2.3 return Fixnum, ruby 2.4 or later return Integer
|
68
|
-
|
68
|
+
assert_match(/expected string, but received #{1.class}: 1/i, e.message)
|
69
69
|
end
|
70
70
|
|
71
71
|
it 'support patch method' do
|
@@ -76,7 +76,7 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
|
|
76
76
|
operation_object.validate_request_params({"integer" => "str"}, HEADER, @validator_option)
|
77
77
|
}
|
78
78
|
|
79
|
-
|
79
|
+
assert_match(/expected integer, but received String: str/i, e.message)
|
80
80
|
end
|
81
81
|
|
82
82
|
it 'unknown param' do
|
@@ -109,7 +109,7 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
|
|
109
109
|
operation_object.validate_request_params({"query_integer_list" => [1, 2]}, HEADER, @validator_option)
|
110
110
|
}
|
111
111
|
|
112
|
-
|
112
|
+
assert_match(/missing required parameters: query_string/i, e.message)
|
113
113
|
end
|
114
114
|
|
115
115
|
it 'invalid type' do
|
@@ -122,7 +122,7 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
|
|
122
122
|
}
|
123
123
|
|
124
124
|
# FIXME: when ruby 2.3 dropped, fix because ruby 2.3 return Fixnum, ruby 2.4 or later return Integer
|
125
|
-
|
125
|
+
assert_match(/expected string, but received #{1.class}: 1/i, e.message)
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
@@ -143,7 +143,7 @@ describe Committee::SchemaValidator::OpenAPI3::OperationWrapper do
|
|
143
143
|
operation_object.validate_request_params({"limit" => "a"}, HEADER, @validator_option)
|
144
144
|
}
|
145
145
|
|
146
|
-
|
146
|
+
assert_match(/expected integer, but received String: a/i, e.message)
|
147
147
|
end
|
148
148
|
end
|
149
149
|
|
data/test/test/methods_test.rb
CHANGED
@@ -138,7 +138,7 @@ describe Committee::Test::Methods do
|
|
138
138
|
e = assert_raises(Committee::InvalidResponse) do
|
139
139
|
assert_schema_conform
|
140
140
|
end
|
141
|
-
assert_match(/
|
141
|
+
assert_match(/response definition does not exist/i, e.message)
|
142
142
|
end
|
143
143
|
|
144
144
|
it "detects an invalid response status code" do
|
@@ -149,7 +149,7 @@ describe Committee::Test::Methods do
|
|
149
149
|
e = assert_raises(Committee::InvalidResponse) do
|
150
150
|
assert_schema_conform
|
151
151
|
end
|
152
|
-
assert_match(/
|
152
|
+
assert_match(/status code definition does not exist/i, e.message)
|
153
153
|
end
|
154
154
|
|
155
155
|
it "outputs deprecation warning" do
|
@@ -175,7 +175,8 @@ describe Committee::Test::Methods do
|
|
175
175
|
e = assert_raises(Committee::InvalidRequest) do
|
176
176
|
assert_request_schema_confirm
|
177
177
|
end
|
178
|
-
|
178
|
+
|
179
|
+
assert_match(/missing required parameters: query_string/i, e.message)
|
179
180
|
end
|
180
181
|
|
181
182
|
it "path undefined in schema" do
|
@@ -201,7 +202,7 @@ describe Committee::Test::Methods do
|
|
201
202
|
e = assert_raises(Committee::InvalidResponse) do
|
202
203
|
assert_response_schema_confirm
|
203
204
|
end
|
204
|
-
assert_match(/
|
205
|
+
assert_match(/response definition does not exist/i, e.message)
|
205
206
|
end
|
206
207
|
|
207
208
|
it "detects an invalid response status code" do
|
@@ -212,7 +213,7 @@ describe Committee::Test::Methods do
|
|
212
213
|
e = assert_raises(Committee::InvalidResponse) do
|
213
214
|
assert_response_schema_confirm
|
214
215
|
end
|
215
|
-
assert_match(/
|
216
|
+
assert_match(/status code definition does not exist/i, e.message)
|
216
217
|
end
|
217
218
|
|
218
219
|
it "path undefined in schema" do
|
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: 3.2.
|
4
|
+
version: 3.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandur
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2019-
|
13
|
+
date: 2019-10-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json_schema
|
@@ -52,14 +52,14 @@ dependencies:
|
|
52
52
|
requirements:
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 0.
|
55
|
+
version: 0.6.1
|
56
56
|
type: :runtime
|
57
57
|
prerelease: false
|
58
58
|
version_requirements: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
60
|
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: 0.
|
62
|
+
version: 0.6.1
|
63
63
|
- !ruby/object:Gem::Dependency
|
64
64
|
name: minitest
|
65
65
|
requirement: !ruby/object:Gem::Requirement
|