sub register_tests { my ($self) = @_; $self->register_test("outgoing", 5); $self->register_test("incoming", 6); } my $validaddress; my $validaddress_domaintest; sub outgoing { my ($self) = @_; my $connection = $self->qp->connection; $connection->relay_client(1); my $transaction = $self->transaction(); my $sender = Qpsmtpd::Address->new(''); my ($code, @strings) = $self->hook_mail($transaction, $sender); is($code, DECLINED, "mail hook declines"); $self->log(LOGDEBUG, "sender = $sender"); isnt($sender, '', "sender has been modified"); my ($exp) = ($sender =~ /prvs=\d(\d\d\d)/); cmp_ok($exp, '==', ((time / 86400 + 7) % 1000), "expires in seven days"); $validaddress = $sender; $sender = Qpsmtpd::Address->new(''); ($code, @strings) = $self->hook_mail($transaction, $sender); is($code, DECLINED, "mail hook declines"); $self->log(LOGDEBUG, "sender = $sender"); is($sender->host, 'bounces.example.com', "sender domain has been modified"); $validaddress_domaintest = $sender; } sub incoming { my ($self) = @_; my $connection = $self->qp->connection; $connection->relay_client(0); my $transaction = $self->transaction(); $transaction->sender(Qpsmtpd::Address->new('<>')); my $recipient = Qpsmtpd::Address->new(''); my ($code, @strings) = $self->hook_rcpt($transaction, $recipient); is($code, DENY, "original address is denied"); my $recipient = $validaddress; my ($code, @strings) = $self->hook_rcpt($transaction, $recipient); is($code, DECLINED, "modified address is declined"); my $gen = $self->{batv_secrets}[0]{gen}; my $secret = $self->{batv_secrets}[0]{secret}; my $day = sprintf("%03d", (time / 86400 - 2) % 1000); my $hash_source = $gen . $day . ''; my $tagval = $gen . $day . substr(sha1_hex($hash_source . $secret), 0, 6); $recipient = Qpsmtpd::Address->new(""); my ($code, @strings) = $self->hook_rcpt($transaction, $recipient); is($code, DENY, "expired address is denied"); $self->log(LOGDEBUG, "result = $code @strings"); like($strings[0], qr/expired/, "expired address is expired"); my $recipient = $validaddress_domaintest; my ($code, @strings) = $self->hook_rcpt($transaction, $recipient); is($code, DECLINED, "modified domain address is declined"); is($recipient->host, 'example.net', "modified domain has been mapped back"); }