From: Matt S Trout Date: Sun, 15 Jul 2012 22:04:08 +0000 (+0000) Subject: user store tests X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8dbc46889fe504dede2f94e854254e919ce68416;p=scpubgit%2FApp-EzPz.git user store tests --- diff --git a/lib/App/EzPz/UserStore.pm b/lib/App/EzPz/UserStore.pm index 672fec3..f2ad65d 100644 --- a/lib/App/EzPz/UserStore.pm +++ b/lib/App/EzPz/UserStore.pm @@ -50,7 +50,7 @@ sub add { sub remove { my ($self, $user) = @_; - $self->_htpasswd->remove_user($user->_htpasswd_user); + $self->_htpasswd->delete_user($user->_htpasswd_user); return $user; } diff --git a/t/users.t b/t/users.t new file mode 100644 index 0000000..18cba49 --- /dev/null +++ b/t/users.t @@ -0,0 +1,61 @@ +use strictures 1; +use Test::More; +use App::EzPz::UserStore; +use File::Temp qw(tempfile); + +my $us = App::EzPz::UserStore->new(htpasswd_file => (tempfile)[1]); + +my $mst = $us->add({ username => 'mst', password => 'boromir' }); + +is($mst->username, 'mst', 'username ok'); +ok($mst->check_password('boromir'), 'right pw ok on user'); +ok(!$mst->check_password('gimli'), 'wrong pw not ok on user'); + +ok($us->check_password('mst', 'boromir'), 'right pw ok on user store'); +ok(!$us->check_password('mst', 'gimli'), 'wrong pw not ok on user store'); + +ok(!$us->check_password('genehack', 'boromir'), 'nonexistent user fails ok'); + +my $mst_clone = $us->add({ username => 'an_mst_clone', password => 'dnatank' }); + +is( + join(',', sort map $_->username, $us->all), + 'an_mst_clone,mst', + 'user list ok with 2 users' +); + +$us->remove($mst_clone); + +is( + join(',', sort map $_->username, $us->all), + 'mst', + 'user list ok after delete' +); + +is( + join(',', $mst->list_names), '', + 'No lists yet' +); + +$mst->add_list_name($_) for qw(list1 list2 list3); + +is( + join(',', $mst->list_names), 'list1,list2,list3', + 'Three lists after add', +); + +$mst->remove_list_name('list2'); + +is( + join(',', $mst->list_names), 'list1,list3', + 'Two lists after move', +); + +$mst->add_list_name('list2'); + +is( + join(',', $mst->list_names), 'list1,list3,list2', + 'Re-add appends', +); + +done_testing;