From: David Kamholz Date: Sun, 27 Nov 2005 21:56:00 +0000 (+0000) Subject: prepare for release of C::P::Authentication::Store::Htpasswd X-Git-Tag: v0.02~13 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Authentication-Store-Htpasswd.git;a=commitdiff_plain;h=cedb9fb4ae54e24ead346e95e1a9f574ea543eb8 prepare for release of C::P::Authentication::Store::Htpasswd --- diff --git a/lib/Catalyst/Plugin/Authentication/Store/Htpasswd.pm b/lib/Catalyst/Plugin/Authentication/Store/Htpasswd.pm index 428e9ba..6e92e1e 100644 --- a/lib/Catalyst/Plugin/Authentication/Store/Htpasswd.pm +++ b/lib/Catalyst/Plugin/Authentication/Store/Htpasswd.pm @@ -38,7 +38,7 @@ database in C<<$c->config>>. Authentication::Credential::Password /; - __PACKAGE__->config->{authentication}{htpasswd} = "..."; + __PACKAGE__->config->{authentication}{htpasswd} = "passwdfile"; sub login : Global { my ( $self, $c ) = @_; @@ -48,29 +48,37 @@ database in C<<$c->config>>. =head1 DESCRIPTION -This plugin uses C to let your application use C<.htpasswd> +This plugin uses C to let your application use C<.htpasswd> files for it's authentication storage. =head1 METHODS -=over 4 - -=item setup +=head2 setup This method will popultate C<< $c->config->{authentication}{store} >> so that L can use it. -=back - =head1 CONFIGURATION -=over 4 - -=item $c->config->{authentication}{htpasswd} +=head2 $c->config->{authentication}{htpasswd} The path to the htpasswd file. -=back +=head1 AUTHORS + +Yuval Kogman C + +David Kamholz C + +=head1 SEE ALSO + +L. + +=head1 COPYRIGHT & LICNESE + + Copyright (c) 2005 the aforementioned authors. All rights + reserved. This program is free software; you can redistribute + it and/or modify it under the same terms as Perl itself. =cut diff --git a/lib/Catalyst/Plugin/Authentication/Store/Htpasswd/Backend.pm b/lib/Catalyst/Plugin/Authentication/Store/Htpasswd/Backend.pm index c5213b0..fa825ca 100644 --- a/lib/Catalyst/Plugin/Authentication/Store/Htpasswd/Backend.pm +++ b/lib/Catalyst/Plugin/Authentication/Store/Htpasswd/Backend.pm @@ -79,25 +79,27 @@ Otherwise, this lets you create a store manually. =head1 METHODS -=over 4 - -=item new $hash_ref +=head2 new $hash_ref Constructs a new store object, which uses the supplied hash ref as it's backing structure. -=item get_user $id +=head2 get_user $id Keys the hash by $id and returns the value. If the return value is unblessed it will be blessed as L. -=item user_supports +=head2 user_supports Chooses a random user from the hash and delegates to it. -=back +=head1 COPYRIGHT & LICNESE + + Copyright (c) 2005 the aforementioned authors. All rights + reserved. This program is free software; you can redistribute + it and/or modify it under the same terms as Perl itself. =cut diff --git a/lib/Catalyst/Plugin/Authentication/Store/Htpasswd/User.pm b/lib/Catalyst/Plugin/Authentication/Store/Htpasswd/User.pm index f018026..42582d6 100644 --- a/lib/Catalyst/Plugin/Authentication/Store/Htpasswd/User.pm +++ b/lib/Catalyst/Plugin/Authentication/Store/Htpasswd/User.pm @@ -37,7 +37,8 @@ sub check_password { sub roles { my $self = shift; - split( /,/, $self->user->extra_info ); + my $field = $self->user->extra_info->[0]; + return defined $field ? split /,/, $field : (); } sub for_session { @@ -66,11 +67,39 @@ __END__ Catalyst::Plugin::Authentication::Store::Htpasswd::User - A user object representing an entry in an htpasswd file. -=head1 SYNOPSIS +=head1 DESCRIPTION - use Catalyst::Plugin::Authentication::Store::Htpasswd::User; +This object wraps an L object. An instance of it will be returned +by C<< $c->user >> when using L. Methods +not defined in this module are passed through to the L object. The +object stringifies to the username. -=head1 DESCRIPTION +=head1 METHODS + +=head2 new($store,$user) + +Creates a new object from a store object, normally an instance of +L, and a user object, +normally an instance of L. + +=head2 id + +Returns the username. + +=head2 check_password($password) + +Returns whether the password is valid. + +=head2 roles + +Returns an array of roles, which is extracted from a comma-separated list in the +third field of the htpasswd file. + +=head1 COPYRIGHT & LICNESE + + Copyright (c) 2005 the aforementioned authors. All rights + reserved. This program is free software; you can redistribute + it and/or modify it under the same terms as Perl itself. =cut diff --git a/t/backend.t b/t/backend.t index 2eb77ca..9fe0d0e 100644 --- a/t/backend.t +++ b/t/backend.t @@ -3,8 +3,7 @@ use strict; use warnings; -use Test::More 'no_plan'; -use Path::Class; +use Test::More tests => 19; use File::Temp qw/tempfile/; @@ -16,14 +15,12 @@ my $passwd = Authen::Htpasswd->new($tmp); $passwd->add_user("user", "s3cr3t"); - can_ok($m, "new"); isa_ok(my $o = $m->new( $passwd ), $m); can_ok($m, "file"); isa_ok( $o->file, "Authen::Htpasswd"); - can_ok( $m, "user_supports"); ok( $m->user_supports(qw/password self_check/), "user_supports self check" ); @@ -37,7 +34,6 @@ ok( $u->supports(qw/password self_check/), "htpasswd users check their own passw can_ok( $u, "check_password"); ok( $u->check_password( "s3cr3t" ), "password is s3cr3t"); - ok( $m->user_supports(qw/session/), "user_supports session"); is( $u->store, $o, "can get store"); diff --git a/t/backend_md5.t b/t/backend_md5.t index c6f524a..61a5fbb 100644 --- a/t/backend_md5.t +++ b/t/backend_md5.t @@ -11,8 +11,6 @@ BEGIN { plan tests => 12; } -use Path::Class; - use File::Temp qw/tempfile/; my $m; BEGIN { use_ok($m = "Catalyst::Plugin::Authentication::Store::Htpasswd::Backend") } @@ -23,14 +21,12 @@ my $passwd = Authen::Htpasswd->new($tmp, { encrypt_hash => 'md5' }); $passwd->add_user("user", "s3cr3t"); - can_ok($m, "new"); isa_ok(my $o = $m->new( $passwd ), $m); can_ok($m, "file"); isa_ok( $o->file, "Authen::Htpasswd"); - can_ok( $m, "user_supports"); ok( $m->user_supports(qw/password self_check/), "user_supports self check" );