| 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/06/30 |
| 8 |
# Last Mod.: %U%, %G% |
| 9 |
# |
| 10 |
# Authors: Xavier Delaruelle, [email protected] |
| 11 |
# |
| 12 |
# Description: Testuite testsequence |
| 13 |
# Command: load, display |
| 14 |
# Modulefiles: loc_rc1/1.0, loc_sym/1.0 |
| 15 |
# Sub-Command: |
| 16 |
# |
| 17 |
# Comment: %C{ |
| 18 |
# Tests the evaluation of the global RC files when access rights |
| 19 |
# to get to it does not allow it |
| 20 |
# }C% |
| 21 |
# |
| 22 |
############################################################################## |
| 23 |
|
| 24 |
# cannot test access if cannot change file permission |
| 25 |
if {!$is_file_perms_editable} { |
| 26 |
send_user "\tskipping access tests as file permissions cannot be changed\n" |
| 27 |
# cannot test access if superuser privileges are in use |
| 28 |
} elseif {$tcl_platform(user) eq "root"} { |
| 29 |
send_user "\tskipping access tests as tests are run by superuser\n" |
| 30 |
# cannot test access if restricted file permissions have no effect |
| 31 |
} elseif {$is_locked_dir_file_readable && $is_locked_file_readable} { |
| 32 |
send_user "\tskipping access tests as locked files or directories are still readable\n" |
| 33 |
} else { |
| 34 |
|
| 35 |
set etcdir "$env(TESTSUITEDIR)/etc" |
| 36 |
set etcmodrc "$etcdir/modulerc" |
| 37 |
set etcrc "$etcdir/rc" |
| 38 |
set homedir "$env(TESTSUITEDIR)/home" |
| 39 |
set homemodrc "$homedir/.modulerc" |
| 40 |
|
| 41 |
set locate_msg "$err_path'sym_foo'" |
| 42 |
set locate2_msg "$err_path'loc_sym/sym_home'" |
| 43 |
set hide_perms "ugo-rx" |
| 44 |
|
| 45 |
# do not consider built cache files (if any) to find available modules |
| 46 |
ignore_modulecache_if_built |
| 47 |
|
| 48 |
|
| 49 |
# |
| 50 |
# Test usage of global RC when read access not granted on this RC file |
| 51 |
# |
| 52 |
|
| 53 |
# lock access to MODULERCFILE also used as MODULERCFILE/modulerc |
| 54 |
change_file_perms $etcmodrc $hide_perms |
| 55 |
|
| 56 |
# access issue on global RC files are silenced |
| 57 |
set env(MODULERCFILE) $etcmodrc |
| 58 |
testouterr_cmd "sh" "load sym_foo" "ERR" "$locate_msg" |
| 59 |
testouterr_cmd "sh" "display sym_foo" "ERR" "$locate_msg" |
| 60 |
|
| 61 |
set env(MODULERCFILE) $etcdir |
| 62 |
testouterr_cmd "sh" "load sym_foo" "ERR" "$locate_msg" |
| 63 |
testouterr_cmd "sh" "display sym_foo" "ERR" "$locate_msg" |
| 64 |
set env(MODULERCFILE) "" |
| 65 |
|
| 66 |
restore_file_perms $etcmodrc |
| 67 |
|
| 68 |
skip_if_quick_mode |
| 69 |
|
| 70 |
# no lock access test for @etcdir@/rc as it may be a config file currently |
| 71 |
# in use in production by an already installed version of Modules |
| 72 |
|
| 73 |
# lock access to HOME/.modulerc |
| 74 |
change_file_perms $homemodrc $hide_perms |
| 75 |
|
| 76 |
set env(HOME) $homedir |
| 77 |
testouterr_cmd "sh" "load loc_sym/sym_home" "ERR" "$locate2_msg" |
| 78 |
testouterr_cmd "sh" "display loc_sym/sym_home" "ERR" "$locate2_msg" |
| 79 |
set env(HOME) $ORIG_HOME |
| 80 |
|
| 81 |
restore_file_perms $homemodrc |
| 82 |
|
| 83 |
|
| 84 |
# |
| 85 |
# Test usage of modulepath RC when read access not granted on this RC file |
| 86 |
# |
| 87 |
|
| 88 |
# lock access to modulepath rc |
| 89 |
set mprc "$modpath.rc" |
| 90 |
change_file_perms $mprc/.modulerc $hide_perms |
| 91 |
|
| 92 |
# setup specific environment |
| 93 |
setenv_path_var MODULEPATH $mprc |
| 94 |
|
| 95 |
# access issue on modulepath RC file is silenced |
| 96 |
testouterr_cmd "sh" "load bar/top" "ERR" "$err_path'bar/top'" |
| 97 |
|
| 98 |
# restore environment |
| 99 |
setenv_path_var MODULEPATH $modpath |
| 100 |
|
| 101 |
restore_file_perms $mprc/.modulerc |
| 102 |
|
| 103 |
|
| 104 |
# |
| 105 |
# Test usage of global RC when read access not granted on its upper directory |
| 106 |
# |
| 107 |
|
| 108 |
# lock access to TESTSUITEDIR/etc also used as MODULERCFILE upper dir |
| 109 |
change_file_perms $etcdir $hide_perms |
| 110 |
|
| 111 |
# different result if a file in a locked directory still readable on this system |
| 112 |
if {$is_locked_dir_file_readable} { |
| 113 |
set lm "loc_rc1/1.0" |
| 114 |
set lmf "$modpath/$lm" |
| 115 |
set lmfre "$modpathre/$lm" |
| 116 |
|
| 117 |
set ans [list] |
| 118 |
lappend ans [list set _LMFILES_ $lmf] |
| 119 |
lappend ans [list set LOADEDMODULES $lm] |
| 120 |
lappend ans [list set testsuite yes] |
| 121 |
|
| 122 |
set env(MODULERCFILE) $etcmodrc |
| 123 |
testouterr_cmd "sh" "load sym_foo" $ans "" |
| 124 |
testouterr_cmd_re "sh" "display sym_foo" "OK" "$modlin\n$lmfre:\n\nmodule-whatis\t$lm\nsetenv\t\ttestsuite yes\n$modlin" |
| 125 |
|
| 126 |
set env(MODULERCFILE) $etcdir |
| 127 |
testouterr_cmd "sh" "load sym_foo" $ans "" |
| 128 |
testouterr_cmd_re "sh" "display sym_foo" "OK" "$modlin\n$lmfre:\n\nmodule-whatis\t$lm\nsetenv\t\ttestsuite yes\n$modlin" |
| 129 |
set env(MODULERCFILE) "" |
| 130 |
|
| 131 |
unset lm |
| 132 |
unset lmf |
| 133 |
unset lmfre |
| 134 |
unset ans |
| 135 |
} else { |
| 136 |
set env(MODULERCFILE) $etcmodrc |
| 137 |
testouterr_cmd "sh" "load sym_foo" "ERR" "$locate_msg" |
| 138 |
testouterr_cmd "sh" "display sym_foo" "ERR" "$locate_msg" |
| 139 |
|
| 140 |
set env(MODULERCFILE) $etcdir |
| 141 |
testouterr_cmd "sh" "load sym_foo" "ERR" "$locate_msg" |
| 142 |
testouterr_cmd "sh" "display sym_foo" "ERR" "$locate_msg" |
| 143 |
set env(MODULERCFILE) "" |
| 144 |
} |
| 145 |
|
| 146 |
restore_file_perms $etcdir |
| 147 |
|
| 148 |
|
| 149 |
# |
| 150 |
# Cleanup |
| 151 |
# |
| 152 |
|
| 153 |
reset_test_env |
| 154 |
|
| 155 |
} |