Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFE: add test for filter_exit #107

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ TESTS := \
file_delete \
file_rename \
filter_exclude \
filter_exit \
filter_saddr_fam \
filter_sessionid \
login_tty \
Expand Down
8 changes: 8 additions & 0 deletions tests/filter_exit/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
TARGETS=$(patsubst %.c,%,$(wildcard *.c))

LDLIBS += -lpthread

all: $(TARGETS)
clean:
rm -f $(TARGETS)

94 changes: 94 additions & 0 deletions tests/filter_exit/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/usr/bin/perl

use strict;

use Test;
BEGIN { plan tests => 4 }

use File::Temp qw/ tempdir tempfile /;

###
# functions

sub key_gen {
my @chars = ( "A" .. "Z", "a" .. "z" );
my $key = "testsuite-" . time . "-";
$key .= $chars[ rand @chars ] for 1 .. 8;
return $key;
}

###
# setup

chomp( my $abi_bits = $ENV{MODE} != 0 ? $ENV{MODE} : `getconf LONG_BIT` );

# reset audit
system("auditctl -D >& /dev/null");

# create stdout/stderr sinks
( my $fh_out, my $stdout ) = tempfile(
TEMPLATE => '/tmp/audit-testsuite-out-XXXX',
UNLINK => 1
);
( my $fh_err, my $stderr ) = tempfile(
TEMPLATE => '/tmp/audit-testsuite-err-XXXX',
UNLINK => 1
);
( my $fh_ses, my $sesout ) = tempfile(
TEMPLATE => '/tmp/audit-testsuite-ses-XXXX',
UNLINK => 1
);
( my $fh_pid, my $pidout ) = tempfile(
TEMPLATE => '/tmp/audit-testsuite-pid-XXXX',
UNLINK => 1
);

###
# tests

my $result;

# create a key and rule
my $key = key_gen();
$result = system(
"auditctl -a always,exit -F arch=b$abi_bits -S write -F exit=-EINVAL -k $key"
);
ok( $result, 0 );

# trigger open syscall error EINVAL
$result = system("echo \"TESTING\" > /proc/self/status 2>/dev/null");
ok( $result, 256 );

# make sure the records had a chance to bubble through to the logs
system("auditctl -m syncmarker-$key");
for ( my $i = 0 ; $i < 10 ; $i++ ) {
if ( system("ausearch -m USER | grep -q syncmarker-$key") eq 0 ) {
last;
}
sleep(0.2);
}

# test for the SYSCALL message
$result =
system("ausearch -i -m SYSCALL -sc write -k $key > $stdout 2> $stderr");
ok( $result, 0 );

# test if we generate the SYSCALL record correctly
my $line;
my $syscall_msg_match = 0;
while ( $line = <$fh_out> ) {

# test if SYSCALL record matches
if ( $line =~ m?^type=SYSCALL ?
and $line =~ m? exit=EINVAL?
and $line =~ m? key=$key ? )
{
$syscall_msg_match = 1;
last;
}
}
ok($syscall_msg_match);

###
# cleanup
system("auditctl -D >& /dev/null");