Debian Codegraph @

testsuite/modules.80-deep/080-access-deep.exp

raw
1 ##############################################################################
2 # Modules Revision 3.0
3 # Providing a flexible user environment
4 #
5 # File: modules.20-locate/%M%
6 # Revision: %I%
7 # First Edition: 2017/04/23
8 # Last Mod.: %U%, %G%
9 #
10 # Authors: Xavier Delaruelle, [email protected]
11 #
12 # Description: Testuite testsequence
13 # Command: load, display, whatis, avail
14 # Modulefiles:
15 # Sub-Command:
16 #
17 # Comment: %C{
18 # Localization of deep modulefile 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 # do not consider built cache files (if any) to find available modules
38 ignore_modulecache_if_built
39
40 # ensure avail tests are made using in depth mode
41 setenv_var MODULES_AVAIL_INDEPTH 1
42
43 # ensure regular avail search match is set for these tests
44 setenv_var MODULES_SEARCH_MATCH starts_with
45
46 #
47 # Variables for this test
48 #
49
50 set m1 "modalias/dir1/1.0"
51 set lm1 "$m1"
52 set lmf1 "$modpath/$lm1"
53 set m2 "modalias/dir1/2.0"
54 set lm2 "modalias/dir2/2.0"
55 set lmf2 "$modpath/$lm2"
56 set m3 "modload/dir2/md1"
57 set lm3 "modload/dir2/1.0"
58 set lmf3 "$modpath/$lm3"
59 set m4 "moddef"
60 set lm4 "moddef/dir2/1.0"
61 set lmf4 "$modpath/$lm4"
62 set m5 "plain/dir2"
63 set lm5 "$m5/2.0"
64 set lmf5 "$modpath/$lm5"
65 set rlm5 "$m5/1.0"
66 set rlmf5 "$modpath/$rlm5"
67 set rlmfre5 "$modpathre/$rlm5"
68 set m6 "plain/dir2"
69 set lm6 "$m6/1.0"
70 set lmf6 "$modpath/$lm6"
71 set m7 "modalias"
72 set lm7 "$m7/3.0"
73 set lmf7 "$modpath/$lm7"
74 set m8 "$m2"
75 set lmrc8 "$modpath/modalias/dir1/.modulerc"
76 set m9 "$m3"
77 set lmrc9 "$modpath/modload/dir2/.modulerc"
78 set m10 "$m4"
79 set lmrc10 "$modpath/moddef/dir2/.modulerc"
80 set rlm10 "$m10/dir2/2.0"
81 set rlmf10 "$modpath/$rlm10"
82 set rlmfre10 "$modpathre/$rlm10"
83 set m12 "$m1"
84 set lmd12 [file dirname $lmf1]
85 set m13 "$m2"
86 set lmd13 [file dirname $lmf2]
87 set m14 "$m3"
88 set lmd14 [file dirname $lmf3]
89 set m15 "$m4"
90 set lmd15 [file dirname $lmf4]
91 set m16 "$m5"
92 set lmd16 [file dirname $lmf5]
93 set m17 "$m13"
94 set lmd17 [file dirname $lmd13]
95 set m18 "$m15"
96 set lmd18 [file dirname $lmd15]
97 set m19 "modvirt/dir1/1.0"
98 set lmd19 "$modpath/modvirt/.common"
99 set m20 "modvirt/dir1/2.0"
100 set m21 "modsym"
101 set lm21 "$m21/dir2/2.0"
102 set lmf21 "$modpath/$lm21"
103 set lmfre21 "$modpathre/$lm21"
104 set lmfh21 "$modpath/$m21/dir1/1.0"
105
106 set pheader "$modlin $modpathre $modlin"
107 set theader "$modpathre:"
108 set access_msg "$error_msgs: Permission denied on"
109 set hide_perms "ugo-rx"
110
111 #
112 # Test access to modulefile when access not granted on this modulefile
113 #
114
115 change_file_perms $lmf1 $hide_perms
116
117 testouterr_cmd "sh" "load $m1" "ERR" "$access_msg '$lmf1'"
118 testouterr_cmd "sh" "display $m1" "ERR" "$access_msg '$lmf1'"
119 testouterr_cmd "sh" "whatis $m1" "ERR" "$access_msg '$lmf1'"
120 testouterr_cmd "sh" "avail -t $m1" "OK" ""
121
122 restore_file_perms $lmf1
123
124 #
125 # Test access to alias when access not granted on target modulefile
126 #
127
128 change_file_perms $lmf2 $hide_perms
129
130 testouterr_cmd "sh" "load $m2" "ERR" "$access_msg '$lmf2'"
131 testouterr_cmd "sh" "display $m2" "ERR" "$access_msg '$lmf2'"
132 testouterr_cmd "sh" "whatis $m2" "ERR" "$access_msg '$lmf2'"
133 # alias defined so it appears even if access to target modulefile is denied
134 testouterr_cmd_re "sh" "avail -t $m2" "OK" "$theader\n$m2\\(@\\)"
135
136 restore_file_perms $lmf2
137
138 #
139 # Test access to symbol when access not granted on target modulefile
140 #
141
142 change_file_perms $lmf3 $hide_perms
143
144 testouterr_cmd "sh" "load $m3" "ERR" "$access_msg '$lmf3'"
145 testouterr_cmd "sh" "display $m3" "ERR" "$access_msg '$lmf3'"
146 testouterr_cmd "sh" "whatis $m3" "ERR" "$access_msg '$lmf3'"
147 # symbol is attached to the modulefile so it does not appear if the access
148 # to the target modulefile is denied
149 testouterr_cmd "sh" "avail -t $m3" "OK" ""
150
151 restore_file_perms $lmf3
152
153 #
154 # Test access to default symbol when access not granted on target modulefile
155 #
156
157 change_file_perms $lmf4 $hide_perms
158
159 # shout error as if we were trying to access the symbol directly
160 testouterr_cmd "sh" "load $m4" "ERR" [if_implicitdefault "$access_msg '$lmf4'" "$err_nodefault'$m4'"]
161 testouterr_cmd "sh" "display $m4" "ERR" [if_implicitdefault "$access_msg '$lmf4'" "$err_nodefault'$m4'"]
162 # no error on whatis/avail, other versions are listed
163 testouterr_cmd_re "sh" "whatis $m4" "OK" "$pheader\n\\s+$m4/dir2/2.0: $m4/dir2/2.0"
164 testouterr_cmd_re "sh" "avail -t $m4" "OK" "$theader\n$m4/dir2/2.0"
165
166 restore_file_perms $lmf4
167
168 #
169 # Test access to implicit default modulefile when access not granted on target
170 # modulefile
171 #
172
173 change_file_perms $lmf5 $hide_perms
174
175 lappend ans [list set TEST $rlm5]
176 if {[is_conf_enabled advversspec implicitdefault]} {
177 lappend ans [list set __MODULES_LMALTNAME $rlm5&as|plain/default&as|plain/latest&as|$m5/default&as|$m5/latest]
178 }
179 lappend ans [list set __MODULES_LMCONFLICT "$rlm5&$m5"]
180 lappend ans [list set _LMFILES_ $rlmf5]
181 lappend ans [list set LOADEDMODULES $rlm5]
182
183 # another implicit default is chosen
184 testouterr_cmd "sh" "load $m5" [if_implicitdefault $ans ERR] [if_implicitdefault {} "$err_nodefault'$m5'"]
185 testouterr_cmd_re "sh" "display $m5" [if_implicitdefault OK ERR] [if_implicitdefault "$modlin\n$rlmfre5:\n\nmodule-whatis\t$rlm5\nconflict\tplain/dir2\nsetenv\t\tTEST $rlm5\n$modlin" "$err_nodefault'$m5'"]
186 testouterr_cmd_re "sh" "whatis $m5" "OK" "$pheader\n\\s+$rlm5: $rlm5"
187 testouterr_cmd_re "sh" "avail -t $m5" "OK" "$theader\n$rlm5"
188
189 # keep file permissions as it is for next test
190
191 #
192 # Test access to implicit default modulefile when access not granted on target
193 # modulefile and there is no other implicit default available
194 #
195
196 change_file_perms $lmf6 $hide_perms
197
198 # nothing found
199 testouterr_cmd "sh" "load $m6" "ERR" "$err_path'$m6'"
200 testouterr_cmd "sh" "display $m6" "ERR" "$err_path'$m6'"
201 testouterr_cmd "sh" "whatis $m6" "ERR" "$err_path'$m6'"
202 testouterr_cmd "sh" "avail -t $m6" "OK" ""
203
204 restore_file_perms $lmf6
205 restore_file_perms $lmf5
206
207 #
208 # Test access to implicit default alias when access not granted on target modulefile
209 #
210
211 change_file_perms $lmf7 $hide_perms
212
213 # shout error as if we were trying to access the alias directly
214 testouterr_cmd "sh" "load $m7" "ERR" [if_implicitdefault "$access_msg '$lmf7'" "$err_nodefault'$m7'"]
215 testouterr_cmd "sh" "display $m7" "ERR" [if_implicitdefault "$access_msg '$lmf7'" "$err_nodefault'$m7'"]
216 # no error on whatis/avail, other versions are listed
217 testouterr_cmd_re "sh" "whatis $m7" "OK" "$pheader\n\\s+$m7/dir1/1.0: $m7/dir1/1.0\n\\s+$m7/dir2/2.0: $m7/dir2/2.0"
218 # alias defined so it appears even if access to target modulefile is denied
219 testouterr_cmd_re "sh" "avail -t $m7" "OK" "$theader\n$m7/1.0\\(@\\)\n$m7/dir1/1.0\n$m7/dir1/2.0\\(@\\)\n$m7/dir2/2.0\n$m7/dir2/3.0\\(@\\)"
220
221 restore_file_perms $lmf7
222
223 #
224 # Test access to alias when access not granted on modulerc defining it
225 #
226
227 change_file_perms $lmrc8 $hide_perms
228
229 # cannot locate module
230 testouterr_cmd "sh" "load $m8" "ERR" "$err_path'$m8'"
231 testouterr_cmd "sh" "display $m8" "ERR" "$err_path'$m8'"
232 testouterr_cmd "sh" "whatis $m8" "ERR" "$err_path'$m8'"
233 testouterr_cmd "sh" "avail -t $m8" "OK" ""
234
235 restore_file_perms $lmrc8
236
237 #
238 # Test access to symbol when access not granted on modulerc defining it
239 #
240
241 change_file_perms $lmrc9 $hide_perms
242
243 # cannot locate module
244 testouterr_cmd "sh" "load $m9" "ERR" "$err_path'$m9'"
245 testouterr_cmd "sh" "display $m9" "ERR" "$err_path'$m9'"
246 testouterr_cmd "sh" "whatis $m9" "ERR" "$err_path'$m9'"
247 testouterr_cmd "sh" "avail -t $m9" "OK" ""
248
249 restore_file_perms $lmrc9
250
251 #
252 # Test access to default symbol when access not granted on modulerc defining it
253 #
254
255 change_file_perms $lmrc10 $hide_perms
256
257 set ans [list]
258 lappend ans [list set TEST $rlm10]
259 if {[is_conf_enabled advversspec implicitdefault]} {
260 lappend ans [list set __MODULES_LMALTNAME $rlm10&as|moddef/default&as|moddef/latest&as|moddef/dir2/default&as|moddef/dir2/latest]
261 }
262 lappend ans [list set _LMFILES_ $rlmf10]
263 lappend ans [list set LOADEDMODULES $rlm10]
264
265 # another implicit default is chosen
266 testouterr_cmd "sh" "load $m10" [if_implicitdefault $ans ERR] [if_implicitdefault {} "$err_nodefault'$m10'"]
267 testouterr_cmd_re "sh" "display $m10" [if_implicitdefault OK ERR] [if_implicitdefault "$modlin\n$rlmfre10:\n\nmodule-whatis\t$rlm10\nsetenv\t\tTEST $rlm10\n$modlin" "$err_nodefault'$m10'"]
268 testouterr_cmd_re "sh" "whatis $m10" "OK" "$pheader\n\\s+$m10/dir2/1.0: $m10/dir2/1.0\n\\s+$m10/dir2/2.0: $m10/dir2/2.0"
269 testouterr_cmd_re "sh" "avail -t $m10" "OK" "$theader\n$m10/dir2/1.0\n$m10/dir2/2.0"
270
271 restore_file_perms $lmrc10
272
273 #
274 # Test access to modulefile when access not granted on its upper directory
275 #
276
277 change_file_perms $lmd12 $hide_perms
278
279 # cannot locate module
280 testouterr_cmd "sh" "load $m12" "ERR" "$err_path'$m12'"
281 testouterr_cmd "sh" "display $m12" "ERR" "$err_path'$m12'"
282 testouterr_cmd "sh" "whatis $m12" "ERR" "$err_path'$m12'"
283 testouterr_cmd "sh" "avail -t $m12" "OK" ""
284
285 restore_file_perms $lmd12
286
287 #
288 # Test access to alias when access not granted on its upper directory
289 #
290
291 change_file_perms $lmd13 $hide_perms
292
293 # cannot locate module
294 testouterr_cmd "sh" "load $m13" "ERR" "$err_path'$lm2'"
295 testouterr_cmd "sh" "display $m13" "ERR" "$err_path'$lm2'"
296 testouterr_cmd "sh" "whatis $m13" "ERR" "$err_path'$lm2'"
297 testouterr_cmd_re "sh" "avail -t $m13" "OK" "$theader\n$m13\\(@\\)"
298
299 restore_file_perms $lmd13
300
301 #
302 # Test access to symbol when access not granted on its upper directory
303 #
304
305 change_file_perms $lmd14 $hide_perms
306
307 # cannot locate module
308 testouterr_cmd "sh" "load $m14" "ERR" "$err_path'$m14'"
309 testouterr_cmd "sh" "display $m14" "ERR" "$err_path'$m14'"
310 testouterr_cmd "sh" "whatis $m14" "ERR" "$err_path'$m14'"
311 testouterr_cmd "sh" "avail -t $m14" "OK" ""
312
313 restore_file_perms $lmd14
314
315 #
316 # Test access to default symbol when access not granted on its upper directory
317 #
318
319 change_file_perms $lmd15 $hide_perms
320
321 # permission denied on sub-directory, so cannot locate module
322 testouterr_cmd "sh" "load $m15" "ERR" "$err_path'$m15'"
323 testouterr_cmd "sh" "display $m15" "ERR" "$err_path'$m15'"
324 testouterr_cmd "sh" "whatis $m15" "ERR" "$err_path'$m15'"
325 testouterr_cmd "sh" "avail -t $m15" "OK" ""
326
327 restore_file_perms $lmd15
328
329 #
330 # Test access to implicit default modulefile when access not granted on its
331 # upper directory
332 #
333
334 change_file_perms $lmd16 $hide_perms
335
336 # permission denied on directory
337 testouterr_cmd "sh" "load $m16" "ERR" "$access_msg '$lmd16'"
338 testouterr_cmd "sh" "display $m16" "ERR" "$access_msg '$lmd16'"
339 testouterr_cmd "sh" "whatis $m16" "ERR" "$access_msg '$lmd16'"
340 testouterr_cmd "sh" "avail -t $m16" "OK" ""
341
342 restore_file_perms $lmd16
343
344 #
345 # Test access to alias when access not granted on its top upper directory
346 #
347
348 change_file_perms $lmd17 $hide_perms
349
350 # cannot locate module
351 testouterr_cmd "sh" "load $m17" "ERR" "$err_path'$m17'"
352 testouterr_cmd "sh" "display $m17" "ERR" "$err_path'$m17'"
353 testouterr_cmd "sh" "whatis $m17" "ERR" "$err_path'$m17'"
354 testouterr_cmd "sh" "avail -t $m17" "OK" ""
355
356 restore_file_perms $lmd17
357
358 #
359 # Test access to default symbol when access not granted on its top upper directory
360 #
361
362 change_file_perms $lmd18 $hide_perms
363
364 # permission denied on directory
365 testouterr_cmd "sh" "load $m18" "ERR" "$access_msg '$lmd18'"
366 testouterr_cmd "sh" "display $m18" "ERR" "$access_msg '$lmd18'"
367 testouterr_cmd "sh" "whatis $m18" "ERR" "$access_msg '$lmd18'"
368 testouterr_cmd "sh" "avail -t $m18" "OK" ""
369
370 restore_file_perms $lmd18
371
372 #
373 # Test access to virtual module when access not granted on its target file
374 # lying in upper directory
375 #
376
377 change_file_perms $lmd19 $hide_perms
378
379 # permission denied on virtual target file
380 testouterr_cmd "sh" "load $m19" "ERR" "$access_msg '$lmd19'"
381 testouterr_cmd "sh" "display $m19" "ERR" "$access_msg '$lmd19'"
382 testouterr_cmd "sh" "whatis $m19" "ERR" "$access_msg '$lmd19'"
383 testouterr_cmd "sh" "avail -t $m19" "OK" ""
384
385 #
386 # Test access to alias when access not granted on its virtual module target
387 # lying in upper directory
388 #
389
390 # permission denied on virtual target file
391 testouterr_cmd "sh" "load $m20" "ERR" "$access_msg '$lmd19'"
392 testouterr_cmd "sh" "display $m20" "ERR" "$access_msg '$lmd19'"
393 testouterr_cmd "sh" "whatis $m20" "ERR" "$access_msg '$lmd19'"
394 # alias defined so it appears even if access to target modulefile is denied
395 testouterr_cmd_re "sh" "avail -t $m20" "OK" "$theader\n$m20\\(@\\)"
396
397 restore_file_perms $lmd19
398
399
400 #
401 # Test access to implicit default modulefile when access not granted on sibbling
402 # modulefile leading to removing sibbling directory
403 #
404
405 change_file_perms $lmfh21 $hide_perms
406
407 set ans [list]
408 lappend ans [list set TEST $lm21]
409 if {[is_conf_enabled advversspec implicitdefault]} {
410 lappend ans [list set __MODULES_LMALTNAME "$lm21&modsym/dir2/3.0&as|modsym/default&as|modsym/latest&as|modsym/dir2/default&as|modsym/dir2/latest"]
411 } else {
412 lappend ans [list set __MODULES_LMALTNAME "$lm21&modsym/dir2/3.0"]
413 }
414 lappend ans [list set __MODULES_LMCONFLICT "$lm21&$m21"]
415 lappend ans [list set _LMFILES_ $lmf21]
416 lappend ans [list set LOADEDMODULES $lm21]
417
418 # implicit default is not impacted
419 testouterr_cmd "sh" "load $m21" [if_implicitdefault $ans ERR] [if_implicitdefault {} "$err_nodefault'$m21'"]
420 testouterr_cmd_re "sh" "display $m21" [if_implicitdefault OK ERR] [if_implicitdefault "$modlin\n$lmfre21:\n\nmodule-whatis\t$lm21\nconflict\t$m21\nsetenv\t\tTEST $lm21\n$modlin" "$err_nodefault'$m21'"]
421 testouterr_cmd_re "sh" "whatis $m21" "OK" "$pheader\n\\s+$lm21: $lm21"
422 testouterr_cmd_re "sh" "avail -t $m21" "OK" "$theader\n$lm21\\(3.0\\)"
423
424 restore_file_perms $lmfh21
425
426
427 #
428 # Cleanup
429 #
430
431 reset_test_env
432
433 }