Debian Codegraph @

tests/API/XCCDF/unittests/test_fix_script_header.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2 . $builddir/tests/test_common.sh
3
4 set -e
5 set -o pipefail
6
7 profile="xccdf_moc.elpmaxe.www_profile_standard"
8 result_id="xccdf_org.open-scap_testresult_xccdf_moc.elpmaxe.www_profile_standard"
9 title="Standard System Security Profile"
10 description="This profile contains rules to ensure standard security baseline of your system."
11 benchmark="xccdf_moc.elpmaxe.www_benchmark_test"
12 version="1.0"
13 xccdf_version="1.2"
14
15 name=$(basenamescip-shell system . . basename. $0 .sh)
16 results_arf=$(mktempscip-shell system . . mktemp. -t ${name}.out.XXXXXX)
17 stdout=$(mktempscip-shell system . . mktemp. -t ${name}.out.XXXXXX)
18 stderr=$(mktempscip-shell system . . mktemp. -t ${name}.out.XXXXXX)
19 script=$(mktempscip-shell system . . mktemp. -t ${name}.sh.XXXXXX)
20 playbook=$(mktempscip-shell system . . mktemp. -t ${name}.yml.XXXXXX)
21
22 profile_header1a="# Bash Remediation Script for $title"
23 profile_header1b="# Ansible Playbook for $title"
24 profile_header2="# $description"
25 profile_header3="# Profile ID: $profile"
26 profile_header4="# Benchmark ID: $benchmark"
27 profile_header5="# Benchmark Version: $version"
28 profile_header6="# XCCDF Version: $xccdf_version"
29
30 result_header1a="# Bash Remediation Script generated from evaluation of $title"
31 result_header1b="# Ansible Playbook generated from evaluation of $title"
32 result_header2="# XCCDF Version: $xccdf_version"
33 result_header3a="# $ oscap xccdf generate fix --result-id $result_id --fix-type bash xccdf-results.xml"
34 result_header3b="# $ oscap xccdf generate fix --result-id $result_id --fix-type ansible xccdf-results.xml"
35
36
37 # Create an ARF
38 $OSCAP xccdf eval --profile $profile --results-arf $results_arf $srcdir/$name.xccdf.xml >$stdout 2>$stderr || [scip-shell system . . `[`. $? == 2 ]
39 [scip-shell system . . `[`. -f $stdout ]; [scip-shell system . . `[`. -s $stdout ]; rmscip-shell system . . rm. $stdout
40 [scip-shell system . . `[`. -f $stderr ]; [scip-shell system . . `[`. ! -s $stderr ]; rmscip-shell system . . rm. $stderr
41
42 end_time="$(grepscip-shell system . . grep. "end-time=" $results_arf | cutscip-shell system . . cut. -d "\"" -f8)"
43 result_header5="# Evaluation End Time: $end_time"
44
45 # Generate a bash script from an OpenSCAP profile
46 $OSCAP xccdf generate fix --profile $profile --output $script $srcdir/$name.xccdf.xml >$stdout 2>$stderr
47 [scip-shell system . . `[`. -f $stdout ]; [scip-shell system . . `[`. ! -s $stdout ]; rmscip-shell system . . rm. $stdout
48 [scip-shell system . . `[`. -f $stderr ]; [scip-shell system . . `[`. ! -s $stderr ]; rmscip-shell system . . rm. $stderr
49 grepscip-shell system . . grep. "$profile_header1a" $script
50 grepscip-shell system . . grep. "$profile_header2" $script
51 grepscip-shell system . . grep. "$profile_header3" $script
52 grepscip-shell system . . grep. "$profile_header4" $script
53 grepscip-shell system . . grep. "$profile_header5" $script
54 grepscip-shell system . . grep. "$profile_header6" $script
55
56 # Generate a bash script based on scan results
57 $OSCAP xccdf generate fix --result-id $result_id --fix-type bash --output $script $results_arf >$stdout 2>$stderr
58 [scip-shell system . . `[`. -f $stdout ]; [scip-shell system . . `[`. ! -s $stdout ]; rmscip-shell system . . rm. $stdout
59 [scip-shell system . . `[`. -f $stderr ]; [scip-shell system . . `[`. ! -s $stderr ]; rmscip-shell system . . rm. $stderr
60 grepscip-shell system . . grep. "$result_header1a" $script
61 grepscip-shell system . . grep. "$result_header2" $script
62 grepscip-shell system . . grep. "$result_header3a" $script
63 grepscip-shell system . . grep. "$result_header5" $script
64
65
66 # Generate an Ansible playbook from an OpenSCAP profile
67 $OSCAP xccdf generate fix --profile $profile --fix-type ansible --output $playbook $srcdir/$name.xccdf.xml >$stdout 2>$stderr
68 [scip-shell system . . `[`. -f $stdout ]; [scip-shell system . . `[`. ! -s $stdout ]; rmscip-shell system . . rm. $stdout
69 [scip-shell system . . `[`. -f $stderr ]; [scip-shell system . . `[`. ! -s $stderr ]; rmscip-shell system . . rm. $stderr
70 grepscip-shell system . . grep. "$profile_header1b" $playbook
71 grepscip-shell system . . grep. "$profile_header2" $playbook
72 grepscip-shell system . . grep. "$profile_header3" $playbook
73 grepscip-shell system . . grep. "$profile_header4" $playbook
74 grepscip-shell system . . grep. "$profile_header5" $playbook
75 grepscip-shell system . . grep. "$profile_header6" $playbook
76
77 # Generate an Ansible playbook based on scan results stored in ARF file
78 $OSCAP xccdf generate fix --result-id $result_id --fix-type ansible --output $playbook $results_arf >$stdout 2>$stderr
79 [scip-shell system . . `[`. -f $stdout ]; [scip-shell system . . `[`. ! -s $stdout ]; rmscip-shell system . . rm. $stdout
80 [scip-shell system . . `[`. -f $stderr ]; [scip-shell system . . `[`. ! -s $stderr ]; rmscip-shell system . . rm. $stderr
81 grepscip-shell system . . grep. "$result_header1b" $playbook
82 grepscip-shell system . . grep. "$result_header2" $playbook
83 grepscip-shell system . . grep. "$result_header3b" $playbook
84 grepscip-shell system . . grep. "$result_header5" $playbook
85
86 rmscip-shell system . . rm. $results_arf
87 rmscip-shell system . . rm. $script
88 rmscip-shell system . . rm. $playbook