Skip to content

Commit

Permalink
Add a version prefix to the private id to make easier to migrate old …
Browse files Browse the repository at this point in the history
…values
  • Loading branch information
rafaelfranca authored and tenderlove committed Dec 17, 2019
1 parent 15da2e5 commit 3232f93
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/rack/session/abstract/id.rb
Expand Up @@ -21,14 +21,16 @@ module Rack
module Session

class SessionId
ID_VERSION = 2

attr_reader :public_id

def initialize(public_id)
@public_id = public_id
end

def private_id
hash_sid public_id
"#{ID_VERSION}::#{hash_sid(public_id)}"
end

alias :cookie_value :public_id
Expand Down
2 changes: 0 additions & 2 deletions test/spec_session_memcache.rb
Expand Up @@ -245,7 +245,6 @@
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}'
Expand All @@ -265,7 +264,6 @@
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}'
Expand Down

0 comments on commit 3232f93

Please sign in to comment.