test/spec_session_cookie.rb in rack-1.3.0.beta vs test/spec_session_cookie.rb in rack-1.3.0.beta2
- old
+ new
@@ -12,10 +12,16 @@
session_id = lambda do |env|
Rack::Response.new(env["rack.session"].inspect).to_a
end
+ session_option = lambda do |opt|
+ lambda do |env|
+ Rack::Response.new(env["rack.session.options"][opt].inspect).to_a
+ end
+ end
+
nothing = lambda do |env|
Rack::Response.new("Nothing").to_a
end
describe 'Base64' do
@@ -85,10 +91,31 @@
res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor)).
get("/", "HTTP_COOKIE" => cookie)
res.body.should.equal '{"counter"=>3}'
end
+ renewer = lambda do |env|
+ env["rack.session.options"][:renew] = true
+ Rack::Response.new("Nothing").to_a
+ end
+
+ only_session_id = lambda do |env|
+ Rack::Response.new(env["rack.session"]["session_id"]).to_a
+ end
+
+ it "renew session id" do
+ res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor)).get("/")
+ res = Rack::MockRequest.new(Rack::Session::Cookie.new(only_session_id)).
+ get("/", "HTTP_COOKIE" => res["Set-Cookie"])
+ old_session_id = res.body
+ res = Rack::MockRequest.new(Rack::Session::Cookie.new(renewer)).
+ get("/", "HTTP_COOKIE" => res["Set-Cookie"])
+ res = Rack::MockRequest.new(Rack::Session::Cookie.new(only_session_id)).
+ get("/", "HTTP_COOKIE" => res["Set-Cookie"])
+ res.body.should.not.equal old_session_id
+ end
+
it "survives broken cookies" do
res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor)).
get("/", "HTTP_COOKIE" => "rack.session=blarghfasel")
res.body.should.equal '{"counter"=>1}'
end
@@ -165,7 +192,19 @@
it "returns even if not read/written if :expire_after is set" do
app = Rack::Session::Cookie.new(nothing, :expire_after => 3600)
res = Rack::MockRequest.new(app).get("/")
res["Set-Cookie"].should.not.be.nil
+ end
+
+ it "exposes :secret in env['rack.session.option']" do
+ app = Rack::Session::Cookie.new(session_option[:secret], :secret => "foo")
+ res = Rack::MockRequest.new(app).get("/")
+ res.body.should == '"foo"'
+ end
+
+ it "exposes :coder in env['rack.session.option']" do
+ app = Rack::Session::Cookie.new(session_option[:coder])
+ res = Rack::MockRequest.new(app).get("/")
+ res.body.should.match(/Base64::Marshal/)
end
end