start of integration testing
[scpubgit/App-EzPz.git] / t / lists.t
CommitLineData
fb960e0e 1use if (!-d 'test-setup'), 'Test::More', skip_all => 'List testing skipped';
2use Test::More;
3use IO::All;
4use App::EzPz::TestSetup;
5use App::EzPz::UserStore;
6use App::EzPz::Web;
7use strictures 1;
8
9unless (-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
17my $lists_base = io->dir('test-setup/lists');
18
19$lists_base->rmtree;
20$lists_base->mkpath;
21
22create_list('test-setup/ezmlm/bin', 'test-setup/lists', $_)
23 for qw(list1 list2 list3);
24
25pass('Setup completed successfully');
26
27my $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
35for 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
45my $app = App::EzPz::Web->new(users => $us);
46
47is($app->run_test_request(GET => '/')->code, 401, 'Auth fail without pw');
48
49is(
50 $app->run_test_request(GET => 'bob:boromir@/')->code, 401,
51 'Auth fail with wrong user'
52);
53
54is(
55 $app->run_test_request(GET => 'mst:spoon@/')->code, 401,
56 'Auth fail with wrong pw'
57);
58
59my $res = $app->run_test_request(GET => 'mst:boromir@/');
60
61is($res->code, 200, 'Auth ok with user+pass');
62
63like($res->content, qr/Welcome user .*mst/, 'Welcome mst');
64
65like($res->content, qr{/list/$_/}, "List $_ on /")
66 for qw(list1 list2 list3);
67
68done_testing;