]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - usr.sbin/praudit/tests/praudit_test.sh
MFC r335287, r335290
[FreeBSD/stable/10.git] / usr.sbin / praudit / tests / praudit_test.sh
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 # $FreeBSD$
26 #
27
28
29 atf_test_case praudit_delim_comma
30 praudit_delim_comma_head()
31 {
32         atf_set "descr" "Verify that comma delimiter is present with -d ',' cmd"
33 }
34
35 praudit_delim_comma_body()
36 {
37         atf_check -o file:$(atf_get_srcdir)/del_comma \
38                 praudit -d "," $(atf_get_srcdir)/trail
39 }
40
41
42 atf_test_case praudit_delim_underscore
43 praudit_delim_underscore_head()
44 {
45         atf_set "descr" "Verify that underscore delimiter is present with -d _"
46 }
47
48 praudit_delim_underscore_body()
49 {
50         atf_check -o file:$(atf_get_srcdir)/del_underscore \
51                 praudit -d "_" $(atf_get_srcdir)/trail
52 }
53
54
55 atf_test_case praudit_no_args
56 praudit_no_args_head()
57 {
58         atf_set "descr" "Verify that praudit outputs default form without " \
59                         "any arguments"
60 }
61
62 praudit_no_args_body()
63 {
64         atf_check -o file:$(atf_get_srcdir)/no_args \
65                 praudit $(atf_get_srcdir)/trail
66 }
67
68
69 atf_test_case praudit_numeric_form
70 praudit_numeric_form_head()
71 {
72         atf_set "descr" "Verify that praudit outputs the numeric form " \
73                         "with -n flag"
74 }
75
76 praudit_numeric_form_body()
77 {
78         atf_check -o file:$(atf_get_srcdir)/numeric_form \
79                 praudit -n $(atf_get_srcdir)/trail
80 }
81
82
83 atf_test_case praudit_raw_form
84 praudit_raw_form_head()
85 {
86         atf_set "descr" "Verify that praudit outputs the raw form with -r flag"
87 }
88
89 praudit_raw_form_body()
90 {
91         atf_check -o file:$(atf_get_srcdir)/raw_form \
92                 praudit -r $(atf_get_srcdir)/trail
93 }
94
95
96 atf_test_case praudit_same_line
97 praudit_same_line_head()
98 {
99         atf_set "descr" "Verify that praudit outputs the trail in the same " \
100                         "line  with -l flag"
101 }
102
103 praudit_same_line_body()
104 {
105         atf_check -o file:$(atf_get_srcdir)/same_line \
106                 praudit -l $(atf_get_srcdir)/trail
107 }
108
109
110 atf_test_case praudit_short_form
111 praudit_short_form_head()
112 {
113         atf_set "descr" "Verify that praudit outputs the short form " \
114                         "with -s flag"
115 }
116
117 praudit_short_form_body()
118 {
119         atf_check -o file:$(atf_get_srcdir)/short_form \
120                 praudit -s $(atf_get_srcdir)/trail
121 }
122
123
124 atf_test_case praudit_xml_form
125 praudit_xml_form_head()
126 {
127         atf_set "descr" "Verify that praudit outputs the XML file with -x flag"
128 }
129
130 praudit_xml_form_body()
131 {
132         atf_check -o file:$(atf_get_srcdir)/xml_form \
133                 praudit -x $(atf_get_srcdir)/trail
134 }
135
136
137 atf_test_case praudit_sync_to_next_record
138 praudit_sync_to_next_record_head()
139 {
140         atf_set "descr" "Verify that praudit(1) outputs the last few audit " \
141                         "records when the initial part of the trail is " \
142                         "corrputed."
143 }
144
145 praudit_sync_to_next_record_body()
146 {
147         # The 'corrupted' binary file contains some redundant
148         # binary symbols before the actual audit record.
149         # Since 'praudit -p' syncs to the next legitimate record,
150         # it would skip the corrupted part and print the desired
151         # audit record to STDOUT.
152         atf_check -o file:$(atf_get_srcdir)/no_args \
153                 praudit -p $(atf_get_srcdir)/corrupted
154 }
155
156
157 atf_test_case praudit_raw_short_exclusive
158 praudit_raw_short_exclusive_head()
159 {
160         atf_set "descr" "Verify that praudit outputs usage message on stderr " \
161                         "when both raw and short options are specified"
162 }
163
164 praudit_raw_short_exclusive_body()
165 {
166         atf_check -s exit:1 -e match:"usage: praudit" \
167                 praudit -rs $(atf_get_srcdir)/trail
168 }
169
170
171 atf_init_test_cases()
172 {
173         atf_add_test_case praudit_delim_comma
174         atf_add_test_case praudit_delim_underscore
175         atf_add_test_case praudit_no_args
176         atf_add_test_case praudit_numeric_form
177         atf_add_test_case praudit_raw_form
178         atf_add_test_case praudit_same_line
179         atf_add_test_case praudit_short_form
180         atf_add_test_case praudit_xml_form
181         atf_add_test_case praudit_sync_to_next_record
182         atf_add_test_case praudit_raw_short_exclusive
183 }