a91e5b24517010a90dc53c34d014176a8c94da02
[scpubgit/App-EzPz.git] / t / lists.t
1 use if (!-d 'test-setup'), 'Test::More', skip_all => 'List testing skipped';
2 use Test::More;
3 use IO::All;
4 use App::EzPz::TestSetup;
5 use App::EzPz::UserStore;
6 use App::EzPz::Web;
7 use strictures 1;
8
9 unless (-d 'test-setup/ezmlm') {
10   create_install(
11     'src/ezmlm-idx-7.1.1.tar.gz',
12     'test-setup/build',
13     'test-setup/ezmlm'
14   );
15 }
16
17 my $lists_base = io->dir('test-setup/lists');
18
19 $lists_base->rmtree;
20 $lists_base->mkpath;
21
22 create_list('test-setup/ezmlm/bin', 'test-setup/lists', $_)
23   for qw(list1 list2 list3);
24
25 pass('Setup completed successfully');
26
27 my $us = App::EzPz::UserStore->new(
28   htpasswd_file => 'test-setup/lists/htpasswd',
29   ezmlm_config => {
30     bindir => 'test-setup/ezmlm/bin',
31     list_base_dir => 'test-setup/lists'
32   }
33 );
34
35 for my $user ($us->add({ username => 'mst', password => 'boromir' })) {
36   $user->add_list_name($_) for qw(list1 list2 list3);
37   for my $list ($user->get_list('list1')) {
38     $list->add_member('joe@example.com');
39     $list->add_member('bob@example.com');
40     $list->deny->add_member('evil@monkey.com');
41     $list->deny->add_member('evil@gibbon.com');
42   }
43 }
44
45 my $app = App::EzPz::Web->new(users => $us);
46
47 is($app->run_test_request(GET => '/')->code, 401, 'Auth fail without pw');
48
49 is(
50   $app->run_test_request(GET => 'bob:boromir@/')->code, 401,
51   'Auth fail with wrong user'
52 );
53
54 is(
55   $app->run_test_request(GET => 'mst:spoon@/')->code, 401,
56   'Auth fail with wrong pw'
57 );
58
59 my $res = $app->run_test_request(GET => 'mst:boromir@/');
60
61 is($res->code, 200, 'Auth ok with user+pass');
62
63 like($res->content, qr/Welcome user .*mst/, 'Welcome mst');
64
65 like($res->content, qr{/list/$_/}, "List $_ on /")
66   for qw(list1 list2 list3);
67
68 done_testing;