[Catalyst-commits] r6517 - in
trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class: .
lib/Catalyst/Plugin/Authentication/Store/DBIx
lib/Catalyst/Plugin/Authentication/Store/DBIx/Class t t/lib
t/lib/TestApp t/lib/TestApp/Model t/lib/TestApp/Schema
jayk at dev.catalyst.perl.org
jayk at dev.catalyst.perl.org
Sun Jul 8 04:41:36 GMT 2007
Author: jayk
Date: 2007-07-08 04:41:34 +0100 (Sun, 08 Jul 2007)
New Revision: 6517
Added:
trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/01-pod.t
trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/02-pod-coverage.t
trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/03-authtest.t
trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/04-authsessions.t
trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/05-auth-roles-relationship.t
trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/06-auth-roles-column.t
trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/auth.db
trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/
trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/SetupDB.pm
trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/TestApp.pm
trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/TestApp/
trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/TestApp/Model/
trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/TestApp/Model/TestApp.pm
trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/TestApp/Schema.pm
trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/TestApp/Schema/
trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/TestApp/Schema/Role.pm
trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/TestApp/Schema/User.pm
trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/TestApp/Schema/UserRole.pm
Removed:
trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/boilerplate.t
trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/pod-coverage.t
trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/pod.t
Modified:
trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/Changes
trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/README
trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/lib/Catalyst/Plugin/Authentication/Store/DBIx/Class.pm
trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/lib/Catalyst/Plugin/Authentication/Store/DBIx/Class/User.pm
Log:
Now throws exceptions when id_field is invalid or can not be determined
several minor adjustments
complete set of tests
Modified: trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/Changes
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/Changes 2007-07-07 20:08:01 UTC (rev 6516)
+++ trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/Changes 2007-07-08 03:41:34 UTC (rev 6517)
@@ -1,5 +1,10 @@
Revision history for Catalyst-Plugin-Authentication-Store-DBIx-Class
+0.10 2007-07-07 3pm CST
+ Proper handling of missing id_field config (load from primary_key)
+ Throw exception if id_field specified does not exist
+ Full test suite added. (based loosely on old DBIC store)
+
0.03 XXX
Switch to Module::Install
Modified: trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/README
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/README 2007-07-07 20:08:01 UTC (rev 6516)
+++ trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/README 2007-07-08 03:41:34 UTC (rev 6517)
@@ -3,7 +3,7 @@
for Catalyst Authentication using DBIx::Class
VERSION
- This documentation refers to version 0.02.
+ This documentation refers to version 0.10.
SYNOPSIS
use Catalyst qw/
@@ -32,23 +32,23 @@
};
# Log a user in:
+
+ sub login : Global {
+ my ( $self, $c ) = @_;
- sub login : Global {
- my ( $self, $c ) = @_;
-
- $c->authenticate({
+ $c->authenticate({
username => $c->req->params->username,
password => $c->req->params->password,
status => [ 'registered', 'loggedin', 'active']
}))
}
-
- # verify a role
-
- if ( $c->check_user_roles( 'editor' ) ) {
+
+ # verify a role
+
+ if ( $c->check_user_roles( 'editor' ) ) {
# do editor stuff
}
-
+
DESCRIPTION
The Catalyst::Plugin::Authentication::Store::DBIx::Class class provides
access to authentication information stored in a database via
@@ -243,13 +243,13 @@
my $rs = $c->model('MyApp::User')->search({ email => $c->request->params->{'email'} });
... # further $rs adjustments
-
- if ($c->authenticate({
+
+ if ($c->authenticate({
password => $password,
'dbix_class' => { resultset = $rs }
})) {
# do successful authentication actions here.
- }
+ }
Be aware that the resultset method will not verify that you are
passing a resultset that is attached to the same user_class as
Modified: trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/lib/Catalyst/Plugin/Authentication/Store/DBIx/Class/User.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/lib/Catalyst/Plugin/Authentication/Store/DBIx/Class/User.pm 2007-07-07 20:08:01 UTC (rev 6516)
+++ trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/lib/Catalyst/Plugin/Authentication/Store/DBIx/Class/User.pm 2007-07-08 03:41:34 UTC (rev 6517)
@@ -23,8 +23,16 @@
if (!exists($self->config->{'id_field'})) {
- $self->config->{'id_field'} = 'id';
+ my @pks = $self->{'resultset'}->result_source->primary_columns;
+ if ($#pks == 0) {
+ $self->config->{'id_field'} = $pks[0];
+ } else {
+ Catalyst::Exception->throw("user table does not contain a single primary key column - please specify 'id_field' in config!");
+ }
}
+ if (!$self->{'resultset'}->result_source->has_column($self->config->{'id_field'})) {
+ Catalyst::Exception->throw("id_field set to " . $self->config->{'id_field'} . " but user table has no column by that name!");
+ }
## if we have lazyloading turned on - we should not query the DB unless something gets read.
## that's the idea anyway - still have to work out how to manage that - so for now we always force
@@ -104,7 +112,10 @@
my @roles = ();
if (exists($self->config->{'role_column'})) {
- @roles = split /[ ,\|]+/, $self->get($self->config->{'role_column'});
+ my $role_data = $self->get($self->config->{'role_column'});
+ if ($role_data) {
+ @roles = split /[ ,\|]+/, $self->get($self->config->{'role_column'});
+ }
$self->_roles(\@roles);
} elsif (exists($self->config->{'role_relation'})) {
my $relation = $self->config->{'role_relation'};
@@ -176,7 +187,7 @@
=head1 VERSION
-This documentation refers to version 0.02.
+This documentation refers to version 0.10.
=head1 SYNOPSIS
Modified: trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/lib/Catalyst/Plugin/Authentication/Store/DBIx/Class.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/lib/Catalyst/Plugin/Authentication/Store/DBIx/Class.pm 2007-07-07 20:08:01 UTC (rev 6516)
+++ trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/lib/Catalyst/Plugin/Authentication/Store/DBIx/Class.pm 2007-07-08 03:41:34 UTC (rev 6517)
@@ -4,7 +4,11 @@
use warnings;
use base qw/Class::Accessor::Fast/;
+<<<<<<< .mine
+our $VERSION= "0.10";
+=======
our $VERSION= "0.03";
+>>>>>>> .r6516
BEGIN {
__PACKAGE__->mk_accessors(qw/config/);
@@ -80,7 +84,7 @@
=head1 VERSION
-This documentation refers to version 0.02.
+This documentation refers to version 0.10.
=head1 SYNOPSIS
@@ -299,7 +303,7 @@
=item Searchargs
The B<searchargs> method of retrieval allows you to specify an arrayref containing
-the two arguments to the search() method from L<DBIx::Class::Resultset>. If provided,
+the two arguments to the search() method from L<DBIx::Class::ResultSet>. If provided,
all other args are ignored, and the search args provided are used directly to locate
the user. An example will probably make more sense:
Added: trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/01-pod.t
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/01-pod.t (rev 0)
+++ trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/01-pod.t 2007-07-08 03:41:34 UTC (rev 6517)
@@ -0,0 +1,6 @@
+#!perl -T
+
+use Test::More;
+eval "use Test::Pod 1.14";
+plan skip_all => "Test::Pod 1.14 required for testing POD" if $@;
+all_pod_files_ok();
Added: trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/02-pod-coverage.t
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/02-pod-coverage.t (rev 0)
+++ trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/02-pod-coverage.t 2007-07-08 03:41:34 UTC (rev 6517)
@@ -0,0 +1,6 @@
+#!perl -T
+
+use Test::More;
+eval "use Test::Pod::Coverage 1.04";
+plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@;
+all_pod_coverage_ok();
Added: trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/03-authtest.t
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/03-authtest.t (rev 0)
+++ trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/03-authtest.t 2007-07-08 03:41:34 UTC (rev 6517)
@@ -0,0 +1,98 @@
+#!perl
+
+use strict;
+use warnings;
+use DBI;
+use File::Path;
+use FindBin;
+use Test::More;
+use lib "$FindBin::Bin/lib";
+
+BEGIN {
+ eval { require DBD::SQLite }
+ or plan skip_all =>
+ "DBD::SQLite is required for this test";
+
+ eval { require DBIx::Class }
+ or plan skip_all =>
+ "DBIx::Class is required for this test";
+
+ plan tests => 14;
+
+ $ENV{TESTAPP_DB_FILE} = "$FindBin::Bin/auth.db" unless exists($ENV{TESTAPP_DB_FILE});
+
+ $ENV{TESTAPP_CONFIG} = {
+ name => 'TestApp',
+ authentication => {
+ default_realm => "users",
+ realms => {
+ users => {
+ credential => {
+ 'class' => "Password",
+ 'password_field' => 'password',
+ 'password_type' => 'clear'
+ },
+ store => {
+ 'class' => 'DBIx::Class',
+ 'user_class' => 'TestApp::User',
+ },
+ },
+ },
+ },
+ };
+
+ $ENV{TESTAPP_PLUGINS} = [
+ qw/Authentication/
+ ];
+}
+
+use SetupDB;
+
+use Catalyst::Test 'TestApp';
+
+# log a user in
+{
+ ok( my $res = request('http://localhost/user_login?username=joeuser&password=hackme'), 'request ok' );
+ is( $res->content, 'joeuser logged in', 'user logged in ok' );
+}
+
+# invalid user
+{
+ ok( my $res = request('http://localhost/user_login?username=foo&password=bar'), 'request ok' );
+ is( $res->content, 'not logged in', 'user not logged in ok' );
+}
+
+# disabled user - no disable check
+{
+ ok( my $res = request('http://localhost/user_login?username=spammer&password=broken'), 'request ok' );
+ is( $res->content, 'spammer logged in', 'status check - disabled user logged in ok' );
+}
+
+# disabled user - should fail login
+{
+ ok( my $res = request('http://localhost/notdisabled_login?username=spammer&password=broken'), 'request ok' );
+ is( $res->content, 'not logged in', 'status check - disabled user not logged in ok' );
+}
+
+# log the user out
+{
+ ok( my $res = request('http://localhost/user_logout'), 'request ok' );
+ is( $res->content, 'logged out', 'user logged out ok' );
+}
+
+# searchargs test
+{
+ ok( my $res = request('http://localhost/searchargs_login?email=nada%40mucho.net&password=much'), 'request ok' );
+ is( $res->content, 'nuffin logged in', 'searchargs based login ok' );
+}
+
+# resultset test
+# searchargs test
+{
+ ok( my $res = request('http://localhost/resultset_login?email=j%40cpants.org&password=letmein'), 'request ok' );
+ is( $res->content, 'jayk logged in', 'resultset based login ok' );
+}
+
+
+# clean up
+unlink $ENV{TESTAPP_DB_FILE};
Added: trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/04-authsessions.t
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/04-authsessions.t (rev 0)
+++ trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/04-authsessions.t 2007-07-08 03:41:34 UTC (rev 6517)
@@ -0,0 +1,92 @@
+#!perl
+
+use strict;
+use warnings;
+use DBI;
+use File::Path;
+use FindBin;
+use Test::More;
+use lib "$FindBin::Bin/lib";
+
+BEGIN {
+ eval { require Test::WWW::Mechanize::Catalyst }
+ or plan skip_all =>
+ "Test::WWW::Mechanize::Catalyst is required for this test";
+
+ eval { require DBD::SQLite }
+ or plan skip_all =>
+ "DBD::SQLite is required for this test";
+
+ eval { require DBIx::Class }
+ or plan skip_all =>
+ "DBIx::Class is required for this test";
+
+ eval { require Catalyst::Plugin::Session;
+ die unless $Catalyst::Plugin::Session::VERSION >= 0.02 }
+ or plan skip_all =>
+ "Catalyst::Plugin::Session >= 0.02 is required for this test";
+
+ plan tests => 8;
+
+ $ENV{TESTAPP_DB_FILE} = "$FindBin::Bin/auth.db" unless exists($ENV{TESTAPP_DB_FILE});
+
+ $ENV{TESTAPP_CONFIG} = {
+ name => 'TestApp',
+ authentication => {
+ default_realm => "users",
+ realms => {
+ users => {
+ credential => {
+ 'class' => "Password",
+ 'password_field' => 'password',
+ 'password_type' => 'clear'
+ },
+ store => {
+ 'class' => 'DBIx::Class',
+ 'user_class' => 'TestApp::User',
+ },
+ },
+ },
+ },
+ };
+
+ $ENV{TESTAPP_PLUGINS} = [
+ qw/Authentication
+ Session
+ Session::Store::Dummy
+ Session::State::Cookie
+ /
+ ];
+}
+
+use SetupDB;
+
+use Test::WWW::Mechanize::Catalyst 'TestApp';
+my $m = Test::WWW::Mechanize::Catalyst->new;
+
+# log a user in
+{
+ $m->get_ok( 'http://localhost/user_login?username=joeuser&password=hackme', undef, 'request ok' );
+ $m->content_is( 'joeuser logged in', 'user logged in ok' );
+}
+
+# verify the user is still logged in
+{
+ $m->get_ok( 'http://localhost/get_session_user', undef, 'request ok' );
+ $m->content_is( 'joeuser', 'user still logged in' );
+}
+
+# log the user out
+{
+ $m->get_ok( 'http://localhost/user_logout', undef, 'request ok' );
+ $m->content_is( 'logged out', 'user logged out ok' );
+}
+
+# verify there is no session
+{
+ $m->get_ok( 'http://localhost/get_session_user', undef, 'request ok' );
+ $m->content_is( '', "user's session deleted" );
+}
+
+# clean up
+unlink $ENV{TESTAPP_DB_FILE};
Added: trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/05-auth-roles-relationship.t
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/05-auth-roles-relationship.t (rev 0)
+++ trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/05-auth-roles-relationship.t 2007-07-08 03:41:34 UTC (rev 6517)
@@ -0,0 +1,87 @@
+#!perl
+
+use strict;
+use warnings;
+use DBI;
+use File::Path;
+use FindBin;
+use Test::More;
+use lib "$FindBin::Bin/lib";
+
+BEGIN {
+ eval { require DBD::SQLite }
+ or plan skip_all =>
+ "DBD::SQLite is required for this test";
+
+ eval { require DBIx::Class }
+ or plan skip_all =>
+ "DBIx::Class is required for this test";
+
+ eval { require Catalyst::Plugin::Authorization::Roles }
+ or plan skip_all =>
+ "Catalyst::Plugin::Authorization::Roles is required for this test";
+
+ plan tests => 8;
+
+ $ENV{TESTAPP_DB_FILE} = "$FindBin::Bin/auth.db" unless exists($ENV{TESTAPP_DB_FILE});
+
+
+ $ENV{TESTAPP_CONFIG} = {
+ name => 'TestApp',
+ authentication => {
+ default_realm => "users",
+ realms => {
+ users => {
+ credential => {
+ 'class' => "Password",
+ 'password_field' => 'password',
+ 'password_type' => 'clear'
+ },
+ store => {
+ 'class' => 'DBIx::Class',
+ 'user_class' => 'TestApp::User',
+ 'role_relation' => 'roles',
+ 'role_field' => 'role'
+ },
+ },
+ },
+ },
+ };
+
+ $ENV{TESTAPP_PLUGINS} = [
+ qw/Authentication
+ Authorization::Roles
+ /
+ ];
+}
+
+use SetupDB;
+
+use Catalyst::Test 'TestApp';
+
+# test user's admin access
+{
+ ok( my $res = request('http://localhost/user_login?username=jayk&password=letmein&detach=is_admin'), 'request ok' );
+ is( $res->content, 'ok', 'user is an admin' );
+}
+
+# test unauthorized user's admin access
+{
+ ok( my $res = request('http://localhost/user_login?username=nuffin&password=much&detach=is_admin'), 'request ok' );
+ is( $res->content, 'failed', 'user is not an admin' );
+}
+
+# test multiple auth roles
+{
+ ok( my $res = request('http://localhost/user_login?username=jayk&password=letmein&detach=is_admin_user'), 'request ok' );
+ is( $res->content, 'ok', 'user is an admin and a user' );
+}
+
+# test multiple unauth roles
+{
+ ok( my $res = request('http://localhost/user_login?username=nuffin&password=much&detach=is_admin_user'), 'request ok' );
+ is( $res->content, 'failed', 'user is not an admin and a user' );
+}
+
+# clean up
+unlink $ENV{TESTAPP_DB_FILE};
Added: trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/06-auth-roles-column.t
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/06-auth-roles-column.t (rev 0)
+++ trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/06-auth-roles-column.t 2007-07-08 03:41:34 UTC (rev 6517)
@@ -0,0 +1,86 @@
+#!perl
+
+use strict;
+use warnings;
+use DBI;
+use File::Path;
+use FindBin;
+use Test::More;
+use lib "$FindBin::Bin/lib";
+
+BEGIN {
+ eval { require DBD::SQLite }
+ or plan skip_all =>
+ "DBD::SQLite is required for this test";
+
+ eval { require DBIx::Class }
+ or plan skip_all =>
+ "DBIx::Class is required for this test";
+
+ eval { require Catalyst::Plugin::Authorization::Roles }
+ or plan skip_all =>
+ "Catalyst::Plugin::Authorization::Roles is required for this test";
+
+ plan tests => 8;
+
+ $ENV{TESTAPP_DB_FILE} = "$FindBin::Bin/auth.db" unless exists($ENV{TESTAPP_DB_FILE});
+
+
+ $ENV{TESTAPP_CONFIG} = {
+ name => 'TestApp',
+ authentication => {
+ default_realm => "users",
+ realms => {
+ users => {
+ credential => {
+ 'class' => "Password",
+ 'password_field' => 'password',
+ 'password_type' => 'clear'
+ },
+ store => {
+ 'class' => 'DBIx::Class',
+ 'user_class' => 'TestApp::User',
+ 'role_column' => 'role_text'
+ },
+ },
+ },
+ },
+ };
+
+ $ENV{TESTAPP_PLUGINS} = [
+ qw/Authentication
+ Authorization::Roles
+ /
+ ];
+}
+
+use SetupDB;
+
+use Catalyst::Test 'TestApp';
+
+# test user's admin access
+{
+ ok( my $res = request('http://localhost/user_login?username=joeuser&password=hackme&detach=is_admin'), 'request ok' );
+ is( $res->content, 'ok', 'user is an admin' );
+}
+
+# test unauthorized user's admin access
+{
+ ok( my $res = request('http://localhost/user_login?username=jayk&password=letmein&detach=is_admin'), 'request ok' );
+ is( $res->content, 'failed', 'user is not an admin' );
+}
+
+# test multiple auth roles
+{
+ ok( my $res = request('http://localhost/user_login?username=nuffin&password=much&detach=is_admin_user'), 'request ok' );
+ is( $res->content, 'ok', 'user is an admin and a user' );
+}
+
+# test multiple unauth roles
+{
+ ok( my $res = request('http://localhost/user_login?username=joeuser&password=hackme&detach=is_admin_user'), 'request ok' );
+ is( $res->content, 'failed', 'user is not an admin and a user' );
+}
+
+# clean up
+unlink $ENV{TESTAPP_DB_FILE};
Added: trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/auth.db
===================================================================
Deleted: trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/boilerplate.t
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/boilerplate.t 2007-07-07 20:08:01 UTC (rev 6516)
+++ trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/boilerplate.t 2007-07-08 03:41:34 UTC (rev 6517)
@@ -1,48 +0,0 @@
-#!perl -T
-
-use strict;
-use warnings;
-use Test::More tests => 3;
-
-sub not_in_file_ok {
- my ($filename, %regex) = @_;
- open my $fh, "<", $filename
- or die "couldn't open $filename for reading: $!";
-
- my %violated;
-
- while (my $line = <$fh>) {
- while (my ($desc, $regex) = each %regex) {
- if ($line =~ $regex) {
- push @{$violated{$desc}||=[]}, $.;
- }
- }
- }
-
- if (%violated) {
- fail("$filename contains boilerplate text");
- diag "$_ appears on lines @{$violated{$_}}" for keys %violated;
- } else {
- pass("$filename contains no boilerplate text");
- }
-}
-
-not_in_file_ok(README =>
- "The README is used..." => qr/The README is used/,
- "'version information here'" => qr/to provide version information/,
-);
-
-not_in_file_ok(Changes =>
- "placeholder date/time" => qr(Date/time)
-);
-
-sub module_boilerplate_ok {
- my ($module) = @_;
- not_in_file_ok($module =>
- 'the great new $MODULENAME' => qr/ - The great new /,
- 'boilerplate description' => qr/Quick summary of what the module/,
- 'stub function definition' => qr/function[12]/,
- );
-}
-
-module_boilerplate_ok('lib/Catalyst/Plugin/Authentication/Store/DBIx/Class.pm');
Added: trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/SetupDB.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/SetupDB.pm (rev 0)
+++ trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/SetupDB.pm 2007-07-08 03:41:34 UTC (rev 6517)
@@ -0,0 +1,37 @@
+# create the database
+my $db_file = $ENV{TESTAPP_DB_FILE};
+unlink $db_file if -e $db_file;
+
+my $dbh = DBI->connect( "dbi:SQLite:$db_file" ) or die $DBI::errstr;
+my $sql = q{
+ CREATE TABLE user (
+ id INTEGER PRIMARY KEY,
+ username TEXT,
+ email TEXT,
+ password TEXT,
+ status TEXT,
+ role_text TEXT,
+ session_data TEXT
+ );
+ CREATE TABLE role (
+ id INTEGER PRIMARY KEY,
+ role TEXT
+ );
+ CREATE TABLE user_role (
+ id INTEGER PRIMARY KEY,
+ user INTEGER,
+ roleid INTEGER
+ );
+
+ INSERT INTO user VALUES (1, 'joeuser', 'joeuser at nowhere.com', 'hackme', 'active', 'admin', NULL);
+ INSERT INTO user VALUES (2, 'spammer', 'bob at spamhaus.com', 'broken', 'disabled', NULL, NULL);
+ INSERT INTO user VALUES (3, 'jayk', 'j at cpants.org', 'letmein', 'active', NULL, NULL);
+ INSERT INTO user VALUES (4, 'nuffin', 'nada at mucho.net', 'much', 'registered', 'user admin', NULL);
+ INSERT INTO role VALUES (1, 'admin');
+ INSERT INTO role VALUES (2, 'user');
+ INSERT INTO user_role VALUES (1, 3, 1);
+ INSERT INTO user_role VALUES (2, 3, 2);
+ INSERT INTO user_role VALUES (3, 4, 2)
+};
+$dbh->do( $_ ) for split /;/, $sql;
+$dbh->disconnect;
\ No newline at end of file
Added: trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/TestApp/Model/TestApp.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/TestApp/Model/TestApp.pm (rev 0)
+++ trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/TestApp/Model/TestApp.pm 2007-07-08 03:41:34 UTC (rev 6517)
@@ -0,0 +1,23 @@
+package TestApp::Model::TestApp;
+
+use base qw/Catalyst::Model::DBIC::Schema/;
+use strict;
+
+
+our $db_file = $ENV{TESTAPP_DB_FILE};
+
+__PACKAGE__->config(
+ schema_class => 'TestApp::Schema',
+ connect_info => [ "dbi:SQLite:$db_file",
+ '',
+ '',
+ { AutoCommit => 1 },
+ ],
+
+);
+
+# Load all of the classes
+#__PACKAGE__->load_classes(qw/Role User UserRole/);
+
+
+1;
Added: trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/TestApp/Schema/Role.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/TestApp/Schema/Role.pm (rev 0)
+++ trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/TestApp/Schema/Role.pm 2007-07-08 03:41:34 UTC (rev 6517)
@@ -0,0 +1,15 @@
+package TestApp::Schema::Role;
+
+use strict;
+use warnings;
+use base 'DBIx::Class';
+
+__PACKAGE__->load_components(qw/ Core /);
+
+__PACKAGE__->table( 'role' );
+__PACKAGE__->add_columns( qw/id role/ );
+__PACKAGE__->set_primary_key( 'id' );
+
+#__PACKAGE__->has_many( map_user_role => 'TestApp::Schema::UserRole' => 'roleid' );
+
+1;
Added: trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/TestApp/Schema/User.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/TestApp/Schema/User.pm (rev 0)
+++ trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/TestApp/Schema/User.pm 2007-07-08 03:41:34 UTC (rev 6517)
@@ -0,0 +1,17 @@
+package TestApp::Schema::User;
+
+use strict;
+use warnings;
+use base 'DBIx::Class';
+
+__PACKAGE__->load_components(qw/ Core /);
+
+__PACKAGE__->table( 'user' );
+__PACKAGE__->add_columns( qw/id username email password status role_text session_data/ );
+__PACKAGE__->set_primary_key( 'id' );
+
+__PACKAGE__->has_many( 'map_user_role' => 'TestApp::Schema::UserRole' => 'user' );
+
+__PACKAGE__->many_to_many( roles => 'map_user_role', 'role');
+
+1;
Added: trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/TestApp/Schema/UserRole.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/TestApp/Schema/UserRole.pm (rev 0)
+++ trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/TestApp/Schema/UserRole.pm 2007-07-08 03:41:34 UTC (rev 6517)
@@ -0,0 +1,15 @@
+package TestApp::Schema::UserRole;
+
+use strict;
+use warnings;
+use base 'DBIx::Class';
+
+__PACKAGE__->load_components(qw/ Core /);
+
+__PACKAGE__->table( 'user_role' );
+__PACKAGE__->add_columns( qw/id user roleid/ );
+__PACKAGE__->set_primary_key( qw/id/ );
+
+__PACKAGE__->belongs_to('role', 'TestApp::Schema::Role', { 'foreign.id' => 'self.roleid'});
+
+1;
Added: trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/TestApp/Schema.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/TestApp/Schema.pm (rev 0)
+++ trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/TestApp/Schema.pm 2007-07-08 03:41:34 UTC (rev 6517)
@@ -0,0 +1,12 @@
+package TestApp::Schema;
+
+# Created by DBIx::Class::Schema::Loader v0.03007 @ 2006-10-18 12:38:33
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Schema';
+
+__PACKAGE__->load_classes;
+
+1;
\ No newline at end of file
Added: trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/TestApp.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/TestApp.pm (rev 0)
+++ trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/lib/TestApp.pm 2007-07-08 03:41:34 UTC (rev 6517)
@@ -0,0 +1,163 @@
+package TestApp;
+
+use strict;
+use Catalyst;
+use Data::Dumper;
+
+TestApp->config( $ENV{TESTAPP_CONFIG} );
+
+TestApp->setup( @{$ENV{TESTAPP_PLUGINS}} );
+
+sub user_login : Global {
+ my ( $self, $c ) = @_;
+
+ ## this allows anyone to login regardless of status.
+ $c->authenticate({ username => $c->request->params->{'username'},
+ password => $c->request->params->{'password'}
+ });
+
+ 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' );
+ }
+}
+
+sub notdisabled_login : Global {
+ my ( $self, $c ) = @_;
+
+ $c->authenticate({ username => $c->request->params->{'username'},
+ password => $c->request->params->{'password'},
+ status => [ 'active', 'registered' ]
+ });
+
+ 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' );
+ }
+}
+
+sub searchargs_login : Global {
+ my ( $self, $c ) = @_;
+
+ my $username = $c->request->params->{'username'} || '';
+ my $email = $c->request->params->{'email'} || '';
+
+ $c->authenticate({
+ password => $c->request->params->{'password'},
+ dbix_class => {
+ searchargs => [ { "-or" => [ username => $username,
+ email => $email ]},
+ { prefetch => qw/ map_user_role /}
+ ]
+ }
+ });
+
+ 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' );
+ }
+}
+
+sub resultset_login : Global {
+ my ( $self, $c ) = @_;
+
+ my $username = $c->request->params->{'username'} || '';
+ my $email = $c->request->params->{'email'} || '';
+
+
+ my $rs = $c->model('TestApp::User')->search({ "-or" => [ username => $username,
+ email => $email ]});
+
+ $c->authenticate({
+ password => $c->request->params->{'password'},
+ dbix_class => { resultset => $rs }
+ });
+
+ 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 {
+ my ( $self, $c ) = @_;
+
+ $c->logout;
+
+ if ( ! $c->user ) {
+ $c->res->body( 'logged out' );
+ }
+ else {
+ $c->res->body( 'not logged ok' );
+ }
+}
+
+sub get_session_user : Global {
+ my ( $self, $c ) = @_;
+
+ if ( $c->user_exists ) {
+ $c->res->body( $c->user->get('username') );
+ }
+}
+
+sub is_admin : Global {
+ my ( $self, $c ) = @_;
+
+ eval {
+ if ( $c->assert_user_roles( qw/admin/ ) ) {
+ $c->res->body( 'ok' );
+ }
+ };
+ if ($@) {
+ $c->res->body( 'failed' );
+ }
+}
+
+sub is_admin_user : Global {
+ my ( $self, $c ) = @_;
+
+ eval {
+ if ( $c->assert_user_roles( qw/admin user/ ) ) {
+ $c->res->body( 'ok' );
+ }
+ };
+ if ($@) {
+ $c->res->body( 'failed' );
+ }
+}
+
+sub set_usersession : Global {
+ my ( $self, $c, $value ) = @_;
+ $c->user_session->{foo} = $value;
+ $c->res->body( 'ok' );
+}
+
+sub get_usersession : Global {
+ my ( $self, $c ) = @_;
+ $c->res->body( $c->user_session->{foo} || '' );
+}
+
+
+1;
Deleted: trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/pod-coverage.t
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/pod-coverage.t 2007-07-07 20:08:01 UTC (rev 6516)
+++ trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/pod-coverage.t 2007-07-08 03:41:34 UTC (rev 6517)
@@ -1,6 +0,0 @@
-#!perl -T
-
-use Test::More;
-eval "use Test::Pod::Coverage 1.04";
-plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@;
-all_pod_coverage_ok();
Deleted: trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/pod.t
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/pod.t 2007-07-07 20:08:01 UTC (rev 6516)
+++ trunk/Catalyst-Plugin-Authentication-Store-DBIx-Class/t/pod.t 2007-07-08 03:41:34 UTC (rev 6517)
@@ -1,6 +0,0 @@
-#!perl -T
-
-use Test::More;
-eval "use Test::Pod 1.14";
-plan skip_all => "Test::Pod 1.14 required for testing POD" if $@;
-all_pod_files_ok();
More information about the Catalyst-commits
mailing list