Committed missed changes from 0.1082
Jay Kuri [Thu, 4 Mar 2010 02:16:46 +0000 (02:16 +0000)]
Changed messaging when user provides no fields in authenticate that match up with user table

Changes
Makefile.PL
lib/Catalyst/Authentication/Store/DBIx/Class.pm
lib/Catalyst/Authentication/Store/DBIx/Class/User.pm
t/00-load.t
t/03-authtest.t
t/08-simpledb-auth-roles-relationship.t
t/09-simpledb-auth-roles-column.t
t/lib/TestApp.pm

diff --git a/Changes b/Changes
index 8a08b1e..7481582 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,10 @@
 Revision history for Catalyst-Plugin-Authentication-Store-DBIx-Class
 
+0.1083  2010-03-03
+        Tweaking exception message to better explain what people did wrong when 
+            they pass bad columns to authenticate.
+
+0.1082  2008-10-27
         Documentation tweak to clarify user_class, store_user_class etc.
 
 0.108   2008-09-25
index 7c22ea0..696031e 100644 (file)
@@ -41,7 +41,7 @@ requires (  'Catalyst::Runtime'                 => 0,
 test_requires 'Test::More';
 
 auto_install;
-resources repository => 'http://dev.catalyst.perl.org/repos/Catalyst/trunk/Catalyst-Authentication-Store-DBIx-Class/';
+resources repository => 'http://dev.catalystframework.org/repos/Catalyst/trunk/Catalyst-Authentication-Store-DBIx-Class';
 
 WriteAll;
 
index c493d7a..3fd1ea8 100644 (file)
@@ -4,7 +4,7 @@ use strict;
 use warnings;
 use base qw/Class::Accessor::Fast/;
 
-our $VERSION= "0.1081";
+our $VERSION= "0.1083";
 
 
 BEGIN {
index 0e397b1..07b26e6 100644 (file)
@@ -93,7 +93,7 @@ sub load {
         if (keys %{$searchargs}) {
             $self->_user($self->resultset->search($searchargs)->first);
         } else {
-            Catalyst::Exception->throw("User retrieval failed: no columns from " . $self->config->{'user_model'} . " were provided");
+            Catalyst::Exception->throw("Failed to load user data.  You passed [" . join(',', keys %{$authinfo}) . "] to authenticate() but your user source (" .  $self->config->{'user_model'} . ") only has these columns: [" . join( ",", $self->resultset->result_source->columns ) . "]   Check your authenticate() call.");
         }
     }
 
index 8d39208..1392a58 100644 (file)
@@ -1,4 +1,4 @@
-#!perl -T
+#!perl 
 
 use Test::More tests => 1;
 
index a9ddf6d..faed777 100644 (file)
@@ -17,7 +17,7 @@ BEGIN {
         or plan skip_all =>
         "DBIx::Class is required for this test";
 
-    plan tests => 15;
+    plan tests => 17;
 
     $ENV{TESTAPP_DB_FILE} = "$FindBin::Bin/auth.db" unless exists($ENV{TESTAPP_DB_FILE});
 
@@ -93,13 +93,21 @@ use Catalyst::Test 'TestApp';
     is( $res->content, 'jayk logged in', 'resultset based login ok' );
 }
 
+# invalid user
+{
+    ok( my $res = request('http://localhost/bad_login?username=foo&password=bar'), 'request ok' );
+    like( $res->content, qr/only has these columns/, 'incorrect parameters to authenticate throws a useful exception' );
+}
+
+
 {
     $ENV{TESTAPP_CONFIG}->{authentication}->{realms}->{users}->{store}->{user_model} = 'Nonexistent::Class';
     my $res = request('http://localhost/user_login?username=joeuser&password=hackme');
     like( $res->content, qr/\$\Qc->model('Nonexistent::Class') did not return a resultset. Did you set user_model correctly?/, 'test for wrong user_class' );
 }
            
-           
+         
+
 
 
 # clean up
index b6b5c1d..5504ce4 100644 (file)
@@ -32,6 +32,7 @@ BEGIN {
             default => {
                                class => 'SimpleDB',
                 user_model => 'TestApp::User',
+                password_type => 'clear'
                        }
                }
     };
index ac5cec9..3c885e2 100644 (file)
@@ -32,7 +32,8 @@ BEGIN {
             default => {
                                class => 'SimpleDB',
                                user_model => 'TestApp::User',
-                               role_column => 'role_text'
+                               role_column => 'role_text',
+                               password_type => 'clear'
                        }
                }
         
index 4f37831..49ee981 100644 (file)
@@ -105,6 +105,30 @@ sub resultset_login : Global {
     }
 }
 
+sub bad_login : Global {
+    my ( $self, $c ) = @_;
+
+    ## this allows anyone to login regardless of status.
+    eval {
+        $c->authenticate({ william => $c->request->params->{'username'},
+                           the_bum => $c->request->params->{'password'}
+                         });
+        1;
+    } or do {
+        return $c->res->body($@);
+    };
+
+    if ( $c->user_exists ) {
+        if ( $c->req->params->{detach} ) {
+            $c->detach( $c->req->params->{detach} );
+        }
+        $c->res->body( $c->user->get('username') . ' logged in' );
+    }
+    else {
+        $c->res->body( 'not logged in' );
+    }
+}
+
 ## need to add a resultset login test and a search args login test
 
 sub user_logout : Global {