Debian Codegraph @

testsuite/modules.30-cache/032-cachebuild-limited-access.exp

raw
1 ##############################################################################
2 # Modules Revision 3.0
3 # Providing a flexible user environment
4 #
5 # File: modules.30-cache/%M%
6 # Revision: %I%
7 # First Edition: 2022/12/11
8 # Last Mod.: %U%, %G%
9 #
10 # Authors: Xavier Delaruelle, [email protected]
11 #
12 # Description: Testuite testsequence
13 # Command: cachebuild
14 # Modulefiles:
15 # Sub-Command:
16 #
17 # Comment: %C{
18 # Test cachebuild sub-command with limited-access content
19 # }C%
20 #
21 ##############################################################################
22
23 # filesystem on Cygwin platform is responding in an unexpected way
24 # skip these tests on this platform for now
25 skip_if_os_in cygwin
26
27 skip_if_quick_mode
28
29 setenv_path_var MODULEPATH $mp1
30
31 # create modulefile/modulerc complex setup
32 lassign [create_diverse_module_setup $mp1] dir_list file_list
33 lassign [extend_diverse_module_setup $mp1] other_dir_list other_file_list
34 lappend dir_list {*}$other_dir_list
35 array set file_arr [concat $file_list $other_file_list]
36
37
38 # expected cache file when no limited access
39 set tscache "#%Module$cache_mcookie_version"
40 foreach f [lsort [array names file_arr]] {
41 set entry {}
42 switch -- $f {
43 .version - .git/ignmod - quux/SCCS/ignmod - {w s/1.0~} -\
44 foo/1.0,v - quxc/1.0~ - .svn/ignmod - .sos/ignmod {}
45 foo/1.0 - empty/notamodule - empty/deep/notadeepmodule {
46 set entry [list modulefile-invalid $f invalid {Magic cookie '#%Module' missing}]
47 }
48 foo/3.0 - quux/nok/5.0 {
49 set entry [list modulefile-invalid $f invalid {Modulefile requires at least Modules version 99}]
50 }
51 default {
52 switch -- $f {
53 foo/.modulerc {set header {}}
54 foo/4.0 - quxc/.modulerc {set header {#%Module5.2}}
55 quxb/.modulerc {set header {#%Module99}}
56 default {set header {#%Module}}
57 }
58
59 if {[file tail $f] in {.modulerc .version}} {
60 set entry [list modulerc-content $f $header $file_arr($f)]
61 } else {
62 set mtime [file mtime $mp1/$f]
63 set entry [list modulefile-content $f $mtime $header $file_arr($f)]
64 }
65 }
66 }
67 if {[string length $entry]} {
68 append tscache "\n$entry"
69 }
70 }
71
72 # make cache without any limited access
73 set tserr [msg_create $mp1cache]
74 testouterrfile_cmd sh "cachebuild $mp1" OK $tserr $mp1cache $tscache
75
76 # cannot test access if cannot change file permission
77 if {!$is_file_perms_editable} {
78 send_user "\tskipping access tests as file permissions cannot be changed\n"
79 # cannot test access if superuser privileges are in use
80 } elseif {$tcl_platform(user) eq "root"} {
81 send_user "\tskipping access tests as tests are run by superuser\n"
82 # cannot test access if restricted file permissions have no effect
83 } elseif {$is_locked_dir_file_readable && $is_locked_file_readable} {
84 send_user "\tskipping access tests as locked files or directories are still readable\n"
85 } else {
86
87 set no_ar_perms ugo-r
88 set no_ax_perms ugo-x
89 set no_arx_perms ugo-rx
90 set no_or_perms o-r
91 set no_ox_perms o-x
92 set no_orx_perms o-rx
93
94
95 change_file_perms $mp1/foo $no_ar_perms
96 change_file_perms $mp1/quux/oth $no_ax_perms
97 change_file_perms $mp1/.modulerc $no_arx_perms
98 change_file_perms $mp1/empty $no_arx_perms
99 change_file_perms $mp1/anotherempty $no_ar_perms
100 change_file_perms $mp1/bar/.version $no_ar_perms
101 change_file_perms $mp1/quxa/.modulerc $no_arx_perms
102 change_file_perms $mp1/baz/.1.10 $no_arx_perms
103 change_file_perms $mp1/quxc/1.0 $no_arx_perms
104 change_file_perms $mp1/quxc/1.0~ $no_arx_perms
105 change_file_perms $mp1/.svn $no_arx_perms
106 change_file_perms $mp1/.sos/ignmod $no_arx_perms
107
108 set tscache1 "#%Module$cache_mcookie_version"
109 foreach f [lsort [concat [array names file_arr] [list foo quux/oth empty anotherempty]]] {
110 set entry {}
111 switch -glob -- $f {
112 .version - .git/ignmod - quux/SCCS/ignmod - {w s/1.0~} -\
113 foo/1.0,v - quxc/1.0~ - .svn/ignmod - .sos/ignmod {}
114 foo/* - quux/oth/* - empty/* {}
115 foo - quux/oth - empty - anotherempty {
116 set entry [list limited-access-directory $f]
117 }
118 .modulerc - bar/.version - quxa/.modulerc - baz/.1.10 - quxc/1.0 {
119 set entry [list limited-access-file $f]
120 }
121 foo/1.0 - empty/notamodule - empty/deep/notadeepmodule {
122 set entry [list modulefile-invalid $f invalid {Magic cookie '#%Module' missing}]
123 }
124 foo/3.0 - quux/nok/5.0 {
125 set entry [list modulefile-invalid $f invalid {Modulefile requires at least Modules version 99}]
126 }
127 default {
128 switch -- $f {
129 foo/.modulerc {set header {}}
130 foo/4.0 - quxc/.modulerc {set header {#%Module5.2}}
131 quxb/.modulerc {set header {#%Module99}}
132 default {set header {#%Module}}
133 }
134
135 if {[file tail $f] in {.modulerc .version}} {
136 set entry [list modulerc-content $f $header $file_arr($f)]
137 } else {
138 set mtime [file mtime $mp1/$f]
139 set entry [list modulefile-content $f $mtime $header $file_arr($f)]
140 }
141 }
142 }
143 if {[string length $entry]} {
144 append tscache1 "\n$entry"
145 }
146 }
147
148 testouterrfile_cmd sh "cachebuild $mp1" OK $tserr $mp1cache $tscache1
149
150
151 # second limited set
152 change_file_perms $mp1/quux $no_ar_perms
153 restore_file_perms $mp1/foo
154 restore_file_perms $mp1/.modulerc
155 restore_file_perms $mp1/bar/.version
156 change_file_perms $mp1/.version $no_ar_perms
157 change_file_perms $mp1/foo/1.0 $no_ar_perms
158 change_file_perms $mp1/foo/.modulerc $no_arx_perms
159
160 set tscache2 "#%Module$cache_mcookie_version"
161 foreach f [lsort [concat [array names file_arr] [list quux empty anotherempty]]] {
162 set entry {}
163 switch -glob -- $f {
164 .version - .git/ignmod - quux/SCCS/ignmod - {w s/1.0~} -\
165 foo/1.0,v - quxc/1.0~ - .svn/ignmod - .sos/ignmod {}
166 quux/* - empty/* {}
167 quux - empty - anotherempty {
168 set entry [list limited-access-directory $f]
169 }
170 quxa/.modulerc - baz/.1.10 - quxc/1.0 - foo/1.0 - foo/.modulerc {
171 set entry [list limited-access-file $f]
172 }
173 empty/notamodule - empty/deep/notadeepmodule {
174 set entry [list modulefile-invalid $f invalid {Magic cookie '#%Module' missing}]
175 }
176 foo/3.0 {
177 set entry [list modulefile-invalid $f invalid {Modulefile requires at least Modules version 99}]
178 }
179 default {
180 switch -- $f {
181 foo/4.0 - quxc/.modulerc {set header {#%Module5.2}}
182 quxb/.modulerc {set header {#%Module99}}
183 default {set header {#%Module}}
184 }
185
186 if {[file tail $f] in {.modulerc .version}} {
187 set entry [list modulerc-content $f $header $file_arr($f)]
188 } else {
189 set mtime [file mtime $mp1/$f]
190 set entry [list modulefile-content $f $mtime $header $file_arr($f)]
191 }
192 }
193 }
194 if {[string length $entry]} {
195 append tscache2 "\n$entry"
196 }
197 }
198
199 testouterrfile_cmd sh "cachebuild $mp1" OK $tserr $mp1cache $tscache2
200
201 restore_file_perms $mp1/quux
202 restore_file_perms $mp1/quux/oth
203 restore_file_perms $mp1/empty
204 restore_file_perms $mp1/anotherempty
205 restore_file_perms $mp1/quxa/.modulerc
206 restore_file_perms $mp1/baz/.1.10
207 restore_file_perms $mp1/quxc/1.0
208 restore_file_perms $mp1/quxc/1.0~
209 restore_file_perms $mp1/.svn
210 restore_file_perms $mp1/.sos/ignmod
211 restore_file_perms $mp1/.version
212 restore_file_perms $mp1/foo/1.0
213 restore_file_perms $mp1/foo/.modulerc
214
215
216 # third limited set: restrictions only applies for other (based on first set)
217 change_file_perms $mp1/foo $no_or_perms
218 change_file_perms $mp1/quux/oth $no_ox_perms
219 change_file_perms $mp1/.modulerc $no_orx_perms
220 change_file_perms $mp1/empty $no_orx_perms
221 change_file_perms $mp1/anotherempty $no_or_perms
222 change_file_perms $mp1/bar/.version $no_or_perms
223 change_file_perms $mp1/quxa/.modulerc $no_orx_perms
224 change_file_perms $mp1/baz/.1.10 $no_orx_perms
225 change_file_perms $mp1/quxc/1.0 $no_orx_perms
226 change_file_perms $mp1/quxc/1.0~ $no_orx_perms
227 change_file_perms $mp1/.svn $no_orx_perms
228 change_file_perms $mp1/.sos/ignmod $no_orx_perms
229
230 testouterrfile_cmd sh "cachebuild $mp1" OK $tserr $mp1cache $tscache1
231
232
233 # fourth limited set: restrictions only applies for other (based on second set)
234 change_file_perms $mp1/quux $no_or_perms
235 restore_file_perms $mp1/foo
236 restore_file_perms $mp1/.modulerc
237 restore_file_perms $mp1/bar/.version
238 change_file_perms $mp1/.version $no_or_perms
239 change_file_perms $mp1/foo/1.0 $no_or_perms
240 change_file_perms $mp1/foo/.modulerc $no_orx_perms
241
242 testouterrfile_cmd sh "cachebuild $mp1" OK $tserr $mp1cache $tscache2
243
244 # cachefile exists and has limited access for others
245 change_file_perms $mp1cache $no_or_perms
246 testouterrfile_cmd sh "cachebuild $mp1" OK $tserr $mp1cache $tscache2
247 restore_file_perms $mp1cache
248
249 restore_file_perms $mp1/quux
250 restore_file_perms $mp1/quux/oth
251 restore_file_perms $mp1/empty
252 restore_file_perms $mp1/anotherempty
253 restore_file_perms $mp1/quxa/.modulerc
254 restore_file_perms $mp1/baz/.1.10
255 restore_file_perms $mp1/quxc/1.0
256 restore_file_perms $mp1/quxc/1.0~
257 restore_file_perms $mp1/.svn
258 restore_file_perms $mp1/.sos/ignmod
259 restore_file_perms $mp1/.version
260 restore_file_perms $mp1/foo/1.0
261 restore_file_perms $mp1/foo/.modulerc
262
263 file delete $mp1cache
264
265
266 # whole modulepath has limited access
267 change_file_perms $mp1 $no_arx_perms
268 set tserr [msg_create $mp1cache $warn_cache_nothingtorec]
269 set tscacheerr [couldnotopen_permdenied $mp1cache]
270 testouterrfile_cmd sh "cachebuild $mp1" OK $tserr $mp1cache $tscacheerr
271 restore_file_perms $mp1
272
273 # whole modulepath has limited access (restriction for others only)
274 # cache file is generated: others will not access this modulepath so the
275 # cache will be consistent for people able to reaching path
276 change_file_perms $mp1 $no_orx_perms
277 set tserr [msg_create $mp1cache]
278 testouterrfile_cmd sh "cachebuild $mp1" OK $tserr $mp1cache $tscache
279 restore_file_perms $mp1
280
281 # check expected siteconfig file is installed
282 set is_stderr_tty [siteconfig_isStderrTty]
283 if {$is_stderr_tty} {
284 # fake we are on Windows platform
285 setenv_var TESTSUITE_ENABLE_SITECONFIG_WINDOWS_PLATFORM 1
286
287 change_file_perms $mp1/foo $no_ar_perms
288 change_file_perms $mp1/quux/oth $no_ax_perms
289 change_file_perms $mp1/.modulerc $no_arx_perms
290 change_file_perms $mp1/empty $no_arx_perms
291 change_file_perms $mp1/anotherempty $no_ar_perms
292 change_file_perms $mp1/bar/.version $no_ar_perms
293 change_file_perms $mp1/quxa/.modulerc $no_arx_perms
294 change_file_perms $mp1/baz/.1.10 $no_arx_perms
295 change_file_perms $mp1/quxc/1.0 $no_arx_perms
296 change_file_perms $mp1/quxc/1.0~ $no_arx_perms
297 change_file_perms $mp1/.svn $no_arx_perms
298 change_file_perms $mp1/.sos/ignmod $no_arx_perms
299
300 set tscachewin1 "#%Module$cache_mcookie_version"
301 foreach f [lsort [concat [array names file_arr] [list foo empty anotherempty]]] {
302 set entry {}
303 switch -glob -- $f {
304 .version - .git/ignmod - quux/SCCS/ignmod - {w s/1.0~} -\
305 foo/1.0,v - quxc/1.0~ - .svn/ignmod - .sos/ignmod {}
306 quxa/.modulerc - .modulerc - bar/.version {}
307 foo/* - empty/* {}
308 foo - empty - anotherempty - baz/.1.10 - quxc/1.0 - quux/oth/3.0 - quux/oth/4.0 {
309 set entry [list modulefile-invalid $f accesserr "Permission denied on '$mp1/$f'"]
310 }
311 foo/1.0 - empty/notamodule - empty/deep/notadeepmodule {
312 set entry [list modulefile-invalid $f invalid {Magic cookie '#%Module' missing}]
313 }
314 foo/3.0 - quux/nok/5.0 {
315 set entry [list modulefile-invalid $f invalid {Modulefile requires at least Modules version 99}]
316 }
317 default {
318 switch -- $f {
319 foo/.modulerc {set header {}}
320 foo/4.0 - quxc/.modulerc {set header {#%Module5.2}}
321 quxb/.modulerc {set header {#%Module99}}
322 default {set header {#%Module}}
323 }
324
325 if {[file tail $f] in {.modulerc .version}} {
326 set entry [list modulerc-content $f $header $file_arr($f)]
327 } else {
328 set mtime [file mtime $mp1/$f]
329 set entry [list modulefile-content $f $mtime $header $file_arr($f)]
330 }
331 }
332 }
333 if {[string length $entry]} {
334 append tscachewin1 "\n$entry"
335 }
336 }
337
338 testouterrfile_cmd sh "cachebuild $mp1" OK $tserr $mp1cache $tscachewin1
339
340 restore_file_perms $mp1/foo
341 restore_file_perms $mp1/.modulerc
342 restore_file_perms $mp1/bar/.version
343 restore_file_perms $mp1/quux/oth
344 restore_file_perms $mp1/empty
345 restore_file_perms $mp1/anotherempty
346 restore_file_perms $mp1/quxa/.modulerc
347 restore_file_perms $mp1/baz/.1.10
348 restore_file_perms $mp1/quxc/1.0
349 restore_file_perms $mp1/quxc/1.0~
350 restore_file_perms $mp1/.svn
351 restore_file_perms $mp1/.sos/ignmod
352
353 change_file_perms $mp1/foo $no_or_perms
354 change_file_perms $mp1/quux/oth $no_ox_perms
355 change_file_perms $mp1/.modulerc $no_orx_perms
356 change_file_perms $mp1/empty $no_orx_perms
357 change_file_perms $mp1/anotherempty $no_or_perms
358 change_file_perms $mp1/bar/.version $no_or_perms
359 change_file_perms $mp1/quxa/.modulerc $no_orx_perms
360 change_file_perms $mp1/baz/.1.10 $no_orx_perms
361 change_file_perms $mp1/quxc/1.0 $no_orx_perms
362 change_file_perms $mp1/quxc/1.0~ $no_orx_perms
363 change_file_perms $mp1/.svn $no_orx_perms
364 change_file_perms $mp1/.sos/ignmod $no_orx_perms
365
366 set tscachewin2 "#%Module$cache_mcookie_version"
367 foreach f [lsort [array names file_arr]] {
368 set entry {}
369 switch -- $f {
370 .version - .git/ignmod - quux/SCCS/ignmod - {w s/1.0~} -\
371 foo/1.0,v - quxc/1.0~ - .svn/ignmod - .sos/ignmod {}
372 foo/1.0 - empty/deep/notadeepmodule - empty/notamodule {
373 set entry [list modulefile-invalid $f invalid {Magic cookie '#%Module' missing}]
374 }
375 foo/3.0 - quux/nok/5.0 {
376 set entry [list modulefile-invalid $f invalid {Modulefile requires at least Modules version 99}]
377 }
378 default {
379 switch -- $f {
380 foo/.modulerc {set header {}}
381 foo/4.0 - quxc/.modulerc {set header {#%Module5.2}}
382 quxb/.modulerc {set header {#%Module99}}
383 default {set header {#%Module}}
384 }
385
386 if {[file tail $f] in {.modulerc .version}} {
387 set entry [list modulerc-content $f $header $file_arr($f)]
388 } else {
389 set mtime [file mtime $mp1/$f]
390 set entry [list modulefile-content $f $mtime $header $file_arr($f)]
391 }
392 }
393 }
394 if {[string length $entry]} {
395 append tscachewin2 "\n$entry"
396 }
397 }
398
399 testouterrfile_cmd sh "cachebuild $mp1" OK $tserr $mp1cache $tscachewin2
400
401 restore_file_perms $mp1/foo
402 restore_file_perms $mp1/.modulerc
403 restore_file_perms $mp1/bar/.version
404 restore_file_perms $mp1/quux/oth
405 restore_file_perms $mp1/empty
406 restore_file_perms $mp1/anotherempty
407 restore_file_perms $mp1/quxa/.modulerc
408 restore_file_perms $mp1/baz/.1.10
409 restore_file_perms $mp1/quxc/1.0
410 restore_file_perms $mp1/quxc/1.0~
411 restore_file_perms $mp1/.svn
412 restore_file_perms $mp1/.sos/ignmod
413
414 unsetenv_var TESTSUITE_ENABLE_SITECONFIG_WINDOWS_PLATFORM
415 }
416
417 }
418
419
420 #
421 # Cleanup
422 #
423
424 file delete $mp1cache
425
426 # delete created files and dirs
427 delete_module_setup $mp1 [array names file_arr] $dir_list
428
429 reset_test_env