Debian Codegraph @

tests/API/XCCDF/unittests/test_generate_fix_ansible_vars.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_com.example.www_profile_test_ansible_vars"
8 profile_tailored="xccdf_com.example.www_profile_test_ansible_vars_tailored"
9 ds="test_generate_fix_ansible_vars_ds.xml"
10 tailoring_file="test_generate_fix_ansible_vars_ds-tailoring.xml"
11 golden="test_generate_fix_ansible_vars_golden.yml"
12 golden_altered="test_generate_fix_ansible_vars_golden_altered.yml"
13 golden_tailored="test_generate_fix_ansible_vars_golden_tailoring.yml"
14 var="www_value_val1"
15
16 name=$(basenamescip-shell system . . basename. $0 .sh)
17 playbook=$(make_temp_file /tmpscip-shell filesystem . . `/tmp`. ${name}.yml)
18 out=$(make_temp_file /tmpscip-shell filesystem . . `/tmp`. ${name}.out)
19
20 $OSCAP xccdf generate fix --profile $profile --fix-type ansible \
21 $srcdir/$ds >$playbook 2>$out
22 [scip-shell system . . `[`. -f $out ]; [scip-shell system . . `[`. ! -s $out ]; :> $out
23 [scip-shell system . . `[`. -f $playbook ]; [scip-shell system . . `[`. -s $playbook ]
24 # Removes comment and blank lines from the generated playbook.
25 xsed -i '/#.*/dscip-shell filesystem . . `/#.*/d`.' $playbook
26 xsed -i '/^[ \t]*$/dscip-shell filesystem . . `/^[ \t]*$/d`.' $playbook
27
28 # Compares golden playbook with generated playbook to ensure that Ansible
29 # variables were generated correctly. Both playbooks must be the same.
30 diffscip-shell system . . diff. -u $srcdir/$golden $playbook >$out
31 [scip-shell system . . `[`. -f $out ]; [scip-shell system . . `[`. ! -s $out ]; :> $out
32
33 # Compares value of Ansible variable $var from the golden altered playbook with
34 # the $var from the generated playbook. Values of the Ansible variables $var
35 # must differ (altered golden playbook has different value set).
36 generated_var=$(grepscip-shell system . . grep. "$var:" $playbook | xsed "s|.*$var:[^0-9]*||")
37 golden_altered_var=$(grepscip-shell system . . grep. "$var:" $srcdir/$golden_altered | xsed "s|.*$var:[^0-9]*||")
38
39 [scip-shell system . . `[`. "$generated_var" != "$golden_altered_var" ]
40
41 # Generates Ansible playbook using tailoring file.
42 $OSCAP xccdf generate fix --fix-type ansible \
43 --profile $profile_tailored --tailoring-file $srcdir/$tailoring_file \
44 $srcdir/$ds >$playbook 2>$out
45 [scip-shell system . . `[`. -f $out ]; [scip-shell system . . `[`. ! -s $out ]; :> $out
46 [scip-shell system . . `[`. -f $playbook ]; [scip-shell system . . `[`. -s $playbook ]
47 # Removes comment and blank lines from the generated playbook.
48 xsed -i '/#.*/dscip-shell filesystem . . `/#.*/d`.' $playbook
49 xsed -i '/^[ \t]*$/dscip-shell filesystem . . `/^[ \t]*$/d`.' $playbook
50
51 # Compares golden tailored playbook with generated playbook to ensure that only
52 # tailored Ansible variables are generated in the playbook. Both playbooks must
53 # be the same.
54 diffscip-shell system . . diff. -u $srcdir/$golden_tailored $playbook >$out
55 [scip-shell system . . `[`. -f $out ]; [scip-shell system . . `[`. ! -s $out ]; :> $out
56
57
58 rmscip-shell system . . rm. $playbook $out