expand t/cat_test.t to test session with authentication
[catagits/Catalyst-Plugin-Session.git] / t / cat_test.t
index 83705e6..7175b1d 100644 (file)
@@ -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;