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.

problem with cookie escaping on integration tests

#3047

Cookie escaping is not working out of the box with integration tests. Here is the problem in more understandable ruby form - since I am bad at explaining:

class CookieTest < ActionController::IntegrationTest
  def setup
    ...
    cookies[:remember_me] = "1;abcdefg"
    p cookies  # => {:remember_me=>"1;abcdefg"} 
  end

  test "cookie escaping" do
    visit '/'
    p cookies  # => {"abcdefg"=>nil, "remember_me"=>"1"} 
  end
end

I can solve the problem by:

class CookieTest < ActionController::IntegrationTest
  def setup
    ...
    cookies[:remember_me] = Rack::Utils.escape("1;abcdefg")
    p cookies  # => {:remember_me=>"1;abcdefg"}
  end

  test "cookie escaping" do
    visit '/'
    p cookies  # => {:remember_me=>"1;abcdefg"} 
  end
end

I think this should work without me explicitly calling Rack::Utils.escape on setip for the value I want to set on cookie.

Reported by Marko Seppä · August 13th, 2009 @ 10:44 AM

State: invalid
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from cookies, integration_test to bugmash, cookies, integration_test

    September 25th, 2009 @ 12:53 PM

  2. John Pignata
    John Pignata

    -1 - cannot verify this bug. Trying to verify with the following test:

    class CookieTest < ActionController::IntegrationTest
      def setup
        @cookie_data = { :remember_me => '1;abcdefg' }
        cookies.merge!(@cookie_data)
      end
    
      test "cookie escaping" do
        p cookies
        assert_equal(@cookie_data, cookies)
      end
    end
    

    September 26th, 2009 @ 03:58 AM

  3. Elomar França
    Elomar França

    This bug cannot be verified on 2-3-stable, only on master, but I am almost sure it's a bug from rack-test 0.5.0 as 2-3-stable doesn't use it.

    In Integration::Session, the method "cookies" returns the cookie_jar from an instance of Rack::Test::Session, defined on rack-test.

    September 26th, 2009 @ 03:12 PM

  4. John Pignata
    John Pignata

    Elomar is correct - I can replicate on master.

    The following code is in rack-test/rack/test/cookie_jar.rb:

          def []=(name, value)
            # TODO: needs proper escaping
            merge("#{name}=#{value}")
          end
    

    This ticket can be closed.

    September 26th, 2009 @ 09:50 PM

  5. John Pignata
  6. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from bugmash, cookies, integration_test to cookies, integration_test
    • State changed from new to invalid

    Filed under "not our problem".

    September 27th, 2009 @ 11:51 AM

  7. Matías Flores
    Matías Flores
    • Tag changed from cookies, integration_test to cookies, integration_test

    not reproducible on 2-3-stable. Elomar is right.

    September 27th, 2009 @ 07:03 PM