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.

[PATCH] Integration test incompatible w/ Session store when multiple cookies

#4998

With Rails 2.3.8 ... (traced to http://github.com/rails/rails/commit/f85ab90e4fbe38ac5ad211d07a8113...)

If you have a rails app that uses any session store that subclasses AbstractStore, and also sets some other type cookie.

Then your integration tests will fail to properly pass your session data from one response to the next request.

class MemCacheStoreTest < ActionController::IntegrationTest
  class TestController < ActionController::Base

...

    def set_session_value_and_a_cookie
      cookies[:foo] = "cookie bar"
      session[:foo] = "session bar"
      head :ok
    end

...

    def test_setting_and_getting_session_value_and_also_a_cookie
      with_test_route_set do
        get '/set_session_value_and_a_cookie'
        assert_response :success
        assert cookies['_session_id'], 
          "Expected to have a '_session_id' cookie, but got #{cookies.inspect}"

        get '/get_session_value'
        assert_response :success
        assert_equal 'foo: "session bar"', response.body
      end
    end

If you run this, you'll get:

1) Failure: test_setting_and_getting_session_value_and_also_a_cookie(MemCacheStoreTest)
Expected to have a '_session_id' cookie, but got {"\n_session_id"=>"7d5797615e8faaadc007df328ed93ee7", "foo"=>"cookie+bar"}.

And so the fix is either to fix Integration test harness to ignore this extra "\n"

          cookies = @headers['Set-Cookie']
          cookies = cookies.to_s.split("\n") unless cookies.is_a?(Array)
          cookies.each do |cookie|
            # old way
            # name, value = cookie.match(/^([^=]*)=([^;]*);/)[1,2]
            # 'fixed' way
            name, value = cookie.match(/^[\n]?([^=]*)=([^;]*);/)[1,2]
            @cookies[name] = value
          end

OR, maybe this is a bug in abstract session store? But this is just a problem for people writing integration tests and seems to work fine with real web browsers.

But, still, I'm curious why AbstractStore prepends the extra "\n"

...
    class AbstractStore
...
      def call(env)
...
          unless headers[SET_COOKIE].blank?
            headers[SET_COOKIE] << "\n#{cookie}"
          else
            headers[SET_COOKIE] = cookie
          end
...

Reported by Jacob Burkhart · June 28th, 2010 @ 07:53 PM

State: stale
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Jacob Burkhart
  2. Jacob Burkhart
    Jacob Burkhart
    • Tag set to integration_test, patch, sessions

    June 28th, 2010 @ 08:18 PM

  3. Jacob Burkhart
    Jacob Burkhart
    • Title changed from Integration test incompatible w/ Session store when multiple cookies to [PATCH] Integration test incompatible w/ Session store when multiple cookies

    June 29th, 2010 @ 10:44 PM

  4. Kenny Buckler
    Kenny Buckler

    My +1 --- our integration suite was decimated by this after upgrading to 2.3.8.

    July 30th, 2010 @ 08:18 PM

  5. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • Tag cleared.
    • Importance changed from to Low

    Automatic cleanup of spam.

    November 8th, 2010 @ 08:26 AM

  6. Paul McMahon
    Paul McMahon

    Thanks for the patch. This bug took forever to track down...

    November 17th, 2010 @ 03:55 AM

  7. rails
    rails
    • 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 18th, 2011 @ 12:00 AM

  8. rails
    rails
    • State changed from open to stale

    February 18th, 2011 @ 12:00 AM

  9. Chris Hapgood
    Chris Hapgood

    Confirmed that in Rails 2.3.8 integration testing sessions are broken and this patch resolves the problem.

    May 2nd, 2011 @ 05:13 PM

  10. af001
    af001

    私の中で、総合評価のとっても低いアバアバクロホリスタークロ銀座店。アバクロは大好きなんですけどね。一昨日の東京駅付近での打ち合わせの後、散歩がてら久々に行ってきました。そしたらビックリ!相変わらアバクロず、踊っているだけの店員さんとかもいましたが、

    May 5th, 2011 @ 02:56 AM