Fix dates in the changelog (2006 not 2005)
[catagits/Catalyst-Plugin-Authentication.git] / t / live_app_session.t
CommitLineData
ff817455 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More;
7
8BEGIN {
63ffb30f 9 eval { require Test::WWW::Mechanize::Catalyst; require Catalyst::Plugin::Session; require Catalyst::Plugin::Session::State::Cookie };
10 plan skip_all => "This test needs Test::WWW::Mechanize::Catalyst, Catalyst::Plugin::Session and Catalyst::Plugin::Session::State::Cookie installed" if $@;
ce0b058d 11 plan tests => 14;
ff817455 12}
13
14{
c4d560a5 15 package User::SessionRestoring;
16 use base qw/Catalyst::Plugin::Authentication::User::Hash/;
17
18 sub for_session { $_[0]->id }
fda95768 19 sub store { $_[0]->{store} }
c4d560a5 20
ff817455 21 package AuthTestApp;
22 use Catalyst qw/
23 Session
24 Session::Store::Dummy
25 Session::State::Cookie
26
27 Authentication
28 Authentication::Store::Minimal
29 Authentication::Credential::Password
30 /;
31
32 use Test::More;
33 use Test::Exception;
34
35 use Digest::MD5 qw/md5/;
36
37 our $users;
38
39 sub moose : Local {
40 my ( $self, $c ) = @_;
41
42 ok(!$c->sessionid, "no session id yet");
ce0b058d 43 ok(!$c->user_exists, "no user exists");
ff817455 44 ok(!$c->user, "no user yet");
45 ok($c->login( "foo", "s3cr3t" ), "can login with clear");
46 is( $c->user, $users->{foo}, "user object is in proper place");
47 }
48
49 sub elk : Local {
50 my ( $self, $c ) = @_;
51
52 ok( $c->sessionid, "session ID was restored" );
ce0b058d 53 ok( $c->user_exists, "user exists" );
ff817455 54 ok( $c->user, "a user was also restored");
55 is_deeply( $c->user, $users->{foo}, "restored user is the right one (deep test - store might change identity)" );
56
57 $c->delete_session("bah");
58 }
59
60 sub fluffy_bunny : Local {
61 my ( $self, $c ) = @_;
62
63 ok( !$c->sessionid, "no session ID was restored");
64 ok( !$c->user, "no user was restored");
65 }
66
67 __PACKAGE__->config->{authentication}{users} = $users = {
c4d560a5 68 foo => User::SessionRestoring->new(
69 id => 'foo',
ff817455 70 password => "s3cr3t",
c4d560a5 71 ),
ff817455 72 };
73
74 __PACKAGE__->setup;
c4d560a5 75
76 $users->{foo}{store} = __PACKAGE__->default_auth_store;
ff817455 77}
78
79use Test::WWW::Mechanize::Catalyst qw/AuthTestApp/; # for the cookie support
80
81my $m = Test::WWW::Mechanize::Catalyst->new;
82
83$m->get_ok("http://localhost/moose", "get ok");
84$m->get_ok("http://localhost/elk", "get ok");
85$m->get_ok("http://localhost/fluffy_bunny", "get ok");
86