2012-06-22 11:38:01 +02:00
|
|
|
#!perl -w
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2014-09-17 08:16:53 +02:00
|
|
|
use Mail::Header;
|
|
|
|
|
2012-06-22 11:38:01 +02:00
|
|
|
use Qpsmtpd::Constants;
|
2014-09-16 20:48:19 +02:00
|
|
|
use Qpsmtpd::Transaction;
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
sub register_tests {
|
|
|
|
my $self = shift;
|
|
|
|
|
2014-09-17 08:16:53 +02:00
|
|
|
eval 'use ClamAV::Client'; ## no critic (Stringy)
|
|
|
|
if (!$@) {
|
|
|
|
warn "Could not load ClamAV::Client";
|
|
|
|
$self->register_test('test_register');
|
|
|
|
$self->register_test('test_get_clamd');
|
2014-11-11 23:59:40 +01:00
|
|
|
}
|
2014-09-17 08:16:53 +02:00
|
|
|
|
|
|
|
$self->register_test('test_err_and_return');
|
|
|
|
$self->register_test('test_get_filename');
|
|
|
|
$self->register_test('test_set_permission');
|
|
|
|
$self->register_test('test_is_too_big');
|
|
|
|
$self->register_test('test_is_multipart');
|
|
|
|
$self->register_test('test_should_scan');
|
2012-06-22 11:38:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub test_register {
|
|
|
|
my $self = shift;
|
|
|
|
|
2014-09-16 21:04:37 +02:00
|
|
|
ok( $self->{_args}{deny_viruses}, "deny_viruses 1");
|
|
|
|
is( $self->{_args}{max_size}, 1024, "max_size 1");
|
|
|
|
ok( $self->{_args}{scan_all}, "scan_all 1");
|
|
|
|
|
|
|
|
my $qp = $self->qp;
|
|
|
|
|
|
|
|
# Re-initialize the plugin with some different options
|
|
|
|
$self->register($qp,qw( scan_all 0 max_size 200 deny_viruses no));
|
|
|
|
ok( ! $self->{_args}{deny_viruses}, "deny_viruses 2");
|
|
|
|
is( $self->{_args}{max_size}, 200, "max_size 2");
|
|
|
|
ok( !$self->{_args}{scan_all}, "scan_all 2");
|
2014-11-11 23:59:40 +01:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2014-09-16 20:57:15 +02:00
|
|
|
sub test_is_multipart {
|
2012-06-22 11:38:01 +02:00
|
|
|
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:57:15 +02:00
|
|
|
ok( ! $self->is_multipart($tran), "is_multipart 1" );
|
2014-09-16 20:48:19 +02:00
|
|
|
$tran->header( Mail::Header->new( [
|
|
|
|
'Content-Type: multipart/alternative; boundary="Jx3Wbb8BMHsO=_?:"'
|
|
|
|
] ) );
|
2014-09-16 20:57:15 +02:00
|
|
|
ok( $self->is_multipart($tran), "is_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" );
|
|
|
|
}
|