rack 1.6.13 → 2.0.9
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rack might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/COPYING +1 -1
- data/HISTORY.md +138 -8
- data/README.rdoc +18 -28
- data/Rakefile +6 -14
- data/SPEC +3 -3
- data/contrib/rack_logo.svg +164 -111
- data/example/protectedlobster.rb +1 -1
- data/example/protectedlobster.ru +1 -1
- data/lib/rack/auth/abstract/request.rb +5 -1
- data/lib/rack/auth/digest/params.rb +2 -3
- data/lib/rack/auth/digest/request.rb +1 -1
- data/lib/rack/body_proxy.rb +14 -9
- data/lib/rack/builder.rb +3 -3
- data/lib/rack/chunked.rb +5 -5
- data/lib/rack/{commonlogger.rb → common_logger.rb} +3 -3
- data/lib/rack/content_length.rb +2 -2
- data/lib/rack/deflater.rb +4 -39
- data/lib/rack/directory.rb +66 -54
- data/lib/rack/etag.rb +5 -4
- data/lib/rack/events.rb +154 -0
- data/lib/rack/file.rb +64 -40
- data/lib/rack/handler/cgi.rb +15 -16
- data/lib/rack/handler/fastcgi.rb +13 -14
- data/lib/rack/handler/lsws.rb +11 -11
- data/lib/rack/handler/scgi.rb +15 -15
- data/lib/rack/handler/thin.rb +3 -0
- data/lib/rack/handler/webrick.rb +24 -26
- data/lib/rack/handler.rb +3 -25
- data/lib/rack/head.rb +15 -17
- data/lib/rack/lint.rb +40 -40
- data/lib/rack/lobster.rb +1 -1
- data/lib/rack/lock.rb +15 -10
- data/lib/rack/logger.rb +2 -2
- data/lib/rack/media_type.rb +38 -0
- data/lib/rack/{methodoverride.rb → method_override.rb} +6 -6
- data/lib/rack/mime.rb +18 -5
- data/lib/rack/mock.rb +36 -54
- data/lib/rack/multipart/generator.rb +5 -5
- data/lib/rack/multipart/parser.rb +270 -157
- data/lib/rack/multipart/uploaded_file.rb +1 -2
- data/lib/rack/multipart.rb +35 -6
- data/lib/rack/{nulllogger.rb → null_logger.rb} +1 -1
- data/lib/rack/query_parser.rb +192 -0
- data/lib/rack/recursive.rb +8 -8
- data/lib/rack/request.rb +394 -305
- data/lib/rack/response.rb +130 -57
- data/lib/rack/rewindable_input.rb +1 -12
- data/lib/rack/runtime.rb +10 -18
- data/lib/rack/sendfile.rb +5 -7
- data/lib/rack/server.rb +30 -23
- data/lib/rack/session/abstract/id.rb +110 -75
- data/lib/rack/session/cookie.rb +24 -17
- data/lib/rack/session/memcache.rb +9 -9
- data/lib/rack/session/pool.rb +8 -8
- data/lib/rack/show_exceptions.rb +386 -0
- data/lib/rack/{showstatus.rb → show_status.rb} +3 -3
- data/lib/rack/static.rb +30 -5
- data/lib/rack/tempfile_reaper.rb +2 -2
- data/lib/rack/urlmap.rb +15 -14
- data/lib/rack/utils.rb +138 -211
- data/lib/rack.rb +70 -21
- data/rack.gemspec +10 -9
- data/test/builder/an_underscore_app.rb +5 -0
- data/test/builder/options.ru +1 -1
- data/test/cgi/test.fcgi +1 -0
- data/test/cgi/test.gz +0 -0
- data/test/helper.rb +34 -0
- data/test/multipart/filename_with_encoded_words +7 -0
- data/test/multipart/filename_with_single_quote +7 -0
- data/test/multipart/quoted +15 -0
- data/test/multipart/rack-logo.png +0 -0
- data/test/multipart/unity3d_wwwform +11 -0
- data/test/registering_handler/rack/handler/registering_myself.rb +1 -1
- data/test/spec_auth_basic.rb +27 -19
- data/test/spec_auth_digest.rb +47 -46
- data/test/spec_body_proxy.rb +27 -27
- data/test/spec_builder.rb +51 -41
- data/test/spec_cascade.rb +24 -22
- data/test/spec_cgi.rb +49 -67
- data/test/spec_chunked.rb +37 -35
- data/test/{spec_commonlogger.rb → spec_common_logger.rb} +23 -21
- data/test/{spec_conditionalget.rb → spec_conditional_get.rb} +29 -28
- data/test/spec_config.rb +3 -2
- data/test/spec_content_length.rb +18 -17
- data/test/spec_content_type.rb +13 -12
- data/test/spec_deflater.rb +85 -49
- data/test/spec_directory.rb +87 -27
- data/test/spec_etag.rb +32 -31
- data/test/spec_events.rb +133 -0
- data/test/spec_fastcgi.rb +50 -72
- data/test/spec_file.rb +120 -77
- data/test/spec_handler.rb +19 -34
- data/test/spec_head.rb +15 -14
- data/test/spec_lint.rb +164 -199
- data/test/spec_lobster.rb +24 -23
- data/test/spec_lock.rb +79 -39
- data/test/spec_logger.rb +4 -3
- data/test/spec_media_type.rb +42 -0
- data/test/{spec_methodoverride.rb → spec_method_override.rb} +34 -35
- data/test/spec_mime.rb +19 -19
- data/test/spec_mock.rb +206 -144
- data/test/spec_multipart.rb +322 -200
- data/test/{spec_nulllogger.rb → spec_null_logger.rb} +5 -4
- data/test/spec_recursive.rb +17 -14
- data/test/spec_request.rb +780 -605
- data/test/spec_response.rb +233 -112
- data/test/spec_rewindable_input.rb +50 -40
- data/test/spec_runtime.rb +11 -10
- data/test/spec_sendfile.rb +30 -35
- data/test/spec_server.rb +78 -52
- data/test/spec_session_abstract_id.rb +11 -33
- data/test/spec_session_abstract_session_hash.rb +45 -0
- data/test/spec_session_cookie.rb +99 -67
- data/test/spec_session_memcache.rb +67 -68
- data/test/spec_session_pool.rb +52 -51
- data/test/{spec_showexceptions.rb → spec_show_exceptions.rb} +23 -28
- data/test/{spec_showstatus.rb → spec_show_status.rb} +36 -35
- data/test/spec_static.rb +71 -32
- data/test/spec_tempfile_reaper.rb +11 -10
- data/test/spec_thin.rb +55 -50
- data/test/spec_urlmap.rb +79 -78
- data/test/spec_utils.rb +441 -346
- data/test/spec_version.rb +2 -8
- data/test/spec_webrick.rb +93 -71
- data/test/static/foo.html +1 -0
- data/test/testrequest.rb +1 -1
- data/test/unregistered_handler/rack/handler/unregistered.rb +1 -1
- data/test/unregistered_handler/rack/handler/unregistered_long_one.rb +1 -1
- metadata +57 -36
- data/KNOWN-ISSUES +0 -44
- data/lib/rack/backports/uri/common_18.rb +0 -56
- data/lib/rack/backports/uri/common_192.rb +0 -52
- data/lib/rack/backports/uri/common_193.rb +0 -29
- data/lib/rack/handler/evented_mongrel.rb +0 -8
- data/lib/rack/handler/mongrel.rb +0 -106
- data/lib/rack/handler/swiftiplied_mongrel.rb +0 -8
- data/lib/rack/showexceptions.rb +0 -387
- data/lib/rack/utils/okjson.rb +0 -600
- data/test/spec_mongrel.rb +0 -182
- /data/lib/rack/{conditionalget.rb → conditional_get.rb} +0 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'rack/session/abstract/id'
|
3
|
+
|
4
|
+
describe Rack::Session::Abstract::SessionHash do
|
5
|
+
attr_reader :hash
|
6
|
+
|
7
|
+
def setup
|
8
|
+
super
|
9
|
+
store = Class.new do
|
10
|
+
def load_session(req)
|
11
|
+
["id", {foo: :bar, baz: :qux}]
|
12
|
+
end
|
13
|
+
def session_exists?(req)
|
14
|
+
true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
@hash = Rack::Session::Abstract::SessionHash.new(store.new, nil)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns keys" do
|
21
|
+
assert_equal ["foo", "baz"], hash.keys
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns values" do
|
25
|
+
assert_equal [:bar, :qux], hash.values
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#fetch" do
|
29
|
+
it "returns value for a matching key" do
|
30
|
+
assert_equal :bar, hash.fetch(:foo)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "works with a default value" do
|
34
|
+
assert_equal :default, hash.fetch(:unknown, :default)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "works with a block" do
|
38
|
+
assert_equal :default, hash.fetch(:unkown) { :default }
|
39
|
+
end
|
40
|
+
|
41
|
+
it "it raises when fetching unknown keys without defaults" do
|
42
|
+
lambda { hash.fetch(:unknown) }.must_raise KeyError
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/test/spec_session_cookie.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'minitest/autorun'
|
1
2
|
require 'rack/session/cookie'
|
2
3
|
require 'rack/lint'
|
3
4
|
require 'rack/mock'
|
@@ -10,7 +11,7 @@ describe Rack::Session::Cookie do
|
|
10
11
|
hash.delete("session_id")
|
11
12
|
Rack::Response.new(hash.inspect).to_a
|
12
13
|
end
|
13
|
-
|
14
|
+
|
14
15
|
session_id = lambda do |env|
|
15
16
|
Rack::Response.new(env["rack.session"].to_hash.inspect).to_a
|
16
17
|
end
|
@@ -73,50 +74,50 @@ describe Rack::Session::Cookie do
|
|
73
74
|
it 'uses base64 to encode' do
|
74
75
|
coder = Rack::Session::Cookie::Base64.new
|
75
76
|
str = 'fuuuuu'
|
76
|
-
coder.encode(str).
|
77
|
+
coder.encode(str).must_equal [str].pack('m')
|
77
78
|
end
|
78
79
|
|
79
80
|
it 'uses base64 to decode' do
|
80
81
|
coder = Rack::Session::Cookie::Base64.new
|
81
82
|
str = ['fuuuuu'].pack('m')
|
82
|
-
coder.decode(str).
|
83
|
+
coder.decode(str).must_equal str.unpack('m').first
|
83
84
|
end
|
84
85
|
|
85
86
|
describe 'Marshal' do
|
86
87
|
it 'marshals and base64 encodes' do
|
87
88
|
coder = Rack::Session::Cookie::Base64::Marshal.new
|
88
89
|
str = 'fuuuuu'
|
89
|
-
coder.encode(str).
|
90
|
+
coder.encode(str).must_equal [::Marshal.dump(str)].pack('m')
|
90
91
|
end
|
91
92
|
|
92
93
|
it 'marshals and base64 decodes' do
|
93
94
|
coder = Rack::Session::Cookie::Base64::Marshal.new
|
94
95
|
str = [::Marshal.dump('fuuuuu')].pack('m')
|
95
|
-
coder.decode(str).
|
96
|
+
coder.decode(str).must_equal ::Marshal.load(str.unpack('m').first)
|
96
97
|
end
|
97
98
|
|
98
99
|
it 'rescues failures on decode' do
|
99
100
|
coder = Rack::Session::Cookie::Base64::Marshal.new
|
100
|
-
coder.decode('lulz').
|
101
|
+
coder.decode('lulz').must_be_nil
|
101
102
|
end
|
102
103
|
end
|
103
104
|
|
104
105
|
describe 'JSON' do
|
105
|
-
it '
|
106
|
+
it 'JSON and base64 encodes' do
|
106
107
|
coder = Rack::Session::Cookie::Base64::JSON.new
|
107
108
|
obj = %w[fuuuuu]
|
108
|
-
coder.encode(obj).
|
109
|
+
coder.encode(obj).must_equal [::JSON.dump(obj)].pack('m')
|
109
110
|
end
|
110
111
|
|
111
|
-
it '
|
112
|
+
it 'JSON and base64 decodes' do
|
112
113
|
coder = Rack::Session::Cookie::Base64::JSON.new
|
113
|
-
str = [::
|
114
|
-
coder.decode(str).
|
114
|
+
str = [::JSON.dump(%w[fuuuuu])].pack('m')
|
115
|
+
coder.decode(str).must_equal ::JSON.parse(str.unpack('m').first)
|
115
116
|
end
|
116
117
|
|
117
118
|
it 'rescues failures on decode' do
|
118
119
|
coder = Rack::Session::Cookie::Base64::JSON.new
|
119
|
-
coder.decode('lulz').
|
120
|
+
coder.decode('lulz').must_be_nil
|
120
121
|
end
|
121
122
|
end
|
122
123
|
|
@@ -124,31 +125,46 @@ describe Rack::Session::Cookie do
|
|
124
125
|
it 'jsons, deflates, and base64 encodes' do
|
125
126
|
coder = Rack::Session::Cookie::Base64::ZipJSON.new
|
126
127
|
obj = %w[fuuuuu]
|
127
|
-
json =
|
128
|
-
coder.encode(obj).
|
128
|
+
json = JSON.dump(obj)
|
129
|
+
coder.encode(obj).must_equal [Zlib::Deflate.deflate(json)].pack('m')
|
129
130
|
end
|
130
131
|
|
131
132
|
it 'base64 decodes, inflates, and decodes json' do
|
132
133
|
coder = Rack::Session::Cookie::Base64::ZipJSON.new
|
133
134
|
obj = %w[fuuuuu]
|
134
|
-
json =
|
135
|
+
json = JSON.dump(obj)
|
135
136
|
b64 = [Zlib::Deflate.deflate(json)].pack('m')
|
136
|
-
coder.decode(b64).
|
137
|
+
coder.decode(b64).must_equal obj
|
137
138
|
end
|
138
139
|
|
139
140
|
it 'rescues failures on decode' do
|
140
141
|
coder = Rack::Session::Cookie::Base64::ZipJSON.new
|
141
|
-
coder.decode('lulz').
|
142
|
+
coder.decode('lulz').must_be_nil
|
142
143
|
end
|
143
144
|
end
|
144
145
|
end
|
145
146
|
|
146
147
|
it "warns if no secret is given" do
|
147
148
|
Rack::Session::Cookie.new(incrementor)
|
148
|
-
@warnings.first.
|
149
|
+
@warnings.first.must_match(/no secret/i)
|
149
150
|
@warnings.clear
|
150
151
|
Rack::Session::Cookie.new(incrementor, :secret => 'abc')
|
151
|
-
@warnings.
|
152
|
+
@warnings.must_be :empty?
|
153
|
+
end
|
154
|
+
|
155
|
+
it "doesn't warn if coder is configured to handle encoding" do
|
156
|
+
Rack::Session::Cookie.new(
|
157
|
+
incrementor,
|
158
|
+
:coder => Object.new,
|
159
|
+
:let_coder_handle_secure_encoding => true)
|
160
|
+
@warnings.must_be :empty?
|
161
|
+
end
|
162
|
+
|
163
|
+
it "still warns if coder is not set" do
|
164
|
+
Rack::Session::Cookie.new(
|
165
|
+
incrementor,
|
166
|
+
:let_coder_handle_secure_encoding => true)
|
167
|
+
@warnings.first.must_match(/no secret/i)
|
152
168
|
end
|
153
169
|
|
154
170
|
it 'uses a coder' do
|
@@ -164,25 +180,25 @@ describe Rack::Session::Cookie do
|
|
164
180
|
}.new
|
165
181
|
response = response_for(:app => [incrementor, { :coder => identity }])
|
166
182
|
|
167
|
-
response["Set-Cookie"].
|
168
|
-
response.body.
|
169
|
-
identity.calls.
|
183
|
+
response["Set-Cookie"].must_include "rack.session="
|
184
|
+
response.body.must_equal '{"counter"=>1}'
|
185
|
+
identity.calls.must_equal [:decode, :encode]
|
170
186
|
end
|
171
187
|
|
172
188
|
it "creates a new cookie" do
|
173
189
|
response = response_for(:app => incrementor)
|
174
|
-
response["Set-Cookie"].
|
175
|
-
response.body.
|
190
|
+
response["Set-Cookie"].must_include "rack.session="
|
191
|
+
response.body.must_equal '{"counter"=>1}'
|
176
192
|
end
|
177
193
|
|
178
194
|
it "loads from a cookie" do
|
179
195
|
response = response_for(:app => incrementor)
|
180
196
|
|
181
197
|
response = response_for(:app => incrementor, :cookie => response)
|
182
|
-
response.body.
|
198
|
+
response.body.must_equal '{"counter"=>2}'
|
183
199
|
|
184
200
|
response = response_for(:app => incrementor, :cookie => response)
|
185
|
-
response.body.
|
201
|
+
response.body.must_equal '{"counter"=>3}'
|
186
202
|
end
|
187
203
|
|
188
204
|
it "renew session id" do
|
@@ -191,29 +207,29 @@ describe Rack::Session::Cookie do
|
|
191
207
|
response = response_for(:app => only_session_id, :cookie => cookie)
|
192
208
|
cookie = response['Set-Cookie'] if response['Set-Cookie']
|
193
209
|
|
194
|
-
response.body.
|
210
|
+
response.body.wont_equal ""
|
195
211
|
old_session_id = response.body
|
196
212
|
|
197
213
|
response = response_for(:app => renewer, :cookie => cookie)
|
198
214
|
cookie = response['Set-Cookie'] if response['Set-Cookie']
|
199
215
|
response = response_for(:app => only_session_id, :cookie => cookie)
|
200
216
|
|
201
|
-
response.body.
|
202
|
-
response.body.
|
217
|
+
response.body.wont_equal ""
|
218
|
+
response.body.wont_equal old_session_id
|
203
219
|
end
|
204
220
|
|
205
221
|
it "destroys session" do
|
206
222
|
response = response_for(:app => incrementor)
|
207
223
|
response = response_for(:app => only_session_id, :cookie => response)
|
208
224
|
|
209
|
-
response.body.
|
225
|
+
response.body.wont_equal ""
|
210
226
|
old_session_id = response.body
|
211
227
|
|
212
228
|
response = response_for(:app => destroy_session, :cookie => response)
|
213
229
|
response = response_for(:app => only_session_id, :cookie => response)
|
214
230
|
|
215
|
-
response.body.
|
216
|
-
response.body.
|
231
|
+
response.body.wont_equal ""
|
232
|
+
response.body.wont_equal old_session_id
|
217
233
|
end
|
218
234
|
|
219
235
|
it "survives broken cookies" do
|
@@ -221,19 +237,19 @@ describe Rack::Session::Cookie do
|
|
221
237
|
:app => incrementor,
|
222
238
|
:cookie => "rack.session=blarghfasel"
|
223
239
|
)
|
224
|
-
response.body.
|
240
|
+
response.body.must_equal '{"counter"=>1}'
|
225
241
|
|
226
242
|
response = response_for(
|
227
243
|
:app => [incrementor, { :secret => "test" }],
|
228
244
|
:cookie => "rack.session="
|
229
245
|
)
|
230
|
-
response.body.
|
246
|
+
response.body.must_equal '{"counter"=>1}'
|
231
247
|
end
|
232
248
|
|
233
249
|
it "barks on too big cookies" do
|
234
250
|
lambda{
|
235
251
|
response_for(:app => bigcookie, :request => { :fatal => true })
|
236
|
-
}.
|
252
|
+
}.must_raise Rack::MockRequest::FatalWarning
|
237
253
|
end
|
238
254
|
|
239
255
|
it "loads from a cookie with integrity hash" do
|
@@ -241,58 +257,74 @@ describe Rack::Session::Cookie do
|
|
241
257
|
|
242
258
|
response = response_for(:app => app)
|
243
259
|
response = response_for(:app => app, :cookie => response)
|
244
|
-
response.body.
|
260
|
+
response.body.must_equal '{"counter"=>2}'
|
245
261
|
|
246
262
|
response = response_for(:app => app, :cookie => response)
|
247
|
-
response.body.
|
263
|
+
response.body.must_equal '{"counter"=>3}'
|
248
264
|
|
249
265
|
app = [incrementor, { :secret => "other" }]
|
250
266
|
|
251
267
|
response = response_for(:app => app, :cookie => response)
|
252
|
-
response.body.
|
268
|
+
response.body.must_equal '{"counter"=>1}'
|
253
269
|
end
|
254
270
|
|
255
|
-
it "loads from a cookie
|
271
|
+
it "loads from a cookie with accept-only integrity hash for graceful key rotation" do
|
256
272
|
response = response_for(:app => [incrementor, { :secret => "test" }])
|
257
273
|
|
258
274
|
app = [incrementor, { :secret => "test2", :old_secret => "test" }]
|
259
275
|
response = response_for(:app => app, :cookie => response)
|
260
|
-
response.body.
|
276
|
+
response.body.must_equal '{"counter"=>2}'
|
261
277
|
|
262
278
|
app = [incrementor, { :secret => "test3", :old_secret => "test2" }]
|
263
279
|
response = response_for(:app => app, :cookie => response)
|
264
|
-
response.body.
|
280
|
+
response.body.must_equal '{"counter"=>3}'
|
265
281
|
end
|
266
282
|
|
267
283
|
it "ignores tampered with session cookies" do
|
268
284
|
app = [incrementor, { :secret => "test" }]
|
269
285
|
response = response_for(:app => app)
|
270
|
-
response.body.
|
286
|
+
response.body.must_equal '{"counter"=>1}'
|
271
287
|
|
272
288
|
response = response_for(:app => app, :cookie => response)
|
273
|
-
response.body.
|
289
|
+
response.body.must_equal '{"counter"=>2}'
|
274
290
|
|
275
291
|
_, digest = response["Set-Cookie"].split("--")
|
276
292
|
tampered_with_cookie = "hackerman-was-here" + "--" + digest
|
277
293
|
|
278
294
|
response = response_for(:app => app, :cookie => tampered_with_cookie)
|
279
|
-
response.body.
|
295
|
+
response.body.must_equal '{"counter"=>1}'
|
280
296
|
end
|
281
297
|
|
282
298
|
it "supports either of secret or old_secret" do
|
283
299
|
app = [incrementor, { :secret => "test" }]
|
284
300
|
response = response_for(:app => app)
|
285
|
-
response.body.
|
301
|
+
response.body.must_equal '{"counter"=>1}'
|
286
302
|
|
287
303
|
response = response_for(:app => app, :cookie => response)
|
288
|
-
response.body.
|
304
|
+
response.body.must_equal '{"counter"=>2}'
|
289
305
|
|
290
306
|
app = [incrementor, { :old_secret => "test" }]
|
291
307
|
response = response_for(:app => app)
|
292
|
-
response.body.
|
308
|
+
response.body.must_equal '{"counter"=>1}'
|
309
|
+
|
310
|
+
response = response_for(:app => app, :cookie => response)
|
311
|
+
response.body.must_equal '{"counter"=>2}'
|
312
|
+
end
|
313
|
+
|
314
|
+
it "supports custom digest class" do
|
315
|
+
app = [incrementor, { :secret => "test", hmac: OpenSSL::Digest::SHA256 }]
|
316
|
+
|
317
|
+
response = response_for(:app => app)
|
318
|
+
response = response_for(:app => app, :cookie => response)
|
319
|
+
response.body.must_equal '{"counter"=>2}'
|
320
|
+
|
321
|
+
response = response_for(:app => app, :cookie => response)
|
322
|
+
response.body.must_equal '{"counter"=>3}'
|
323
|
+
|
324
|
+
app = [incrementor, { :secret => "other" }]
|
293
325
|
|
294
326
|
response = response_for(:app => app, :cookie => response)
|
295
|
-
response.body.
|
327
|
+
response.body.must_equal '{"counter"=>1}'
|
296
328
|
end
|
297
329
|
|
298
330
|
it "can handle Rack::Lint middleware" do
|
@@ -300,7 +332,7 @@ describe Rack::Session::Cookie do
|
|
300
332
|
|
301
333
|
lint = Rack::Lint.new(session_id)
|
302
334
|
response = response_for(:app => lint, :cookie => response)
|
303
|
-
response.body.
|
335
|
+
response.body.wont_be :nil?
|
304
336
|
end
|
305
337
|
|
306
338
|
it "can handle middleware that inspects the env" do
|
@@ -318,73 +350,73 @@ describe Rack::Session::Cookie do
|
|
318
350
|
|
319
351
|
inspector = TestEnvInspector.new(session_id)
|
320
352
|
response = response_for(:app => inspector, :cookie => response)
|
321
|
-
response.body.
|
353
|
+
response.body.wont_be :nil?
|
322
354
|
end
|
323
355
|
|
324
356
|
it "returns the session id in the session hash" do
|
325
357
|
response = response_for(:app => incrementor)
|
326
|
-
response.body.
|
358
|
+
response.body.must_equal '{"counter"=>1}'
|
327
359
|
|
328
360
|
response = response_for(:app => session_id, :cookie => response)
|
329
|
-
response.body.
|
330
|
-
response.body.
|
361
|
+
response.body.must_match(/"session_id"=>/)
|
362
|
+
response.body.must_match(/"counter"=>1/)
|
331
363
|
end
|
332
364
|
|
333
365
|
it "does not return a cookie if set to secure but not using ssl" do
|
334
366
|
app = [incrementor, { :secure => true }]
|
335
367
|
|
336
368
|
response = response_for(:app => app)
|
337
|
-
response["Set-Cookie"].
|
369
|
+
response["Set-Cookie"].must_be_nil
|
338
370
|
|
339
371
|
response = response_for(:app => app, :request => { "HTTPS" => "on" })
|
340
|
-
response["Set-Cookie"].
|
341
|
-
response["Set-Cookie"].
|
372
|
+
response["Set-Cookie"].wont_be :nil?
|
373
|
+
response["Set-Cookie"].must_match(/secure/)
|
342
374
|
end
|
343
375
|
|
344
376
|
it "does not return a cookie if cookie was not read/written" do
|
345
377
|
response = response_for(:app => nothing)
|
346
|
-
response["Set-Cookie"].
|
378
|
+
response["Set-Cookie"].must_be_nil
|
347
379
|
end
|
348
380
|
|
349
381
|
it "does not return a cookie if cookie was not written (only read)" do
|
350
382
|
response = response_for(:app => session_id)
|
351
|
-
response["Set-Cookie"].
|
383
|
+
response["Set-Cookie"].must_be_nil
|
352
384
|
end
|
353
385
|
|
354
386
|
it "returns even if not read/written if :expire_after is set" do
|
355
387
|
app = [nothing, { :expire_after => 3600 }]
|
356
388
|
request = { "rack.session" => { "not" => "empty" }}
|
357
389
|
response = response_for(:app => app, :request => request)
|
358
|
-
response["Set-Cookie"].
|
390
|
+
response["Set-Cookie"].wont_be :nil?
|
359
391
|
end
|
360
392
|
|
361
393
|
it "returns no cookie if no data was written and no session was created previously, even if :expire_after is set" do
|
362
394
|
app = [nothing, { :expire_after => 3600 }]
|
363
395
|
response = response_for(:app => app)
|
364
|
-
response["Set-Cookie"].
|
396
|
+
response["Set-Cookie"].must_be_nil
|
365
397
|
end
|
366
398
|
|
367
399
|
it "exposes :secret in env['rack.session.option']" do
|
368
400
|
response = response_for(:app => [session_option[:secret], { :secret => "foo" }])
|
369
|
-
response.body.
|
401
|
+
response.body.must_equal '"foo"'
|
370
402
|
end
|
371
403
|
|
372
404
|
it "exposes :coder in env['rack.session.option']" do
|
373
405
|
response = response_for(:app => session_option[:coder])
|
374
|
-
response.body.
|
406
|
+
response.body.must_match(/Base64::Marshal/)
|
375
407
|
end
|
376
408
|
|
377
409
|
it "allows passing in a hash with session data from middleware in front" do
|
378
410
|
request = { 'rack.session' => { :foo => 'bar' }}
|
379
411
|
response = response_for(:app => session_id, :request => request)
|
380
|
-
response.body.
|
412
|
+
response.body.must_match(/foo/)
|
381
413
|
end
|
382
414
|
|
383
415
|
it "allows modifying session data with session data from middleware in front" do
|
384
416
|
request = { 'rack.session' => { :foo => 'bar' }}
|
385
417
|
response = response_for(:app => incrementor, :request => request)
|
386
|
-
response.body.
|
387
|
-
response.body.
|
418
|
+
response.body.must_match(/counter/)
|
419
|
+
response.body.must_match(/foo/)
|
388
420
|
end
|
389
421
|
|
390
422
|
it "allows more than one '--' in the cookie when calculating digests" do
|
@@ -403,8 +435,8 @@ describe Rack::Session::Cookie do
|
|
403
435
|
}.new
|
404
436
|
_app = [ app, { :secret => "test", :coder => unsafe_coder } ]
|
405
437
|
response = response_for(:app => _app)
|
406
|
-
response.body.
|
438
|
+
response.body.must_equal "1--"
|
407
439
|
response = response_for(:app => _app, :cookie => response)
|
408
|
-
response.body.
|
440
|
+
response.body.must_equal "1--2--"
|
409
441
|
end
|
410
442
|
end
|