rack 1.4.7 → 2.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +77 -0
- data/{COPYING → MIT-LICENSE} +4 -2
- data/README.rdoc +122 -456
- data/Rakefile +32 -31
- data/SPEC +119 -29
- data/bin/rackup +1 -0
- data/contrib/rack_logo.svg +164 -111
- data/example/lobster.ru +2 -0
- data/example/protectedlobster.rb +4 -2
- data/example/protectedlobster.ru +3 -1
- data/lib/rack/auth/abstract/handler.rb +7 -5
- data/lib/rack/auth/abstract/request.rb +8 -6
- data/lib/rack/auth/basic.rb +5 -2
- data/lib/rack/auth/digest/md5.rb +10 -8
- data/lib/rack/auth/digest/nonce.rb +6 -3
- data/lib/rack/auth/digest/params.rb +5 -4
- data/lib/rack/auth/digest/request.rb +4 -2
- data/lib/rack/body_proxy.rb +11 -9
- data/lib/rack/builder.rb +63 -20
- data/lib/rack/cascade.rb +10 -9
- data/lib/rack/chunked.rb +45 -11
- data/lib/rack/{commonlogger.rb → common_logger.rb} +24 -15
- data/lib/rack/{conditionalget.rb → conditional_get.rb} +20 -6
- data/lib/rack/config.rb +7 -0
- data/lib/rack/content_length.rb +12 -6
- data/lib/rack/content_type.rb +4 -2
- data/lib/rack/core_ext/regexp.rb +14 -0
- data/lib/rack/deflater.rb +73 -42
- data/lib/rack/directory.rb +77 -56
- data/lib/rack/etag.rb +25 -13
- data/lib/rack/events.rb +156 -0
- data/lib/rack/file.rb +4 -143
- data/lib/rack/files.rb +178 -0
- data/lib/rack/handler/cgi.rb +18 -17
- data/lib/rack/handler/fastcgi.rb +21 -17
- data/lib/rack/handler/lsws.rb +14 -12
- data/lib/rack/handler/scgi.rb +27 -21
- data/lib/rack/handler/thin.rb +19 -5
- data/lib/rack/handler/webrick.rb +66 -24
- data/lib/rack/handler.rb +29 -19
- data/lib/rack/head.rb +21 -14
- data/lib/rack/lint.rb +259 -65
- data/lib/rack/lobster.rb +17 -10
- data/lib/rack/lock.rb +19 -10
- data/lib/rack/logger.rb +4 -2
- data/lib/rack/media_type.rb +43 -0
- data/lib/rack/method_override.rb +52 -0
- data/lib/rack/mime.rb +43 -6
- data/lib/rack/mock.rb +109 -44
- data/lib/rack/multipart/generator.rb +11 -12
- data/lib/rack/multipart/parser.rb +302 -115
- data/lib/rack/multipart/uploaded_file.rb +4 -3
- data/lib/rack/multipart.rb +40 -9
- data/lib/rack/null_logger.rb +39 -0
- data/lib/rack/query_parser.rb +218 -0
- data/lib/rack/recursive.rb +14 -11
- data/lib/rack/reloader.rb +12 -5
- data/lib/rack/request.rb +484 -270
- data/lib/rack/response.rb +196 -77
- data/lib/rack/rewindable_input.rb +5 -14
- data/lib/rack/runtime.rb +13 -6
- data/lib/rack/sendfile.rb +44 -20
- data/lib/rack/server.rb +175 -61
- data/lib/rack/session/abstract/id.rb +276 -133
- data/lib/rack/session/cookie.rb +75 -40
- data/lib/rack/session/memcache.rb +4 -87
- data/lib/rack/session/pool.rb +24 -18
- data/lib/rack/show_exceptions.rb +392 -0
- data/lib/rack/{showstatus.rb → show_status.rb} +11 -9
- data/lib/rack/static.rb +65 -38
- data/lib/rack/tempfile_reaper.rb +24 -0
- data/lib/rack/urlmap.rb +40 -15
- data/lib/rack/utils.rb +316 -285
- data/lib/rack.rb +78 -23
- data/rack.gemspec +26 -19
- metadata +44 -209
- data/KNOWN-ISSUES +0 -30
- 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 -100
- data/lib/rack/handler/swiftiplied_mongrel.rb +0 -8
- data/lib/rack/methodoverride.rb +0 -33
- data/lib/rack/nulllogger.rb +0 -18
- data/lib/rack/showexceptions.rb +0 -378
- data/test/builder/anything.rb +0 -5
- data/test/builder/comment.ru +0 -4
- data/test/builder/end.ru +0 -5
- data/test/builder/line.ru +0 -1
- data/test/builder/options.ru +0 -2
- data/test/cgi/assets/folder/test.js +0 -1
- data/test/cgi/assets/fonts/font.eot +0 -1
- data/test/cgi/assets/images/image.png +0 -1
- data/test/cgi/assets/index.html +0 -1
- data/test/cgi/assets/javascripts/app.js +0 -1
- data/test/cgi/assets/stylesheets/app.css +0 -1
- data/test/cgi/lighttpd.conf +0 -26
- data/test/cgi/lighttpd.errors +0 -1
- data/test/cgi/rackup_stub.rb +0 -6
- data/test/cgi/sample_rackup.ru +0 -5
- data/test/cgi/test +0 -9
- data/test/cgi/test+directory/test+file +0 -1
- data/test/cgi/test.fcgi +0 -8
- data/test/cgi/test.ru +0 -5
- data/test/gemloader.rb +0 -10
- data/test/multipart/bad_robots +0 -259
- data/test/multipart/binary +0 -0
- data/test/multipart/content_type_and_no_filename +0 -6
- data/test/multipart/empty +0 -10
- data/test/multipart/fail_16384_nofile +0 -814
- data/test/multipart/file1.txt +0 -1
- data/test/multipart/filename_and_modification_param +0 -7
- data/test/multipart/filename_with_escaped_quotes +0 -6
- data/test/multipart/filename_with_escaped_quotes_and_modification_param +0 -7
- data/test/multipart/filename_with_percent_escaped_quotes +0 -6
- data/test/multipart/filename_with_unescaped_percentages +0 -6
- data/test/multipart/filename_with_unescaped_percentages2 +0 -6
- data/test/multipart/filename_with_unescaped_percentages3 +0 -6
- data/test/multipart/filename_with_unescaped_quotes +0 -6
- data/test/multipart/ie +0 -6
- data/test/multipart/mixed_files +0 -21
- data/test/multipart/nested +0 -10
- data/test/multipart/none +0 -9
- data/test/multipart/semicolon +0 -6
- data/test/multipart/text +0 -15
- data/test/multipart/three_files_three_fields +0 -31
- data/test/multipart/webkit +0 -32
- data/test/rackup/config.ru +0 -31
- data/test/registering_handler/rack/handler/registering_myself.rb +0 -8
- data/test/spec_auth.rb +0 -57
- data/test/spec_auth_basic.rb +0 -81
- data/test/spec_auth_digest.rb +0 -259
- data/test/spec_body_proxy.rb +0 -69
- data/test/spec_builder.rb +0 -207
- data/test/spec_cascade.rb +0 -61
- data/test/spec_cgi.rb +0 -102
- data/test/spec_chunked.rb +0 -87
- data/test/spec_commonlogger.rb +0 -57
- data/test/spec_conditionalget.rb +0 -102
- data/test/spec_config.rb +0 -22
- data/test/spec_content_length.rb +0 -86
- data/test/spec_content_type.rb +0 -45
- data/test/spec_deflater.rb +0 -187
- data/test/spec_directory.rb +0 -88
- data/test/spec_etag.rb +0 -98
- data/test/spec_fastcgi.rb +0 -107
- data/test/spec_file.rb +0 -200
- data/test/spec_handler.rb +0 -59
- data/test/spec_head.rb +0 -48
- data/test/spec_lint.rb +0 -515
- data/test/spec_lobster.rb +0 -58
- data/test/spec_lock.rb +0 -167
- data/test/spec_logger.rb +0 -23
- data/test/spec_methodoverride.rb +0 -72
- data/test/spec_mock.rb +0 -269
- data/test/spec_mongrel.rb +0 -182
- data/test/spec_multipart.rb +0 -479
- data/test/spec_nulllogger.rb +0 -23
- data/test/spec_recursive.rb +0 -72
- data/test/spec_request.rb +0 -955
- data/test/spec_response.rb +0 -313
- data/test/spec_rewindable_input.rb +0 -118
- data/test/spec_runtime.rb +0 -49
- data/test/spec_sendfile.rb +0 -90
- data/test/spec_server.rb +0 -121
- data/test/spec_session_abstract_id.rb +0 -43
- data/test/spec_session_cookie.rb +0 -361
- data/test/spec_session_memcache.rb +0 -321
- data/test/spec_session_pool.rb +0 -209
- data/test/spec_showexceptions.rb +0 -92
- data/test/spec_showstatus.rb +0 -84
- data/test/spec_static.rb +0 -145
- data/test/spec_thin.rb +0 -86
- data/test/spec_urlmap.rb +0 -213
- data/test/spec_utils.rb +0 -554
- data/test/spec_webrick.rb +0 -143
- data/test/static/another/index.html +0 -1
- data/test/static/index.html +0 -1
- data/test/testrequest.rb +0 -78
- data/test/unregistered_handler/rack/handler/unregistered.rb +0 -7
- data/test/unregistered_handler/rack/handler/unregistered_long_one.rb +0 -7
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
### WARNING: there be hax in this file.
|
|
2
|
-
|
|
3
|
-
require 'rack/session/abstract/id'
|
|
4
|
-
|
|
5
|
-
describe Rack::Session::Abstract::ID do
|
|
6
|
-
id = Rack::Session::Abstract::ID
|
|
7
|
-
|
|
8
|
-
def silence_warning
|
|
9
|
-
o, $VERBOSE = $VERBOSE, nil
|
|
10
|
-
yield
|
|
11
|
-
ensure
|
|
12
|
-
$VERBOSE = o
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def reload_id
|
|
16
|
-
$".delete $".find { |part| part =~ %r{session/abstract/id.rb} }
|
|
17
|
-
silence_warning { require 'rack/session/abstract/id' }
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
should "use securerandom when available" do
|
|
21
|
-
begin
|
|
22
|
-
fake = false
|
|
23
|
-
silence_warning do
|
|
24
|
-
::SecureRandom = fake = true unless defined?(SecureRandom)
|
|
25
|
-
end
|
|
26
|
-
reload_id
|
|
27
|
-
id::DEFAULT_OPTIONS[:secure_random].should.eql(fake || SecureRandom)
|
|
28
|
-
ensure
|
|
29
|
-
Object.send(:remove_const, :SecureRandom) if fake
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
should "not use securerandom when unavailable" do
|
|
34
|
-
begin
|
|
35
|
-
sr = Object.send(:remove_const, :SecureRandom) if defined?(SecureRandom)
|
|
36
|
-
reload_id
|
|
37
|
-
id::DEFAULT_OPTIONS[:secure_random].should.eql false
|
|
38
|
-
ensure
|
|
39
|
-
::SecureRandom = sr if defined?(sr)
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
end
|
data/test/spec_session_cookie.rb
DELETED
|
@@ -1,361 +0,0 @@
|
|
|
1
|
-
require 'rack/session/cookie'
|
|
2
|
-
require 'rack/lint'
|
|
3
|
-
require 'rack/mock'
|
|
4
|
-
|
|
5
|
-
describe Rack::Session::Cookie do
|
|
6
|
-
incrementor = lambda do |env|
|
|
7
|
-
env["rack.session"]["counter"] ||= 0
|
|
8
|
-
env["rack.session"]["counter"] += 1
|
|
9
|
-
hash = env["rack.session"].dup
|
|
10
|
-
hash.delete("session_id")
|
|
11
|
-
Rack::Response.new(hash.inspect).to_a
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
session_id = lambda do |env|
|
|
15
|
-
Rack::Response.new(env["rack.session"].to_hash.inspect).to_a
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
session_option = lambda do |opt|
|
|
19
|
-
lambda do |env|
|
|
20
|
-
Rack::Response.new(env["rack.session.options"][opt].inspect).to_a
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
nothing = lambda do |env|
|
|
25
|
-
Rack::Response.new("Nothing").to_a
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
renewer = lambda do |env|
|
|
29
|
-
env["rack.session.options"][:renew] = true
|
|
30
|
-
Rack::Response.new("Nothing").to_a
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
only_session_id = lambda do |env|
|
|
34
|
-
Rack::Response.new(env["rack.session"]["session_id"].to_s).to_a
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
bigcookie = lambda do |env|
|
|
38
|
-
env["rack.session"]["cookie"] = "big" * 3000
|
|
39
|
-
Rack::Response.new(env["rack.session"].inspect).to_a
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
destroy_session = lambda do |env|
|
|
43
|
-
env["rack.session"].destroy
|
|
44
|
-
Rack::Response.new("Nothing").to_a
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def response_for(options={})
|
|
48
|
-
request_options = options.fetch(:request, {})
|
|
49
|
-
cookie = if options[:cookie].is_a?(Rack::Response)
|
|
50
|
-
options[:cookie]["Set-Cookie"]
|
|
51
|
-
else
|
|
52
|
-
options[:cookie]
|
|
53
|
-
end
|
|
54
|
-
request_options["HTTP_COOKIE"] = cookie || ""
|
|
55
|
-
|
|
56
|
-
app_with_cookie = Rack::Session::Cookie.new(*options[:app])
|
|
57
|
-
app_with_cookie = Rack::Lint.new(app_with_cookie)
|
|
58
|
-
Rack::MockRequest.new(app_with_cookie).get("/", request_options)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
before do
|
|
62
|
-
@warnings = warnings = []
|
|
63
|
-
Rack::Session::Cookie.class_eval do
|
|
64
|
-
define_method(:warn) { |m| warnings << m }
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
after do
|
|
69
|
-
Rack::Session::Cookie.class_eval { remove_method :warn }
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
describe 'Base64' do
|
|
73
|
-
it 'uses base64 to encode' do
|
|
74
|
-
coder = Rack::Session::Cookie::Base64.new
|
|
75
|
-
str = 'fuuuuu'
|
|
76
|
-
coder.encode(str).should.equal [str].pack('m')
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
it 'uses base64 to decode' do
|
|
80
|
-
coder = Rack::Session::Cookie::Base64.new
|
|
81
|
-
str = ['fuuuuu'].pack('m')
|
|
82
|
-
coder.decode(str).should.equal str.unpack('m').first
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
describe 'Marshal' do
|
|
86
|
-
it 'marshals and base64 encodes' do
|
|
87
|
-
coder = Rack::Session::Cookie::Base64::Marshal.new
|
|
88
|
-
str = 'fuuuuu'
|
|
89
|
-
coder.encode(str).should.equal [::Marshal.dump(str)].pack('m')
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
it 'marshals and base64 decodes' do
|
|
93
|
-
coder = Rack::Session::Cookie::Base64::Marshal.new
|
|
94
|
-
str = [::Marshal.dump('fuuuuu')].pack('m')
|
|
95
|
-
coder.decode(str).should.equal ::Marshal.load(str.unpack('m').first)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
it 'rescues failures on decode' do
|
|
99
|
-
coder = Rack::Session::Cookie::Base64::Marshal.new
|
|
100
|
-
coder.decode('lulz').should.equal nil
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
it "warns if no secret is given" do
|
|
106
|
-
cookie = Rack::Session::Cookie.new(incrementor)
|
|
107
|
-
@warnings.first.should =~ /no secret/i
|
|
108
|
-
@warnings.clear
|
|
109
|
-
cookie = Rack::Session::Cookie.new(incrementor, :secret => 'abc')
|
|
110
|
-
@warnings.should.be.empty?
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
it 'uses a coder' do
|
|
114
|
-
identity = Class.new {
|
|
115
|
-
attr_reader :calls
|
|
116
|
-
|
|
117
|
-
def initialize
|
|
118
|
-
@calls = []
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
def encode(str); @calls << :encode; str; end
|
|
122
|
-
def decode(str); @calls << :decode; str; end
|
|
123
|
-
}.new
|
|
124
|
-
cookie = Rack::Session::Cookie.new(incrementor, :coder => identity)
|
|
125
|
-
res = Rack::MockRequest.new(cookie).get("/")
|
|
126
|
-
res["Set-Cookie"].should.include("rack.session=")
|
|
127
|
-
res.body.should.equal '{"counter"=>1}'
|
|
128
|
-
identity.calls.should.equal [:decode, :encode]
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
it "creates a new cookie" do
|
|
132
|
-
res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor)).get("/")
|
|
133
|
-
res["Set-Cookie"].should.include("rack.session=")
|
|
134
|
-
res.body.should.equal '{"counter"=>1}'
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
it "loads from a cookie" do
|
|
138
|
-
res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor)).get("/")
|
|
139
|
-
cookie = res["Set-Cookie"]
|
|
140
|
-
res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor)).
|
|
141
|
-
get("/", "HTTP_COOKIE" => cookie)
|
|
142
|
-
res.body.should.equal '{"counter"=>2}'
|
|
143
|
-
cookie = res["Set-Cookie"]
|
|
144
|
-
res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor)).
|
|
145
|
-
get("/", "HTTP_COOKIE" => cookie)
|
|
146
|
-
res.body.should.equal '{"counter"=>3}'
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
renewer = lambda do |env|
|
|
150
|
-
env["rack.session.options"][:renew] = true
|
|
151
|
-
Rack::Response.new("Nothing").to_a
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
only_session_id = lambda do |env|
|
|
155
|
-
Rack::Response.new(env["rack.session"]["session_id"].to_s).to_a
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
it "renew session id" do
|
|
159
|
-
res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor)).get("/")
|
|
160
|
-
res = Rack::MockRequest.new(Rack::Session::Cookie.new(only_session_id)).
|
|
161
|
-
get("/", "HTTP_COOKIE" => res["Set-Cookie"])
|
|
162
|
-
|
|
163
|
-
res.body.should.not.equal ""
|
|
164
|
-
old_session_id = res.body
|
|
165
|
-
|
|
166
|
-
res = Rack::MockRequest.new(Rack::Session::Cookie.new(renewer)).
|
|
167
|
-
get("/", "HTTP_COOKIE" => res["Set-Cookie"])
|
|
168
|
-
res = Rack::MockRequest.new(Rack::Session::Cookie.new(only_session_id)).
|
|
169
|
-
get("/", "HTTP_COOKIE" => res["Set-Cookie"])
|
|
170
|
-
|
|
171
|
-
res.body.should.not.equal ""
|
|
172
|
-
res.body.should.not.equal old_session_id
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
it "survives broken cookies" do
|
|
176
|
-
res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor)).
|
|
177
|
-
get("/", "HTTP_COOKIE" => "rack.session=blarghfasel")
|
|
178
|
-
res.body.should.equal '{"counter"=>1}'
|
|
179
|
-
|
|
180
|
-
app = Rack::Session::Cookie.new(incrementor, :secret => 'test')
|
|
181
|
-
res = Rack::MockRequest.new(app).get("/", "HTTP_COOKIE" => "rack.session=")
|
|
182
|
-
res.body.should.equal '{"counter"=>1}'
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
bigcookie = lambda do |env|
|
|
186
|
-
env["rack.session"]["cookie"] = "big" * 3000
|
|
187
|
-
Rack::Response.new(env["rack.session"].inspect).to_a
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
it "barks on too big cookies" do
|
|
191
|
-
lambda{
|
|
192
|
-
Rack::MockRequest.new(Rack::Session::Cookie.new(bigcookie)).
|
|
193
|
-
get("/", :fatal => true)
|
|
194
|
-
}.should.raise(Rack::MockRequest::FatalWarning)
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
it "loads from a cookie with integrity hash" do
|
|
198
|
-
res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor, :secret => 'test')).get("/")
|
|
199
|
-
cookie = res["Set-Cookie"]
|
|
200
|
-
res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor, :secret => 'test')).
|
|
201
|
-
get("/", "HTTP_COOKIE" => cookie)
|
|
202
|
-
res.body.should.equal '{"counter"=>2}'
|
|
203
|
-
cookie = res["Set-Cookie"]
|
|
204
|
-
res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor, :secret => 'test')).
|
|
205
|
-
get("/", "HTTP_COOKIE" => cookie)
|
|
206
|
-
res.body.should.equal '{"counter"=>3}'
|
|
207
|
-
res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor, :secret => 'other')).
|
|
208
|
-
get("/", "HTTP_COOKIE" => cookie)
|
|
209
|
-
res.body.should.equal '{"counter"=>1}'
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
it "loads from a cookie wih accept-only integrity hash for graceful key rotation" do
|
|
213
|
-
res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor, :secret => 'test')).get("/")
|
|
214
|
-
cookie = res["Set-Cookie"]
|
|
215
|
-
res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor, :secret => 'test2', :old_secret => 'test')).
|
|
216
|
-
get("/", "HTTP_COOKIE" => cookie)
|
|
217
|
-
res.body.should.equal '{"counter"=>2}'
|
|
218
|
-
cookie = res["Set-Cookie"]
|
|
219
|
-
res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor, :secret => 'test3', :old_secret => 'test2')).
|
|
220
|
-
get("/", "HTTP_COOKIE" => cookie)
|
|
221
|
-
res.body.should.equal '{"counter"=>3}'
|
|
222
|
-
end
|
|
223
|
-
|
|
224
|
-
it "ignores tampered with session cookies" do
|
|
225
|
-
app = Rack::Session::Cookie.new(incrementor, :secret => 'test')
|
|
226
|
-
response1 = Rack::MockRequest.new(app).get("/")
|
|
227
|
-
response1.body.should.equal '{"counter"=>1}'
|
|
228
|
-
response1 = Rack::MockRequest.new(app).get("/", "HTTP_COOKIE" => response1["Set-Cookie"])
|
|
229
|
-
response1.body.should.equal '{"counter"=>2}'
|
|
230
|
-
|
|
231
|
-
_, digest = response1["Set-Cookie"].split("--")
|
|
232
|
-
tampered_with_cookie = "hackerman-was-here" + "--" + digest
|
|
233
|
-
response2 = Rack::MockRequest.new(app).get("/", "HTTP_COOKIE" =>
|
|
234
|
-
tampered_with_cookie)
|
|
235
|
-
|
|
236
|
-
# Tampered cookie was ignored. Counter is back to 1.
|
|
237
|
-
response2.body.should.equal '{"counter"=>1}'
|
|
238
|
-
end
|
|
239
|
-
|
|
240
|
-
it "supports either of secret or old_secret" do
|
|
241
|
-
app = Rack::Session::Cookie.new(incrementor, :secret => 'test')
|
|
242
|
-
res = Rack::MockRequest.new(app).get("/")
|
|
243
|
-
res.body.should.equal '{"counter"=>1}'
|
|
244
|
-
res = Rack::MockRequest.new(app).get("/", "HTTP_COOKIE" => res["Set-Cookie"])
|
|
245
|
-
res.body.should.equal '{"counter"=>2}'
|
|
246
|
-
app = Rack::Session::Cookie.new(incrementor, :old_secret => 'test')
|
|
247
|
-
res = Rack::MockRequest.new(app).get("/")
|
|
248
|
-
res.body.should.equal '{"counter"=>1}'
|
|
249
|
-
res = Rack::MockRequest.new(app).get("/", "HTTP_COOKIE" => res["Set-Cookie"])
|
|
250
|
-
res.body.should.equal '{"counter"=>2}'
|
|
251
|
-
end
|
|
252
|
-
|
|
253
|
-
describe "1.9 bugs relating to inspecting yet-to-be-loaded from cookie data: Rack::Session::Abstract::SessionHash" do
|
|
254
|
-
|
|
255
|
-
it "can handle Rack::Lint middleware" do
|
|
256
|
-
app = Rack::Session::Cookie.new(incrementor)
|
|
257
|
-
res = Rack::MockRequest.new(app).get("/")
|
|
258
|
-
|
|
259
|
-
app = Rack::Session::Cookie.new(Rack::Lint.new(session_id))
|
|
260
|
-
res = Rack::MockRequest.new(app).get("/", "HTTP_COOKIE" => res["Set-Cookie"])
|
|
261
|
-
res.body.should.not.be.nil
|
|
262
|
-
end
|
|
263
|
-
|
|
264
|
-
it "can handle a middleware that inspects the env" do
|
|
265
|
-
class TestEnvInspector
|
|
266
|
-
def initialize(app)
|
|
267
|
-
@app = app
|
|
268
|
-
end
|
|
269
|
-
def call(env)
|
|
270
|
-
env.inspect
|
|
271
|
-
@app.call(env)
|
|
272
|
-
end
|
|
273
|
-
end
|
|
274
|
-
|
|
275
|
-
app = Rack::Session::Cookie.new(incrementor)
|
|
276
|
-
res = Rack::MockRequest.new(app).get("/")
|
|
277
|
-
|
|
278
|
-
app = Rack::Session::Cookie.new(TestEnvInspector.new(session_id))
|
|
279
|
-
res = Rack::MockRequest.new(app).get("/", "HTTP_COOKIE" => res["Set-Cookie"])
|
|
280
|
-
res.body.should.not.be.nil
|
|
281
|
-
end
|
|
282
|
-
|
|
283
|
-
end
|
|
284
|
-
|
|
285
|
-
it "returns the session id in the session hash" do
|
|
286
|
-
app = Rack::Session::Cookie.new(incrementor)
|
|
287
|
-
res = Rack::MockRequest.new(app).get("/")
|
|
288
|
-
res.body.should.equal '{"counter"=>1}'
|
|
289
|
-
|
|
290
|
-
app = Rack::Session::Cookie.new(session_id)
|
|
291
|
-
res = Rack::MockRequest.new(app).get("/", "HTTP_COOKIE" => res["Set-Cookie"])
|
|
292
|
-
res.body.should.match(/"session_id"=>/)
|
|
293
|
-
res.body.should.match(/"counter"=>1/)
|
|
294
|
-
end
|
|
295
|
-
|
|
296
|
-
it "does not return a cookie if set to secure but not using ssl" do
|
|
297
|
-
app = Rack::Session::Cookie.new(incrementor, :secure => true)
|
|
298
|
-
res = Rack::MockRequest.new(app).get("/")
|
|
299
|
-
res["Set-Cookie"].should.be.nil
|
|
300
|
-
|
|
301
|
-
res = Rack::MockRequest.new(app).get("/", "HTTPS" => "on")
|
|
302
|
-
res["Set-Cookie"].should.not.be.nil
|
|
303
|
-
res["Set-Cookie"].should.match(/secure/)
|
|
304
|
-
end
|
|
305
|
-
|
|
306
|
-
it "does not return a cookie if cookie was not read/written" do
|
|
307
|
-
app = Rack::Session::Cookie.new(nothing)
|
|
308
|
-
res = Rack::MockRequest.new(app).get("/")
|
|
309
|
-
res["Set-Cookie"].should.be.nil
|
|
310
|
-
end
|
|
311
|
-
|
|
312
|
-
it "does not return a cookie if cookie was not written (only read)" do
|
|
313
|
-
app = Rack::Session::Cookie.new(session_id)
|
|
314
|
-
res = Rack::MockRequest.new(app).get("/")
|
|
315
|
-
res["Set-Cookie"].should.be.nil
|
|
316
|
-
end
|
|
317
|
-
|
|
318
|
-
it "returns even if not read/written if :expire_after is set" do
|
|
319
|
-
app = Rack::Session::Cookie.new(nothing, :expire_after => 3600)
|
|
320
|
-
res = Rack::MockRequest.new(app).get("/", 'rack.session' => {'not' => 'empty'})
|
|
321
|
-
res["Set-Cookie"].should.not.be.nil
|
|
322
|
-
end
|
|
323
|
-
|
|
324
|
-
it "returns no cookie if no data was written and no session was created previously, even if :expire_after is set" do
|
|
325
|
-
app = Rack::Session::Cookie.new(nothing, :expire_after => 3600)
|
|
326
|
-
res = Rack::MockRequest.new(app).get("/")
|
|
327
|
-
res["Set-Cookie"].should.be.nil
|
|
328
|
-
end
|
|
329
|
-
|
|
330
|
-
it "exposes :secret in env['rack.session.option']" do
|
|
331
|
-
app = Rack::Session::Cookie.new(session_option[:secret], :secret => "foo")
|
|
332
|
-
res = Rack::MockRequest.new(app).get("/")
|
|
333
|
-
res.body.should == '"foo"'
|
|
334
|
-
end
|
|
335
|
-
|
|
336
|
-
it "exposes :coder in env['rack.session.option']" do
|
|
337
|
-
app = Rack::Session::Cookie.new(session_option[:coder])
|
|
338
|
-
res = Rack::MockRequest.new(app).get("/")
|
|
339
|
-
res.body.should.match(/Base64::Marshal/)
|
|
340
|
-
end
|
|
341
|
-
|
|
342
|
-
it "allows passing in a hash with session data from middleware in front" do
|
|
343
|
-
app = Rack::Session::Cookie.new(session_id)
|
|
344
|
-
res = Rack::MockRequest.new(app).get("/", 'rack.session' => {:foo => 'bar'})
|
|
345
|
-
res.body.should.match(/foo/)
|
|
346
|
-
end
|
|
347
|
-
|
|
348
|
-
it "allows modifying session data with session data from middleware in front" do
|
|
349
|
-
request = { 'rack.session' => { :foo => 'bar' }}
|
|
350
|
-
response = response_for(:app => incrementor, :request => request)
|
|
351
|
-
response.body.should.match(/counter/)
|
|
352
|
-
response.body.should.match(/foo/)
|
|
353
|
-
end
|
|
354
|
-
|
|
355
|
-
it "allows modifying session data with session data from middleware in front" do
|
|
356
|
-
request = { 'rack.session' => { :foo => 'bar' }}
|
|
357
|
-
response = response_for(:app => incrementor, :request => request)
|
|
358
|
-
response.body.should.match(/counter/)
|
|
359
|
-
response.body.should.match(/foo/)
|
|
360
|
-
end
|
|
361
|
-
end
|