committee 2.1.1 → 2.2.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: 8b9b7fded711273c72d2e35628376206b082f115
4
- data.tar.gz: f89a74a16ed6d15b2a6f8f363182776675e7418d
3
+ metadata.gz: 7cf658ad230d67fb6c13503bf5837e25b26d0b4c
4
+ data.tar.gz: b14e13fbb725f67962327c6c6bdcd181371092d3
5
5
  SHA512:
6
- metadata.gz: 7e356500e91bf48bde973b1cfa352e1fafa788d0be4b8d1f4303b338a29b2b49f0f7688b0caa84ac28f33eddadef762ed04c9bd60a8f01c5c9fac185a85fc5d3
7
- data.tar.gz: ec9773029e7b1052b634f78e64370cbe1f265d94c89fd4893069d1854f9e8bb336c6d0de0049a71fcbca5c83479907ccb89c8bb25382145db87cc9b3c7a51197
6
+ metadata.gz: dfb150d3c57ab70d774fa19ca3e0185d504337dbcfc00e228542b42a57ce4bcb5245782072eea85260534eb0f1daf0c54eb16ff9f3e70c125d3602d939c28b78
7
+ data.tar.gz: 25361aec8a3976712649e857bd25616af8ebb1e87844e79aa69db12030d235527a035356a74fbfa584566a7f98f8081b904dc96bf62dd1e2256cda52f9371d6a
@@ -25,7 +25,7 @@ module Committee
25
25
 
26
26
  params = if params
27
27
  params
28
- elsif @allow_form_params && @request.media_type == "application/x-www-form-urlencoded"
28
+ elsif @allow_form_params && %w[application/x-www-form-urlencoded multipart/form-data].include?(@request.media_type)
29
29
  # Actually, POST means anything in the request body, could be from
30
30
  # PUT or PATCH too. Silly Rack.
31
31
  p = @request.POST
@@ -16,6 +16,8 @@ describe "executables in bin/" do
16
16
  end
17
17
 
18
18
  it "has roughly valid Ruby structure for committee-stub" do
19
- load File.join(@bin_dir, "committee-stub")
19
+ assert_output(%r{Usage: rackup \[options\] \[JSON Schema file\]}) do
20
+ load File.join(@bin_dir, "committee-stub")
21
+ end
20
22
  end
21
23
  end
@@ -249,7 +249,7 @@ describe Committee::Middleware::RequestValidation do
249
249
  header "Content-Type", "application/json"
250
250
  post "/apps", JSON.generate(params)
251
251
  assert_equal 400, last_response.status
252
- assert_match /invalid request/i, last_response.body
252
+ assert_match(/invalid request/i, last_response.body)
253
253
  end
254
254
 
255
255
  it "passes with coerce_date_times enabled and without a schema for a link" do
@@ -267,7 +267,7 @@ describe Committee::Middleware::RequestValidation do
267
267
  }
268
268
  post "/apps", JSON.generate(params)
269
269
  assert_equal 400, last_response.status
270
- assert_match /invalid request/i, last_response.body
270
+ assert_match(/invalid request/i, last_response.body)
271
271
  end
272
272
 
273
273
  it "rescues JSON errors" do
@@ -275,7 +275,7 @@ describe Committee::Middleware::RequestValidation do
275
275
  header "Content-Type", "application/json"
276
276
  post "/apps", "{x:y}"
277
277
  assert_equal 400, last_response.status
278
- assert_match /valid json/i, last_response.body
278
+ assert_match(/valid json/i, last_response.body)
279
279
  end
280
280
 
281
281
  it "takes a prefix" do
@@ -337,7 +337,7 @@ describe Committee::Middleware::RequestValidation do
337
337
  header "Content-Type", "application/json"
338
338
  get "/search/apps", {"per_page" => "foo", "query" => "cloudnasium"}
339
339
  assert_equal 400, last_response.status
340
- assert_match /invalid request/i, last_response.body
340
+ assert_match(/invalid request/i, last_response.body)
341
341
  end
342
342
 
343
343
  it "passes through a valid request for OpenAPI" do
@@ -355,7 +355,7 @@ describe Committee::Middleware::RequestValidation do
355
355
  @app = new_rack_app(schema: open_api_2_schema)
356
356
  get "/api/pets?limit=foo", nil, { "HTTP_AUTH_TOKEN" => "xxx" }
357
357
  assert_equal 400, last_response.status
358
- assert_match /invalid request/i, last_response.body
358
+ assert_match(/invalid request/i, last_response.body)
359
359
  end
360
360
 
361
361
  it "passes through a valid request for OpenAPI including path parameters" do
@@ -370,7 +370,7 @@ describe Committee::Middleware::RequestValidation do
370
370
  # not that ID is expect to be an integer
371
371
  get "/api/pets/not-integer"
372
372
  assert_equal 400, last_response.status
373
- assert_match /invalid request/i, last_response.body
373
+ assert_match(/invalid request/i, last_response.body)
374
374
  end
375
375
 
376
376
  private
@@ -17,14 +17,14 @@ describe Committee::Middleware::ResponseValidation do
17
17
  @app = new_rack_app("{}", {}, schema: hyper_schema)
18
18
  get "/apps"
19
19
  assert_equal 500, last_response.status
20
- assert_match /{} is not an array/i, last_response.body
20
+ assert_match(/{} is not an array/i, last_response.body)
21
21
  end
22
22
 
23
23
  it "detects a response invalid due to not being JSON" do
24
24
  @app = new_rack_app("", {}, schema: hyper_schema)
25
25
  get "/apps"
26
26
  assert_equal 500, last_response.status
27
- assert_match /valid JSON/i, last_response.body
27
+ assert_match(/valid JSON/i, last_response.body)
28
28
  end
29
29
 
30
30
  it "ignores a non-2xx invalid response" do
@@ -39,7 +39,7 @@ describe Committee::Middleware::ResponseValidation do
39
39
 
40
40
  get "/apps"
41
41
  assert_equal 500, last_response.status
42
- assert_match /valid JSON/i, last_response.body
42
+ assert_match(/valid JSON/i, last_response.body)
43
43
  end
44
44
 
45
45
  it "passes through a 204 (no content) response" do
@@ -52,7 +52,7 @@ describe Committee::Middleware::ResponseValidation do
52
52
  @app = new_rack_app("[{x:y}]", {}, schema: hyper_schema)
53
53
  get "/apps"
54
54
  assert_equal 500, last_response.status
55
- assert_match /valid json/i, last_response.body
55
+ assert_match(/valid json/i, last_response.body)
56
56
  end
57
57
 
58
58
  it "takes a prefix" do
@@ -80,7 +80,7 @@ describe Committee::Middleware::ResponseValidation do
80
80
  @app = new_rack_app("", {}, schema: open_api_2_schema)
81
81
  get "/api/pets"
82
82
  assert_equal 500, last_response.status
83
- assert_match /valid JSON/i, last_response.body
83
+ assert_match(/valid JSON/i, last_response.body)
84
84
  end
85
85
 
86
86
  private
@@ -23,33 +23,39 @@ describe Committee::RequestUnpacker do
23
23
  end
24
24
 
25
25
  it "doesn't unpack JSON under other Content-Types" do
26
- env = {
27
- "CONTENT_TYPE" => "application/x-www-form-urlencoded",
28
- "rack.input" => StringIO.new('{"x":"y"}'),
29
- }
30
- request = Rack::Request.new(env)
31
- params, _ = Committee::RequestUnpacker.new(request).call
32
- assert_equal({}, params)
26
+ %w[application/x-www-form-urlencoded multipart/form-data].each do |content_type|
27
+ env = {
28
+ "CONTENT_TYPE" => content_type,
29
+ "rack.input" => StringIO.new('{"x":"y"}'),
30
+ }
31
+ request = Rack::Request.new(env)
32
+ params, _ = Committee::RequestUnpacker.new(request).call
33
+ assert_equal({}, params)
34
+ end
33
35
  end
34
36
 
35
37
  it "unpacks JSON under other Content-Types with optimistic_json" do
36
- env = {
37
- "CONTENT_TYPE" => "application/x-www-form-urlencoded",
38
- "rack.input" => StringIO.new('{"x":"y"}'),
39
- }
40
- request = Rack::Request.new(env)
41
- params, _ = Committee::RequestUnpacker.new(request, optimistic_json: true).call
42
- assert_equal({ "x" => "y" }, params)
38
+ %w[application/x-www-form-urlencoded multipart/form-data].each do |content_type|
39
+ env = {
40
+ "CONTENT_TYPE" => content_type,
41
+ "rack.input" => StringIO.new('{"x":"y"}'),
42
+ }
43
+ request = Rack::Request.new(env)
44
+ params, _ = Committee::RequestUnpacker.new(request, optimistic_json: true).call
45
+ assert_equal({ "x" => "y" }, params)
46
+ end
43
47
  end
44
48
 
45
49
  it "returns {} when unpacking non-JSON with optimistic_json" do
46
- env = {
47
- "CONTENT_TYPE" => "application/x-www-form-urlencoded",
48
- "rack.input" => StringIO.new('x=y&foo=42'),
49
- }
50
- request = Rack::Request.new(env)
51
- params, _ = Committee::RequestUnpacker.new(request, optimistic_json: true).call
52
- assert_equal({}, params)
50
+ %w[application/x-www-form-urlencoded multipart/form-data].each do |content_type|
51
+ env = {
52
+ "CONTENT_TYPE" => content_type,
53
+ "rack.input" => StringIO.new('x=y&foo=42'),
54
+ }
55
+ request = Rack::Request.new(env)
56
+ params, _ = Committee::RequestUnpacker.new(request, optimistic_json: true).call
57
+ assert_equal({}, params)
58
+ end
53
59
  end
54
60
 
55
61
  it "unpacks an empty hash on an empty request body" do
@@ -63,53 +69,61 @@ describe Committee::RequestUnpacker do
63
69
  end
64
70
 
65
71
  it "doesn't unpack form params" do
66
- env = {
67
- "CONTENT_TYPE" => "application/x-www-form-urlencoded",
68
- "rack.input" => StringIO.new("x=y"),
69
- }
70
- request = Rack::Request.new(env)
71
- params, _ = Committee::RequestUnpacker.new(request).call
72
- assert_equal({}, params)
72
+ %w[application/x-www-form-urlencoded multipart/form-data].each do |content_type|
73
+ env = {
74
+ "CONTENT_TYPE" => content_type,
75
+ "rack.input" => StringIO.new("x=y"),
76
+ }
77
+ request = Rack::Request.new(env)
78
+ params, _ = Committee::RequestUnpacker.new(request).call
79
+ assert_equal({}, params)
80
+ end
73
81
  end
74
82
 
75
83
  it "unpacks form params with allow_form_params" do
76
- env = {
77
- "CONTENT_TYPE" => "application/x-www-form-urlencoded",
78
- "rack.input" => StringIO.new("x=y"),
79
- }
80
- request = Rack::Request.new(env)
81
- params, _ = Committee::RequestUnpacker.new(request, allow_form_params: true).call
82
- assert_equal({ "x" => "y" }, params)
84
+ %w[application/x-www-form-urlencoded multipart/form-data].each do |content_type|
85
+ env = {
86
+ "CONTENT_TYPE" => content_type,
87
+ "rack.input" => StringIO.new("x=y"),
88
+ }
89
+ request = Rack::Request.new(env)
90
+ params, _ = Committee::RequestUnpacker.new(request, allow_form_params: true).call
91
+ assert_equal({ "x" => "y" }, params)
92
+ end
83
93
  end
84
94
 
85
95
  it "coerces form params with coerce_form_params and a schema" do
86
- schema = JsonSchema::Schema.new
87
- schema.properties = { "x" => JsonSchema::Schema.new }
88
- schema.properties["x"].type = ["integer"]
89
-
90
- env = {
91
- "CONTENT_TYPE" => "application/x-www-form-urlencoded",
92
- "rack.input" => StringIO.new("x=1"),
93
- }
94
- request = Rack::Request.new(env)
95
- params, _ = Committee::RequestUnpacker.new(
96
- request,
97
- allow_form_params: true,
98
- coerce_form_params: true,
99
- schema: schema
100
- ).call
101
- assert_equal({ "x" => 1 }, params)
96
+ %w[application/x-www-form-urlencoded multipart/form-data].each do |content_type|
97
+ schema = JsonSchema::Schema.new
98
+ schema.properties = { "x" => JsonSchema::Schema.new }
99
+ schema.properties["x"].type = ["integer"]
100
+
101
+ env = {
102
+ "CONTENT_TYPE" => content_type,
103
+ "rack.input" => StringIO.new("x=1"),
104
+ }
105
+ request = Rack::Request.new(env)
106
+ params, _ = Committee::RequestUnpacker.new(
107
+ request,
108
+ allow_form_params: true,
109
+ coerce_form_params: true,
110
+ schema: schema
111
+ ).call
112
+ assert_equal({ "x" => 1 }, params)
113
+ end
102
114
  end
103
115
 
104
116
  it "unpacks form & query params with allow_form_params and allow_query_params" do
105
- env = {
106
- "CONTENT_TYPE" => "application/x-www-form-urlencoded",
107
- "rack.input" => StringIO.new("x=y"),
108
- "QUERY_STRING" => "a=b"
109
- }
110
- request = Rack::Request.new(env)
111
- params, _ = Committee::RequestUnpacker.new(request, allow_form_params: true, allow_query_params: true).call
112
- assert_equal({ "x" => "y", "a" => "b" }, params)
117
+ %w[application/x-www-form-urlencoded multipart/form-data].each do |content_type|
118
+ env = {
119
+ "CONTENT_TYPE" => content_type,
120
+ "rack.input" => StringIO.new("x=y"),
121
+ "QUERY_STRING" => "a=b"
122
+ }
123
+ request = Rack::Request.new(env)
124
+ params, _ = Committee::RequestUnpacker.new(request, allow_form_params: true, allow_query_params: true).call
125
+ assert_equal({ "x" => "y", "a" => "b" }, params)
126
+ end
113
127
  end
114
128
 
115
129
  it "unpacks query params with allow_query_params" do
@@ -40,7 +40,7 @@ describe Committee::Test::Methods do
40
40
  e = assert_raises(Committee::InvalidResponse) do
41
41
  assert_schema_conform
42
42
  end
43
- assert_match /response header must be set to/i, e.message
43
+ assert_match(/response header must be set to/i, e.message)
44
44
  end
45
45
 
46
46
  it "accepts schema string (legacy behavior)" 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: 2.1.1
4
+ version: 2.2.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: 2018-08-04 00:00:00.000000000 Z
12
+ date: 2018-09-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json_schema
@@ -79,14 +79,14 @@ dependencies:
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '10.3'
82
+ version: '12.3'
83
83
  type: :development
84
84
  prerelease: false
85
85
  version_requirements: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '10.3'
89
+ version: '12.3'
90
90
  - !ruby/object:Gem::Dependency
91
91
  name: rr
92
92
  requirement: !ruby/object:Gem::Requirement
@@ -204,7 +204,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
204
204
  requirements:
205
205
  - - ">="
206
206
  - !ruby/object:Gem::Version
207
- version: '0'
207
+ version: 2.0.0
208
208
  required_rubygems_version: !ruby/object:Gem::Requirement
209
209
  requirements:
210
210
  - - ">="