test/spec_session_memcache.rb in rack-2.0.7 vs test/spec_session_memcache.rb in rack-2.0.8
- old
+ new
@@ -224,16 +224,53 @@
end
pool = Rack::Session::Memcache.new(hash_check)
req = Rack::MockRequest.new(pool)
res0 = req.get("/")
- session_id = (cookie = res0["Set-Cookie"])[session_match, 1]
- ses0 = pool.pool.get(session_id, true)
+ session_id = Rack::Session::SessionId.new (cookie = res0["Set-Cookie"])[session_match, 1]
+ ses0 = pool.pool.get(session_id.private_id, true)
req.get("/", "HTTP_COOKIE" => cookie)
- ses1 = pool.pool.get(session_id, true)
+ ses1 = pool.pool.get(session_id.private_id, true)
ses1.wont_equal ses0
+ end
+
+ it "can read the session with the legacy id" do
+ pool = Rack::Session::Memcache.new(incrementor)
+ req = Rack::MockRequest.new(pool)
+
+ res0 = req.get("/")
+ cookie = res0["Set-Cookie"]
+ session_id = Rack::Session::SessionId.new cookie[session_match, 1]
+ ses0 = pool.pool.get(session_id.private_id, true)
+ pool.pool.set(session_id.public_id, ses0, 0, true)
+ pool.pool.delete(session_id.private_id)
+
+ res1 = req.get("/", "HTTP_COOKIE" => cookie)
+ res1["Set-Cookie"].must_be_nil
+ res1.body.must_equal '{"counter"=>2}'
+ pool.pool.get(session_id.private_id, true).wont_be_nil
+ end
+
+ it "drops the session in the legacy id as well" do
+ pool = Rack::Session::Memcache.new(incrementor)
+ req = Rack::MockRequest.new(pool)
+ drop = Rack::Utils::Context.new(pool, drop_session)
+ dreq = Rack::MockRequest.new(drop)
+
+ res0 = req.get("/")
+ cookie = res0["Set-Cookie"]
+ session_id = Rack::Session::SessionId.new cookie[session_match, 1]
+ ses0 = pool.pool.get(session_id.private_id, true)
+ pool.pool.set(session_id.public_id, ses0, 0, true)
+ pool.pool.delete(session_id.private_id)
+
+ res2 = dreq.get("/", "HTTP_COOKIE" => cookie)
+ res2["Set-Cookie"].must_be_nil
+ res2.body.must_equal '{"counter"=>2}'
+ pool.pool.get(session_id.private_id, true).must_be_nil
+ pool.pool.get(session_id.public_id, true).must_be_nil
end
# anyone know how to do this better?
it "cleanly merges sessions when multithreaded" do
skip unless $DEBUG