Skip to content

Commit

Permalink
Merge pull request #37 from mstruve/ignore-blank-sessions
Browse files Browse the repository at this point in the history
Don't Store Blank Session Keys in Redis
  • Loading branch information
tubbo authored Sep 27, 2018
2 parents fad94f8 + 53493e8 commit a7cfaf1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rack/session/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def initialize(app, options = {})
end

def generate_unique_sid(session)
return generate_sid if session.empty?
loop do
sid = generate_sid
first = with do |c|
Expand Down
6 changes: 6 additions & 0 deletions test/rack/session/redis_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
sesion_store.threadsafe?.must_equal(true)
end

it "does not store a blank session" do
session_store = Rack::Session::Redis.new(incrementor)
sid = session_store.generate_unique_sid({})
session_store.with { |c| c.get(sid).must_be_nil }
end

it "locks the store mutex" do
mutex = Mutex.new
mutex.expects(:lock).once
Expand Down

0 comments on commit a7cfaf1

Please sign in to comment.