Debian Codegraph @

tests/probes/symlink/test_offline_mode_symlink.sh

raw symbols SCIP
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_offline_mode_symlink {
13 probecheck "symlink" || return 255
14
15 DF="test_offline_mode_symlink.xml"
16 RF="offline_mode_results.xml"
17
18 rm -f $RF
19
20 tmpdir=$(make_temp_dir /tmp test_offline_mode_symlink)
21
22 touch $tmpdir/some_file
23 touch $tmpdir/file_to_remove
24 ln -s /some_file $tmpdir/normal_symlink
25 ln -s some_file $tmpdir/normal_symlink_relative
26 ln -s /file_to_remove $tmpdir/broken_symlink
27 ln -s file_to_remove $tmpdir/broken_symlink_relative
28 rm -f $tmpdir/file_to_remove
29 ln -s /circular_symlink $tmpdir/circular_symlink
30 touch $tmpdir/other_file
31 ln -s /other_file $tmpdir/middle_symlink
32 ln -s /middle_symlink $tmpdir/chained_symlink
33 mkdir $tmpdir/etc
34 touch $tmpdir/etc/shadow
35 ln -s /etc/shadow $tmpdir/etc/passwd
36 touch $tmpdir/file_in_root
37 ln -s ../../../../../file_in_root $tmpdir/path_traversal_symlink
38 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 rm -f /tmp/symlinktarget
41 touch /tmp/symlinktarget
42 rm -f /tmp/symlinktest
43 ln -s /tmp/symlinktarget /tmp/symlinktest
44
45
46
47 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 rm -f $DF
58 rm -f /tmp/symlinktest
59 rm -f /tmp/symlinktarget
60 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 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