Skip Menu |

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

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

People
Owner: Nobody in particular
Requestors: andreas.marienborg [...] gmail.com
Cc:
AdminCc:

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



Subject: HTTP::Cookies dies when trying to extract_cookies
The problem is that the URI object in the request is a URI::_generic, which does not have a host and port accessors, making the methods in HTTP::Cookies that tries to use them fail. I have created a patch that spoofs the host and port to localhost and 80, by replacing the URI object in the request before setting it in the response and passing it to extract_cookies on the cookie_jar. Please let me know it is not the right solution or push me in the right direction.
Subject: test-www-mechanize-catalyst-fix-cookie-extraction-01.patch
--- Catalyst.pm.old 2007-09-10 14:21:55.000000000 +0200 +++ Catalyst.pm 2007-09-10 14:24:50.000000000 +0200 @@ -39,6 +39,12 @@ my $response = Test::WWW::Mechanize::Catalyst::Aux::request($request); $response->header( 'Content-Base', $request->uri ); + + # extract_cookies complains loudly if the url in $response->request + # doesn't have the methods host and port :/ + if ($request->uri->as_string =~ m{^/}) { + $request->uri(URI->new('http://localhost:80/' . $request->uri->as_string)); + } $response->request($request); $self->cookie_jar->extract_cookies($response) if $self->cookie_jar;
Is there a chance that you could provide a test case? Cheers, Leon
On Mon Sep 17 15:54:14 2007, LBROCARD wrote: Show quoted text
> Is there a chance that you could provide a test case? > > Cheers, Leon
The included test fails without the change, and passes with it. Dunno if it should be more "complex" in any way?
diff -urN Test-WWW-Mechanize-Catalyst-0.41.orig/lib/Test/WWW/Mechanize/Catalyst.pm Test-WWW-Mechanize-Catalyst-0.41/lib/Test/WWW/Mechanize/Catalyst.pm --- Test-WWW-Mechanize-Catalyst-0.41.orig/lib/Test/WWW/Mechanize/Catalyst.pm 2008-03-04 10:35:23.000000000 +0100 +++ Test-WWW-Mechanize-Catalyst-0.41/lib/Test/WWW/Mechanize/Catalyst.pm 2008-03-04 10:51:56.000000000 +0100 @@ -40,6 +40,9 @@ my $response = Test::WWW::Mechanize::Catalyst::Aux::request($request); $response->header( 'Content-Base', $request->uri ); $response->request($request); + if ($request->uri->as_string =~ m{^/}) { + $request->uri(URI->new('http://localhost:80/' . $request->uri->as_string)); + } $self->cookie_jar->extract_cookies($response) if $self->cookie_jar; # fail tests under the Catalyst debug screen diff -urN Test-WWW-Mechanize-Catalyst-0.41.orig/t/cookies.t Test-WWW-Mechanize-Catalyst-0.41/t/cookies.t --- Test-WWW-Mechanize-Catalyst-0.41.orig/t/cookies.t 1970-01-01 01:00:00.000000000 +0100 +++ Test-WWW-Mechanize-Catalyst-0.41/t/cookies.t 2008-03-04 10:55:52.000000000 +0100 @@ -0,0 +1,24 @@ +#!perl -T +use strict; +use warnings; +use lib 'lib'; +use Test::More; + +eval { use Catalyst::Plugin::Session; }; + +if ($@) { + diag($@); + plan skip_all => "Need Catalyst::Plugin::Session to run this test"; +} else { + plan tests => 3; +}; +use lib 't/lib'; +use Test::WWW::Mechanize::Catalyst 'CattySession'; + +my $m = Test::WWW::Mechanize::Catalyst->new; +$m->credentials( 'user', 'pass' ); + +$m->get_ok("/"); +$m->title_is("Root"); + +is( $m->status, 200 ); diff -urN Test-WWW-Mechanize-Catalyst-0.41.orig/t/lib/CattySession.pm Test-WWW-Mechanize-Catalyst-0.41/t/lib/CattySession.pm --- Test-WWW-Mechanize-Catalyst-0.41.orig/t/lib/CattySession.pm 1970-01-01 01:00:00.000000000 +0100 +++ Test-WWW-Mechanize-Catalyst-0.41/t/lib/CattySession.pm 2008-03-04 10:50:50.000000000 +0100 @@ -0,0 +1,50 @@ +package CattySession; + +use strict; + +#use Catalyst; +use Catalyst qw/-Debug + Session + Session::State::Cookie + Session::Store::Dummy +/; +use Cwd; +use MIME::Base64; + +our $VERSION = '0.01'; + +CattySession->config( + name => 'CattySession', + root => cwd . '/t/root', +); + +CattySession->setup(); + +sub auto : Private { + my ( $self, $context ) = @_; + if ($context->session) { + return 1; + } + +} +sub default : Private { + my ( $self, $context ) = @_; + my $html = html( "Root", "This is the root page" ); + $context->response->content_type("text/html"); + $context->response->output($html); +} + +sub html { + my ( $title, $body ) = @_; + return qq{ +<html> +<head><title>$title</title></head> +<body> +$body +<a href="/hello/">Hello</a>. +</body></html> +}; +} + +1; +
From: jshirley+cpan [...] gmail.com
On Tue Mar 04 04:57:38 2008, ANDREMAR wrote: Show quoted text
> On Mon Sep 17 15:54:14 2007, LBROCARD wrote:
> > Is there a chance that you could provide a test case? > > > > Cheers, Leon
> > The included test fails without the change, and passes with it. Dunno if > it should be more "complex" in any way?
I'd love to get this fixed, it is impacting my development as well. None of my TWMC tests work without the patch, or unless I specify CATALYST_SERVER=1. Leon, if you would like can we throw this source in the Catalyst repos (I didn't see it in there, but maybe I simply missed it) and I'll submit patch + test case there so you can bake a release? You can catch me on IRC (jshirley in #catalyst and #catalyst-dev) or via email. Thanks, -Jay
Thanks your patch is in version 0.42, which will hit CPAN soon.