user store tests
[scpubgit/App-EzPz.git] / t / users.t
1 use strictures 1;
2 use Test::More;
3 use App::EzPz::UserStore;
4 use File::Temp qw(tempfile);
5
6 my $us = App::EzPz::UserStore->new(htpasswd_file => (tempfile)[1]);
7
8 my $mst = $us->add({ username => 'mst', password => 'boromir' });
9
10 is($mst->username, 'mst', 'username ok');
11 ok($mst->check_password('boromir'), 'right pw ok on user');
12 ok(!$mst->check_password('gimli'), 'wrong pw not ok on user');
13
14 ok($us->check_password('mst', 'boromir'), 'right pw ok on user store');
15 ok(!$us->check_password('mst', 'gimli'), 'wrong pw not ok on user store');
16
17 ok(!$us->check_password('genehack', 'boromir'), 'nonexistent user fails ok');
18
19 my $mst_clone = $us->add({ username => 'an_mst_clone', password => 'dnatank' });
20
21 is(
22   join(',', sort map $_->username, $us->all),
23   'an_mst_clone,mst',
24   'user list ok with 2 users'
25 );
26
27 $us->remove($mst_clone);
28
29 is(
30   join(',', sort map $_->username, $us->all),
31   'mst',
32   'user list ok after delete'
33 );
34
35 is(
36   join(',', $mst->list_names), '',
37   'No lists yet'
38 );
39
40 $mst->add_list_name($_) for qw(list1 list2 list3);
41
42 is(
43   join(',', $mst->list_names), 'list1,list2,list3',
44   'Three lists after add',
45 );
46
47 $mst->remove_list_name('list2');
48
49 is(
50   join(',', $mst->list_names), 'list1,list3',
51   'Two lists after move',
52 );
53
54 $mst->add_list_name('list2');
55
56 is(
57   join(',', $mst->list_names), 'list1,list3,list2',
58   'Re-add appends',
59 );
60
61 done_testing;