2012-06-22 11:38:01 +02:00
|
|
|
#!perl -w
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Qpsmtpd::Constants;
|
2014-09-16 20:48:19 +02:00
|
|
|
use Qpsmtpd::Transaction;
|
|
|
|
use Mail::Header;
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
sub register_tests {
|
|
|
|
my $self = shift;
|
|
|
|
|
2014-09-16 19:56:32 +02:00
|
|
|
SKIP: {
|
|
|
|
eval 'use ClamAV::Client'; ## no critic (Stringy)
|
|
|
|
skip "Could not load ClamAV::Client", 4
|
|
|
|
if $@;
|
2012-06-22 11:38:01 +02:00
|
|
|
$self->register_test('test_register', 3);
|
|
|
|
$self->register_test('test_get_clamd', 1);
|
2014-09-16 19:56:32 +02:00
|
|
|
}
|
2012-06-22 11:38:01 +02:00
|
|
|
$self->register_test('test_err_and_return', 2);
|
|
|
|
$self->register_test('test_get_filename', 1);
|
|
|
|
$self->register_test('test_set_permission', 1);
|
|
|
|
$self->register_test('test_is_too_big', 2);
|
|
|
|
$self->register_test('test_is_not_multipart', 2);
|
2014-09-16 20:48:19 +02:00
|
|
|
$self->register_test('test_should_scan',4);
|
2012-06-22 11:38:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub test_register {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
ok( $self->{_args}{deny_viruses} eq 'yes', "deny_viruses");
|
2014-09-16 19:56:32 +02:00
|
|
|
ok( $self->{_args}{max_size} == 1024, "max_size");
|
|
|
|
ok( $self->{_args}{scan_all} == 1, "scan_all");
|
2012-06-22 11:38:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
sub test_err_and_return {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
$self->{_args}{defer_on_error} = 1;
|
|
|
|
my ($code, $mess) = $self->err_and_return( "test oops" );
|
|
|
|
cmp_ok( DENYSOFT, '==', $code, "oops ($mess)");
|
|
|
|
|
|
|
|
$self->{_args}{defer_on_error} = 0;
|
|
|
|
($code, $mess) = $self->err_and_return( "test oops" );
|
|
|
|
cmp_ok( DECLINED, '==', $code, "oops ($mess)");
|
|
|
|
}
|
|
|
|
|
|
|
|
sub test_get_filename {
|
|
|
|
my $self = shift;
|
2014-09-16 08:41:31 +02:00
|
|
|
my $tran = $self->qp->transaction();
|
|
|
|
$tran->{_body_array} = ['line','two'];
|
|
|
|
|
2012-06-22 11:38:01 +02:00
|
|
|
my $filename = $self->get_filename();
|
|
|
|
ok( $filename, "get_filename ($filename)" );
|
|
|
|
}
|
|
|
|
|
|
|
|
sub test_set_permission {
|
|
|
|
my $self = shift;
|
|
|
|
ok( $self->set_permission(), "set_permission" );
|
|
|
|
}
|
|
|
|
|
|
|
|
sub test_get_clamd {
|
|
|
|
my $self = shift;
|
|
|
|
my $clamd = $self->get_clamd();
|
|
|
|
ok( ref $clamd, "get_clamd: " . ref $clamd );
|
|
|
|
}
|
|
|
|
|
|
|
|
sub test_is_too_big {
|
|
|
|
my $self = shift;
|
2014-09-16 20:48:19 +02:00
|
|
|
my $tran = Qpsmtpd::Transaction->new();
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
$self->{_args}{max_size} = 8;
|
2014-09-16 20:48:19 +02:00
|
|
|
$tran->{_body_size} = 7 * 1024;
|
|
|
|
ok( ! $self->is_too_big( $tran ), "is_too_big 1");
|
2012-06-22 11:38:01 +02:00
|
|
|
|
2014-09-16 20:48:19 +02:00
|
|
|
$tran->{_body_size} = 9 * 1024;
|
|
|
|
ok( $self->is_too_big( $tran ), "is_too_big 2");
|
2012-06-22 11:38:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub test_is_not_multipart {
|
|
|
|
my $self = shift;
|
2014-09-16 20:48:19 +02:00
|
|
|
my $tran = Qpsmtpd::Transaction->new();
|
2012-06-22 11:38:01 +02:00
|
|
|
|
2014-09-16 20:48:19 +02:00
|
|
|
ok( $self->is_not_multipart($tran), "not_multipart 1" );
|
|
|
|
$tran->header( Mail::Header->new( [
|
|
|
|
'Content-Type: multipart/alternative; boundary="Jx3Wbb8BMHsO=_?:"'
|
|
|
|
] ) );
|
|
|
|
ok( ! $self->is_not_multipart($tran), "not_multipart 2" );
|
2012-06-22 11:38:01 +02:00
|
|
|
}
|
|
|
|
|
2014-09-16 20:48:19 +02:00
|
|
|
sub test_should_scan {
|
|
|
|
my $self = shift;
|
|
|
|
my $trans = Qpsmtpd::Transaction->new();
|
|
|
|
$trans->{_body_size} = 1;
|
|
|
|
$self->{_args}{scan_all} = 1;
|
|
|
|
ok( $self->should_scan($trans), "Should scan small message, scan_all=1");
|
|
|
|
$self->{_args}{scan_all} = 0;
|
|
|
|
ok( ! $self->should_scan($trans), "Should not scan small message, scan_all=0");
|
|
|
|
$trans->{_body_size} = 99999999999;
|
|
|
|
ok( !$self->should_scan($trans), "Should not scan large message" );
|
|
|
|
$trans->{_body_size} = 1;
|
|
|
|
$trans->header( Mail::Header->new( [
|
|
|
|
'Content-Type: multipart/alternative; boundary="Jx3Wbb8BMHsO=_?:"'
|
|
|
|
] ) );
|
|
|
|
ok( $self->should_scan($trans), "Should not scan multi-part message" );
|
|
|
|
}
|