[Catalyst-commits] r6509 - in
branches/Catalyst-Plugin-Authentication:
lib/Catalyst/Plugin/Authentication
lib/Catalyst/Plugin/Authentication/Credential
lib/Catalyst/Plugin/Authentication/Store
lib/Catalyst/Plugin/Authentication/User t
jayk at dev.catalyst.perl.org
jayk at dev.catalyst.perl.org
Fri Jul 6 03:16:23 GMT 2007
Author: jayk
Date: 2007-07-06 03:16:21 +0100 (Fri, 06 Jul 2007)
New Revision: 6509
Added:
branches/Catalyst-Plugin-Authentication/t/AuthRealmTestApp.pm
branches/Catalyst-Plugin-Authentication/t/live_app_realms.t
Modified:
branches/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/Credential/Password.pm
branches/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/Store/Minimal.pm
branches/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/User.pm
branches/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/User/Hash.pm
Log:
Bug fixes and test from nilsonsfj - Cheers!
Modified: branches/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/Credential/Password.pm
===================================================================
--- branches/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/Credential/Password.pm 2007-07-05 19:54:06 UTC (rev 6508)
+++ branches/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/Credential/Password.pm 2007-07-06 02:16:21 UTC (rev 6509)
@@ -25,7 +25,7 @@
$self->_config->{'password_hash_type'} ||= 'SHA-1';
my $passwordtype = $self->_config->{'password_type'};
- if (!grep /$passwordtype/, ('clear', 'hashed', 'salted_hash', 'crypted', 'self_check')) {
+ if (!grep /$passwordtype/, ('none', 'clear', 'hashed', 'salted_hash', 'crypted', 'self_check')) {
Catalyst::Exception->throw(__PACKAGE__ . " used with unsupported password type: " . $self->_config->{'password_type'});
}
return $self;
Modified: branches/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/Store/Minimal.pm
===================================================================
--- branches/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/Store/Minimal.pm 2007-07-05 19:54:06 UTC (rev 6508)
+++ branches/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/Store/Minimal.pm 2007-07-06 02:16:21 UTC (rev 6509)
@@ -42,6 +42,11 @@
my $user = $self->userhash->{$id};
if ( ref $user ) {
+ if ( Scalar::Util::blessed($user)
+ and $user->isa('Catalyst::Plugin::Authentication::User::Hash') )
+ {
+ return $user;
+ }
if ( ref $user eq "HASH" ) {
$user->{id} ||= $id;
return bless $user, "Catalyst::Plugin::Authentication::User::Hash";
Modified: branches/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/User/Hash.pm
===================================================================
--- branches/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/User/Hash.pm 2007-07-05 19:54:06 UTC (rev 6508)
+++ branches/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/User/Hash.pm 2007-07-06 02:16:21 UTC (rev 6509)
@@ -19,6 +19,9 @@
$self->_accessor( $key, @_ );
}
+# this class effectively handles any method calls
+sub can { 1 }
+
sub id {
my $self = shift;
$self->_accessor( "id", @_ );
Modified: branches/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/User.pm
===================================================================
--- branches/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/User.pm 2007-07-05 19:54:06 UTC (rev 6508)
+++ branches/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/User.pm 2007-07-06 02:16:21 UTC (rev 6509)
@@ -49,7 +49,7 @@
my ($self, $field) = @_;
my $object;
- if ($object = $self->get_object && $object->can($field)) {
+ if ($object = $self->get_object and $object->can($field)) {
return $object->$field();
} else {
return undef;
Added: branches/Catalyst-Plugin-Authentication/t/AuthRealmTestApp.pm
===================================================================
--- branches/Catalyst-Plugin-Authentication/t/AuthRealmTestApp.pm (rev 0)
+++ branches/Catalyst-Plugin-Authentication/t/AuthRealmTestApp.pm 2007-07-06 02:16:21 UTC (rev 6509)
@@ -0,0 +1,115 @@
+package AuthRealmTestApp;
+use warnings;
+use strict;
+
+use Catalyst qw/Authentication/;
+
+use Test::More;
+use Test::Exception;
+
+our $members = {
+ bob => {
+ password => "s00p3r"
+ },
+ william => {
+ password => "s3cr3t"
+ }
+};
+
+our $admins = {
+ joe => {
+ password => "31337"
+ }
+};
+
+sub moose : Local {
+ my ( $self, $c ) = @_;
+
+ ok(!$c->user, "no user");
+
+ while ( my ($user, $info) = each %$members ) {
+
+ ok(
+ $c->authenticate(
+ { username => $user, password => $info->{password} },
+ 'members'
+ ),
+ "user $user authentication"
+ );
+
+ # check existing realms
+ ok( $c->user_in_realm('members'), "user in members realm");
+ ok(!$c->user_in_realm('admins'), "user not in admins realm");
+
+ # check an invalid realm
+ ok(!$c->user_in_realm('foobar'), "user not in foobar realm");
+
+ # check if we've got the right user
+ is( $c->user, $info, "user object is in proper place");
+
+ $c->logout;
+
+ # sanity check
+ ok(!$c->user, "no more user after logout");
+
+ }
+
+ while ( my ($user, $info) = each %$admins ) {
+
+ ok(
+ $c->authenticate(
+ { username => $user, password => $info->{password} },
+ 'admins'
+ ),
+ "user $user authentication"
+ );
+
+ # check existing realms
+ ok(!$c->user_in_realm('members'), "user not in members realm");
+ ok( $c->user_in_realm('admins'), "user in admins realm");
+
+ # check an invalid realm
+ ok(!$c->user_in_realm('foobar'), "user not in foobar realm");
+
+ # check if we've got the right user
+ is( $c->user, $info, "user object is in proper place");
+
+ $c->logout;
+
+ # sanity check
+ ok(!$c->user, "no more user after logout");
+
+ }
+
+ $c->res->body( "ok" );
+}
+
+__PACKAGE__->config->{authentication} = {
+ default_realm => 'members',
+ realms => {
+ members => {
+ credential => {
+ class => 'Password',
+ password_field => 'password',
+ password_type => 'clear'
+ },
+ store => {
+ class => 'Minimal',
+ users => $members
+ }
+ },
+ admins => {
+ credential => {
+ class => 'Password',
+ password_field => 'password',
+ password_type => 'clear'
+ },
+ store => {
+ class => 'Minimal',
+ users => $admins
+ }
+ }
+ }
+};
+
+__PACKAGE__->setup;
Added: branches/Catalyst-Plugin-Authentication/t/live_app_realms.t
===================================================================
--- branches/Catalyst-Plugin-Authentication/t/live_app_realms.t (rev 0)
+++ branches/Catalyst-Plugin-Authentication/t/live_app_realms.t 2007-07-06 02:16:21 UTC (rev 6509)
@@ -0,0 +1,15 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+
+BEGIN {
+ plan "no_plan";
+}
+
+use lib 't/lib';
+use Catalyst::Test qw/AuthRealmTestApp/;
+
+ok(get("/moose"), "get ok");
More information about the Catalyst-commits
mailing list