rack_respond_to_malformed_formats 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@ require "yaml"
|
|
5
5
|
|
6
6
|
module Rack
|
7
7
|
class RespondToMalformedFormats
|
8
|
-
VERSION = "0.0.
|
8
|
+
VERSION = "0.0.4"
|
9
9
|
|
10
10
|
def initialize(app, options = {})
|
11
11
|
@app = app
|
@@ -41,6 +41,7 @@ module Rack
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def parse_json(body)
|
44
|
+
return false if body.nil? || body.to_s.empty?
|
44
45
|
JSON.parse(body)
|
45
46
|
false
|
46
47
|
rescue JSON::ParserError => e
|
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "rack_respond_to_malformed_formats"
|
6
|
-
s.version = "0.0.
|
6
|
+
s.version = "0.0.4"
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.authors = ["Case Commons, LLC"]
|
9
9
|
s.email = ["casecommons-dev@googlegroups.com"]
|
@@ -45,6 +45,32 @@ describe Rack::RespondToMalformedFormats do
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
context "and it is nil" do
|
49
|
+
it "should not break" do
|
50
|
+
test_input = nil
|
51
|
+
app = lambda { |env| [200, {"Content-Type" => "application/json"}, response_for_env(env)] }
|
52
|
+
request = Rack::MockRequest.env_for("/", :params => "", "CONTENT_TYPE" => "application/json", :input => test_input)
|
53
|
+
response = wrapped_app(app).call(request)
|
54
|
+
|
55
|
+
response[0].should == 200
|
56
|
+
response[1]["Content-Type"].should == "application/json"
|
57
|
+
read(response.last).should == 'Got: '
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "and it is blank" do
|
62
|
+
it "should not break" do
|
63
|
+
test_input = ''
|
64
|
+
app = lambda { |env| [200, {"Content-Type" => "application/json"}, response_for_env(env)] }
|
65
|
+
request = Rack::MockRequest.env_for("/", :params => "", "CONTENT_TYPE" => "application/json", :input => test_input)
|
66
|
+
response = wrapped_app(app).call(request)
|
67
|
+
|
68
|
+
response[0].should == 200
|
69
|
+
response[1]["Content-Type"].should == "application/json"
|
70
|
+
read(response.last).should == 'Got: '
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
48
74
|
context "and it is invalid" do
|
49
75
|
it "should return a 400 with a message" do
|
50
76
|
test_input = '{"foo":'
|
@@ -71,6 +97,32 @@ describe Rack::RespondToMalformedFormats do
|
|
71
97
|
end
|
72
98
|
end
|
73
99
|
|
100
|
+
context "and it is nil" do
|
101
|
+
it "should not break" do
|
102
|
+
test_input = nil
|
103
|
+
app = lambda { |env| [200, {"Content-Type" => "application/xml"}, response_for_env(env)] }
|
104
|
+
request = Rack::MockRequest.env_for("/", :params => "", "CONTENT_TYPE" => "application/json", :input => test_input)
|
105
|
+
response = wrapped_app(app).call(request)
|
106
|
+
|
107
|
+
response[0].should == 200
|
108
|
+
response[1]["Content-Type"].should == "application/xml"
|
109
|
+
read(response.last).should == 'Got: '
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context "and it is blank" do
|
114
|
+
it "should not break" do
|
115
|
+
test_input = ''
|
116
|
+
app = lambda { |env| [200, {"Content-Type" => "application/xml"}, response_for_env(env)] }
|
117
|
+
request = Rack::MockRequest.env_for("/", :params => "", "CONTENT_TYPE" => "application/xml", :input => test_input)
|
118
|
+
response = wrapped_app(app).call(request)
|
119
|
+
|
120
|
+
response[0].should == 200
|
121
|
+
response[1]["Content-Type"].should == "application/xml"
|
122
|
+
read(response.last).should == 'Got: '
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
74
126
|
context "and it is invalid" do
|
75
127
|
it "should return a 400 with a message" do
|
76
128
|
test_input = '<ml><foo>bar'
|
@@ -97,6 +149,32 @@ describe Rack::RespondToMalformedFormats do
|
|
97
149
|
end
|
98
150
|
end
|
99
151
|
|
152
|
+
context "and it is nil" do
|
153
|
+
it "should not break" do
|
154
|
+
test_input = nil
|
155
|
+
app = lambda { |env| [200, {"Content-Type" => "application/yaml"}, response_for_env(env)] }
|
156
|
+
request = Rack::MockRequest.env_for("/", :params => "", "CONTENT_TYPE" => "application/json", :input => test_input)
|
157
|
+
response = wrapped_app(app).call(request)
|
158
|
+
|
159
|
+
response[0].should == 200
|
160
|
+
response[1]["Content-Type"].should == "application/yaml"
|
161
|
+
read(response.last).should == 'Got: '
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context "and it is blank" do
|
166
|
+
it "should not break" do
|
167
|
+
test_input = ''
|
168
|
+
app = lambda { |env| [200, {"Content-Type" => "application/yaml"}, response_for_env(env)] }
|
169
|
+
request = Rack::MockRequest.env_for("/", :params => "", "CONTENT_TYPE" => "application/yaml", :input => test_input)
|
170
|
+
response = wrapped_app(app).call(request)
|
171
|
+
|
172
|
+
response[0].should == 200
|
173
|
+
response[1]["Content-Type"].should == "application/yaml"
|
174
|
+
read(response.last).should == 'Got: '
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
100
178
|
context "and it is invalid" do
|
101
179
|
it "should return a 400 with a message" do
|
102
180
|
test_input = "--- what:\nawagasd"
|
metadata
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack_respond_to_malformed_formats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
6
11
|
platform: ruby
|
7
12
|
authors:
|
8
13
|
- Case Commons, LLC
|
@@ -10,7 +15,7 @@ autorequire:
|
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
17
|
|
13
|
-
date: 2011-
|
18
|
+
date: 2011-06-08 00:00:00 -04:00
|
14
19
|
default_executable:
|
15
20
|
dependencies:
|
16
21
|
- !ruby/object:Gem::Dependency
|
@@ -21,6 +26,11 @@ dependencies:
|
|
21
26
|
requirements:
|
22
27
|
- - ">="
|
23
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 15
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 4
|
33
|
+
- 4
|
24
34
|
version: 1.4.4
|
25
35
|
type: :runtime
|
26
36
|
version_requirements: *id001
|
@@ -58,17 +68,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
58
68
|
requirements:
|
59
69
|
- - ">="
|
60
70
|
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
61
74
|
version: "0"
|
62
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
76
|
none: false
|
64
77
|
requirements:
|
65
78
|
- - ">="
|
66
79
|
- !ruby/object:Gem::Version
|
80
|
+
hash: 3
|
81
|
+
segments:
|
82
|
+
- 0
|
67
83
|
version: "0"
|
68
84
|
requirements: []
|
69
85
|
|
70
86
|
rubyforge_project:
|
71
|
-
rubygems_version: 1.
|
87
|
+
rubygems_version: 1.3.7
|
72
88
|
signing_key:
|
73
89
|
specification_version: 3
|
74
90
|
summary: Intercept malformed XML and JSON requests and return XML and JSON 400 responses not HTML 500
|