File: 080-access-deep.exp

package info (click to toggle)
modules 5.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 23,036 kB
  • sloc: exp: 79,659; sh: 6,142; tcl: 5,900; makefile: 1,493; ansic: 474; python: 265; csh: 202; perl: 47; ruby: 44; lisp: 13
file content (433 lines) | stat: -rw-r--r-- 14,010 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
##############################################################################
#   Modules Revision 3.0
#   Providing a flexible user environment
#
#   File:		modules.20-locate/%M%
#   Revision:		%I%
#   First Edition:	2017/04/23
#   Last Mod.:		%U%, %G%
#
#   Authors:		Xavier Delaruelle, xavier.delaruelle@cea.fr
#
#   Description:	Testuite testsequence
#   Command:		load, display, whatis, avail
#   Modulefiles:
#   Sub-Command:
#
#   Comment:	%C{
#			Localization of deep modulefile when access rights to get to it
#           does not allow it
#		}C%
#
##############################################################################

skip_if_quick_mode

# cannot test access if cannot change file permission
if {!$is_file_perms_editable} {
    send_user "\tskipping access tests as file permissions cannot be changed\n"
# cannot test access if superuser privileges are in use
} elseif {$tcl_platform(user) eq "root"} {
    send_user "\tskipping access tests as tests are run by superuser\n"
# cannot test access if restricted file permissions have no effect
} elseif {$is_locked_dir_file_readable && $is_locked_file_readable} {
    send_user "\tskipping access tests as locked files or directories are still readable\n"
} else {

# do not consider built cache files (if any) to find available modules
ignore_modulecache_if_built

# ensure avail tests are made using in depth mode
setenv_var MODULES_AVAIL_INDEPTH 1

# ensure regular avail search match is set for these tests
setenv_var MODULES_SEARCH_MATCH starts_with

#
# Variables for this test
#

set m1 "modalias/dir1/1.0"
set lm1 "$m1"
set lmf1 "$modpath/$lm1"
set m2 "modalias/dir1/2.0"
set lm2 "modalias/dir2/2.0"
set lmf2 "$modpath/$lm2"
set m3 "modload/dir2/md1"
set lm3 "modload/dir2/1.0"
set lmf3 "$modpath/$lm3"
set m4 "moddef"
set lm4 "moddef/dir2/1.0"
set lmf4 "$modpath/$lm4"
set m5 "plain/dir2"
set lm5 "$m5/2.0"
set lmf5 "$modpath/$lm5"
set rlm5 "$m5/1.0"
set rlmf5 "$modpath/$rlm5"
set rlmfre5 "$modpathre/$rlm5"
set m6 "plain/dir2"
set lm6 "$m6/1.0"
set lmf6 "$modpath/$lm6"
set m7 "modalias"
set lm7 "$m7/3.0"
set lmf7 "$modpath/$lm7"
set m8 "$m2"
set lmrc8 "$modpath/modalias/dir1/.modulerc"
set m9 "$m3"
set lmrc9 "$modpath/modload/dir2/.modulerc"
set m10 "$m4"
set lmrc10 "$modpath/moddef/dir2/.modulerc"
set rlm10 "$m10/dir2/2.0"
set rlmf10 "$modpath/$rlm10"
set rlmfre10 "$modpathre/$rlm10"
set m12 "$m1"
set lmd12 [file dirname $lmf1]
set m13 "$m2"
set lmd13 [file dirname $lmf2]
set m14 "$m3"
set lmd14 [file dirname $lmf3]
set m15 "$m4"
set lmd15 [file dirname $lmf4]
set m16 "$m5"
set lmd16 [file dirname $lmf5]
set m17 "$m13"
set lmd17 [file dirname $lmd13]
set m18 "$m15"
set lmd18 [file dirname $lmd15]
set m19 "modvirt/dir1/1.0"
set lmd19 "$modpath/modvirt/.common"
set m20 "modvirt/dir1/2.0"
set m21 "modsym"
set lm21 "$m21/dir2/2.0"
set lmf21 "$modpath/$lm21"
set lmfre21 "$modpathre/$lm21"
set lmfh21 "$modpath/$m21/dir1/1.0"

set pheader "$modlin $modpathre $modlin"
set theader "$modpathre:"
set access_msg "$error_msgs: Permission denied on"
set hide_perms "ugo-rx"

#
# Test access to modulefile when access not granted on this modulefile
#

change_file_perms $lmf1 $hide_perms

testouterr_cmd "sh" "load $m1" "ERR" "$access_msg '$lmf1'"
testouterr_cmd "sh" "display $m1" "ERR" "$access_msg '$lmf1'"
testouterr_cmd "sh" "whatis $m1" "ERR" "$access_msg '$lmf1'"
testouterr_cmd "sh" "avail -t $m1" "OK" ""

restore_file_perms $lmf1

#
# Test access to alias when access not granted on target modulefile
#

change_file_perms $lmf2 $hide_perms

testouterr_cmd "sh" "load $m2" "ERR" "$access_msg '$lmf2'"
testouterr_cmd "sh" "display $m2" "ERR" "$access_msg '$lmf2'"
testouterr_cmd "sh" "whatis $m2" "ERR" "$access_msg '$lmf2'"
# alias defined so it appears even if access to target modulefile is denied
testouterr_cmd_re "sh" "avail -t $m2" "OK" "$theader\n$m2\\(@\\)"

restore_file_perms $lmf2

#
# Test access to symbol when access not granted on target modulefile
#

change_file_perms $lmf3 $hide_perms

testouterr_cmd "sh" "load $m3" "ERR" "$access_msg '$lmf3'"
testouterr_cmd "sh" "display $m3" "ERR" "$access_msg '$lmf3'"
testouterr_cmd "sh" "whatis $m3" "ERR" "$access_msg '$lmf3'"
# symbol is attached to the modulefile so it does not appear if the access
# to the target modulefile is denied
testouterr_cmd "sh" "avail -t $m3" "OK" ""

restore_file_perms $lmf3

#
# Test access to default symbol when access not granted on target modulefile
#

change_file_perms $lmf4 $hide_perms

# shout error as if we were trying to access the symbol directly
testouterr_cmd "sh" "load $m4" "ERR" [if_implicitdefault "$access_msg '$lmf4'" "$err_nodefault'$m4'"]
testouterr_cmd "sh" "display $m4" "ERR" [if_implicitdefault "$access_msg '$lmf4'" "$err_nodefault'$m4'"]
# no error on whatis/avail, other versions are listed
testouterr_cmd_re "sh" "whatis $m4" "OK" "$pheader\n\\s+$m4/dir2/2.0: $m4/dir2/2.0"
testouterr_cmd_re "sh" "avail -t $m4" "OK" "$theader\n$m4/dir2/2.0"

restore_file_perms $lmf4

#
# Test access to implicit default modulefile when access not granted on target
# modulefile
#

change_file_perms $lmf5 $hide_perms

lappend ans [list set TEST $rlm5]
if {[is_conf_enabled advversspec implicitdefault]} {
    lappend ans [list set __MODULES_LMALTNAME $rlm5&as|plain/default&as|plain/latest&as|$m5/default&as|$m5/latest]
}
lappend ans [list set __MODULES_LMCONFLICT "$rlm5&$m5"]
lappend ans [list set _LMFILES_ $rlmf5]
lappend ans [list set LOADEDMODULES $rlm5]

# another implicit default is chosen
testouterr_cmd "sh" "load $m5" [if_implicitdefault $ans ERR] [if_implicitdefault {} "$err_nodefault'$m5'"]
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'"]
testouterr_cmd_re "sh" "whatis $m5" "OK" "$pheader\n\\s+$rlm5: $rlm5"
testouterr_cmd_re "sh" "avail -t $m5" "OK" "$theader\n$rlm5"

# keep file permissions as it is for next test

#
# Test access to implicit default modulefile when access not granted on target
# modulefile and there is no other implicit default available
#

change_file_perms $lmf6 $hide_perms

# nothing found
testouterr_cmd "sh" "load $m6" "ERR" "$err_path'$m6'"
testouterr_cmd "sh" "display $m6" "ERR" "$err_path'$m6'"
testouterr_cmd "sh" "whatis $m6" "ERR" "$err_path'$m6'"
testouterr_cmd "sh" "avail -t $m6" "OK" ""

restore_file_perms $lmf6
restore_file_perms $lmf5

#
# Test access to implicit default alias when access not granted on target modulefile
#

change_file_perms $lmf7 $hide_perms

# shout error as if we were trying to access the alias directly
testouterr_cmd "sh" "load $m7" "ERR" [if_implicitdefault "$access_msg '$lmf7'" "$err_nodefault'$m7'"]
testouterr_cmd "sh" "display $m7" "ERR" [if_implicitdefault "$access_msg '$lmf7'" "$err_nodefault'$m7'"]
# no error on whatis/avail, other versions are listed
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"
# alias defined so it appears even if access to target modulefile is denied
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\\(@\\)"

restore_file_perms $lmf7

#
# Test access to alias when access not granted on modulerc defining it
#

change_file_perms $lmrc8 $hide_perms

# cannot locate module
testouterr_cmd "sh" "load $m8" "ERR" "$err_path'$m8'"
testouterr_cmd "sh" "display $m8" "ERR" "$err_path'$m8'"
testouterr_cmd "sh" "whatis $m8" "ERR" "$err_path'$m8'"
testouterr_cmd "sh" "avail -t $m8" "OK" ""

restore_file_perms $lmrc8

#
# Test access to symbol when access not granted on modulerc defining it
#

change_file_perms $lmrc9 $hide_perms

# cannot locate module
testouterr_cmd "sh" "load $m9" "ERR" "$err_path'$m9'"
testouterr_cmd "sh" "display $m9" "ERR" "$err_path'$m9'"
testouterr_cmd "sh" "whatis $m9" "ERR" "$err_path'$m9'"
testouterr_cmd "sh" "avail -t $m9" "OK" ""

restore_file_perms $lmrc9

#
# Test access to default symbol when access not granted on modulerc defining it
#

change_file_perms $lmrc10 $hide_perms

set ans [list]
lappend ans [list set TEST $rlm10]
if {[is_conf_enabled advversspec implicitdefault]} {
    lappend ans [list set __MODULES_LMALTNAME $rlm10&as|moddef/default&as|moddef/latest&as|moddef/dir2/default&as|moddef/dir2/latest]
}
lappend ans [list set _LMFILES_ $rlmf10]
lappend ans [list set LOADEDMODULES $rlm10]

# another implicit default is chosen
testouterr_cmd "sh" "load $m10" [if_implicitdefault $ans ERR] [if_implicitdefault {} "$err_nodefault'$m10'"]
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'"]
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"
testouterr_cmd_re "sh" "avail -t $m10" "OK" "$theader\n$m10/dir2/1.0\n$m10/dir2/2.0"

restore_file_perms $lmrc10

#
# Test access to modulefile when access not granted on its upper directory
#

change_file_perms $lmd12 $hide_perms

# cannot locate module
testouterr_cmd "sh" "load $m12" "ERR" "$err_path'$m12'"
testouterr_cmd "sh" "display $m12" "ERR" "$err_path'$m12'"
testouterr_cmd "sh" "whatis $m12" "ERR" "$err_path'$m12'"
testouterr_cmd "sh" "avail -t $m12" "OK" ""

restore_file_perms $lmd12

#
# Test access to alias when access not granted on its upper directory
#

change_file_perms $lmd13 $hide_perms

# cannot locate module
testouterr_cmd "sh" "load $m13" "ERR" "$err_path'$lm2'"
testouterr_cmd "sh" "display $m13" "ERR" "$err_path'$lm2'"
testouterr_cmd "sh" "whatis $m13" "ERR" "$err_path'$lm2'"
testouterr_cmd_re "sh" "avail -t $m13" "OK" "$theader\n$m13\\(@\\)"

restore_file_perms $lmd13

#
# Test access to symbol when access not granted on its upper directory
#

change_file_perms $lmd14 $hide_perms

# cannot locate module
testouterr_cmd "sh" "load $m14" "ERR" "$err_path'$m14'"
testouterr_cmd "sh" "display $m14" "ERR" "$err_path'$m14'"
testouterr_cmd "sh" "whatis $m14" "ERR" "$err_path'$m14'"
testouterr_cmd "sh" "avail -t $m14" "OK" ""

restore_file_perms $lmd14

#
# Test access to default symbol when access not granted on its upper directory
#

change_file_perms $lmd15 $hide_perms

# permission denied on sub-directory, so cannot locate module
testouterr_cmd "sh" "load $m15" "ERR" "$err_path'$m15'"
testouterr_cmd "sh" "display $m15" "ERR" "$err_path'$m15'"
testouterr_cmd "sh" "whatis $m15" "ERR" "$err_path'$m15'"
testouterr_cmd "sh" "avail -t $m15" "OK" ""

restore_file_perms $lmd15

#
# Test access to implicit default modulefile when access not granted on its
# upper directory
#

change_file_perms $lmd16 $hide_perms

# permission denied on directory
testouterr_cmd "sh" "load $m16" "ERR" "$access_msg '$lmd16'"
testouterr_cmd "sh" "display $m16" "ERR" "$access_msg '$lmd16'"
testouterr_cmd "sh" "whatis $m16" "ERR" "$access_msg '$lmd16'"
testouterr_cmd "sh" "avail -t $m16" "OK" ""

restore_file_perms $lmd16

#
# Test access to alias when access not granted on its top upper directory
#

change_file_perms $lmd17 $hide_perms

# cannot locate module
testouterr_cmd "sh" "load $m17" "ERR" "$err_path'$m17'"
testouterr_cmd "sh" "display $m17" "ERR" "$err_path'$m17'"
testouterr_cmd "sh" "whatis $m17" "ERR" "$err_path'$m17'"
testouterr_cmd "sh" "avail -t $m17" "OK" ""

restore_file_perms $lmd17

#
# Test access to default symbol when access not granted on its top upper directory
#

change_file_perms $lmd18 $hide_perms

# permission denied on directory
testouterr_cmd "sh" "load $m18" "ERR" "$access_msg '$lmd18'"
testouterr_cmd "sh" "display $m18" "ERR" "$access_msg '$lmd18'"
testouterr_cmd "sh" "whatis $m18" "ERR" "$access_msg '$lmd18'"
testouterr_cmd "sh" "avail -t $m18" "OK" ""

restore_file_perms $lmd18

#
# Test access to virtual module when access not granted on its target file
# lying in upper directory
#

change_file_perms $lmd19 $hide_perms

# permission denied on virtual target file
testouterr_cmd "sh" "load $m19" "ERR" "$access_msg '$lmd19'"
testouterr_cmd "sh" "display $m19" "ERR" "$access_msg '$lmd19'"
testouterr_cmd "sh" "whatis $m19" "ERR" "$access_msg '$lmd19'"
testouterr_cmd "sh" "avail -t $m19" "OK" ""

#
# Test access to alias when access not granted on its virtual module target
# lying in upper directory
#

# permission denied on virtual target file
testouterr_cmd "sh" "load $m20" "ERR" "$access_msg '$lmd19'"
testouterr_cmd "sh" "display $m20" "ERR" "$access_msg '$lmd19'"
testouterr_cmd "sh" "whatis $m20" "ERR" "$access_msg '$lmd19'"
# alias defined so it appears even if access to target modulefile is denied
testouterr_cmd_re "sh" "avail -t $m20" "OK" "$theader\n$m20\\(@\\)"

restore_file_perms $lmd19


#
# Test access to implicit default modulefile when access not granted on sibbling
# modulefile leading to removing sibbling directory
#

change_file_perms $lmfh21 $hide_perms

set ans [list]
lappend ans [list set TEST $lm21]
if {[is_conf_enabled advversspec implicitdefault]} {
    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"]
} else {
    lappend ans [list set __MODULES_LMALTNAME "$lm21&modsym/dir2/3.0"]
}
lappend ans [list set __MODULES_LMCONFLICT "$lm21&$m21"]
lappend ans [list set _LMFILES_ $lmf21]
lappend ans [list set LOADEDMODULES $lm21]

# implicit default is not impacted
testouterr_cmd "sh" "load $m21" [if_implicitdefault $ans ERR] [if_implicitdefault {} "$err_nodefault'$m21'"]
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'"]
testouterr_cmd_re "sh" "whatis $m21" "OK" "$pheader\n\\s+$lm21: $lm21"
testouterr_cmd_re "sh" "avail -t $m21" "OK" "$theader\n$lm21\\(3.0\\)"

restore_file_perms $lmfh21


#
# Cleanup
#

reset_test_env

}