| 1 | #!/usr/bin/perl -w |
|---|
| 2 | # Test remote administration capability |
|---|
| 3 | |
|---|
| 4 | use strict; |
|---|
| 5 | |
|---|
| 6 | BEGIN { chdir 't' if -d 't' } |
|---|
| 7 | use lib '../lib'; |
|---|
| 8 | |
|---|
| 9 | use Test::More tests => 2; |
|---|
| 10 | use Test::File::Contents; |
|---|
| 11 | |
|---|
| 12 | use Lancelot::SMTPTest qw/run_program/; |
|---|
| 13 | |
|---|
| 14 | use File::Path; |
|---|
| 15 | use Lancelot::DB; |
|---|
| 16 | |
|---|
| 17 | my $smtpport = 4712; # for now |
|---|
| 18 | my $dir = "../smtp-test"; |
|---|
| 19 | |
|---|
| 20 | my $listname = 'pl-testlist@example.com'; |
|---|
| 21 | |
|---|
| 22 | rmtree("$ENV{HOME}/.pl/$listname", 0); |
|---|
| 23 | |
|---|
| 24 | my $db = new Lancelot::DB $listname, { create => 1 }; |
|---|
| 25 | $db->set_config('list.name', 'Pl-testlist'); |
|---|
| 26 | $db->set_config('smtp.server', 'localhost'); |
|---|
| 27 | $db->set_config('smtp.port', $smtpport); |
|---|
| 28 | $db->set_config('mail.workflow.admin', 'admin'); |
|---|
| 29 | $db->set_config('mail.delimiter', '+'); |
|---|
| 30 | $db->add_address('hugo@example.com'); |
|---|
| 31 | |
|---|
| 32 | my @cmd = ('../blib/script/pl-incoming', '--verbose=STDERR:all=debug', $listname); |
|---|
| 33 | |
|---|
| 34 | # First try sending an administrative request to a non-administrator |
|---|
| 35 | |
|---|
| 36 | my $message = <<'END'; |
|---|
| 37 | Delivered-To: pl-testlist+admin@example.com |
|---|
| 38 | Return-Path: hugo@example.com |
|---|
| 39 | From: hugo@example.com |
|---|
| 40 | To: pl-testlist+admin@example.com |
|---|
| 41 | Subject: remote admin test |
|---|
| 42 | Message-ID: <ra-1@example.com> |
|---|
| 43 | |
|---|
| 44 | list |
|---|
| 45 | END |
|---|
| 46 | |
|---|
| 47 | run_program("lrr-na", \@cmd, $message, $dir); |
|---|
| 48 | |
|---|
| 49 | file_contents_is("$dir/msg.lrr-na.0", <<'END', "list request reply (not admin)"); |
|---|
| 50 | SMTP-From: pl-testlist+owner@example.com |
|---|
| 51 | SMTP-To: hugo@example.com |
|---|
| 52 | From: Pl-testlist Management <pl-testlist+owner@example.com> |
|---|
| 53 | To: hugo@example.com |
|---|
| 54 | Subject: Unauthorised administrative request (remote admin test) |
|---|
| 55 | In-Reply-To: <ra-1@example.com> |
|---|
| 56 | |
|---|
| 57 | You tried to send an administrative request to the list but we do not |
|---|
| 58 | have you down as a list administrator. Your message has been ignored. |
|---|
| 59 | |
|---|
| 60 | Do not hesitate to contact us if you have any questions. |
|---|
| 61 | |
|---|
| 62 | The Pl-testlist Management Team |
|---|
| 63 | |
|---|
| 64 | END |
|---|
| 65 | |
|---|
| 66 | # Now try it as an administrator |
|---|
| 67 | |
|---|
| 68 | $db->set_address_options('hugo@example.com', { admin => 1 }); |
|---|
| 69 | |
|---|
| 70 | run_program("lrr", \@cmd, $message, $dir); |
|---|
| 71 | |
|---|
| 72 | file_contents_eq_or_diff("$dir/msg.lrr.0", <<'END', "list request reply", { style => 'Unified' }); |
|---|
| 73 | SMTP-From: pl-testlist+owner@example.com |
|---|
| 74 | SMTP-To: hugo@example.com |
|---|
| 75 | From: Pl-testlist Management <pl-testlist+owner@example.com> |
|---|
| 76 | To: hugo@example.com |
|---|
| 77 | Subject: Results of your administrative request (remote admin test) |
|---|
| 78 | In-Reply-To: <ra-1@example.com> |
|---|
| 79 | |
|---|
| 80 | Thank you for your administrative request. Here are the results: |
|---|
| 81 | |
|---|
| 82 | .. list |
|---|
| 83 | SA---- hugo@example.com |
|---|
| 84 | |
|---|
| 85 | (Lines beginning with ".." echo your commands. Lines beginning with |
|---|
| 86 | "I:" contain informational messages, and lines beginning with "E:" |
|---|
| 87 | contain error messages. If an error message appears, the operation |
|---|
| 88 | in question will not have been performed.) |
|---|
| 89 | |
|---|
| 90 | Do not hesitate to contact us if you have any questions. |
|---|
| 91 | |
|---|
| 92 | The Pl-testlist Management Team |
|---|
| 93 | |
|---|
| 94 | END |
|---|