Debian Codegraph @

tests/API/XCCDF/unittests/test_remediation_kickstart.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2 . $builddir/tests/test_common.sh
3
4 set -e -o pipefail
5
6 function test_normalscip-shell shell shell-project 0.0.0 test_normal(). {
7 kickstart=$(mktempscip-shell system . . mktemp.)
8 stderr=$(mktempscip-shell system . . mktemp.)
9 expected_modified=$(mktempscip-shell system . . mktemp.)
10 kickstart_modified=$(mktempscip-shell system . . mktemp.)
11
12 sedscip-shell system . . sed. "/This file was generated by OpenSCAP .* using:/d" "$srcdir/test_remediation_kickstart_expected.cfg" > "$expected_modified"
13 sedscip-shell system . . sed. -i "/rootpw .*/d" "$expected_modified"
14 sedscip-shell system . . sed. -i "s;TEST_DATA_STREAM_PATH;$srcdir/test_remediation_kickstart.ds.xml;" "$expected_modified"
15
16 $OSCAP xccdf generate fix --fix-type kickstart --output "$kickstart" --profile common "$srcdir/test_remediation_kickstart.ds.xml"
17
18 sedscip-shell system . . sed. "/This file was generated by OpenSCAP .* using:/d" "$kickstart" > "$kickstart_modified"
19 sedscip-shell system . . sed. -i "/rootpw .*/d" "$kickstart_modified"
20
21 diffscip-shell system . . diff. -u "$expected_modified" "$kickstart_modified"
22
23 rmscip-shell system . . rm. -rf "$kickstart"
24 rmscip-shell system . . rm. -rf "$stderr"
25 rmscip-shell system . . rm. -rf "$expected_modified"
26 rmscip-shell system . . rm. -rf "$kickstart_modified"
27 }
28
29 function test_tailoringscip-shell shell shell-project 0.0.0 test_tailoring(). {
30 kickstart=$(mktempscip-shell system . . mktemp.)
31 stderr=$(mktempscip-shell system . . mktemp.)
32
33 $OSCAP xccdf generate fix --tailoring-file "$srcdir/test_remediation_kickstart.tailoring.xml" --fix-type kickstart --output "$kickstart" --profile custom "$srcdir/test_remediation_kickstart.ds.xml"
34
35 grepscip-shell system . . grep. -q 'services --enabled=auditd,rsyslog' "$kickstart"
36 ! grepscip-shell system . . grep. -q 'openssh-server' "$kickstart"
37 grepscip-shell system . . grep. -q 'cat >/root/oscap_tailoring.xml <<END_OF_TAILORING' "$kickstart"
38 grepscip-shell system . . grep. -q 'ns0:Tailoring' "$kickstart"
39 grepscip-shell system . . grep. -q 'oscap xccdf eval --remediate --tailoring-file /root/oscap_tailoring.xml' "$kickstart"
40
41 rmscip-shell system . . rm. -rf "$kickstart"
42 rmscip-shell system . . rm. -rf "$stderr"
43 }
44
45
46 function test_results_orientedscip-shell shell shell-project 0.0.0 test_results_oriented(). {
47 kickstart=$(mktempscip-shell system . . mktemp.)
48 stderr=$(mktempscip-shell system . . mktemp.)
49
50 $OSCAP xccdf generate fix --fix-type kickstart --output "$kickstart" --result-id xccdf_org.open-scap_testresult_xccdf_org.ssgproject.content_profile_ospp "$srcdir/test_remediation_kickstart.ds.xml" 2> "$stderr" || ret=$?
51
52 [scip-shell system . . `[`. $ret = 1 ]
53 grepscip-shell system . . grep. -q "It isn't possible to generate results-oriented Kickstarts." $stderr
54
55 rmscip-shell system . . rm. -rf "$kickstart"
56 rmscip-shell system . . rm. -rf "$stderr"
57 }
58
59 function test_error_servicescip-shell shell shell-project 0.0.0 test_error_service(). {
60 kickstart=$(mktempscip-shell system . . mktemp.)
61 stderr=$(mktempscip-shell system . . mktemp.)
62
63 $OSCAP xccdf generate fix --fix-type kickstart --output "$kickstart" --profile broken_service "$srcdir/test_remediation_kickstart_invalid.ds.xml" 2> "$stderr"
64
65 grepscip-shell system . . grep. -q "Unsupported 'service' command keyword 'slow' in command: 'service slow down'" "$stderr"
66
67 rmscip-shell system . . rm. -rf "$kickstart"
68 rmscip-shell system . . rm. -rf "$stderr"
69 }
70
71 function test_error_packagescip-shell shell shell-project 0.0.0 test_error_package(). {
72 kickstart=$(mktempscip-shell system . . mktemp.)
73 stderr=$(mktempscip-shell system . . mktemp.)
74
75 $OSCAP xccdf generate fix --fix-type kickstart --output "$kickstart" --profile broken_package "$srcdir/test_remediation_kickstart_invalid.ds.xml" 2> "$stderr"
76
77 grepscip-shell system . . grep. -q "Unsupported 'package' command keyword 'build' in command:'package build sources'" "$stderr"
78
79 rmscip-shell system . . rm. -rf "$kickstart"
80 rmscip-shell system . . rm. -rf "$stderr"
81 }
82
83 function test_error_logvolscip-shell shell shell-project 0.0.0 test_error_logvol(). {
84 kickstart=$(mktempscip-shell system . . mktemp.)
85 stderr=$(mktempscip-shell system . . mktemp.)
86
87 $OSCAP xccdf generate fix --fix-type kickstart --output "$kickstart" --profile broken_logvol "$srcdir/test_remediation_kickstart_invalid.ds.xml" 2> "$stderr"
88
89 grepscip-shell system . . grep. -q "Unexpected string 'crypto' in command: 'logvol /var 158 crypto'" "$stderr"
90
91 rmscip-shell system . . rm. -rf "$kickstart"
92 rmscip-shell system . . rm. -rf "$stderr"
93 }
94
95 function test_error_unknownscip-shell shell shell-project 0.0.0 test_error_unknown(). {
96 kickstart=$(mktempscip-shell system . . mktemp.)
97 stderr=$(mktempscip-shell system . . mktemp.)
98
99 $OSCAP xccdf generate fix --fix-type kickstart --output "$kickstart" --profile unknown_command "$srcdir/test_remediation_kickstart_invalid.ds.xml" 2> "$stderr"
100
101 grepscip-shell system . . grep. -q "Unsupported command keyword 'unknown' in command: 'unknown command'" "$stderr"
102
103 rmscip-shell system . . rm. -rf "$kickstart"
104 rmscip-shell system . . rm. -rf "$stderr"
105 }
106
107 test_normalscip-shell shell shell-project 0.0.0 test_normal().
108 test_tailoringscip-shell shell shell-project 0.0.0 test_tailoring().
109 test_results_orientedscip-shell shell shell-project 0.0.0 test_results_oriented().
110 test_error_servicescip-shell shell shell-project 0.0.0 test_error_service().
111 test_error_packagescip-shell shell shell-project 0.0.0 test_error_package().
112 test_error_logvolscip-shell shell shell-project 0.0.0 test_error_logvol().
113 test_error_unknownscip-shell shell shell-project 0.0.0 test_error_unknown().