| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # Copyright 2018 Red Hat Inc., Durham, North Carolina. |
| 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # OpenSCAP Test Suite |
| 7 | # |
| 8 | # Authors: |
| 9 | # Jan Černý <[email protected]> |
| 10 | |
| 11 | . $builddir/tests/test_common.sh |
| 12 | |
| 13 | set -e -o pipefail |
| 14 | |
| 15 | function test_offline_mode_textfilecontent54 { |
| 16 | temp_dir="$(mktemp -d)" |
| 17 | |
| 18 | mkdir -p $temp_dir/tmp/zzz |
| 19 | mkdir -p /tmp/zzz |
| 20 | |
| 21 | # prepare /bar.txt |
| 22 | echo "Hello from the inside" > "$temp_dir/tmp/bar.txt" |
| 23 | echo "Hello from the outside" > "/tmp/bar.txt" |
| 24 | |
| 25 | # prepare /zzz/foo.txt |
| 26 | mkdir -p "$temp_dir/tmp/zzz" |
| 27 | echo "Bye from the inside" > "$temp_dir/tmp/zzz/foo.txt" |
| 28 | echo "Bye from the outside" > "/tmp/zzz/foo.txt" |
| 29 | |
| 30 | # prepare file that is available only outside |
| 31 | echo "I'm outside" > "/tmp/only_outside.txt" |
| 32 | |
| 33 | # prepare pattern matching files |
| 34 | echo "bar filepath pattern" > "$temp_dir/tmp/bar.filepath" |
| 35 | echo "foo filepath pattern" > "$temp_dir/tmp/zzz/foo.filepath" |
| 36 | |
| 37 | echo "bar filename pattern" > "$temp_dir/tmp/bar.filename" |
| 38 | echo "foo filename pattern" > "$temp_dir/tmp/zzz/foo.filename" |
| 39 | result="$(mktemp)" |
| 40 | |
| 41 | set_chroot_offline_test_mode "$temp_dir" |
| 42 | $OSCAP oval eval --results $result $srcdir/test_offline_mode_textfilecontent54.xml |
| 43 | unset_chroot_offline_test_mode |
| 44 | |
| 45 | [ -s "$result" ] |
| 46 | |
| 47 | assert_exists 1 '/oval_results/results/system/oval_system_characteristics/system_data' |
| 48 | |
| 49 | tfc_item='/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:textfilecontent_item' |
| 50 | assert_exists 6 $tfc_item |
| 51 | assert_exists 3 $tfc_item'/ind-sys:path[text()="/tmp"]' |
| 52 | assert_exists 3 $tfc_item'/ind-sys:path[text()="/tmp/zzz"]' |
| 53 | |
| 54 | assert_exists 1 $tfc_item'/ind-sys:filepath[text()="/tmp/bar.txt"]' |
| 55 | assert_exists 1 $tfc_item'/ind-sys:filename[text()="bar.txt"]' |
| 56 | assert_exists 1 $tfc_item'/ind-sys:text[text()="Hello from the inside"]' |
| 57 | |
| 58 | assert_exists 1 $tfc_item'/ind-sys:filepath[text()="/tmp/zzz/foo.txt"]' |
| 59 | assert_exists 1 $tfc_item'/ind-sys:filename[text()="foo.txt"]' |
| 60 | assert_exists 1 $tfc_item'/ind-sys:text[text()="Bye from the inside"]' |
| 61 | |
| 62 | assert_exists 1 '/oval_results/results/system/definitions/definition[@definition_id="oval:x:def:3" and @result="true"]' |
| 63 | |
| 64 | assert_exists 1 $tfc_item'/ind-sys:filepath[text()="/tmp/bar.filepath"]' |
| 65 | assert_exists 1 $tfc_item'/ind-sys:filename[text()="bar.filepath"]' |
| 66 | assert_exists 1 $tfc_item'/ind-sys:text[text()="bar filepath pattern"]' |
| 67 | |
| 68 | assert_exists 1 $tfc_item'/ind-sys:filepath[text()="/tmp/zzz/foo.filepath"]' |
| 69 | assert_exists 1 $tfc_item'/ind-sys:filename[text()="foo.filepath"]' |
| 70 | assert_exists 1 $tfc_item'/ind-sys:text[text()="foo filepath pattern"]' |
| 71 | |
| 72 | assert_exists 1 '/oval_results/results/system/definitions/definition[@definition_id="oval:x:def:4" and @result="true"]' |
| 73 | assert_exists 1 '/oval_results/results/system/definitions/definition[@definition_id="oval:x:def:5" and @result="true"]' |
| 74 | |
| 75 | assert_exists 1 $tfc_item'/ind-sys:filepath[text()="/tmp/bar.filename"]' |
| 76 | assert_exists 1 $tfc_item'/ind-sys:filename[text()="bar.filename"]' |
| 77 | assert_exists 1 $tfc_item'/ind-sys:text[text()="bar filename pattern"]' |
| 78 | |
| 79 | assert_exists 1 $tfc_item'/ind-sys:filepath[text()="/tmp/zzz/foo.filename"]' |
| 80 | assert_exists 1 $tfc_item'/ind-sys:filename[text()="foo.filename"]' |
| 81 | assert_exists 1 $tfc_item'/ind-sys:text[text()="foo filename pattern"]' |
| 82 | |
| 83 | assert_exists 1 '/oval_results/results/system/definitions/definition[@definition_id="oval:x:def:6" and @result="true"]' |
| 84 | assert_exists 1 '/oval_results/results/system/definitions/definition[@definition_id="oval:x:def:7" and @result="true"]' |
| 85 | |
| 86 | rm -rf "$temp_dir" |
| 87 | rm -f "$result" |
| 88 | rm -f "/tmp/bar.txt" "/tmp/only_outside.txt" |
| 89 | rm -rf "/tmp/zzz" |
| 90 | } |
| 91 | |
| 92 | # Testing. |
| 93 | |
| 94 | test_init "test_offline_mode_textfilecontent54.log" |
| 95 | |
| 96 | test_run "test_offline_mode_textfilecontent54" test_offline_mode_textfilecontent54 |
| 97 | |
| 98 | test_exit |