Skip to content

Commit

Permalink
Also drop the session with the public id when destroying sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelfranca authored and tenderlove committed Dec 17, 2019
1 parent 9fe40c6 commit 1a532d1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rack/session/memcache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def set_session(env, session_id, new_session, options)

def destroy_session(env, session_id, options)
with_lock(env) do
@pool.delete(session_id.public_id)
@pool.delete(session_id.private_id)
generate_sid unless options[:drop]
end
Expand Down
21 changes: 21 additions & 0 deletions test/spec_session_memcache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,27 @@
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
unless $DEBUG
Expand Down

0 comments on commit 1a532d1

Please sign in to comment.