[Catalyst-commits] r6562 - in trunk/Catalyst-Plugin-Authentication:
. lib/Catalyst/Plugin/Authentication
lib/Catalyst/Plugin/Authentication/Credential
lib/Catalyst/Plugin/Authentication/Store
lib/Catalyst/Plugin/Authentication/User t
matthewt at dev.catalyst.perl.org
matthewt at dev.catalyst.perl.org
Tue Jul 17 17:59:23 GMT 2007
Author: matthewt
Date: 2007-07-17 17:59:23 +0100 (Tue, 17 Jul 2007)
New Revision: 6562
Added:
trunk/Catalyst-Plugin-Authentication/t/AuthRealmTestApp.pm
trunk/Catalyst-Plugin-Authentication/t/live_app_realms.t
Modified:
trunk/Catalyst-Plugin-Authentication/
trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/Credential/Password.pm
trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/Store/Minimal.pm
trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/User.pm
trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/User/Hash.pm
Log:
r53844 at cain (orig r6509): jayk | 2007-07-06 02:16:21 +0000
Bug fixes and test from nilsonsfj - Cheers!
Property changes on: trunk/Catalyst-Plugin-Authentication
___________________________________________________________________
Name: svk:merge
- 4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-Plugin-Authentication:6318
+ 4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-Plugin-Authentication:6509
Modified: trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/Credential/Password.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/Credential/Password.pm 2007-07-17 16:59:18 UTC (rev 6561)
+++ trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/Credential/Password.pm 2007-07-17 16:59:23 UTC (rev 6562)
@@ -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: trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/Store/Minimal.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/Store/Minimal.pm 2007-07-17 16:59:18 UTC (rev 6561)
+++ trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/Store/Minimal.pm 2007-07-17 16:59:23 UTC (rev 6562)
@@ -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: trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/User/Hash.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/User/Hash.pm 2007-07-17 16:59:18 UTC (rev 6561)
+++ trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/User/Hash.pm 2007-07-17 16:59:23 UTC (rev 6562)
@@ -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: trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/User.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/User.pm 2007-07-17 16:59:18 UTC (rev 6561)
+++ trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/User.pm 2007-07-17 16:59:23 UTC (rev 6562)
@@ -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: trunk/Catalyst-Plugin-Authentication/t/AuthRealmTestApp.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication/t/AuthRealmTestApp.pm (rev 0)
+++ trunk/Catalyst-Plugin-Authentication/t/AuthRealmTestApp.pm 2007-07-17 16:59:23 UTC (rev 6562)
@@ -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: trunk/Catalyst-Plugin-Authentication/t/live_app_realms.t
===================================================================
--- trunk/Catalyst-Plugin-Authentication/t/live_app_realms.t (rev 0)
+++ trunk/Catalyst-Plugin-Authentication/t/live_app_realms.t 2007-07-17 16:59:23 UTC (rev 6562)
@@ -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