Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 810 lines (662 sloc) 28.999 kb
#!/usr/bin/perl -w -I../commonlib/perllib
#
# test-run:
# Test harness for TheyWorkForYou
#
# Requires:
# * ../conf/general file set up for and matching the below requirements
# * a database with name ending "_testharness"; this script will drop and remake the
# database, so make sure it is never used for anything important
# * email addresses (email_n below) configured to pipe to ./test-mailin with fast
# local delivery.
# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved.
# Email: louise@mysociety.org; WWW: http://www.mysociety.org/
my $rcsid = ''; $rcsid .= '$Id: test-run,v 1.16 2010-01-13 10:51:03 louise Exp $';
use strict;
require 5.8.0;
use Getopt::Long;
use FindBin;
use lib "$FindBin::Bin/commonlib/perllib";
use lib "$FindBin::Bin/../commonlib/perllib";
use Carp qw(verbose);
BEGIN {
use mySociety::Config;
mySociety::Config::set_file('../conf/general');
}
use mySociety::WebTestHarness;
use mySociety::HandleMail;
sub help {
print <<END
Usage: test-run [OPTION]
Options are
--verbose=n Choose 0 (no progress), 1 (basic actions), 2 (full debug)
END
}
# Parse command line
our $verbose = 0; # currently 3 levels: 0, 1 and 2
our $help;
if (!GetOptions(
'verbose=i' => \$verbose,
'help' => \$help,
)) {
help();
exit(1);
}
if ($help) {
help();
exit(0);
}
#----------------------------------
# Configure test harness class
print "Set up web test harness...\n" if $verbose > 0;
our $wth = new mySociety::WebTestHarness();
our $base_url = 'http://' . mySociety::Config::get('DOMAIN');
our $email_domain = mySociety::Config::get('EMAILDOMAIN');
our $alert_command = 'php5 ./alertmailer.php --nomail 2>&1';
our $alerts_ok = 'Everything went swimmingly';
$wth->database_connect('');
$wth->database_drop_reload('../db/schema.sql');
$wth->email_setup({ eveld_bin => undef,
log_mailbox => "log_mailbox" });
#----------------------------------
sub email_n { my $n = shift; return "twfy-testharness+$n\@$email_domain"; }
#----------------------------------
# Send one mail to a mail handling script
sub call_handlemail($) {
my $content = shift;
call_handler($content, 'handlemail');
}
#----------------------------------
sub call_handler($$){
my ($content, $handler) = @_;
my ($rd, $wr);
$rd = new IO::Handle();
$wr = new IO::Handle();
my $p = new IO::Pipe($rd, $wr);
my ($p2, $pid) = mySociety::TempFiles::pipe_via("./$handler", $wr);
$p2->print($content);
$p2->close();
waitpid($pid, 0);
}
#----------------------------------
sub check_mail_log($$){
my ($mail_log, $expected_contents) = @_;
open FILE, "<", mySociety::Config::get('MAIL_LOG_PREFIX') . $mail_log;
my @lines = ();
my $line;
while ($line = <FILE>) {
chomp $line;
push @lines, $line;
}
my $found_contents = join("\n", @lines);
$expected_contents = join("\n", split("\n", $expected_contents));
die 'Expected mail not found in ' . $mail_log if ($expected_contents ne $found_contents);
}
#----------------------------------
sub clear_mail_log($){
my ($log) = @_;
system("> " . mySociety::Config::get('MAIL_LOG_PREFIX') . $log);
}
#----------------------------------
sub expect_mail_outcome($$){
my ($mail_log, $mail) = @_;
clear_mail_log($mail_log);
call_handlemail($mail);
check_mail_log($mail_log, $mail);
}
#----------------------------------
sub signup_for_alert($$){
my ($email, $test_alert) = @_;
$wth->browser_get($base_url . "/alert/");
$wth->browser_check_contents("Request a TheyWorkForYou.com Email Alert");
$wth->browser_submit_form(form_number => 2,
fields => { keyword => $test_alert,
email => $email},);
$wth->browser_check_contents("We're nearly done...");
# Shouldn't consider sending an email alert yet
my $alerts_output = `$alert_command`;
die 'Active email alert for unconfirmed user' if ($alerts_output =~ /$test_alert/);
die 'There was a problem sending alerts' unless ($alerts_output =~ /$alerts_ok/);
my $confirmation_email = $wth->email_get_containing('%To: ' . $email . '%');
die "TWFY email alert confirmation link not found\n" if ($confirmation_email !~ m#^\s+(http://.*$)#m);
my $confirmation_url = $1;
print "Confirmation URL: " . $confirmation_url . "\n" if $verbose > 1;
$wth->browser_get($confirmation_url);
$wth->browser_check_contents("Your alert has been confirmed.");
# Now should consider the alert
$alerts_output = `$alert_command`;
die 'No active email alert for confirmed user' unless ($alerts_output =~ /$test_alert/);
die 'There was a problem sending alerts' unless ($alerts_output =~ /$alerts_ok/);
return $confirmation_url;
}
#--------------------------------
sub transient_non_dsn_bounce_mail($){
my ($email) = @_;
my $transient_non_dsn_bounce_mail = 'Return-path: <>
Envelope-to: twfy-live@sponge.ukcod.org.uk
Delivery-date: Fri, 03 Apr 2009 00:48:02 +0100
Date: Fri, 3 Apr 2009 10:47:58 +1100
From: Mail Delivery Subsystem <MAILER-DAEMON@tpgi.com.au>
Message-Id: <200904022347.n32NC8SF011703@oberon.tpg.com.au>
To: <twfy-bounce@' . $email_domain . '>
MIME-Version: 1.0
Content-Type: multipart/report; report-type=delivery-status;
boundary="n32NC8SF011703.1238716078/oberon.tpg.com.au"
Subject: Returned mail: see transcript for details
Auto-Submitted: auto-generated (failure)
Status: O
Content-Length: 2070
Lines: 56
This is a MIME-encapsulated message
--n32NC8SF011703.1238716078/oberon.tpg.com.au
The original message was received at Fri, 20 Mar 2009 06:16:45 +1100
from sponge.ukcod.org.uk [82.111.230.211]
This message was generated by the TPG Internet Email System.
----- The following addresses had permanent fatal errors -----
<' . $email . '>
----- Transcript of session follows -----
<' . $email . '>... Deferred: Connection timed out with mail.anon.com.au.
Message could not be delivered for 2 weeks
Message will be deleted from queue
--n32NC8SF011703.1238716078/oberon.tpg.com.au
Content-Type: message/delivery-status
Reporting-MTA: dns; oberon.tpg.com.au
Arrival-Date: Fri, 20 Mar 2009 06:16:45 +1100
Final-Recipient: RFC822; ' . $email . '
Action: failed
Status: 4.4.7
Remote-MTA: DNS; mail.anon.com.au
Last-Attempt-Date: Fri, 3 Apr 2009 10:47:58 +1100
--n32NC8SF011703.1238716078/oberon.tpg.com.au
Content-Type: text/rfc822-headers
Return-Path: <twfy-bounce@' . $email_domain . '>
X-TPG-Antivirus: Passed
X-TPG-DNSBL: Passed
To: ' . $email . '
Subject: Your TheyWorkForYou email alert
From: TheyWorkForYou <twfy-DO-NOT-REPLY@theyworkforyou.com>
Content-Type: text/plain; charset=iso-8859-1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Precedence: bulk
X-Mailer: PHP/5.2.0-8+etch13
Message-Id: <E1LkKFo-0002Uv-JN@sponge.ukcod.org.uk>
Date: Thu, 19 Mar 2009 15:33:56 +0000
--n32NC8SF011703.1238716078/oberon.tpg.com.au--
';
return $transient_non_dsn_bounce_mail;
}
#--------------------------------
sub permanent_non_dsn_bounce_mail($){
my ($email) = @_;
my $permanent_non_dsn_bounce_mail = 'Return-path: <>
Envelope-to: twfy-live@sponge.ukcod.org.uk
Delivery-date: Fri, 03 Apr 2009 09:52:08 +0100
X-Failed-Recipients: ' . $email . '
Auto-Submitted: auto-replied
From: Mail Delivery System <Mailer-Daemon@sponge.ukcod.org.uk>
To: twfy-bounce@' . $email_domain . '
Subject: Mail delivery failed: returning message to sender
Message-Id: <E1Lpf8C-0006hf-8O@sponge.ukcod.org.uk>
Date: Fri, 03 Apr 2009 09:52:08 +0100
Status: O
Content-Length: 2685
Lines: 70
This message was created automatically by mail delivery software.
A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:
' . $email . '
SMTP error from remote mail server after RCPT TO:<' . $email . '>:
host smtp.fsmail.net [193.252.22.153]: 550 5.7.1 <' . $email . '>:
Recipient address rejected: User unknown
------ This is a copy of the message, including all the headers. ------
Return-path: <twfy-bounce@' . $email_domain . '>
To: ' . $email . '
Subject: Your TheyWorkForYou email alert
From: TheyWorkForYou <twfy-DO-NOT-REPLY@theyworkforyou.com>
Content-Type: text/plain; charset=iso-8859-1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Precedence: bulk
X-Mailer: PHP/5.2.0-8+etch13
Message-Id: <E1Lpf8C-0006hZ-3t@sponge.ukcod.org.uk>
Date: Fri, 03 Apr 2009 09:52:08 +0100
Message content';
return $permanent_non_dsn_bounce_mail;
}
#--------------------------------
sub unparsable_bounce_mail($){
my ($email) = @_;
my $unparsable_bounce_mail = 'Return-path: <>
Envelope-to: twfy-live@sponge.ukcod.org.uk
Delivery-date: Fri, 03 Apr 2009 10:36:16 +0100
Fri, 03 Apr 2009 11:36:05 +0200
To: <twfy-bounce@' . $email_domain . '>
From: Anon <' . $email . '>
Subject: Thank you for your e mail
Date: Fri, 03 Apr 2009 11:36:05 +0200
Message-Id: <0MKstg-1Lpfoj257V-0009oQ@mx.kundenserver.de>
Precedence: bulk
X-Original-Id: 0MKstg-1Lpfoj0YRe-0009oQ
X-Provags-Id: V01U2FsdGVkX1+7b0AKAEtIQ16b+SG3kRSauGSTIeCmc32UFrg
Er16IFJ2dYKITqvBopHFTS7oXXyCebpenIF2Ic9nvJ9T+FsQkk
LPVD3pQCfY=
Status: O
Content-Length: 78
Lines: 3
Thank you for your email. We will get back to you soon
';
return $unparsable_bounce_mail;
}
#----------------------------------
sub non_bounce_reply_mail($){
my ($email) = @_;
my $non_bounce_reply_mail ='Return-path: <' . $email . '>
Envelope-to: twfy-testharness@balti.ukcod.org.uk
Delivery-date: Thu, 02 Apr 2009 16:22:51 +0100
Date: Thu, 02 Apr 2009 16:22:39 +0100 (BST)
From: ' . $email . '
Subject: Wow!
In-reply-to: <E1LpOkV-0005gP-A4@sponge.ukcod.org.uk>
To: twfy-bounce@' . $email_domain . '
Message-id: <0KHH0020JC1RBO20@anon.ac.uk>
MIME-version: 1.0
Content-type: TEXT/PLAIN; CHARSET=UTF-8
Content-transfer-encoding: 7BIT
References: <E1LpOkV-0005gP-A4@sponge.ukcod.org.uk>
X-UKC-SpamScore: /
X-UKC-SpamCheck: NO,
* 0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay lines
Status: O
Content-Length: 124
Lines: 5
Thanks for the alert!
Me
';
return $non_bounce_reply_mail;
}
#----------------------------------
sub transient_dsn_bounce_mail($){
my ($email) = @_;
my $transient_dsn_bounce = 'Return-path: <>
Envelope-to: twfy-live@sponge.ukcod.org.uk
Delivery-date: Thu, 02 Apr 2009 15:06:03 +0100
Date: Thu, 2 Apr 2009 10:05:49 -0400
From: Mail Delivery Subsystem <MAILER-DAEMON@aol.com>
Message-Id: <200904021405.n32E5e8a001645@rly-da04.mx.aol.com>
To: <twfy-bounce@' . $email_domain . '>
MIME-Version: 1.0
Content-Type: multipart/report; report-type=delivery-status;
boundary="n32E5e8a001645.1238681149/rly-da04.mx.aol.com"
Subject: Returned mail: see transcript for details
Auto-Submitted: auto-generated (failure)
X-AOL-INRLY: sponge.ukcod.org.uk [82.111.230.211] rly-da04
X-AOL-IP: 205.188.159.50
Status: O
Content-Length: 2562
Lines: 75
This is a MIME-encapsulated message
--n32E5e8a001645.1238681149/rly-da04.mx.aol.com
The original message was received at Thu, 2 Apr 2009 10:05:38 -0400
from sponge.ukcod.org.uk [82.111.230.211]
*** ATTENTION ***
Your e-mail is being returned to you because there was a problem with its
delivery. The address which was undeliverable is listed in the section
labeled: "----- The following addresses had permanent fatal errors -----".
The reason your mail is being returned to you is listed in the section
labeled: "----- Transcript of Session Follows -----".
The line beginning with "<<<" describes the specific reason your e-mail could
not be delivered. The next line contains a second error message which is a
general translation for other e-mail servers.
Please direct further questions regarding this message to your e-mail
administrator.
--AOL Postmaster
----- The following addresses had permanent fatal errors -----
<'. $email . '>
(reason: 552 anon MAILBOX FULL)
----- Transcript of session follows -----
... while talking to air-da04.mail.aol.com.:
>>> RCPT To:<' . $email . '>
<<< 552 amckinney2365 MAILBOX FULL
554 5.0.0 Service unavailable
--n32E5e8a001645.1238681149/rly-da04.mx.aol.com
Content-Type: message/delivery-status
Reporting-MTA: dns; rly-da04.mx.aol.com
Arrival-Date: Thu, 2 Apr 2009 10:05:38 -0400
Final-Recipient: RFC822; ' . $email . '
Action: failed
Status: 5.2.2
Remote-MTA: DNS; air-da04.mail.aol.com
Diagnostic-Code: SMTP; 552 anon MAILBOX FULL
Last-Attempt-Date: Thu, 2 Apr 2009 10:05:49 -0400
--n32E5e8a001645.1238681149/rly-da04.mx.aol.com
Content-Type: text/rfc822-headers
To: anon@aol.com
Subject: Your TheyWorkForYou email alert
From: TheyWorkForYou <twfy-DO-NOT-REPLY@theyworkforyou.com>
Content-Type: text/plain; charset=iso-8859-1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Precedence: bulk
X-Mailer: PHP/5.2.0-8+etch13
Message-Id: <E1LpNY2-0008RP-99@sponge.ukcod.org.uk>
Date: Thu, 02 Apr 2009 15:05:38 +0100
X-AOL-IP: 82.111.230.211
X-AOL-SCOLL-SCORE:0:2:368789632:93952408
X-AOL-SCOLL-URL_COUNT:0
--n32E5e8a001645.1238681149/rly-da04.mx.aol.com--';
return $transient_dsn_bounce;
}
#----------------------------------
sub permanent_dsn_bounce_mail($$){
my ($email, $recipient) = @_;
my $permanent_dsn_bounce = 'Return-path: <>
Envelope-to: twfy-live@sponge.ukcod.org.uk
Delivery-date: Thu, 02 Apr 2009 15:06:05 +0100
X-IPRELAY: dti.local
From: postmaster@berr.gsi.gov.uk
To: ' . $recipient .'
Date: Thu, 2 Apr 2009 15:05:51 +0100
MIME-Version: 1.0
Content-Type: multipart/report; report-type=delivery-status;
boundary="9B095B5ADSN=_01C979B73CB9E88400052D1BSDCBHD01.dti.loc"
X-DSNContext: 335a7efd - 4523 - 00000001 - 80040546
Message-ID: <CH4RC6tnx00025e87@SDCBHD01.dti.local>
Subject: Delivery Status Notification (Failure)
Status: O
Content-Length: 6225
Lines: 137
This is a MIME-formatted message.
Portions of this message may be unreadable without a MIME-capable mail program.
--9B095B5ADSN=_01C979B73CB9E88400052D1BSDCBHD01.dti.loc
Content-Type: text/plain; charset=unicode-1-1-utf-7
This is an automatically generated Delivery Status Notification.
Delivery to the following recipients failed.
' . $email . '
The original of this email was scanned for viruses by the Government Secure Intranet virus scanning service supplied by Cable&Wireless in partnership with MessageLabs. (CCTM Certificate Number 2007/11/0032.) On leaving the GSi this email was certified virus free.
Communications via the GSi may be automatically logged, monitored and/or recorded for legal purposes.
--9B095B5ADSN=_01C979B73CB9E88400052D1BSDCBHD01.dti.loc
Content-Type: message/delivery-status
Reporting-MTA: dns;SDCBHD01.dti.local
Received-From-MTA: dns;sdcirn01.dti.local
Arrival-Date: Thu, 2 Apr 2009 15:05:51 +0100
Final-Recipient: rfc822;' . $email . '
Action: failed
Status: 5.1.1
--9B095B5ADSN=_01C979B73CB9E88400052D1BSDCBHD01.dti.loc
Content-Type: message/rfc822
To: ' . $email . '
Subject: Your TheyWorkForYou email alert
From: TheyWorkForYou <twfy-DO-NOT-REPLY@theyworkforyou.com>
Content-Type: text/plain; charset=iso-8859-1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Precedence: bulk
X-Mailer: PHP/5.2.0-8+etch13
Message-Id: <E1LpNXt-0008Pv-QH@sponge.ukcod.org.uk>
Date: Thu, 02 Apr 2009 15:05:29 +0100
Return-Path: twfy-bounce@theyworkforyou.com
X-OriginalArrivalTime: 02 Apr 2009 14:05:51.0502 (UTC) FILETIME=[217F22E0:01C9B39C]
Message content
--9B095B5ADSN=_01C979B73CB9E88400052D1BSDCBHD01.dti.loc--';
return $permanent_dsn_bounce;
}
#----------------------------------
sub arf_mail($$){
my ($email, $token) = @_;
my $arf_mail = q!Return-Path: <scomp@aol.net>
To: mysociety@ukcod.org.uk
From: scomp@aol.net
Date: Sun, 17 May 2009 15:12:21 EDT
Subject: Email Feedback Report for IP 82.111.230.211
MIME-Version: 1.0
Content-Type: multipart/report; report-type=feedback-report; boundary="boundary-1138-29572-2659438-16788"
X-AOL-INRLY: sponge.ukcod.org.uk [82.111.230.211] scmp-m44
X-Loop: scomp
X-AOL-IP: 172.21.139.222
Message-ID: <200905171512.7d674a106199ee@omr-d22.mx.aol.com>
--boundary-1138-29572-2659438-16788
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit
This is an email abuse report for an email message with the message-id of E1M2NR6-0002oC-IW@sponge.ukcod.org.uk received from IP address 82.111.230.211 on Fri, 08 May 2009 06:36:13 -0400
For information, please review the top portion of the following page:
http://postmaster.aol.com/tools/fbl.html
For information about AOL E-mail guidelines, please see
http://postmaster.aol.com/guidelines/
If you would like to cancel or change the configuration for your FBL please use the tool located at:
http://postmaster.aol.com/waters/fbl_change_form.html
--boundary-1138-29572-2659438-16788
Content-Disposition: inline
Content-Type: message/feedback-report
Feedback-Type: abuse
User-Agent: AOL SComp
Version: 0.1
Received-Date: Fri, 08 May 2009 06:36:13 -0400
Source-IP: 82.111.230.211
Reported-Domain: sponge.ukcod.org.uk
Redacted-Address: redacted
Redacted-Address: redacted@
--boundary-1138-29572-2659438-16788
Content-Type: message/rfc822
Content-Disposition: inline
Return-Path: <twfy-bounce@theyworkforyou.com>
Received: from rly-mf05.mx.aol.com (rly-mf05.mail.aol.com [172.20.29.175]) by air-mf04.mail.aol.com (v123.4) with ESMTP id MAILINMF043-9614a040b1c5f; Fri, 08 May 2009 06:36:23 -0400
Received: from sponge.ukcod.org.uk (sponge.ukcod.org.uk [82.111.230.211]) by rly-mf05.mx.aol.com (v123.4) with ESMTP id MAILRELAYINMF057-9614a040b1c5f; Fri, 08 May 2009 06:36:13 -0400
Received: from twfy-live by sponge.ukcod.org.uk with local (Exim 4.63)
(envelope-from <twfy-bounce@theyworkforyou.com>)
id 1M2NR6-0002oC-IW
for redacted; Fri, 08 May 2009 11:36:12 +0100
To: redacted@aol.com
Subject: Your TheyWorkForYou email alert
From: TheyWorkForYou <twfy-DO-NOT-REPLY@theyworkforyou.com>
Content-Type: text/plain; charset=iso-8859-1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Precedence: bulk
X-Mailer: PHP/5.2.0-8+etch15
Message-Id: <E1M2NR6-0002oC-IW@sponge.ukcod.org.uk>
Date: Fri, 08 May 2009 11:36:12 +0100
X-AOL-IP: 82.111.230.211
speaker:Julia Goldsworthy : 2 Written Answers
=============================================
Written Answers - Work and Pensions: Council Tax Benefit (7 May 2009)
http://www.theyworkforyou.com/wrans/?id=2009-05-07a.273284.h&s=speaker%3A11581#g273284.q0
Julia Goldsworthy: To ask the Secretary of State for Work and Pensions
if he will estimate the expenditure required from the public purse to
raise personal allowances for council tax benefit to £193 per week for
all households, excluding households with a couple where one or both are
aged 65 years or over, in circumstances where the current level of
capital allowance is (a) maintained and (b) abolished;...
Written Answers - Work and Pensions: Council Tax Benefit (7 May 2009)
http://www.theyworkforyou.com/wrans/?id=2009-05-07a.268179.h&s=speaker%3A11581#g268179.q0
Julia Goldsworthy: To ask the Secretary of State for Work and Pensions
what the effect on the public purse would be of increasing personal
allowances for the purposes of calculating council tax benefits to £193
per week for (a) a single person aged 60 to 64 years, (b) a couple,
one or both of whom is aged 60 to 65 years, (c) a single person aged
under 25 years, (d) a single person aged 25 to 60 years...
To cancel your alert for speaker:Julia Goldsworthy, please use:
! . $base_url . q!/D/!. $token . q!
====================
If you register on the site, you will be able to manage your
alerts there as well as write annotations. :)
If clicking any of these links doesn't work, you may have
to copy and then paste them into the 'Location' or
'Address' box of your web browser, and then press 'enter'
or 'return' on your keyboard.
Best wishes,
TheyWorkForYou.com
------------------------------------------------------------
TheyWorkForYou email alerts need love and support to look
after. Please set up a monthly donation, especially if you
rely on them for work:
http://www.mysociety.org/donate/
------------------------------------------------------------
--boundary-1138-29572-2659438-16788--
!;
return $arf_mail;
}
#----------------------------------
sub do_alert_signup_test(){
signup_for_alert(email_n(0), 'Test basic signup');
}
#----------------------------------
sub do_frontpage_test(){
$wth->browser_get($base_url);
$wth->browser_check_contents("Recently in the UK Parliament");
}
#----------------------------------
sub do_permanent_dsn_bounce_without_verp_test(){
my $bounced_alert = 'Getting a DSN bounce';
my $email = email_n(2);
signup_for_alert($email, $bounced_alert);
my $permanent_dsn_bounce = permanent_dsn_bounce_mail($email, 'twfy-bounce@' . $email_domain);
expect_mail_outcome('deleted', $permanent_dsn_bounce);
# Alert should no longer be in the set considered for emails
my $alerts_output = `$alert_command`;
die 'Active email alert for deleted user' if ($alerts_output =~ /$bounced_alert/);
die 'There was a problem sending alerts' unless ($alerts_output =~ /$alerts_ok/);
}
#----------------------------------
sub do_transient_dsn_bounce_without_verp_test(){
my $bounced_alert = 'Getting a transient DSN bounce';
my $email = email_n(3);
signup_for_alert($email, $bounced_alert);
my $transient_dsn_bounce = transient_dsn_bounce_mail($email);
expect_mail_outcome('ignored', $transient_dsn_bounce);
# Alert should still be in the set considered for emails
my $alerts_output = `$alert_command`;
die 'No active email alert for confirmed user after transient bounce' unless ($alerts_output =~ /$bounced_alert/);
die 'There was a problem sending alerts' unless ($alerts_output =~ /$alerts_ok/);
}
#----------------------------------
sub do_permanent_dsn_bounce_without_verp_no_email_test(){
my $bounced_alert = 'Permanent DSN bounce no email';
my $email = email_n(4);
signup_for_alert($email, $bounced_alert);
my $bounced_email = permanent_dsn_bounce_mail('anon', 'twfy-bounce@' . $email_domain);
expect_mail_outcome('unparsed', $bounced_email);
# Alert should still be in the set considered for emails
my $alerts_output = `$alert_command`;
die 'No active email alert for confirmed user after permanent bounce where email cannot be parsed' unless ($alerts_output =~ /$bounced_alert/);
die 'There was a problem sending alerts' unless ($alerts_output =~ /$alerts_ok/);
}
#----------------------------------
sub do_unparsable_bounce_without_verp_test(){
my $bounced_alert = 'Unparsable non-DSN bounce';
my $email = email_n(5);
signup_for_alert($email, $bounced_alert);
my $bounced_email = unparsable_bounce_mail($email);
expect_mail_outcome('unparsed', $bounced_email);
# Alert should still be in the set considered for emails
my $alerts_output = `$alert_command`;
die 'No active email alert for confirmed user after unparsed bounce' unless ($alerts_output =~ /$bounced_alert/);
die 'There was a problem sending alerts' unless ($alerts_output =~ /$alerts_ok/);
}
#----------------------------------
sub do_permanent_bounce_without_verp_test(){
my $bounced_alert = 'Permanent non-DSN bounce';
my $email = email_n(6);
signup_for_alert($email, $bounced_alert);
my $bounced_email = permanent_non_dsn_bounce_mail($email);
expect_mail_outcome('deleted', $bounced_email);
# Alert should no longer be in the set considered for emails
my $alerts_output = `$alert_command`;
die 'Active email alert for deleted user' if ($alerts_output =~ /$bounced_alert/);
die 'There was a problem sending alerts' unless ($alerts_output =~ /$alerts_ok/);
}
#----------------------------------
sub do_transient_bounce_without_verp_test(){
my $bounced_alert = 'Getting a transient non-DSN bounce';
my $email = email_n(7);
signup_for_alert($email, $bounced_alert);
my $transient_non_dsn_bounce = transient_non_dsn_bounce_mail($email);
expect_mail_outcome('ignored', $transient_non_dsn_bounce);
# Alert should still be in the set considered for emails
my $alerts_output = `$alert_command`;
die 'No active email alert for confirmed user after transient bounce' unless ($alerts_output =~ /$bounced_alert/);
die 'There was a problem sending alerts' unless ($alerts_output =~ /$alerts_ok/);
}
#----------------------------------
sub do_verp_bounce_test(){
my $bounced_alert = 'Permanent DSN bounce no email with VERP';
my $email = email_n(8);
signup_for_alert($email, $bounced_alert);
my $verp_envelope_sender = mySociety::HandleMail::verp_envelope_sender($email, 'twfy', $email_domain);
my $bounced_email = permanent_dsn_bounce_mail('anon', $verp_envelope_sender);
expect_mail_outcome('deleted', $bounced_email);
# Alert should no longer be in the set considered for emails
my $alerts_output = `$alert_command`;
die 'Active email alert for deleted user' if ($alerts_output =~ /$bounced_alert/);
die 'There was a problem sending alerts' unless ($alerts_output =~ /$alerts_ok/);
}
#----------------------------------
sub do_non_bounce_reply_without_verp_test(){
my $responded_alert = 'Being responsive';
my $email = email_n(1);
signup_for_alert($email, $responded_alert);
my $non_bounce_email = non_bounce_reply_mail($email);
call_handlemail($non_bounce_email);
# Should get an automated response
my $automated_email = $wth->email_get_containing('%To: ' . $email . '%');
die "Alert reply autoresponse not found\n" if ($automated_email !~ m#This is an automatic response to your email#m);
# Alert should still be in the set considered for emails
my $alerts_output = `$alert_command`;
die 'No active email alert for confirmed user after non bounce reply' unless ($alerts_output =~ /$responded_alert/);
die 'There was a problem sending alerts' unless ($alerts_output =~ /$alerts_ok/);
}
#----------------------------------
sub do_arf_test(){
my $arfed_alert = 'Getting an ARF from AOL';
my $email = email_n(9);
my $confirmation_url = signup_for_alert($email, $arfed_alert);
my $arf_mail;
if ($confirmation_url =~ /\/A\/(\S+)/){
my $token = $1;
$arf_mail = arf_mail($email, $token);
}else{
die "Couldn't get token from confirmation email for ARF test";
}
call_handler($arf_mail, 'handlearfmail');
# Alert should no longer be in the set considered for emails
my $alerts_output = `$alert_command`;
die 'Active email alert for deleted user after ARF mail' if ($alerts_output =~ /$arfed_alert/);
die 'There was a problem sending alerts' unless ($alerts_output =~ /$alerts_ok/);
}
#----------------------------------
# Test front page exists
print "Testing front page...\n" if $verbose > 0;
do_frontpage_test();
# Test signing up for an email alert
print "Testing alert signup...\n" if $verbose > 0;
do_alert_signup_test();
# Test the handling of a non-bounce reply to an alert - should get an automated response
print "Testing non-bounce reply gets automated response...\n" if $verbose > 0;
do_non_bounce_reply_without_verp_test();
# Test the deletion of a recipient whose alerts produce permanent bounces
print "Testing deletion of recipient following permanent DSN bounce...\n" if $verbose > 0;
do_permanent_dsn_bounce_without_verp_test();
# Test the handling of a transient DSN bounce
print "Testing transient DSN bounce is ignored...\n" if $verbose > 0;
do_transient_dsn_bounce_without_verp_test();
# Test the handling of a permanent DSN bounce where the recipient can't be figured out
print "Testing permanent DSN bounce where recipient can't be parsed - logged as unparsed...\n" if $verbose > 0;
do_permanent_dsn_bounce_without_verp_no_email_test();
# Test the handling of an unparsable bounce
print "Testing unparsable bounce - logged as unparsed...\n" if $verbose > 0;
do_unparsable_bounce_without_verp_test();
# Test the handling of a non-DSN bounce that we've classified as permanent
print "Testing permanent non DSN bounce - unsubscribe user...\n" if $verbose > 0;
do_permanent_bounce_without_verp_test();
# Test the handling of a non-DSN bounce that we've classified as transient
print "Testing transient non DSN bounce - ignore...\n" if $verbose > 0;
do_transient_bounce_without_verp_test();
# Test the end-to-end VERP bounce process
print "Testing that VERP bounces get parsed successfully...\n" if $verbose > 0;
do_verp_bounce_test();
# Test the handling of AOL Abuse Reporting Format mails
print "Testing that Abuse Report Mails for alerts result in alert deletion...\n" if $verbose > 0;
do_arf_test();
print "Checking no emails left at end...\n" if $verbose > 0;
$wth->email_check_none_left();
print "Everything completed...\n" if $verbose > 0;
Jump to Line
Something went wrong with that request. Please try again.