| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # Copyright 2015 Red Hat Inc., Durham, North Carolina. |
| 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # OpenScap Probes Test Suite. |
| 7 | |
| 8 | . $builddir/tests/test_common.sh |
| 9 | |
| 10 | set -e -o pipefail |
| 11 | |
| 12 | function test_probes_symlink { |
| 13 | probecheck "symlink" || return 255 |
| 14 | |
| 15 | DF="test_probes_symlink.xml" |
| 16 | RF="results.xml" |
| 17 | |
| 18 | rm -f $RF |
| 19 | |
| 20 | tmpdir=$(make_temp_dir /tmp test_symlink) |
| 21 | |
| 22 | touch $tmpdir/some_file |
| 23 | touch $tmpdir/file_to_remove |
| 24 | ln -s $tmpdir/some_file $tmpdir/normal_symlink |
| 25 | ln -s $tmpdir/file_to_remove $tmpdir/broken_symlink |
| 26 | rm -f $tmpdir/file_to_remove |
| 27 | ln -s $tmpdir/circular_symlink $tmpdir/circular_symlink |
| 28 | touch $tmpdir/other_file |
| 29 | ln -s $tmpdir/other_file $tmpdir/middle_symlink |
| 30 | ln -s $tmpdir/middle_symlink $tmpdir/chained_symlink |
| 31 | |
| 32 | bash ${srcdir}/test_probes_symlink.xml.sh $tmpdir > "$DF" |
| 33 | |
| 34 | $OSCAP oval eval --results $RF $DF |
| 35 | |
| 36 | result=$RF |
| 37 | |
| 38 | p='oval_results/results/system/oval_system_characteristics/' |
| 39 | assert_exists 6 $p'collected_objects/object' |
| 40 | assert_exists 2 $p'collected_objects/object[@flag="complete"]' |
| 41 | assert_exists 2 $p'system_data/unix-sys:symlink_item' |
| 42 | assert_exists 2 $p'system_data/unix-sys:symlink_item[@status="exists"]' |
| 43 | assert_exists 1 $p'system_data/unix-sys:symlink_item/unix-sys:filepath[text()="'$tmpdir/normal_symlink'"]' |
| 44 | assert_exists 1 $p'system_data/unix-sys:symlink_item/unix-sys:canonical_path[text()="'$tmpdir'/some_file"]' |
| 45 | assert_exists 1 $p'system_data/unix-sys:symlink_item/unix-sys:filepath[text()="'$tmpdir/chained_symlink'"]' |
| 46 | assert_exists 1 $p'system_data/unix-sys:symlink_item/unix-sys:canonical_path[text()="'$tmpdir'/other_file"]' |
| 47 | assert_exists 2 $p'collected_objects/object[@flag="error"]' |
| 48 | assert_exists 2 $p'collected_objects/object[@flag="does not exist"]' |
| 49 | assert_exists 4 $p'collected_objects/object/message' |
| 50 | |
| 51 | rm -rf $tmpdir |
| 52 | rm -f $RF |
| 53 | rm -f $DF |
| 54 | } |
| 55 | |
| 56 | test_probes_symlink |