Epic cleanup and code shuffle in tests to avoid warnings
[catagits/Catalyst-Plugin-Authentication.git] / t / lib / AuthTestApp.pm
index 529e32f..c7c49df 100644 (file)
@@ -1,81 +1,41 @@
 package AuthTestApp;
+use strict;
+use warnings;
+use base qw/Catalyst/;
 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 number_of_elements { return scalar @_ }
-
-sub moose : Local {
-       my ( $self, $c ) = @_;
-
-       is(number_of_elements($c->user), 1, "Array undef");
-       is($c->user, undef, "no user, returns undef");
-       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");
+our $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 => {},
+};
 
-       throws_ok { $c->login( "baz", "foo" ) } qr/support.*mechanism/, "can't login without any supported mech";
+__PACKAGE__->config('Plugin::Authentication' =>{users => $users});
 
-       $c->res->body( "ok" );
-}
+__PACKAGE__->setup;
 
-__PACKAGE__->config->{'Plugin::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 => {},
-};
+1;
 
-__PACKAGE__->setup;