added some tests for data_respond

This commit is contained in:
Matt Simerson 2014-12-26 21:51:28 -08:00
parent e9497d7e51
commit d6fabb2b40

View File

@ -23,6 +23,7 @@ __helo_no_host();
__helo_repeat_host();
__helo_respond('helo_respond');
__helo_respond('ehlo_respond');
__data_respond('data_respond');
done_testing();
@ -114,3 +115,60 @@ sub __helo_respond {
#warn Data::Dumper::Dumper($smtpd->{_response});
}
sub __data_respond {
is( $smtpd->data_respond(DONE), 1, 'data_respond, DONE' );
is( $smtpd->data_respond(DENY), 1, 'data_respond, DENY' );
is( $smtpd->data_respond(DENYSOFT), 1, 'data_respond, DENYSOFT' );
is( $smtpd->data_respond(DENY_DISCONNECT), 1, 'data_respond, DENY_DISCONNECT' );
is( $smtpd->data_respond(DECLINED), 1, 'data_respond, DECLINED' );
# the tests above all return 1 early due to DATA checks. Once the
# transaction is populated, only checks that fail early will return.
($smtpd) = _new_transaction();
is( $smtpd->data_respond(DONE), 1, 'data_respond, DONE' );
($smtpd) = _new_transaction();
is( $smtpd->data_respond(DENY), 1, 'data_respond, DENY' );
($smtpd) = _new_transaction();
is( $smtpd->data_respond(DENYSOFT), 1, 'data_respond, DENYSOFT' );
($smtpd) = _new_transaction();
is( $smtpd->data_respond(DENY_DISCONNECT), 1, 'data_respond, DENY_DISCONNECT' );
# data_respond also runs the data_post hooks, so this will require a bit
# more work to get under test...
#($smtpd) = _new_transaction();
#is( $smtpd->data_respond(DECLINED, _test_message()), 1, 'data_respond, DECLINED' );
}
sub _new_transaction () {
my ($smtpd, $conn) = Test::Qpsmtpd->new_conn();
$smtpd->transaction->sender(Qpsmtpd::Address->new('sender@example.com'));
$smtpd->transaction->add_recipient(Qpsmtpd::Address->new('recip@example.com'));
return $smtpd;
};
sub _test_message {
# with \r\n (aka CRLF) endings, as a proper SMTP formatted email would
return <<"EOM"
From: Jennifer <jennifer\@example.com>\r
Subject: Persian New Year's Soup with Beans, Noodles, and Herbs Recipe at Epicurious.com\r
Date: Sun, 02 Oct 2011 14:06:06 -0700\r
Message-id: <67CC87B2-095C-45C6-BF9B-5A589AD6C264\@example.com>\r
To: Matt <matt\@example.net>\r
\r
\r
--Boundary_(ID_lBFzGVLdxsIk2GYiWhQRRQ)\r
Content-type: text/plain; CHARSET=US-ASCII\r
Content-transfer-encoding: 7BIT\r
\r
This sounds good. Can we do have it this week?\r
\r
http://www.epicurious.com/recipes/food/views/Persian-New-Years-Soup-with-Beans-Noodles-and-Herbs-em-Ash-e-reshteh-em-363446\r
\r
.\r
EOM
;
}