Skip Menu |

This queue is for tickets about the Catalyst-Authentication-AuthTkt CPAN distribution.

Report information
The Basics
Id: 73786
Status: resolved
Priority: 0/
Queue: Catalyst-Authentication-AuthTkt

People
Owner: Nobody in particular
Requestors: bobtfish [...] bobtfish.net
Cc:
AdminCc:

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



Subject: Broken with 5.9
Patches to fix the tests with Catalyst 5.9, and to perform a little cleanup / modernisation by changing the config key for the auth plugin to be up to date and moving the auth_url to a controller attribute (fixing a doc inconsistency also).
Subject: 0002-Update-to-be-more-modern.patch
From eaac5ed5d4847ef0a420711fefc3662d65d954e5 Mon Sep 17 00:00:00 2001 From: Tomas Doran <bobtfish@bobtfish.net> Date: Fri, 6 Jan 2012 08:26:57 +0000 Subject: [PATCH 2/2] Update to be more modern --- Makefile.PL | 3 +-- lib/Catalyst/Authentication/AuthTkt.pm | 19 +++++++++++++------ t/01-authtkt.t | 6 +++--- t/MyApp/lib/MyApp/Controller/Root.pm | 14 ++++++++++---- t/MyApp/myapp.conf | 8 +++++--- 5 files changed, 32 insertions(+), 18 deletions(-) diff --git a/Makefile.PL b/Makefile.PL index dd2d7a3..d74d1b7 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -20,8 +20,7 @@ WriteMakefile( 'Catalyst::Plugin::Session' => 0, 'Catalyst::Plugin::Session::Store::Dummy' => 0, 'Catalyst::Plugin::Session::State::Cookie' => 0, - 'HTTP::Request::AsCGI' => 0, - + 'Moose' => 0, }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, diff --git a/lib/Catalyst/Authentication/AuthTkt.pm b/lib/Catalyst/Authentication/AuthTkt.pm index 888c1bb..ff4f1ee 100644 --- a/lib/Catalyst/Authentication/AuthTkt.pm +++ b/lib/Catalyst/Authentication/AuthTkt.pm @@ -17,9 +17,8 @@ Catalyst::Authentication::AuthTkt - shim for Apache::AuthTkt ); # Configure an authentication realm in your app config: - <authentication> + <Plugin::Authentication> default_realm authtkt - auth_url http://yourdomain/login <realms> <authtkt> class AuthTkt @@ -57,10 +56,18 @@ Catalyst::Authentication::AuthTkt - shim for Apache::AuthTkt </store> </authtkt> </realms> - </authentication> - + </Plugin::Authentication> + <Controller::Root> + auth_url http://yourdomain/login + </Controller::Root> + + # and then in your Root controller: + + has auth_url => ( + is => 'ro', + required => 1, + ); - # and then in your Root controller 'auto': sub auto : Private { my ( $self, $c ) = @_; @@ -68,7 +75,7 @@ Catalyst::Authentication::AuthTkt - shim for Apache::AuthTkt return 1 if $c->authenticate; # no valid login found so redirect. - $c->response->redirect( $c->config->{authentication_url} ); + $c->response->redirect( $self->auth_url} ); # tell Catalyst to abort processing. return 0; diff --git a/t/01-authtkt.t b/t/01-authtkt.t index d6d3026..c1cacef 100644 --- a/t/01-authtkt.t +++ b/t/01-authtkt.t @@ -33,7 +33,7 @@ ok( my %config = $conf->getall, "parse config file" ); #dump \%config; -my $store = $config{authentication}->{realms}->{authtkt}->{store}; +my $store = $config{'Plugin::Authentication'}->{realms}->{authtkt}->{store}; my $secret = $store->{secret}; my $cookie_name = $store->{cookie_name}; @@ -41,7 +41,7 @@ my $res; ok( $res = my_request('/'), "get /" ); is( $res->headers->{status}, 302, "req redirects without auth tkt" ); is( $res->headers->{location}, - $config{authentication}->{auth_url}, + $config{'Controller::Root'}->{auth_url}, "auth url" ); @@ -68,7 +68,7 @@ is( $res->content, ok( $res = my_request( '/', $session_cookie ), "get / with no auth_tkt" ); is( $res->headers->{status}, 302, "req redirects without auth tkt" ); is( $res->headers->{location}, - $config{authentication}->{auth_url}, + $config{'Controller::Root'}->{auth_url}, "auth url" ); diff --git a/t/MyApp/lib/MyApp/Controller/Root.pm b/t/MyApp/lib/MyApp/Controller/Root.pm index 102c68c..cdac3a6 100644 --- a/t/MyApp/lib/MyApp/Controller/Root.pm +++ b/t/MyApp/lib/MyApp/Controller/Root.pm @@ -1,12 +1,18 @@ package MyApp::Controller::Root; +use Moose; -use strict; -use warnings; -use base 'Catalyst::Controller'; +BEGIN { extends 'Catalyst::Controller' } use Data::Dump qw( dump ); __PACKAGE__->config( namespace => '' ); +has auth_url => ( + is => 'ro', + required => 1, +); + +no Moose; + sub debug_session_and_user { my ( $self, $c ) = @_; @@ -33,7 +39,7 @@ sub auto : Private { } # no valid login found so redirect. - $c->response->redirect( $c->config->{authentication}->{auth_url} ); + $c->response->redirect( $self->auth_url ); # tell Catalyst to abort processing. return 0; diff --git a/t/MyApp/myapp.conf b/t/MyApp/myapp.conf index cd3d1c5..b06d755 100644 --- a/t/MyApp/myapp.conf +++ b/t/MyApp/myapp.conf @@ -1,7 +1,9 @@ name MyApp -<authentication> - default_realm authtkt +<Controller::Root> auth_url http://localhost:3000/login +</Controller::Root> +<Plugin::Authentication> + default_realm authtkt <realms> <authtkt> class AuthTkt @@ -30,4 +32,4 @@ name MyApp </store> </authtkt> </realms> -</authentication> +</Plugin::Authentication> -- 1.6.5.GIT
Subject: 0001-Fix-test.patch
From 11b21a262b4d61d9ad9f13ca335215a38e881e60 Mon Sep 17 00:00:00 2001 From: Tomas Doran <bobtfish@bobtfish.net> Date: Fri, 6 Jan 2012 08:18:09 +0000 Subject: [PATCH 1/2] Fix test --- t/01-authtkt.t | 37 ++++++++++--------------------------- 1 files changed, 10 insertions(+), 27 deletions(-) diff --git a/t/01-authtkt.t b/t/01-authtkt.t index 8097760..d6d3026 100644 --- a/t/01-authtkt.t +++ b/t/01-authtkt.t @@ -12,29 +12,19 @@ my $class = 'MyApp'; # based on Catalyst::Test local_request() but # hack in session cookie support. +my $scookie; sub my_request { my $uri = shift or die "uri required"; - my $cookie = shift || ''; - $ENV{COOKIE} = $cookie; my $request = Catalyst::Utils::request($uri); - my $cgi = HTTP::Request::AsCGI->new( $request, %ENV )->setup; - $class->handle_request; - my $response = $cgi->restore->response; - $response->{_request} = $request; - return $response; -} - -# I'm told sleep() won't work under win32 -sub mock_sleep { - my $len = shift || 0; - - #diag("mock sleep for $len secs"); - my $end = time() + $len; - while ( time() <= $end ) { - - #diag( "mock sleep: " . localtime() ); + if ($scookie) { + $request->header('Cookie', $scookie); } - + my $response = request($request); + if (!$scookie && $response->header('Set-Cookie')) { + $scookie = $response->header('Set-Cookie'); + $scookie =~ s/;.*//; + } + return $response; } ok( my $conf = Config::General->new("t/MyApp/myapp.conf"), @@ -57,11 +47,6 @@ is( $res->headers->{location}, #diag( dump $res ); -# keep initial session alive to test user persistence -my $session_cookie = $res->headers->{'set-cookie'}; - -#mock_sleep(1); - ok( my $AAT = Apache::AuthTkt->new( secret => $secret, ), "new AAT" ); ok( my $auth_ticket = $AAT->ticket( uid => 'catalyst-tester', @@ -72,14 +57,12 @@ ok( my $auth_ticket = $AAT->ticket( "new auth_tkt" ); -ok( $res = my_request( "/?$cookie_name=$auth_ticket", $session_cookie ), +ok( $res = my_request( "/?$cookie_name=$auth_ticket" ), "get / with auth_tkt" ); is( $res->content, 'Logged in as user catalyst-tester with roles ("group1", "group2")', "logged in" ); -#mock_sleep(1); - # request again with no cookie or tkt set # to test session persistence ok( $res = my_request( '/', $session_cookie ), "get / with no auth_tkt" ); -- 1.6.5.GIT
Thanks. Patches applied in r687 and uploaded 0.12 to cpan.