Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

A dysfunctional session cookie is created in integration tests when any other cookie is created in the same request

#5328

This applies to 2.3.8 and also the current 2-3-stable branch.

Look into actionpack/lib/action_controller/session/abstract_store.rb, around line 204:

unless headers[SET_COOKIE].blank?

headers[SET_COOKIE] << "\n#{cookie}"

else

headers[SET_COOKIE] = cookie

end

The \n causes a dysfunctional session cookie to be created during integration tests every time when any other cookie is written (i.e. when the array headers[SET_COOKIE] is not empty).

This can cause sessions to be broken in integration tests.

The problem does not affect production use, probably because \n is interpreted differently by the browsers.

Such behavior was introduced with the commit 524d8edf68ab94315a128cbd7570d1cf4faf7d7a by Joshua Peek in Feb 08 2009, titled "Update bundled Rack for Ruby 1.9 spec changes".

How to reproduce:

in pages_controller.rb:

def test

logger.debug "REQUEST: cookies: #{cookies.inspect}"
cookies[:foo] = "bar"

end

in session_test.rb:

require 'test_helper'

class SessionCookieTest < ActionController::IntegrationTest

def test_login_and_browse_site

get "/pages/test"
get "/pages/test"

end end

Run it and observe the following inside test.log:

REQUEST: cookies: {}
REQUEST: cookies: {"\n_session_id"=>"66f367a068d1b76e4c5316186c8c6036", "foo"=>"bar"}

This is, my friend, a broken session.

Reported by Yar Dmitriev · August 7th, 2010 @ 02:19 PM

State: stale
Milestone: none
Assigned to: josh josh
Importance: none

Activity

  1. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to open

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 05:00 PM

  2. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 05:00 PM

  3. Yar Dmitriev
    Yar Dmitriev

    3-0-stable does not have this problem.

    (But 2-3-stable, I believe, still does.)

    February 24th, 2011 @ 03:40 PM