Skip to content

Commit

Permalink
add mango/auth test
Browse files Browse the repository at this point in the history
  • Loading branch information
davemenninger committed Nov 13, 2014
1 parent c5a41c6 commit 6259e06
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
16 changes: 3 additions & 13 deletions lib/Lrrr/Authentication.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ package Lrrr::Authentication;
sub load_user {
my ($class, $app, $username) = @_;

#return 1;
#my $self = shift;
#my $username = shift;

my $collection = $app->mango->db('test')->collection('users');
my $collection = $app->mango->db->collection('users');
my $user = $collection->find_one( {username => $username} );

return {
Expand All @@ -19,16 +15,10 @@ sub load_user {
sub validate_user {
my ($class, $app, $username, $password, $extas) = @_;

#return 1;
#my $self = shift;
#my $username = shift || '';
#my $password = shift || '';
#my $extradata = shift || {};

my $collection = $app->mango->db('test')->collection('users');
my $collection = $app->mango->db->collection('users');
my $user = $collection->find_one( {username => $username} );

return $user->{username} if ( $password eq $user->{password} );
return $user->{username} if ( defined $user->{username} && defined $user->{password} && $password eq $user->{password} );
return undef;
}

Expand Down
26 changes: 26 additions & 0 deletions t/mango.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use Mojo::Base -strict;

use Test::More;
use Test::Mojo;

#plan skip_all => 'set TEST_ONLINE to enable this test'
# unless $ENV{TEST_ONLINE};

use Mango;

my $t = Test::Mojo->new('Lrrr');

# Clean up before start
my $collection = $t->app->mango->db->collection('users');
$collection->drop if $collection->options;
#$collection->create;

# insert user and pass
$collection->insert({username => 'bender', password => 'rodriguez'});
# test login, hidden
$t->post_ok('/login' => form => { u => 'bender', p => 'rodriguez' })->status_is(200)->content_like(qr/ok/i);

# Cleanup at end
$collection->drop;

done_testing();

0 comments on commit 6259e06

Please sign in to comment.