xref: /freebsd/usr.sbin/praudit/tests/praudit_test.sh (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
1#
2# Copyright (c) 2018 Aniket Pandey
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions
6# are met:
7# 1. Redistributions of source code must retain the above copyright
8#    notice, this list of conditions and the following disclaimer.
9# 2. Redistributions in binary form must reproduce the above copyright
10#    notice, this list of conditions and the following disclaimer in the
11#    documentation and/or other materials provided with the distribution.
12#
13# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23# SUCH DAMAGE.
24#
25#
26
27
28atf_test_case praudit_delim_comma
29praudit_delim_comma_head()
30{
31	atf_set "descr" "Verify that comma delimiter is present with -d ',' cmd"
32}
33
34praudit_delim_comma_body()
35{
36	atf_check -o file:$(atf_get_srcdir)/del_comma \
37		praudit -d "," $(atf_get_srcdir)/trail
38}
39
40
41atf_test_case praudit_delim_underscore
42praudit_delim_underscore_head()
43{
44	atf_set "descr" "Verify that underscore delimiter is present with -d _"
45}
46
47praudit_delim_underscore_body()
48{
49	atf_check -o file:$(atf_get_srcdir)/del_underscore \
50		praudit -d "_" $(atf_get_srcdir)/trail
51}
52
53
54atf_test_case praudit_no_args
55praudit_no_args_head()
56{
57	atf_set "descr" "Verify that praudit outputs default form without " \
58			"any arguments"
59}
60
61praudit_no_args_body()
62{
63	atf_check -o file:$(atf_get_srcdir)/no_args \
64		praudit $(atf_get_srcdir)/trail
65}
66
67
68atf_test_case praudit_numeric_form
69praudit_numeric_form_head()
70{
71	atf_set "descr" "Verify that praudit outputs the numeric form " \
72			"with -n flag"
73}
74
75praudit_numeric_form_body()
76{
77	atf_check -o file:$(atf_get_srcdir)/numeric_form \
78		praudit -n $(atf_get_srcdir)/trail
79}
80
81
82atf_test_case praudit_raw_form
83praudit_raw_form_head()
84{
85	atf_set "descr" "Verify that praudit outputs the raw form with -r flag"
86}
87
88praudit_raw_form_body()
89{
90	atf_check -o file:$(atf_get_srcdir)/raw_form \
91		praudit -r $(atf_get_srcdir)/trail
92}
93
94
95atf_test_case praudit_same_line
96praudit_same_line_head()
97{
98	atf_set "descr" "Verify that praudit outputs the trail in the same " \
99			"line  with -l flag"
100}
101
102praudit_same_line_body()
103{
104	atf_check -o file:$(atf_get_srcdir)/same_line \
105		praudit -l $(atf_get_srcdir)/trail
106}
107
108
109atf_test_case praudit_short_form
110praudit_short_form_head()
111{
112	atf_set "descr" "Verify that praudit outputs the short form " \
113			"with -s flag"
114}
115
116praudit_short_form_body()
117{
118	atf_check -o file:$(atf_get_srcdir)/short_form \
119		praudit -s $(atf_get_srcdir)/trail
120}
121
122
123atf_test_case praudit_xml_form
124praudit_xml_form_head()
125{
126	atf_set "descr" "Verify that praudit outputs the XML file with -x flag"
127}
128
129praudit_xml_form_body()
130{
131	atf_check -o file:$(atf_get_srcdir)/xml_form \
132		praudit -x $(atf_get_srcdir)/trail
133}
134
135
136atf_test_case praudit_sync_to_next_record
137praudit_sync_to_next_record_head()
138{
139	atf_set "descr" "Verify that praudit(1) outputs the last few audit " \
140			"records when the initial part of the trail is " \
141			"corrputed."
142}
143
144praudit_sync_to_next_record_body()
145{
146	# The 'corrupted' binary file contains some redundant
147	# binary symbols before the actual audit record.
148	# Since 'praudit -p' syncs to the next legitimate record,
149	# it would skip the corrupted part and print the desired
150	# audit record to STDOUT.
151	atf_check -o file:$(atf_get_srcdir)/no_args \
152		praudit -p $(atf_get_srcdir)/corrupted
153}
154
155
156atf_test_case praudit_raw_short_exclusive
157praudit_raw_short_exclusive_head()
158{
159	atf_set "descr" "Verify that praudit outputs usage message on stderr " \
160			"when both raw and short options are specified"
161}
162
163praudit_raw_short_exclusive_body()
164{
165	atf_check -s exit:1 -e match:"usage: praudit" \
166		praudit -rs $(atf_get_srcdir)/trail
167}
168
169
170atf_init_test_cases()
171{
172	atf_add_test_case praudit_delim_comma
173	atf_add_test_case praudit_delim_underscore
174	atf_add_test_case praudit_no_args
175	atf_add_test_case praudit_numeric_form
176	atf_add_test_case praudit_raw_form
177	atf_add_test_case praudit_same_line
178	atf_add_test_case praudit_short_form
179	atf_add_test_case praudit_xml_form
180	atf_add_test_case praudit_sync_to_next_record
181	atf_add_test_case praudit_raw_short_exclusive
182}
183