use IO::All;
use IPC::System::Simple qw(run);
use Cwd;
-use Exporter;
+use base qw(Exporter);
use strictures 1;
our @EXPORT = qw(create_install create_list);
die "Usage: ezpz-create-test-ezmlm-install ezmlm-source.tgz build-dir install-dir"
unless @_ == 3;
- my ($ezmlm_tarball_path, $build_dir_path, $install_to_path) = @ARGV;
+ my ($ezmlm_tarball_path, $build_dir_path, $install_to_path) = @_;
my $ezmlm_tarball = io->file(io->file($ezmlm_tarball_path)->rel2abs);
- my $orig_cwd = io->dir(cwd);
+ my $cwd = cwd;
- my $build_dir = io->dir($build_dir_path)->absolute;
- my $install_to = io->dir($install_to_path)->absolute;
+ my $build_dir = io->dir(io->dir($build_dir_path)->rel2abs);
+ my $install_to = io->dir(io->dir($install_to_path)->rel2abs);
unless ($build_dir->exists) {
$build_dir->mkpath;
$build_dir->chdir;
run 'tar', 'xzf', $ezmlm_tarball;
- $orig_cwd->chdir;
+ chdir($cwd);
}
my ($src_dir) = ($build_dir->all_dirs)[0];
run './ezmlm-test';
$install_to->catdir('bin')->mkpath;
run make => 'install';
+
+ chdir(cwd);
}
sub create_list {
my ($ezmlm_bin_path, $list_base_path, $list_name) = @_;
- my $ezmlm_bin = io->dir($ezmlm_bin_path)->absolute;
+ my $ezmlm_bin = io->dir(io->dir($ezmlm_bin_path)->rel2abs);
- my $list_base = io->dir($list_base_path)->absolute;
+ my $list_base = io->dir(io->dir($list_base_path)->rel2abs);
run(
$ezmlm_bin->catfile('ezmlm-make'),
$list_name,
'example.com'
);
+}
+
+1;
--- /dev/null
+use if (!-d 'test-setup'), 'Test::More', skip_all => 'List testing skipped';
+use Test::More;
+use IO::All;
+use App::EzPz::TestSetup;
+use App::EzPz::UserStore;
+use App::EzPz::Web;
+use strictures 1;
+
+unless (-d 'test-setup/ezmlm') {
+ create_install(
+ 'src/ezmlm-idx-7.1.1.tar.gz',
+ 'test-setup/build',
+ 'test-setup/ezmlm'
+ );
+}
+
+my $lists_base = io->dir('test-setup/lists');
+
+$lists_base->rmtree;
+$lists_base->mkpath;
+
+create_list('test-setup/ezmlm/bin', 'test-setup/lists', $_)
+ for qw(list1 list2 list3);
+
+pass('Setup completed successfully');
+
+my $us = App::EzPz::UserStore->new(
+ htpasswd_file => 'test-setup/lists/htpasswd',
+ ezmlm_config => {
+ bindir => 'test-setup/ezmlm/bin',
+ list_base_dir => 'test-setup/lists'
+ }
+);
+
+for my $user ($us->add({ username => 'mst', password => 'boromir' })) {
+ $user->add_list_name($_) for qw(list1 list2 list3);
+ for my $list ($user->get_list('list1')) {
+ $list->add_member('joe@example.com');
+ $list->add_member('bob@example.com');
+ $list->deny->add_member('evil@monkey.com');
+ $list->deny->add_member('evil@gibbon.com');
+ }
+}
+
+my $app = App::EzPz::Web->new(users => $us);
+
+is($app->run_test_request(GET => '/')->code, 401, 'Auth fail without pw');
+
+is(
+ $app->run_test_request(GET => 'bob:boromir@/')->code, 401,
+ 'Auth fail with wrong user'
+);
+
+is(
+ $app->run_test_request(GET => 'mst:spoon@/')->code, 401,
+ 'Auth fail with wrong pw'
+);
+
+my $res = $app->run_test_request(GET => 'mst:boromir@/');
+
+is($res->code, 200, 'Auth ok with user+pass');
+
+like($res->content, qr/Welcome user .*mst/, 'Welcome mst');
+
+like($res->content, qr{/list/$_/}, "List $_ on /")
+ for qw(list1 list2 list3);
+
+done_testing;