Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
_deHTMLxs.c
_deHTMLxs.o
bin/razor-admin
bin/razor-check
bin/razor-client
Expand All @@ -8,7 +9,10 @@ BUGS
Changes
CONTRIBUTING.md
CREDITS
deHTMLxs.bs
deHTMLxs.c
deHTMLxs.h
deHTMLxs.o
deHTMLxs.xs
docs/razor-admin.pod
docs/razor-agent.conf.pod
Expand Down Expand Up @@ -47,6 +51,7 @@ SECURITY.md
SERVICE_POLICY
t/basic.t
t/config.t
t/control_flow.t
t/errorhandler.t
t/logger.t
t/manager.t
Expand Down
6 changes: 3 additions & 3 deletions lib/Razor2/Client/Agent.pm
Original file line number Diff line number Diff line change
Expand Up @@ -788,16 +788,16 @@ sub reportit {
}
print "$_\n";
}
exit 0;
return 1;
}

if ( $self->{conf}->{simulate} ) {
$self->log( 4, "Done. (simulate only)" );
exit 0;
return 1;
}
unless ( scalar @$objects ) {
$self->log( 4, "Done. No valid mail or signatures to check." );
exit 1;
return 1;
}

$self->{s}->{list} = $self->{s}->{nomination};
Expand Down
8 changes: 3 additions & 5 deletions lib/Razor2/Client/Core.pm
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ sub compute_sigs {
$self->log2file( 15, $objp->{body}, "$objp->{id}.before_preproc.as_reported" );
$self->log2file( 15, $objp->{cleaned}, "$objp->{id}.after_preproc" );

if ( $clen eq 0 ) {
if ( $clen == 0 ) {
$self->log( 6, "preproc: mail $objp->{id} went from $olen bytes to 0, erasing" );
$objp->{skipme} = 1;
next;
Expand All @@ -548,7 +548,7 @@ sub compute_sigs {
$objp->{skipme} = 1;
next;
}
elsif ( $clen eq $olen ) {
elsif ( $clen == $olen ) {
$self->log( 6, "preproc: mail $objp->{id} unchanged, bytes=$olen" );
}
else {
Expand Down Expand Up @@ -1012,9 +1012,7 @@ sub check_logic {

# default is not spam
$obj->{spam} = 0;
if ( $obj->{skipme} ) {
next;
}
return if $obj->{skipme};

#
# Logic for Spam
Expand Down
121 changes: 121 additions & 0 deletions t/control_flow.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#!perl

use strict;
use warnings;

use Test::More;

# Test 1: check_logic returns early for skipme objects without warnings
subtest 'check_logic returns cleanly for skipme objects' => sub {
use_ok('Razor2::Client::Core');

# Create a minimal Core object with required methods
my $core = bless {
conf => { logic_method => 4, logic_engines => 'any' },
s => { engines => {} },
}, 'Razor2::Client::Core';

# Stub log method
no warnings 'redefine', 'once';
local *Razor2::Client::Core::log = sub { };

my $obj = { skipme => 1, spam => 42 };

# check_logic should return without warnings (not use 'next')
my @warnings;
local $SIG{__WARN__} = sub { push @warnings, $_[0] };
$core->check_logic($obj);

is( $obj->{spam}, 0, 'check_logic sets spam=0 for skipme objects' );
is( scalar @warnings, 0, 'check_logic does not produce warnings for skipme' )
or diag "Got warnings: @warnings";
};

# Test 2: reportit returns instead of exiting for simulate mode
subtest 'reportit returns for simulate mode' => sub {
use_ok('Razor2::Client::Agent');

# Create a minimal agent with enough structure for reportit to reach simulate check
my $agent = bless {
conf => { simulate => 1 },
opt => { foreground => 1 },
breed => 'report',
name_version => 'test-1.0',
args => '',
s => {},
razorhome => '/tmp',
}, 'Razor2::Client::Agent';

# Stub methods that reportit calls before reaching simulate check
no warnings 'redefine';
local *Razor2::Client::Agent::log = sub { };
local *Razor2::Client::Agent::get_ident = sub { { user => 'test', pass => 'test' } };
local *Razor2::Client::Agent::parse_mbox = sub { ['fake mail'] };
local *Razor2::Client::Agent::prepare_objects = sub { [ { id => 1 } ] };
local *Razor2::Client::Agent::get_server_info = sub { 1 };
local *Razor2::Client::Agent::compute_sigs = sub { ['sig1'] };

my $rc = $agent->reportit({});
is( $rc, 1, 'reportit returns 1 for simulate mode instead of exiting' );
};

# Test 3: reportit returns for printhash mode
subtest 'reportit returns for printhash mode' => sub {

my $agent = bless {
conf => {},
opt => { foreground => 1, printhash => 1 },
breed => 'report',
name_version => 'test-1.0',
args => '',
s => {},
razorhome => '/tmp',
}, 'Razor2::Client::Agent';

no warnings 'redefine';
local *Razor2::Client::Agent::log = sub { };
local *Razor2::Client::Agent::get_ident = sub { { user => 'test', pass => 'test' } };
local *Razor2::Client::Agent::parse_mbox = sub { ['fake mail'] };
local *Razor2::Client::Agent::prepare_objects = sub { [ { id => 1 } ] };
local *Razor2::Client::Agent::get_server_info = sub { 1 };
local *Razor2::Client::Agent::compute_sigs = sub { ['e4: sig1'] };

# Capture STDOUT from the print statements
my $output = '';
open my $capture, '>', \$output;
my $old_stdout = select $capture;

my $rc = $agent->reportit({});

select $old_stdout;
close $capture;

is( $rc, 1, 'reportit returns 1 for printhash mode instead of exiting' );
};

# Test 4: reportit returns for empty objects
subtest 'reportit returns for no valid objects' => sub {

my $agent = bless {
conf => {},
opt => { foreground => 1 },
breed => 'report',
name_version => 'test-1.0',
args => '',
s => {},
razorhome => '/tmp',
}, 'Razor2::Client::Agent';

no warnings 'redefine';
local *Razor2::Client::Agent::log = sub { };
local *Razor2::Client::Agent::get_ident = sub { { user => 'test', pass => 'test' } };
local *Razor2::Client::Agent::parse_mbox = sub { ['fake mail'] };
local *Razor2::Client::Agent::prepare_objects = sub { [] };
local *Razor2::Client::Agent::get_server_info = sub { 1 };
local *Razor2::Client::Agent::compute_sigs = sub { ['sig1'] };

my $rc = $agent->reportit({});
is( $rc, 1, 'reportit returns 1 for empty objects instead of exiting' );
};

done_testing;
Loading