| 1 | #!/usr/bin/envscip-shell filesystem . . `/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_offline_mode_symlinkscip-shell shell shell-project 0.0.0 test_offline_mode_symlink(). { |
| 13 | probecheck "symlink" || return 255 |
| 14 | |
| 15 | DF="test_offline_mode_symlink.xml" |
| 16 | RF="offline_mode_results.xml" |
| 17 | |
| 18 | rmscip-shell system . . rm. -f $RF |
| 19 | |
| 20 | tmpdir=$(make_temp_dir /tmpscip-shell filesystem . . `/tmp`. test_offline_mode_symlink) |
| 21 | |
| 22 | touchscip-shell system . . touch. $tmpdir/some_file |
| 23 | touchscip-shell system . . touch. $tmpdir/file_to_remove |
| 24 | lnscip-shell system . . ln. -s /some_filescip-shell filesystem . . `/some_file`. $tmpdir/normal_symlink |
| 25 | lnscip-shell system . . ln. -s some_file $tmpdir/normal_symlink_relative |
| 26 | lnscip-shell system . . ln. -s /file_to_removescip-shell filesystem . . `/file_to_remove`. $tmpdir/broken_symlink |
| 27 | lnscip-shell system . . ln. -s file_to_remove $tmpdir/broken_symlink_relative |
| 28 | rmscip-shell system . . rm. -f $tmpdir/file_to_remove |
| 29 | lnscip-shell system . . ln. -s /circular_symlinkscip-shell filesystem . . `/circular_symlink`. $tmpdir/circular_symlink |
| 30 | touchscip-shell system . . touch. $tmpdir/other_file |
| 31 | lnscip-shell system . . ln. -s /other_filescip-shell filesystem . . `/other_file`. $tmpdir/middle_symlink |
| 32 | lnscip-shell system . . ln. -s /middle_symlinkscip-shell filesystem . . `/middle_symlink`. $tmpdir/chained_symlink |
| 33 | mkdirscip-shell system . . mkdir. $tmpdir/etc |
| 34 | touchscip-shell system . . touch. $tmpdir/etc/shadow |
| 35 | lnscip-shell system . . ln. -s /etc/shadowscip-shell filesystem . . `/etc/shadow`. $tmpdir/etc/passwd |
| 36 | touchscip-shell system . . touch. $tmpdir/file_in_root |
| 37 | lnscip-shell system . . ln. -s ../../../../../file_in_root $tmpdir/path_traversal_symlink |
| 38 | lnscip-shell system . . ln. -s ./some_file $tmpdir/symlink_with_dot_in_path |
| 39 | #temporary ugly solution trying to ensure that files don't exist before being created |
| 40 | rmscip-shell system . . rm. -f /tmp/symlinktargetscip-shell filesystem . . `/tmp/symlinktarget`. |
| 41 | touchscip-shell system . . touch. /tmp/symlinktargetscip-shell filesystem . . `/tmp/symlinktarget`. |
| 42 | rmscip-shell system . . rm. -f /tmp/symlinktestscip-shell filesystem . . `/tmp/symlinktest`. |
| 43 | lnscip-shell system . . ln. -s /tmp/symlinktargetscip-shell filesystem . . `/tmp/symlinktarget`. /tmp/symlinktestscip-shell filesystem . . `/tmp/symlinktest`. |
| 44 | |
| 45 | |
| 46 | |
| 47 | bashscip-shell system . . bash. ${srcdir}/test_offline_mode_symlink.xml.sh "" > "$DF" |
| 48 | |
| 49 | set_chroot_offline_test_mode "$tmpdir" |
| 50 | |
| 51 | $OSCAP oval eval --results $RF $DF |
| 52 | |
| 53 | unset_chroot_offline_test_mode |
| 54 | |
| 55 | result=$RF |
| 56 | |
| 57 | rmscip-shell system . . rm. -f $DF |
| 58 | rmscip-shell system . . rm. -f /tmp/symlinktestscip-shell filesystem . . `/tmp/symlinktest`. |
| 59 | rmscip-shell system . . rm. -f /tmp/symlinktargetscip-shell filesystem . . `/tmp/symlinktarget`. |
| 60 | rmscip-shell system . . rm. -rf $tmpdir |
| 61 | |
| 62 | p='oval_results/results/system/oval_system_characteristics/' |
| 63 | assert_exists 12 $p'collected_objects/object' |
| 64 | assert_exists 6 $p'collected_objects/object[@flag="complete"]' |
| 65 | assert_exists 6 $p'system_data/unix-sys:symlink_item' |
| 66 | assert_exists 6 $p'system_data/unix-sys:symlink_item[@status="exists"]' |
| 67 | assert_exists 1 $p'system_data/unix-sys:symlink_item/unix-sys:filepath[text()="'/normal_symlink'"]' |
| 68 | assert_exists 1 $p'system_data/unix-sys:symlink_item/unix-sys:filepath[text()="'/normal_symlink_relative'"]' |
| 69 | assert_exists 3 $p'system_data/unix-sys:symlink_item/unix-sys:canonical_path[text()="/some_file"]' |
| 70 | assert_exists 1 $p'system_data/unix-sys:symlink_item/unix-sys:filepath[text()="'/chained_symlink'"]' |
| 71 | assert_exists 1 $p'system_data/unix-sys:symlink_item/unix-sys:canonical_path[text()="/other_file"]' |
| 72 | assert_exists 1 $p'system_data/unix-sys:symlink_item/unix-sys:filepath[text()="'/etc/passwd'"]' |
| 73 | assert_exists 1 $p'system_data/unix-sys:symlink_item/unix-sys:canonical_path[text()="/etc/shadow"]' |
| 74 | assert_exists 1 $p'system_data/unix-sys:symlink_item/unix-sys:filepath[text()="'/path_traversal_symlink'"]' |
| 75 | assert_exists 1 $p'system_data/unix-sys:symlink_item/unix-sys:canonical_path[text()="/file_in_root"]' |
| 76 | assert_exists 1 $p'system_data/unix-sys:symlink_item/unix-sys:filepath[text()="'/symlink_with_dot_in_path'"]' |
| 77 | assert_exists 3 $p'collected_objects/object[@flag="error"]' |
| 78 | assert_exists 3 $p'collected_objects/object[@flag="does not exist"]' |
| 79 | assert_exists 6 $p'collected_objects/object/message' |
| 80 | |
| 81 | rmscip-shell system . . rm. -f $RF |
| 82 | |
| 83 | } |
| 84 | |
| 85 | test_init "test_offline_mode_symlink.log" |
| 86 | |
| 87 | test_run "test_offline_mode_symlink" test_offline_mode_symlink |
| 88 | |
| 89 | test_exit |
| 90 |