This project is archived and is in readonly mode.

#4998 ✓stale
Jacob Burkhart

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

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

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
...

Comments and changes to this ticket

  • Jacob Burkhart
  • Jacob Burkhart

    Jacob Burkhart June 28th, 2010 @ 08:18 PM

    • Tag set to integration_test, patch, sessions
  • Jacob Burkhart

    Jacob Burkhart June 29th, 2010 @ 10:44 PM

    • Title changed from “Integration test incompatible w/ Session store when multiple cookies” to “[PATCH] Integration test incompatible w/ Session store when multiple cookies”
  • Kenny Buckler

    Kenny Buckler July 30th, 2010 @ 08:18 PM

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

  • Jeff Kreeftmeijer

    Jeff Kreeftmeijer November 8th, 2010 @ 08:26 AM

    • Tag cleared.
    • Importance changed from “” to “Low”

    Automatic cleanup of spam.

  • Paul McMahon

    Paul McMahon November 17th, 2010 @ 03:55 AM

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

  • rails

    rails February 18th, 2011 @ 12:00 AM

    • 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.

  • rails

    rails February 18th, 2011 @ 12:00 AM

    • State changed from “open” to “stale”
  • Chris Hapgood

    Chris Hapgood May 2nd, 2011 @ 05:13 PM

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

  • af001

    af001 May 5th, 2011 @ 02:56 AM

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

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Pages