Debian Codegraph @

tests/DS/test_ds_use_local_remote_resources.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 # Author:
4 # Jan Černý <[email protected]>
5
6 set -e -o pipefail
7
8 . $builddir/tests/test_common.sh
9
10 PROFILE="xccdf_com.example.www_profile_test_remote_res"
11
12 result=$(mktemp)
13 stderr=$(mktemp)
14 tmpdir1=$(mktemp -d)
15 tmpdir2=$(mktemp -d)
16 tmpdir3=$(mktemp -d)
17 cp "${srcdir}/ds_use_local_remote_resources/remote_content_1.3.ds.xml" "$tmpdir2"
18 cp "${srcdir}/ds_use_local_remote_resources/remote.oval.xml" "$tmpdir3"
19 pushd "$tmpdir1"
20
21 $OSCAP xccdf eval --local-files "$tmpdir3" --profile "$PROFILE" --results "$result" "$tmpdir2/remote_content_1.3.ds.xml" 2>"$stderr" || ret=$?
22 [ "$ret" = 2 ]
23
24 grep -q "WARNING: Datastream component 'scap_org.open-scap_cref_remote.oval.xml' points out to the remote 'https://www.example.com/security/data/oval/remote.oval.xml'. Use '--fetch-remote-resources' option to download it." "$stderr" && false
25 grep -q "WARNING: Skipping 'https://www.example.com/security/data/oval/remote.oval.xml' file which is referenced from datastream" "$stderr" && false
26 grep -q "WARNING: Using local file '$tmpdir3/remote.oval.xml' instead of 'https://www.example.com/security/data/oval/remote.oval.xml'" "$stderr"
27
28 assert_exists 1 '//rule-result[@idref="xccdf_com.example.www_rule_test-pass"]/result[text()="pass"]'
29 # the remote_res rule is a multicheck with 2 oval definitions so it's twice here
30 assert_exists 1 '//rule-result[@idref="xccdf_com.example.www_rule_test-remote_res"]/result[text()="pass"]'
31 assert_exists 1 '//rule-result[@idref="xccdf_com.example.www_rule_test-remote_res"]/result[text()="fail"]'
32 assert_exists 1 '//rule-result[@idref="xccdf_com.example.www_rule_test-pass2"]/result[text()="pass"]'
33
34 popd
35 rm -f "$result" "$stderr"
36 rm -rf "$tmpdir1" "$tmpdir2" "$tmpdir3"
37
38 # test the same without --local-files to make sure the $tmpdir/remote.oval.xml isn't loaded by oscap
39
40 result=$(mktemp)
41 stderr=$(mktemp)
42 tmpdir=$(mktemp -d)
43 cp "${srcdir}/ds_use_local_remote_resources/remote_content_1.3.ds.xml" "$tmpdir"
44 cp "${srcdir}/ds_use_local_remote_resources/remote.oval.xml" "$tmpdir"
45 pushd "$tmpdir"
46
47 $OSCAP xccdf eval --profile "$PROFILE" --results "$result" "remote_content_1.3.ds.xml" 2>"$stderr" || ret=$?
48 [ "$ret" = 2 ]
49
50 grep -q "WARNING: Datastream component 'scap_org.open-scap_cref_remote.oval.xml' points out to the remote 'https://www.example.com/security/data/oval/remote.oval.xml'. Use '--fetch-remote-resources' option to download it." "$stderr"
51 grep -q "WARNING: Skipping 'https://www.example.com/security/data/oval/remote.oval.xml' file which is referenced from datastream" "$stderr"
52
53 assert_exists 1 '//rule-result[@idref="xccdf_com.example.www_rule_test-pass"]/result[text()="pass"]'
54 assert_exists 1 '//rule-result[@idref="xccdf_com.example.www_rule_test-remote_res"]/result[text()="notchecked"]'
55 assert_exists 1 '//rule-result[@idref="xccdf_com.example.www_rule_test-pass2"]/result[text()="pass"]'
56
57 popd
58 rm -f "$result" "$stderr"
59 rm -rf "$tmpdir"
60
61 # test that a warning is shown when --local-files is provided but the file doesn't exist
62 result=$(mktemp)
63 stderr=$(mktemp)
64 tmpdir1=$(mktemp -d)
65 tmpdir2=$(mktemp -d)
66 tmpdir3=$(mktemp -d)
67 cp "${srcdir}/ds_use_local_remote_resources/remote_content_1.3.ds.xml" "$tmpdir2"
68 pushd "$tmpdir1"
69
70 # $tmpdir3 is empty, it doesn't contain any content
71 $OSCAP xccdf eval --local-files "$tmpdir3" --profile "$PROFILE" --results "$result" "$tmpdir2/remote_content_1.3.ds.xml" 2>"$stderr" || ret=$?
72 [ "$ret" = 2 ]
73
74 grep -q "WARNING: Data stream component 'scap_org.open-scap_cref_remote.oval.xml' points out to the remote 'https://www.example.com/security/data/oval/remote.oval.xml'. The option --local-files '$tmpdir3' has been provided, but the file '$tmpdir3/remote.oval.xml' can't be used locally: No such file or directory." "$stderr"
75
76 assert_exists 1 '//rule-result[@idref="xccdf_com.example.www_rule_test-pass"]/result[text()="pass"]'
77 assert_exists 1 '//rule-result[@idref="xccdf_com.example.www_rule_test-remote_res"]/result[text()="notchecked"]'
78 assert_exists 1 '//rule-result[@idref="xccdf_com.example.www_rule_test-pass2"]/result[text()="pass"]'
79
80 popd
81 rm -f "$result" "$stderr"
82 rm -rf "$tmpdir1" "$tmpdir2" "$tmpdir3"
83
84
85 # test that a warning is shown when --local-files is provided with SCAP 1.2 DS
86 result=$(mktemp)
87 stderr=$(mktemp)
88 tmpdir=$(mktemp -d)
89 $OSCAP xccdf eval --local-files "$tmpdir" --profile "$PROFILE" --results "$result" "${srcdir}/ds_continue_without_remote_resources/remote_content_1.2.ds.xml" 2>"$stderr" || ret=$?
90 [ "$ret" = 2 ]
91 grep -q "WARNING: The '--local-files' option can be used only with SCAP 1.3 source data streams, but the provided data stream is version '1.2'. No local files will be used." "$stderr"
92 rm -rf "$result" "$stderr" "$tmpdir"