Debian Codegraph @

testsuite/modules.61-coll/080-access-coll.exp

raw
1 ##############################################################################
2 # Modules Revision 3.0
3 # Providing a flexible user environment
4 #
5 # File: modules.61-coll/%M%
6 # Revision: %I%
7 # First Edition: 2017/06/27
8 # Last Mod.: %U%, %G%
9 #
10 # Authors: Xavier Delaruelle, [email protected]
11 #
12 # Description: Testuite testsequence
13 # Command: savelist, save, restore, saverm, saveshow
14 # Modulefiles:
15 # Sub-Command:
16 #
17 # Comment: %C{
18 # Handling of collections when access rights to get to it
19 # does not allow it
20 # }C%
21 #
22 ##############################################################################
23
24 skip_if_quick_mode
25
26 # cannot test access if cannot change file permission
27 if {!$is_file_perms_editable} {
28 send_user "\tskipping access tests as file permissions cannot be changed\n"
29 # cannot test access if superuser privileges are in use
30 } elseif {$tcl_platform(user) eq "root"} {
31 send_user "\tskipping access tests as tests are run by superuser\n"
32 # cannot test access if restricted file permissions have no effect
33 } elseif {$is_locked_dir_file_readable && $is_locked_file_readable} {
34 send_user "\tskipping access tests as locked files or directories are still readable\n"
35 } else {
36
37 #
38 # Variables for this test
39 #
40
41 set coll_list "$coll1\n${coll1}.save\n$coll2\n$coll3\n$coll4f\n$coll6f\n$colld\ninfocmd\ninfocmdexp"
42 set coll_list_nocoll1 "${coll1}.save\n$coll2\n$coll3\n$coll4f\n$coll6f\n$colld\ninfocmd\ninfocmdexp"
43
44 if {$install_implicitdefault eq {y}} {
45 lappend ans [list unset mload]
46 lappend ans [list set __MODULES_LMALTNAME $c1lmalt]
47 lappend ans [list set t15 t15]
48 lappend ans [list set _LMFILES_ $c1lmf]
49 lappend ans [list set LOADEDMODULES $c1lm]
50 lappend ans [list set testsuite yes]
51 lappend ans [list set MODULE_VERSION "1.10"]
52 lappend ans [list set MODULEPATH $c1modpath]
53 set c1errmsg "Loading loc_rc1/1.0\nLoading load/15\nLoading verssort/1.10\nload $cdmod4\nLoading $cdmod4\nload $c1mod5\nLoading $c1mod5\nload $c1mod6\nLoading $c1mod6"
54 } else {
55 lappend ans [list unset mload]
56 lappend ans [list set __MODULES_LMALTNAME $c1lmalt]
57 lappend ans [list set t15 t15]
58 lappend ans [list set _LMFILES_ $c1lmfnodefault]
59 lappend ans [list set LOADEDMODULES $c1lmnodefault]
60 lappend ans [list set testsuite yes]
61 lappend ans [list set MODULEPATH $c1modpath]
62 lappend ans [list ERR]
63 set c1errmsg "Loading loc_rc1/1.0\nLoading load/15\n$err_nodefault'verssort'\nload $cdmod4\nLoading $cdmod4\nload $c1mod5\nLoading $c1mod5\nload $c1mod6\nLoading $c1mod6"
64 }
65
66 set pheader "$modlin $modpathre $modlin"
67 set read_msg "$error_msgs: Collection $coll1 cannot be read."
68 set save_msg "$error_msgs: Collection $coll1 cannot be saved."
69 set found_msg [err_coll_notfound $coll1]
70 set perm_msg " [couldnotopen_permdenied $coll1fp]"
71 set accessdir_msg "$error_msgs: Cannot access collection directory."
72 set permdir_msg " couldn't read directory \"$homewithcolldotmod/\": permission denied"
73 set delete_msg "$error_msgs: Collection $coll1 cannot be removed."
74 set permdel_msg " error deleting \"$coll1fp\": permission denied"
75 set rmc1errmsg [couldnotopen_nofile $coll1fp]
76 set hide_perms "ugo-rx"
77 set write_perms "ugo-w"
78
79 # set HOME to location containing collections
80 if {$verbose} {
81 send_user "\tSetup HOME = $homewithcoll\n"
82 }
83 set env(HOME) "$homewithcoll"
84
85 # backup collection that will be altered by tests
86 set coll1fpsave "${coll1fp}.save"
87 file copy -force $coll1fp $coll1fpsave
88
89
90 #
91 # Test access to collection when read access not granted on this collection
92 #
93
94 change_file_perms $coll1fp $hide_perms
95
96 testouterr_cmd "sh" "savelist -t" "OK" "[msg_named_coll]\n$coll_list_nocoll1"
97 testouterr_cmd "sh" "saveshow $coll1" "ERR" [err_permdenied $coll1fp]
98 testouterr_cmd "sh" "restore $coll1" "ERR" [err_permdenied $coll1fp]
99 testouterr_cmd "sh" "save $coll1" "OK" ""
100 testoutfile_cmd "sh" "saverm $coll1" "OK" "$coll1fp" "$rmc1errmsg"
101
102 # restore altered collection and permissions
103 file copy -force $coll1fpsave $coll1fp
104 restore_file_perms $coll1fp
105
106
107 #
108 # Test access to collection when write access not granted on this collection
109 #
110
111 change_file_perms $coll1fp $write_perms
112
113 testouterr_cmd "sh" "savelist -t" "OK" "[msg_named_coll]\n$coll_list"
114 testouterr_cmd_re "sh" "saveshow $coll1" "OK" "$modlin\n$coll1fpre:\n\n$presavedc1cont1re\n$modlin"
115 testouterr_cmd_re "sh" "restore $coll1" $ans "$c1errmsg"
116 testouterr_cmd "sh" "save $coll1" "ERR" "$save_msg\n$perm_msg"
117 testoutfile_cmd "sh" "saverm $coll1" "OK" "$coll1fp" "$rmc1errmsg"
118
119 # restore altered collection and permissions
120 file copy -force $coll1fpsave $coll1fp
121 restore_file_perms $coll1fp
122
123
124 #
125 # Test access to collection when read access not granted on its upper directory
126 #
127
128 change_file_perms $homewithcolldotmod $hide_perms
129
130 testouterr_cmd "sh" "savelist -t" "ERR" "$accessdir_msg\n$permdir_msg"
131 # different result if a file in a locked directory still readable on this system
132 if {$is_locked_dir_file_readable} {
133 testouterr_cmd_re "sh" "saveshow $coll1" "OK" "$modlin\n$coll1fpre:\n\n$presavedc1cont1re\n$modlin"
134 testouterr_cmd_re "sh" "restore $coll1" $ans "$c1errmsg"
135 testouterr_cmd "sh" "save $coll1" "OK" ""
136 testoutfile_cmd "sh" "saverm $coll1" "OK" "$coll1fp" "$rmc1errmsg"
137 } else {
138 testouterr_cmd "sh" "saveshow $coll1" "ERR" "$found_msg"
139 testouterr_cmd "sh" "restore $coll1" "ERR" "$found_msg"
140 testouterr_cmd "sh" "save $coll1" "ERR" "$save_msg\n$perm_msg"
141 testouterr_cmd "sh" "saverm $coll1" "ERR" "$found_msg"
142 }
143
144 # restore altered collection and permissions
145 restore_file_perms $homewithcolldotmod
146 file copy -force $coll1fpsave $coll1fp
147
148
149 #
150 # Test access to collection when write access not granted on its upper directory
151 #
152
153 change_file_perms $homewithcolldotmod $write_perms
154
155 testouterr_cmd "sh" "savelist -t" "OK" "[msg_named_coll]\n$coll_list"
156 testouterr_cmd_re "sh" "saveshow $coll1" "OK" "$modlin\n$coll1fpre:\n\n$presavedc1cont1re\n$modlin"
157 testouterr_cmd_re "sh" "restore $coll1" $ans "$c1errmsg"
158 testouterr_cmd "sh" "save $coll1" "OK" ""
159 # different result if a file in a locked directory still readable on this system
160 if {$is_locked_dir_file_readable} {
161 testoutfile_cmd "sh" "saverm $coll1" "OK" "$coll1fp" "$rmc1errmsg"
162 } else {
163 testouterr_cmd "sh" "saverm $coll1" "ERR" "$delete_msg\n$permdel_msg"
164 }
165
166 # restore altered collection and permissions
167 restore_file_perms $homewithcolldotmod
168 file copy -force $coll1fpsave $coll1fp
169
170
171 #
172 # Cleanup
173 #
174
175 # remove collection backup
176 file delete $coll1fpsave
177
178 reset_test_env
179
180 }