Skip Menu |

This queue is for tickets about the Test-WWW-Mechanize-Catalyst CPAN distribution.

Report information
The Basics
Id: 28754
Status: rejected
Priority: 0/
Queue: Test-WWW-Mechanize-Catalyst

People
Owner: Nobody in particular
Requestors: danieltwc [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.39
Fixed in: (no value)



Subject: Base incorrect after redirected request
One of my tests runs through a number of local actions of the form: /search?query=test&source=web The source parameter controls where a request is redirected. The destination can be a remote host, e.g.: http://search.ufl.edu/web?query=test If I attempt to run another test against a local action after such a redirection, such as: $mech->get_ok("/search?query=test&source=news"); the request base appears to still be the base from the redirection. In this case the URL ends up being: http://search.ufl.edu/search?query=test&source=news instead of: http://localhost/search?query=test&source=news For now I've specified localhost explicitly but the documentation implies this is optional. Relevant versions include: $ perl -MTest::WWW::Mechanize::Catalyst\ 999 Test::WWW::Mechanize::Catalyst version 999 required--this is only version 0.39. $ perl -MTest::WWW::Mechanize\ 999 Test::WWW::Mechanize version 999 required--this is only version 1.14. $ perl -MWWW::Mechanize\ 999 WWW::Mechanize version 999 required--this is only version 1.30. $ perl -MLWP\ 999 LWP version 999 required--this is only version 5.805.
Is there any chance that you could provide a test case? Cheers, Leon
Here's a patch to redirect.t that illustrates what I was seeing with 0.39. It adds an action to Catty.pm that redirects to an external site and tests the redirection and subsequent local actions. As of 0.40, the default behavior with respect to external requests is the same as 0.38, so the original problem should probably be considered fixed. For completeness I've included a note about what happens when allow_external is on, i.e. what is correct when the test does: $m->allow_external(1); $m->get_ok('external'); $m->get_ok('hello'); With allow_external on, Test::WWW::Mechanize::Catalyst requests http://www.ufl.edu/hello instead of http://localhost/hello. While digging further I also noticed a possible issue with the Content-Base header after redirection. The patch includes a test that should fail (#37) because the content base is set to http://www.ufl.edu/hello instead of http://localhost/hello.
diff -ur Test-WWW-Mechanize-Catalyst-0.41.orig/t/lib/Catty.pm Test-WWW-Mechanize-Catalyst-0.41/t/lib/Catty.pm --- Test-WWW-Mechanize-Catalyst-0.41.orig/t/lib/Catty.pm 2007-09-19 22:50:24.000000000 -0400 +++ Test-WWW-Mechanize-Catalyst-0.41/t/lib/Catty.pm 2007-09-19 23:08:24.000000000 -0400 @@ -53,6 +53,13 @@ return; } +# redirect to an external location +sub external : Global { + my ( $self, $context ) = @_; + $context->response->redirect('http://www.ufl.edu/'); + return; +} + sub check_auth_basic : Global { my ( $self, $context ) = @_; diff -ur Test-WWW-Mechanize-Catalyst-0.41.orig/t/redirect.t Test-WWW-Mechanize-Catalyst-0.41/t/redirect.t --- Test-WWW-Mechanize-Catalyst-0.41.orig/t/redirect.t 2007-09-19 22:50:24.000000000 -0400 +++ Test-WWW-Mechanize-Catalyst-0.41/t/redirect.t 2007-09-19 23:32:25.000000000 -0400 @@ -2,7 +2,7 @@ use strict; use warnings; use lib 'lib'; -use Test::More tests => 27; +use Test::More tests => 39; use lib 't/lib'; use Test::WWW::Mechanize::Catalyst 'Catty'; @@ -15,6 +15,7 @@ is( $m->base, "http://localhost/hello", "check got to hello 1/4" ); is( $m->ct, "text/html", "check got to hello 2/4" ); + is( $m->response->header('Content-Base'), "http://localhost/hello" ); $m->title_is( "Hello",, "check got to hello 3/4" ); $m->content_contains( "Hi there",, "check got to hello 4/4" ); @@ -30,3 +31,18 @@ ok( $prev, "have a previous previous" ); is( $prev->code, 302, "was a redirect" ); like( $prev->header('Location'), '/hi$/', "to the right place" ); + +# redirect externally +# XXX: $m->get_ok( "hello" ) fails when external requests are allowed +#$m->allow_external(1); +$m->get_ok( "$root/external", "external redirection" ); +$prev = $m->response->previous; +ok( $prev, "have a previous response" ); +is( $prev->code, 302, "was a redirect" ); +like( $prev->header('Location'), '/www\.ufl\.edu/', "to the right place" ); + +$m->get_ok( "hello", "check got to hello 1/4" ); +is( $m->ct, "text/html", "check got to hello 2/4" ); +is( $m->response->header('Content-Base'), "http://localhost/hello" ); +$m->title_is( "Hello",, "check got to hello 3/4" ); +$m->content_contains( "Hi there", "check got to hello 4/4" );
This is a problem with how WWW::Mechanize operates, and by the time Test::WWW::Mechanize::Catalyst gets hold of the request object, it has already been 'mangled' to have the external host set. Nothing I can do. I've added a doc patch at least mentioning this fact.