Skip to content
Permalink
Browse files

Fix to handle same_site option for session pool

Follow up of #1543.
  • Loading branch information
kamipo authored and ioquatix committed Feb 10, 2020
1 parent 784dcd2 commit 18f708b5b691f0219be35e453dbb7ef8397060c9
Showing with 20 additions and 1 deletion.
  1. +1 −0 lib/rack/session/abstract/id.rb
  2. +0 −1 lib/rack/session/cookie.rb
  3. +19 −0 test/spec_session_pool.rb
@@ -252,6 +252,7 @@ def initialize(app, options = {})
@default_options = self.class::DEFAULT_OPTIONS.merge(options)
@key = @default_options.delete(:key)
@cookie_only = @default_options.delete(:cookie_only)
@same_site = @default_options.delete(:same_site)
initialize_sid
end

@@ -118,7 +118,6 @@ def initialize(app, options = {})
Called from: #{caller[0]}.
MSG
@coder = options[:coder] ||= Base64::Marshal.new
@same_site = options.delete :same_site
super(app, options.merge!(cookie_only: true))
end

@@ -178,6 +178,25 @@
pool.pool[session_id.public_id].must_be_nil
end

it "passes through same_site option to session pool" do
pool = Rack::Session::Pool.new(incrementor, same_site: :none)
req = Rack::MockRequest.new(pool)
res = req.get("/")
res["Set-Cookie"].must_include "SameSite=None"
end

it "allows using a lambda to specify same_site option, because some browsers require different settings" do
pool = Rack::Session::Pool.new(incrementor, same_site: lambda { |req, res| :none })
req = Rack::MockRequest.new(pool)
res = req.get("/")
res["Set-Cookie"].must_include "SameSite=None"

pool = Rack::Session::Pool.new(incrementor, same_site: lambda { |req, res| :lax })
req = Rack::MockRequest.new(pool)
res = req.get("/")
res["Set-Cookie"].must_include "SameSite=Lax"
end

# anyone know how to do this better?
it "should merge sessions when multithreaded" do
unless $DEBUG

0 comments on commit 18f708b

Please sign in to comment.
You can’t perform that action at this time.