committee 1.3.0 → 1.4.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: becdf8694f016697cfe01ac64b851bf45c90c64e
4
- data.tar.gz: 88e687a7af19cf547342bacce32b5fb72212f0b5
3
+ metadata.gz: 6b05a8a59c6673176acda0f5ec37736b2292ac6d
4
+ data.tar.gz: a293f3f5cf8412f4dd0c40ee97fc3c571f8d4f9f
5
5
  SHA512:
6
- metadata.gz: 7b618b8007da0078eeba04958a12e11f4fd1d87f55e631f1d2585c483a762b513ffc58e4f41e89f9b6b6f63f6ae984e425bff59070e8fba13603ef3a95295ce2
7
- data.tar.gz: 45007433833b8e24b943662060c9f156dc951b41107859686639352b4d99a8956f9ec705d176f493583d9013dcdca5e63eba2a9c90456347404284590dfefc6c
6
+ metadata.gz: a3f7d92b542ca2cfc9e60fb69d5c3d71f4d24b4a2d3ba14200e815812116f097a34756314e359b1674c7003b0796e111d405d08f9dea03000720b7e027302b79
7
+ data.tar.gz: 3337cdc111ea2d368b39d433e88b3a0f28b4f064b595ea4c849b8c217e724af13fde1a7327f14bce55bb22ec0a6250acd0a24bc2d2802894265ff0792f02c243
@@ -5,7 +5,7 @@ module Committee
5
5
  end
6
6
 
7
7
  def call(request, data)
8
- check_content_type!(request)
8
+ check_content_type!(request, data)
9
9
  if @link.schema
10
10
  valid, errors = @link.schema.validate(data)
11
11
  if !valid
@@ -17,13 +17,22 @@ module Committee
17
17
 
18
18
  private
19
19
 
20
- def check_content_type!(request)
21
- if request.content_type
20
+ def check_content_type!(request, data)
21
+ if request.content_type && !empty_request?(request)
22
22
  unless Rack::Mime.match?(@link.enc_type, request.content_type)
23
23
  raise Committee::InvalidRequest,
24
24
  %{"Content-Type" request header must be set to "#{@link.enc_type}".}
25
25
  end
26
26
  end
27
27
  end
28
+
29
+ def empty_request?(request)
30
+ # small optimization: assume GET and DELETE don't have bodies
31
+ return true if request.get? || request.delete?
32
+
33
+ data = request.body.read
34
+ request.body.rewind
35
+ data.empty?
36
+ end
28
37
  end
29
38
  end
@@ -10,7 +10,9 @@ describe Committee::RequestValidator do
10
10
  # POST /apps/:id
11
11
  @link = @link = @schema.properties["app"].links[0]
12
12
  @request = Rack::Request.new({
13
- "CONTENT_TYPE" => "application/json",
13
+ "CONTENT_TYPE" => "application/json",
14
+ "rack.input" => StringIO.new("{}"),
15
+ "REQUEST_METHOD" => "POST"
14
16
  })
15
17
  end
16
18
 
@@ -24,7 +26,10 @@ describe Committee::RequestValidator do
24
26
  it "detects an invalid request Content-Type" do
25
27
  e = assert_raises(Committee::InvalidRequest) {
26
28
  @request =
27
- Rack::Request.new("CONTENT_TYPE" => "application/x-www-form-urlencoded")
29
+ Rack::Request.new({
30
+ "CONTENT_TYPE" => "application/x-www-form-urlencoded",
31
+ "rack.input" => StringIO.new("{}"),
32
+ })
28
33
  call({})
29
34
  }
30
35
  message =
@@ -32,6 +37,15 @@ describe Committee::RequestValidator do
32
37
  assert_equal message, e.message
33
38
  end
34
39
 
40
+ it "allows an invalid Content-Type with an empty body" do
41
+ @request =
42
+ Rack::Request.new({
43
+ "CONTENT_TYPE" => "application/x-www-form-urlencoded",
44
+ "rack.input" => StringIO.new(""),
45
+ })
46
+ call({})
47
+ end
48
+
35
49
  it "detects a parameter of the wrong pattern" do
36
50
  data = {
37
51
  "name" => "%@!"
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.3.0
4
+ version: 1.4.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-16 00:00:00.000000000 Z
12
+ date: 2014-06-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json_schema