test/spec_response.rb in rack-1.6.4 vs test/spec_response.rb in rack-1.6.5
- old
+ new
@@ -95,9 +95,73 @@
response = Rack::Response.new
response.set_cookie "foo", {:value => "bar", :httponly => false, :http_only => true}
response["Set-Cookie"].should.equal "foo=bar"
end
+ it "can set SameSite cookies with symbol value :lax" do
+ response = Rack::Response.new
+ response.set_cookie "foo", {:value => "bar", :same_site => :lax}
+ response["Set-Cookie"].should.equal "foo=bar; SameSite=Lax"
+ end
+
+ it "can set SameSite cookies with symbol value :Lax" do
+ response = Rack::Response.new
+ response.set_cookie "foo", {:value => "bar", :same_site => :lax}
+ response["Set-Cookie"].should.equal "foo=bar; SameSite=Lax"
+ end
+
+ it "can set SameSite cookies with string value 'Lax'" do
+ response = Rack::Response.new
+ response.set_cookie "foo", {:value => "bar", :same_site => "Lax"}
+ response["Set-Cookie"].should.equal "foo=bar; SameSite=Lax"
+ end
+
+ it "can set SameSite cookies with boolean value true" do
+ response = Rack::Response.new
+ response.set_cookie "foo", {:value => "bar", :same_site => true}
+ response["Set-Cookie"].should.equal "foo=bar; SameSite=Strict"
+ end
+
+ it "can set SameSite cookies with symbol value :strict" do
+ response = Rack::Response.new
+ response.set_cookie "foo", {:value => "bar", :same_site => :strict}
+ response["Set-Cookie"].should.equal "foo=bar; SameSite=Strict"
+ end
+
+ it "can set SameSite cookies with symbol value :Strict" do
+ response = Rack::Response.new
+ response.set_cookie "foo", {:value => "bar", :same_site => :Strict}
+ response["Set-Cookie"].should.equal "foo=bar; SameSite=Strict"
+ end
+
+ it "can set SameSite cookies with string value 'Strict'" do
+ response = Rack::Response.new
+ response.set_cookie "foo", {:value => "bar", :same_site => "Strict"}
+ response["Set-Cookie"].should.equal "foo=bar; SameSite=Strict"
+ end
+
+ it "validates the SameSite option value" do
+ response = Rack::Response.new
+ lambda {
+ response.set_cookie "foo", {:value => "bar", :same_site => "Foo"}
+ }.should.raise(ArgumentError).
+ message.should.match(/Invalid SameSite value: "Foo"/)
+ end
+
+ it "can set SameSite cookies with symbol value" do
+ response = Rack::Response.new
+ response.set_cookie "foo", {:value => "bar", :same_site => :Strict}
+ response["Set-Cookie"].should.equal "foo=bar; SameSite=Strict"
+ end
+
+ [ nil, false ].each do |non_truthy|
+ it "omits SameSite attribute given a #{non_truthy.inspect} value" do
+ response = Rack::Response.new
+ response.set_cookie "foo", {:value => "bar", :same_site => non_truthy}
+ response["Set-Cookie"].should.equal "foo=bar"
+ end
+ end
+
it "can delete cookies" do
response = Rack::Response.new
response.set_cookie "foo", "bar"
response.set_cookie "foo2", "bar2"
response.delete_cookie "foo"