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.

Integration::Session fails to follow_redirect! because of Rack headers['location] changes

#1555

Given a freshly created edge app and a controller (e.g. Posts) that just redirects one URL to another URL (e.g. /posts/private =302=> /posts/index ) the following simple steps in an Integration story fail.


get '/posts/private' 
assert_response :redirect # passes
follow_redirect! # should try to get /posts/index
assert_response :success # fails with a 404

What happens is that no matter what the URL follow_redirect! always tries to get /h which is actually the wrongly interpreted first character of http://www.example.com/posts/index

I've tracked the issue down to line 129 of integration.rb:


get(interpret_uri(headers['location'].first))

The bug seems to have appeared after this commit:

http://github.com/rails/rails/co...

Before these Rack related changes, calling headers['location'] would return an Array of Strings. Now it returns a single String (in my case http://www.example.com/posts/index) and calling first on it returns the first character.

Removing the call to first makes my integration story pass but raises an error in line 35 of integration_test.rb (test_follow_redirect_calls_get_and_returns_status):


@session.stubs(:headers).returns({"location" => ["www.google.com"]})

The test can be fixed by removing the square brackets i.e. make headers['location'] stub return an String.

I am almost certain that the test needs fixing because line 342 of Rack's lint.rb (Rake::Lint#check_headers) that states that "header values must consist of Strings" and it seems to be exactly what is returned from the @app.call(env)

http://github.com/chneukirchen/r...

I am attaching a tiny patch for this with no extra tests, just the corrected ones, as the dispatch code is way over my head and I can't seem to find a way to test it more end to end. Testing with stubs seems to have hidden the bug in this case...

Reported by Christos Zisopoulos · December 11th, 2008 @ 12:13 AM

State: resolved
Milestone: 2.x
Assigned to: josh josh
Importance: none

Activity

  1. josh
    josh
    • Assigned user set to josh
    • State changed from new to open

    December 11th, 2008 @ 12:28 AM

  2. Repository
    Repository
    • State changed from open to resolved

    (from [69387ce0169b95d3a170cfb1c66a7570b1746e37]) Fix for Integration::Session follow_redirect! headers['location'] bug with Rack [#1555 Integration::Session fails to follow_redirect! because of Rack headers['locat... state:resolved]

    Signed-off-by: Joshua Peek josh@joshpeek.com http://github.com/rails/rails/co...

    December 11th, 2008 @ 12:37 AM