From 15b973cffaf77db8ce69819d1bdf6436c2fd8744 Mon Sep 17 00:00:00 2001 From: asomers Date: Fri, 3 Aug 2018 14:36:29 +0000 Subject: [PATCH] MFC r335287, r335290 r335287: praudit(1): return 0 on success Cherry pick https://github.com/openbsm/openbsm/commit/ed83bb3 Submitted by: aniketp Reviewed by: rwatson, 0mp Obtained from: OpenBSM Sponsored by: Google, Inc. (GSoC 2018) Pull Request: https://github.com/openbsm/openbsm/pull/32 r335290: praudit(1): add tests Submitted by: aniketp X-MFC-With: 335287 Sponsored by: Google, Inc. (GSoC 2018) Differential Revision: https://reviews.freebsd.org/D15751 git-svn-id: svn://svn.freebsd.org/base/stable/10@337256 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- contrib/openbsm/bin/praudit/praudit.1 | 4 +- contrib/openbsm/bin/praudit/praudit.c | 2 +- etc/mtree/BSD.tests.dist | 2 + usr.sbin/praudit/Makefile | 3 + usr.sbin/praudit/tests/Makefile | 23 +++ usr.sbin/praudit/tests/input/corrupted | Bin 0 -> 144 bytes usr.sbin/praudit/tests/input/del_comma | 7 + usr.sbin/praudit/tests/input/del_underscore | 7 + usr.sbin/praudit/tests/input/no_args | 7 + usr.sbin/praudit/tests/input/numeric_form | 7 + usr.sbin/praudit/tests/input/raw_form | 7 + usr.sbin/praudit/tests/input/same_line | 1 + usr.sbin/praudit/tests/input/short_form | 7 + usr.sbin/praudit/tests/input/trail | Bin 0 -> 113 bytes usr.sbin/praudit/tests/input/xml_form | 12 ++ usr.sbin/praudit/tests/praudit_test.sh | 183 ++++++++++++++++++++ 16 files changed, 270 insertions(+), 2 deletions(-) create mode 100644 usr.sbin/praudit/tests/Makefile create mode 100644 usr.sbin/praudit/tests/input/corrupted create mode 100644 usr.sbin/praudit/tests/input/del_comma create mode 100644 usr.sbin/praudit/tests/input/del_underscore create mode 100644 usr.sbin/praudit/tests/input/no_args create mode 100644 usr.sbin/praudit/tests/input/numeric_form create mode 100644 usr.sbin/praudit/tests/input/raw_form create mode 100644 usr.sbin/praudit/tests/input/same_line create mode 100644 usr.sbin/praudit/tests/input/short_form create mode 100644 usr.sbin/praudit/tests/input/trail create mode 100644 usr.sbin/praudit/tests/input/xml_form create mode 100644 usr.sbin/praudit/tests/praudit_test.sh diff --git a/contrib/openbsm/bin/praudit/praudit.1 b/contrib/openbsm/bin/praudit/praudit.1 index 2954ba3da..606168f8c 100644 --- a/contrib/openbsm/bin/praudit/praudit.1 +++ b/contrib/openbsm/bin/praudit/praudit.1 @@ -25,7 +25,7 @@ .\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd August 4, 2009 +.Dd June 11, 2018 .Dt PRAUDIT 1 .Os .Sh NAME @@ -88,6 +88,8 @@ Events are displayed as per their descriptions given in .Pa /etc/security/audit_event ; UIDs and GIDs are expanded to their names; dates and times are displayed in human-readable format. +.Sh EXIT STATUS +.Ex -std .Sh FILES .Bl -tag -width ".Pa /etc/security/audit_control" -compact .It Pa /etc/security/audit_class diff --git a/contrib/openbsm/bin/praudit/praudit.c b/contrib/openbsm/bin/praudit/praudit.c index f7954344b..13cf31a11 100644 --- a/contrib/openbsm/bin/praudit/praudit.c +++ b/contrib/openbsm/bin/praudit/praudit.c @@ -169,5 +169,5 @@ main(int argc, char **argv) if (oflags & AU_OFLAG_XML) au_print_xml_footer(stdout); - return (1); + return (0); } diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist index 695368bf0..d1ad44d4f 100644 --- a/etc/mtree/BSD.tests.dist +++ b/etc/mtree/BSD.tests.dist @@ -682,6 +682,8 @@ .. nmtree .. + praudit + .. pw .. rpcbind diff --git a/usr.sbin/praudit/Makefile b/usr.sbin/praudit/Makefile index 6a61fd131..65f4ac768 100644 --- a/usr.sbin/praudit/Makefile +++ b/usr.sbin/praudit/Makefile @@ -13,4 +13,7 @@ WARNS?= 3 DPADD= ${LIBBSM} LDADD= -lbsm +HAS_TESTS= +SUBDIR.${MK_TESTS}+= tests + .include diff --git a/usr.sbin/praudit/tests/Makefile b/usr.sbin/praudit/tests/Makefile new file mode 100644 index 000000000..628ed695f --- /dev/null +++ b/usr.sbin/praudit/tests/Makefile @@ -0,0 +1,23 @@ +# $FreeBSD$ + +PACKAGE= tests + +TESTSDIR= ${TESTSBASE}/usr.sbin/praudit + +ATF_TESTS_SH= praudit_test + +${PACKAGE}FILES+= \ + input/trail \ + input/corrupted \ + input/del_comma \ + input/del_underscore \ + input/no_args \ + input/numeric_form \ + input/raw_form \ + input/same_line \ + input/short_form \ + input/xml_form + +TEST_METADATA+= timeout="10" + +.include diff --git a/usr.sbin/praudit/tests/input/corrupted b/usr.sbin/praudit/tests/input/corrupted new file mode 100644 index 0000000000000000000000000000000000000000..7e3c56268b24061634a797b79201d5138a10a094 GIT binary patch literal 144 zcma!Zh;xc_Qjc?hLg%>Pjd89JP9c{F0|P@LH^X)YhG;pTRt5&f8eK-9kPHKRN`7u) zW*&ns6OhZqz* + + + + + + + + + + + diff --git a/usr.sbin/praudit/tests/praudit_test.sh b/usr.sbin/praudit/tests/praudit_test.sh new file mode 100644 index 000000000..eeaee25ee --- /dev/null +++ b/usr.sbin/praudit/tests/praudit_test.sh @@ -0,0 +1,183 @@ +# +# Copyright (c) 2018 Aniket Pandey +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# + + +atf_test_case praudit_delim_comma +praudit_delim_comma_head() +{ + atf_set "descr" "Verify that comma delimiter is present with -d ',' cmd" +} + +praudit_delim_comma_body() +{ + atf_check -o file:$(atf_get_srcdir)/del_comma \ + praudit -d "," $(atf_get_srcdir)/trail +} + + +atf_test_case praudit_delim_underscore +praudit_delim_underscore_head() +{ + atf_set "descr" "Verify that underscore delimiter is present with -d _" +} + +praudit_delim_underscore_body() +{ + atf_check -o file:$(atf_get_srcdir)/del_underscore \ + praudit -d "_" $(atf_get_srcdir)/trail +} + + +atf_test_case praudit_no_args +praudit_no_args_head() +{ + atf_set "descr" "Verify that praudit outputs default form without " \ + "any arguments" +} + +praudit_no_args_body() +{ + atf_check -o file:$(atf_get_srcdir)/no_args \ + praudit $(atf_get_srcdir)/trail +} + + +atf_test_case praudit_numeric_form +praudit_numeric_form_head() +{ + atf_set "descr" "Verify that praudit outputs the numeric form " \ + "with -n flag" +} + +praudit_numeric_form_body() +{ + atf_check -o file:$(atf_get_srcdir)/numeric_form \ + praudit -n $(atf_get_srcdir)/trail +} + + +atf_test_case praudit_raw_form +praudit_raw_form_head() +{ + atf_set "descr" "Verify that praudit outputs the raw form with -r flag" +} + +praudit_raw_form_body() +{ + atf_check -o file:$(atf_get_srcdir)/raw_form \ + praudit -r $(atf_get_srcdir)/trail +} + + +atf_test_case praudit_same_line +praudit_same_line_head() +{ + atf_set "descr" "Verify that praudit outputs the trail in the same " \ + "line with -l flag" +} + +praudit_same_line_body() +{ + atf_check -o file:$(atf_get_srcdir)/same_line \ + praudit -l $(atf_get_srcdir)/trail +} + + +atf_test_case praudit_short_form +praudit_short_form_head() +{ + atf_set "descr" "Verify that praudit outputs the short form " \ + "with -s flag" +} + +praudit_short_form_body() +{ + atf_check -o file:$(atf_get_srcdir)/short_form \ + praudit -s $(atf_get_srcdir)/trail +} + + +atf_test_case praudit_xml_form +praudit_xml_form_head() +{ + atf_set "descr" "Verify that praudit outputs the XML file with -x flag" +} + +praudit_xml_form_body() +{ + atf_check -o file:$(atf_get_srcdir)/xml_form \ + praudit -x $(atf_get_srcdir)/trail +} + + +atf_test_case praudit_sync_to_next_record +praudit_sync_to_next_record_head() +{ + atf_set "descr" "Verify that praudit(1) outputs the last few audit " \ + "records when the initial part of the trail is " \ + "corrputed." +} + +praudit_sync_to_next_record_body() +{ + # The 'corrupted' binary file contains some redundant + # binary symbols before the actual audit record. + # Since 'praudit -p' syncs to the next legitimate record, + # it would skip the corrupted part and print the desired + # audit record to STDOUT. + atf_check -o file:$(atf_get_srcdir)/no_args \ + praudit -p $(atf_get_srcdir)/corrupted +} + + +atf_test_case praudit_raw_short_exclusive +praudit_raw_short_exclusive_head() +{ + atf_set "descr" "Verify that praudit outputs usage message on stderr " \ + "when both raw and short options are specified" +} + +praudit_raw_short_exclusive_body() +{ + atf_check -s exit:1 -e match:"usage: praudit" \ + praudit -rs $(atf_get_srcdir)/trail +} + + +atf_init_test_cases() +{ + atf_add_test_case praudit_delim_comma + atf_add_test_case praudit_delim_underscore + atf_add_test_case praudit_no_args + atf_add_test_case praudit_numeric_form + atf_add_test_case praudit_raw_form + atf_add_test_case praudit_same_line + atf_add_test_case praudit_short_form + atf_add_test_case praudit_xml_form + atf_add_test_case praudit_sync_to_next_record + atf_add_test_case praudit_raw_short_exclusive +} -- 2.42.0