Factor test applications out to separate files due to change in Catalyst::Test in...
Daniel Westermann-Clark [Sun, 30 Apr 2006 14:46:44 +0000 (14:46 +0000)]
Changes
lib/Catalyst/Plugin/Authentication.pm
t/lib/AuthSessionTestApp.pm [new file with mode: 0644]
t/lib/AuthTestApp.pm [new file with mode: 0644]
t/live_app.t
t/live_app_session.t

diff --git a/Changes b/Changes
index ef44597..af63ebd 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,8 @@
 Revision history for Perl extension Catalyst::Plugin::Authentication
 
+0.08
+        - factor test applications out to files due to changes in Catalyst::Test
+
 0.07    2006-03-17 17:33:12
         - allow base64 hashed passwords
 
index 17873fa..7b872af 100644 (file)
@@ -22,7 +22,7 @@ use Class::Inspector;
 #      constant->import(have_want => eval { require Want });
 #}
 
-our $VERSION = "0.07";
+our $VERSION = "0.08";
 
 sub set_authenticated {
     my ( $c, $user ) = @_;
diff --git a/t/lib/AuthSessionTestApp.pm b/t/lib/AuthSessionTestApp.pm
new file mode 100644 (file)
index 0000000..4bc8de4
--- /dev/null
@@ -0,0 +1,62 @@
+package User::SessionRestoring;
+use base qw/Catalyst::Plugin::Authentication::User::Hash/;
+
+sub for_session { $_[0]->id }
+sub store { $_[0]->{store} }
+
+package AuthSessionTestApp;
+use Catalyst qw/
+       Session
+       Session::Store::Dummy
+       Session::State::Cookie
+
+       Authentication
+       Authentication::Store::Minimal
+       Authentication::Credential::Password
+/;
+
+use Test::More;
+use Test::Exception;
+
+use Digest::MD5 qw/md5/;
+
+our $users;
+
+sub moose : Local {
+       my ( $self, $c ) = @_;
+
+       ok(!$c->sessionid, "no session id yet");
+       ok(!$c->user_exists, "no user exists");
+       ok(!$c->user, "no user yet");
+       ok($c->login( "foo", "s3cr3t" ), "can login with clear");
+       is( $c->user, $users->{foo}, "user object is in proper place");
+}
+
+sub elk : Local {
+       my ( $self, $c ) = @_;
+
+       ok( $c->sessionid, "session ID was restored" );
+       ok( $c->user_exists, "user exists" );
+       ok( $c->user, "a user was also restored");
+       is_deeply( $c->user, $users->{foo}, "restored user is the right one (deep test - store might change identity)" );
+
+       $c->delete_session("bah");
+}
+
+sub fluffy_bunny : Local {
+       my ( $self, $c ) = @_;
+
+       ok( !$c->sessionid, "no session ID was restored");
+       ok( !$c->user, "no user was restored");
+}
+
+__PACKAGE__->config->{authentication}{users} = $users = {
+       foo => User::SessionRestoring->new(
+               id => 'foo',
+               password => "s3cr3t",
+       ),
+};
+
+__PACKAGE__->setup;
+
+$users->{foo}{store} = __PACKAGE__->default_auth_store;
diff --git a/t/lib/AuthTestApp.pm b/t/lib/AuthTestApp.pm
new file mode 100644 (file)
index 0000000..c8a92e8
--- /dev/null
@@ -0,0 +1,77 @@
+package AuthTestApp;
+use Catalyst qw/
+       Authentication
+       Authentication::Store::Minimal
+       Authentication::Credential::Password
+/;
+
+use Test::More;
+use Test::Exception;
+
+use Digest::MD5 qw/md5/;
+use Digest::SHA1 qw/sha1_base64/;
+
+our $users;
+
+sub moose : Local {
+       my ( $self, $c ) = @_;
+
+       ok(!$c->user, "no user");
+       ok($c->login( "foo", "s3cr3t" ), "can login with clear");
+       is( $c->user, $users->{foo}, "user object is in proper place");
+
+       ok( !$c->user->roles, "no roles for foo" );
+       my @new = qw/foo bar gorch/;
+       $c->user->roles( @new );
+       is_deeply( [ $c->user->roles ], \@new, "roles set as array");
+
+       $c->logout;
+       ok(!$c->user, "no more user, after logout");
+
+       ok($c->login( "bar", "s3cr3t" ), "can login with crypted");
+       is( $c->user, $users->{bar}, "user object is in proper place");
+       $c->logout;
+
+       ok($c->login("gorch", "s3cr3t"), "can login with hashed");
+       is( $c->user, $users->{gorch}, "user object is in proper place");
+       $c->logout;
+
+       ok($c->login("shabaz", "s3cr3t"), "can login with base64 hashed");
+       is( $c->user, $users->{shabaz}, "user object is in proper place");
+       $c->logout;
+
+       ok($c->login("sadeek", "s3cr3t"), "can login with padded base64 hashed");
+       is( $c->user, $users->{sadeek}, "user object is in proper place");
+       $c->logout;
+
+       ok(!$c->login( "bar", "bad pass" ), "can't login with bad password");
+       ok(!$c->user, "no user");
+
+       throws_ok { $c->login( "baz", "foo" ) } qr/support.*mechanism/, "can't login without any supported mech";
+
+       $c->res->body( "ok" );
+}
+
+__PACKAGE__->config->{authentication}{users} = $users = {
+       foo => {
+               password => "s3cr3t",
+       },
+       bar => {
+               crypted_password => crypt("s3cr3t", "x8"),
+       },
+       gorch => {
+               hashed_password => md5("s3cr3t"),
+               hash_algorithm => "MD5",
+       },
+       shabaz => {
+               hashed_password => sha1_base64("s3cr3t"),
+               hash_algorithm => "SHA-1"
+       },
+       sadeek => {
+               hashed_password => sha1_base64("s3cr3t").'=',
+               hash_algorithm => "SHA-1"
+       },
+       baz => {},
+};
+
+__PACKAGE__->setup;
index ebb0c29..d27d291 100644 (file)
@@ -5,87 +5,7 @@ use warnings;
 
 use Test::More 'no_plan';
 
-{
-       package AuthTestApp;
-       use Catalyst qw/
-               Authentication
-               Authentication::Store::Minimal
-               Authentication::Credential::Password
-       /;
-
-       use Test::More;
-       use Test::Exception;
-
-       use Digest::MD5 qw/md5/;
-    use Digest::SHA1 qw/sha1_base64/;
-
-       our $users;
-
-       sub moose : Local {
-               my ( $self, $c ) = @_;
-
-               ok(!$c->user, "no user");
-               ok($c->login( "foo", "s3cr3t" ), "can login with clear");
-               is( $c->user, $users->{foo}, "user object is in proper place");
-
-               ok( !$c->user->roles, "no roles for foo" );
-               my @new = qw/foo bar gorch/;
-               $c->user->roles( @new );
-               is_deeply( [ $c->user->roles ], \@new, "roles set as array");
-
-               $c->logout;
-               ok(!$c->user, "no more user, after logout");
-
-
-               ok($c->login( "bar", "s3cr3t" ), "can login with crypted");
-               is( $c->user, $users->{bar}, "user object is in proper place");
-               $c->logout;
-
-               ok($c->login("gorch", "s3cr3t"), "can login with hashed");
-               is( $c->user, $users->{gorch}, "user object is in proper place");
-               $c->logout;
-
-               ok($c->login("shabaz", "s3cr3t"), "can login with base64 hashed");
-               is( $c->user, $users->{shabaz}, "user object is in proper place");
-               $c->logout;
-
-               ok($c->login("sadeek", "s3cr3t"), "can login with padded base64 hashed");
-               is( $c->user, $users->{sadeek}, "user object is in proper place");
-               $c->logout;
-
-               ok(!$c->login( "bar", "bad pass" ), "can't login with bad password");
-               ok(!$c->user, "no user");
-
-               throws_ok { $c->login( "baz", "foo" ) } qr/support.*mechanism/, "can't login without any supported mech";
-
-               $c->res->body( "ok" );
-       }
-
-       __PACKAGE__->config->{authentication}{users} = $users = {
-               foo => {
-                       password => "s3cr3t",
-               },
-               bar => {
-                       crypted_password => crypt("s3cr3t", "x8"),
-               },
-               gorch => {
-                       hashed_password => md5("s3cr3t"),
-                       hash_algorithm => "MD5",
-               },
-        shabaz => {
-            hashed_password => sha1_base64("s3cr3t"),
-            hash_algorithm => "SHA-1"
-        },
-        sadeek => {
-            hashed_password => sha1_base64("s3cr3t").'=',
-            hash_algorithm => "SHA-1"
-        },
-               baz => {},
-       };
-
-       __PACKAGE__->setup;
-}
-
+use lib 't/lib';
 use Catalyst::Test qw/AuthTestApp/;
 
-ok( get("/moose"), "get ok");
+ok(get("/moose"), "get ok");
index 2ec39a4..b23a767 100644 (file)
@@ -11,76 +11,11 @@ BEGIN {
        plan tests => 14;
 }
 
-{
-       package User::SessionRestoring;
-       use base qw/Catalyst::Plugin::Authentication::User::Hash/;
-
-       sub for_session { $_[0]->id }
-       sub store { $_[0]->{store} }
-       
-       package AuthTestApp;
-       use Catalyst qw/
-               Session
-               Session::Store::Dummy
-               Session::State::Cookie
-
-               Authentication
-               Authentication::Store::Minimal
-               Authentication::Credential::Password
-       /;
-
-       use Test::More;
-       use Test::Exception;
-
-       use Digest::MD5 qw/md5/;
-
-       our $users;
-
-       sub moose : Local {
-               my ( $self, $c ) = @_;
-
-               ok(!$c->sessionid, "no session id yet");
-               ok(!$c->user_exists, "no user exists");
-               ok(!$c->user, "no user yet");
-               ok($c->login( "foo", "s3cr3t" ), "can login with clear");
-               is( $c->user, $users->{foo}, "user object is in proper place");
-       }
-
-       sub elk : Local {
-               my ( $self, $c ) = @_;
-
-               ok( $c->sessionid, "session ID was restored" );
-               ok( $c->user_exists, "user exists" );
-               ok( $c->user, "a user was also restored");
-               is_deeply( $c->user, $users->{foo}, "restored user is the right one (deep test - store might change identity)" );
-
-               $c->delete_session("bah");
-       }
-
-       sub fluffy_bunny : Local {
-               my ( $self, $c ) = @_;
-
-               ok( !$c->sessionid, "no session ID was restored");
-               ok( !$c->user, "no user was restored");
-       }
-
-       __PACKAGE__->config->{authentication}{users} = $users = {
-               foo => User::SessionRestoring->new(
-                       id => 'foo',
-                       password => "s3cr3t",
-               ),
-       };
-
-       __PACKAGE__->setup;
-
-       $users->{foo}{store} = __PACKAGE__->default_auth_store;
-}
-
-use Test::WWW::Mechanize::Catalyst qw/AuthTestApp/; # for the cookie support
+use lib 't/lib';
+use Test::WWW::Mechanize::Catalyst qw/AuthSessionTestApp/; # for the cookie support
 
 my $m = Test::WWW::Mechanize::Catalyst->new;
 
 $m->get_ok("http://localhost/moose", "get ok");
 $m->get_ok("http://localhost/elk", "get ok");
 $m->get_ok("http://localhost/fluffy_bunny", "get ok");
-