From: Gerda Shank Date: Fri, 25 May 2012 17:53:09 +0000 (-0400) Subject: expand t/cat_test.t to test session with authentication X-Git-Tag: 0.36~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1b41775af56999425409a6729a9fcc37aa342b60;p=catagits%2FCatalyst-Plugin-Session.git expand t/cat_test.t to test session with authentication --- diff --git a/t/cat_test.t b/t/cat_test.t index 83705e6..7175b1d 100644 --- a/t/cat_test.t +++ b/t/cat_test.t @@ -9,9 +9,13 @@ use HTTP::Request::Common; use FindBin qw($Bin); use lib "$Bin/lib"; +# this test was copied from CatalystX::SimpleLogin + BEGIN { plan skip_all => "Need Catalyst::Plugin::Session::State::Cookie" unless do { local $@; eval { require Catalyst::Plugin::Session::State::Cookie; } }; + plan skip_all => "Need Catalyst::Plugin::Authentication" + unless do { local $@; eval { require Catalyst::Plugin::Authentication; } }; } use Catalyst::Test 'SessionTestApp'; @@ -22,10 +26,17 @@ is($res->code, 200, 'succeeded'); my $cookie = $res->header('Set-Cookie'); ok($cookie, 'Have a cookie'); -# this checks that cookie persists across a redirect -($res, $c) = ctx_request(GET 'http://localhost/do_redirect', Cookie => $cookie); +# check that the cookie has not been reset by the get +($res, $c) = ctx_request(GET 'http://localhost/page', Cookie => $cookie); +like($c->res->body, qr/logged in/, 'Am logged in'); +my $new_cookie = $res->header('Set-Cookie'); +is( $cookie, $new_cookie, 'cookie is the same' ); + +# this checks that cookie exists after a logout and redirect +# Catalyst::Plugin::Authentication removes the user session (remove_persisted_user) +($res, $c) = ctx_request(GET 'http://localhost/logout_redirect', Cookie => $cookie); is($res->code, 302, 'redirected'); -is($res->header('Location'), 'http://localhost/page', 'Redirected after do_redirect'); -ok($res->header('Set-Cookie'), 'Cookie is still there after redirect'); +is($res->header('Location'), 'http://localhost/from_logout_redirect', 'Redirected after logout_redirect'); +ok($res->header('Set-Cookie'), 'Cookie is there after redirect'); done_testing; diff --git a/t/lib/SessionTestApp.pm b/t/lib/SessionTestApp.pm index 9f211e7..f569aaa 100644 --- a/t/lib/SessionTestApp.pm +++ b/t/lib/SessionTestApp.pm @@ -1,19 +1,39 @@ #!/usr/bin/env perl package SessionTestApp; -use Catalyst qw/Session Session::Store::Dummy Session::State::Cookie/; +use Catalyst qw/Session Session::Store::Dummy Session::State::Cookie Authentication/; use strict; use warnings; __PACKAGE__->config('Plugin::Session' => { - # needed for live_verify_user_agent.t; should be harmless for other tests - verify_user_agent => 1, - - # need for live_verify_address.t; should be harmless for other tests - verify_address => 1, + # needed for live_verify_user_agent.t; should be harmless for other tests + verify_user_agent => 1, + verify_address => 1, -}); + }, + + 'Plugin::Authentication' => { + default => { + credential => { + class => 'Password', + password_field => 'password', + password_type => 'clear' + }, + store => { + class => 'Minimal', + users => { + bob => { + password => "s00p3r", + }, + william => { + password => "s3cr3t", + }, + }, + }, + }, + }, +); __PACKAGE__->setup; diff --git a/t/lib/SessionTestApp/Controller/Root.pm b/t/lib/SessionTestApp/Controller/Root.pm index 203815b..a6d86d1 100644 --- a/t/lib/SessionTestApp/Controller/Root.pm +++ b/t/lib/SessionTestApp/Controller/Root.pm @@ -28,10 +28,17 @@ sub logout : Global { $c->delete_session("logout"); } -sub do_redirect : Global { +sub logout_redirect : Global { my ( $self, $c ) = @_; - # session is not deleted - $c->res->redirect( $c->uri_for('page') ); + + $c->logout; + $c->res->output("redirect from here"); + $c->res->redirect( $c->uri_for('from_logout_redirect') ); +} + +sub from_logout_redirect : Global { + my ( $self, $c ) = @_; + $c->res->output( "got here from logout_redirect" ); } sub set_session_variable : Global {