[Jifty-commit] r3145 - in jifty/trunk/t/TestApp-Plugin-PasswordAuth: lib/TestApp/Plugin/PasswordAuth t

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Mon Apr 16 16:53:26 EDT 2007


The problem here is that you're running in a multiuser configuration and
haven't gone and set up a current_user_can. IE, the acls start locked.
and you need to loosen them. 


On Mon, Apr 16, 2007 at 04:52:04PM -0400, jifty-commit at lists.jifty.org wrote:
> Author: yves
> Date: Mon Apr 16 16:52:03 2007
> New Revision: 3145
> 
> Added:
>    jifty/trunk/t/TestApp-Plugin-PasswordAuth/lib/TestApp/Plugin/PasswordAuth/CurrentUser.pm
>    jifty/trunk/t/TestApp-Plugin-PasswordAuth/t/11-current_user.t
> Modified:
>    jifty/trunk/t/TestApp-Plugin-PasswordAuth/lib/TestApp/Plugin/PasswordAuth/Dispatcher.pm
>    jifty/trunk/t/TestApp-Plugin-PasswordAuth/lib/TestApp/Plugin/PasswordAuth/Model/User.pm
>    jifty/trunk/t/TestApp-Plugin-PasswordAuth/t/00-model-User.t
> 
> Log:
> some failing tests on new plugin password, for me test 9 is ok : object id is good, but tests 10 to 14 fail, current user can't read his name mail or mygroup
> 
> 
> Added: jifty/trunk/t/TestApp-Plugin-PasswordAuth/lib/TestApp/Plugin/PasswordAuth/CurrentUser.pm
> ==============================================================================
> --- (empty file)
> +++ jifty/trunk/t/TestApp-Plugin-PasswordAuth/lib/TestApp/Plugin/PasswordAuth/CurrentUser.pm	Mon Apr 16 16:52:03 2007
> @@ -0,0 +1,30 @@
> +package TestApp::Plugin::PasswordAuth::CurrentUser;
> +
> +use strict;
> +use warnings;
> +
> +use base qw(Jifty::CurrentUser);
> +
> +__PACKAGE__->mk_accessors(qw(group));
> +
> +sub _init {
> +   my $self = shift;
> +   my %args = (@_);
> +
> +   if (delete $args{'_bootstrap'} ) {
> +       $self->is_bootstrap_user(1);
> +   } elsif (keys %args) {
> +       $self->user_object(TestApp::Plugin::PasswordAuth::Model::User->new(current_user => $self));
> +       $self->user_object->load_by_cols(%args);
> +
> +       if ( $self->user_object->mygroup eq 'admin') {
> +           $self->is_superuser(1);
> +       };
> +
> +       $self->group($self->user_object->mygroup);
> +   };
> +   $self->SUPER::_init(%args);
> +};
> +
> +
> +1;
> 
> Modified: jifty/trunk/t/TestApp-Plugin-PasswordAuth/lib/TestApp/Plugin/PasswordAuth/Dispatcher.pm
> ==============================================================================
> --- jifty/trunk/t/TestApp-Plugin-PasswordAuth/lib/TestApp/Plugin/PasswordAuth/Dispatcher.pm	(original)
> +++ jifty/trunk/t/TestApp-Plugin-PasswordAuth/lib/TestApp/Plugin/PasswordAuth/Dispatcher.pm	Mon Apr 16 16:52:03 2007
> @@ -1,7 +1,12 @@
> -use strict;
> -use warnings;
>  package TestApp::Plugin::PasswordAuth::Dispatcher;
>  use Jifty::Dispatcher -base;
>  
> +on qr{/setuser/(.*)} => run {
> +    my $name = $1;
> +
> +    my $current_user = TestApp::Plugin::PasswordAuth::CurrentUser->new( name => $name );
> +    Jifty->web->current_user( $current_user );
> +    show '/index.html';
> +};
>  
>  1;
> 
> Modified: jifty/trunk/t/TestApp-Plugin-PasswordAuth/lib/TestApp/Plugin/PasswordAuth/Model/User.pm
> ==============================================================================
> --- jifty/trunk/t/TestApp-Plugin-PasswordAuth/lib/TestApp/Plugin/PasswordAuth/Model/User.pm	(original)
> +++ jifty/trunk/t/TestApp-Plugin-PasswordAuth/lib/TestApp/Plugin/PasswordAuth/Model/User.pm	Mon Apr 16 16:52:03 2007
> @@ -7,6 +7,9 @@
>  # Mixins
>  
>  use TestApp::Plugin::PasswordAuth::Record schema {
> +   column 'mygroup' =>
> +             valid_values are qw/admin moderator user/,
> +             default is 'user';
>  
>  };
>  
> 
> Modified: jifty/trunk/t/TestApp-Plugin-PasswordAuth/t/00-model-User.t
> ==============================================================================
> --- jifty/trunk/t/TestApp-Plugin-PasswordAuth/t/00-model-User.t	(original)
> +++ jifty/trunk/t/TestApp-Plugin-PasswordAuth/t/00-model-User.t	Mon Apr 16 16:52:03 2007
> @@ -7,10 +7,11 @@
>  A basic test harness for the User model.
>  
>  =cut
> +
>  use lib 't/lib';
>  use Jifty::SubTest;
>  
> -use Jifty::Test tests => 15;
> +use Jifty::Test tests => 17;
>  
>  # Make sure we can load the model
>  use_ok('TestApp::Plugin::PasswordAuth::Model::User');
> @@ -39,6 +40,9 @@
>  is($o->color, 'gray');
>  is ($o->swallow_type, 'african');
>  
> +can_ok($o, 'mygroup');
> +is ($o->mygroup, 'user', 'Default user is in group user');
> +
>  
>  my $p = TestApp::Plugin::PasswordAuth::Model::User->new(current_user => $system_user);
>   ($id) = $p->create( name => 'jesse2',
> 
> Added: jifty/trunk/t/TestApp-Plugin-PasswordAuth/t/11-current_user.t
> ==============================================================================
> --- (empty file)
> +++ jifty/trunk/t/TestApp-Plugin-PasswordAuth/t/11-current_user.t	Mon Apr 16 16:52:03 2007
> @@ -0,0 +1,56 @@
> +#!/usr/bin/env perl
> +use warnings;
> +use strict;
> +
> +=head1 DESCRIPTION
> +
> +Basic tests for CurrentUser.
> +
> +=cut
> +
> +use lib 't/lib';
> +use Jifty::SubTest;
> +
> +use Jifty::Test tests => 14;
> +#use Jifty::Test::WWW::Mechanize;
> +
> +use_ok('TestApp::Plugin::PasswordAuth::Model::User');
> +use_ok('TestApp::Plugin::PasswordAuth::CurrentUser');
> +
> +# Get a system user
> +my $system_user = TestApp::Plugin::PasswordAuth::CurrentUser->superuser;
> +ok($system_user, "Found a system user");
> +
> +# Create two users
> +my $o = TestApp::Plugin::PasswordAuth::Model::User->new(current_user => $system_user);
> +$o->create( name => 'A User', email => 'auser at example.com', swallow_type => 'african',
> +            password => 'secret' );
> +ok($o->id, "New user has valid id set");
> +is($o->mygroup, 'user', "User is not admin");
> +$o->create( name => 'Bob', email => 'bob at example.com', swallow_type => 'african', 
> +            password => 'secret2', mygroup => 'admin' );
> +ok($o->id, "New user has valid id set");
> +is($o->mygroup, 'admin', "User is admin");
> +
> +# Create a CurrentUser
> +my $bob = TestApp::Plugin::PasswordAuth::CurrentUser->new( name => 'Bob' );
> +ok($bob->id, "CurrentUser has a valid id set");
> +is($bob->id, $o->id, "The ids match");
> +is($bob->user_object->name, 'Bob', "The CurrentUser is Bob");
> +is($bob->user_object->email, 'bob at example.com', 'The CurrentUser email is bob at example.com');
> +is($bob->user_object->swallow_type, 'african', "The CurrentUser swallow_type is african");
> +is($bob->user_object->mygroup, 'admin', "The CurrentUser group is admin");
> +ok($bob->is_superuser, "CurrentUser is a superuser");
> +
> +#my $server = Jifty::Test->make_server;
> +#isa_ok($server, 'Jifty::Server');
> +
> +#my $URL = $server->started_ok;
> +#my $mech = Jifty::Test::WWW::Mechanize->new();
> +
> +#$mech->get_ok("$URL/currentuser", "Got currentuser page");
> +#$mech->content_contains("No current user set.", "Good, no current user yet");
> +#$mech->get_ok("$URL/setuser/Bob", "Setting currentuser to Bob");
> +#$mech->get_ok("$URL/currentuser", "Refetched currentuser page");
> +#$mech->content_contains("Current user is Bob", "Now the current_user is set");
> +#$mech->content_contains("The current user is a superuser", "... and the current_user is a superuser");
> _______________________________________________
> Jifty-commit mailing list
> Jifty-commit at lists.jifty.org
> http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-commit
> 

-- 


More information about the Jifty-commit mailing list