mirror of
https://github.com/envmodules/modules.git
synced 2026-06-18 00:06:53 +08:00
testsuite: add 080-access tests in 10-use suite
Test behaviors when modulepath cannot be accessed. Centralize by the way the change_file_perms and restore_file_perms procedures that are now used in different parts of the testsuite.
This commit is contained in:
@@ -294,3 +294,32 @@ proc testoutfile_cmd {test_shell cmd answer filepath ansfile} {
|
||||
_test_ok $test_shell "$cmd"
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# Change and restore file permissions to trigger specific behaviors
|
||||
#
|
||||
|
||||
proc change_file_perms {name perms} {
|
||||
global verbose file_orig_perms
|
||||
|
||||
# backup original file permission to restore them later
|
||||
set file_orig_perms($name) [file attributes $name -permissions]
|
||||
|
||||
if { $verbose > 0 } {
|
||||
send_user "\tChange permissions of file $name ($perms)\n"
|
||||
}
|
||||
|
||||
# lock file by removing read and execution perms
|
||||
file attributes $name -permissions $perms
|
||||
}
|
||||
|
||||
proc restore_file_perms {name} {
|
||||
global verbose file_orig_perms
|
||||
|
||||
if { $verbose > 0 } {
|
||||
send_user "\tRestore permissions of file $name ($file_orig_perms($name))\n"
|
||||
}
|
||||
|
||||
# restore file original permissions
|
||||
file attributes $name -permissions $file_orig_perms($name)
|
||||
}
|
||||
|
||||
107
testsuite/modules.10-use/080-access.exp
Normal file
107
testsuite/modules.10-use/080-access.exp
Normal file
@@ -0,0 +1,107 @@
|
||||
##############################################################################
|
||||
# Modules Revision 3.0
|
||||
# Providing a flexible user environment
|
||||
#
|
||||
# File: modules.20-locate/%M%
|
||||
# Revision: %I%
|
||||
# First Edition: 2017/05/27
|
||||
# Last Mod.: %U%, %G%
|
||||
#
|
||||
# Authors: Xavier Delaruelle, xavier.delaruelle@cea.fr
|
||||
#
|
||||
# Description: Testuite testsequence
|
||||
# Command: use, unuse, load, display, whatis, avail, aliases
|
||||
# Modulefiles:
|
||||
# Sub-Command:
|
||||
#
|
||||
# Comment: %C{
|
||||
# Modulepath handling when access rights to get to it does not
|
||||
# allow it
|
||||
# }C%
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
#
|
||||
# Variables for this test
|
||||
#
|
||||
|
||||
set module "loc_rc6"
|
||||
|
||||
set orig_modpath $::env(MODULEPATH)
|
||||
set use_modpath_sh "MODULEPATH=$orig_modpath; export MODULEPATH;"
|
||||
set use_modshare_sh "MODULEPATH_modshare=$orig_modpath:1; export MODULEPATH_modshare;"
|
||||
set unuse_modpath_sh "unset MODULEPATH;"
|
||||
set unuse_modshare_sh "unset MODULEPATH_modshare;"
|
||||
|
||||
set err_sh "/bin/false;"
|
||||
set locate_msg "$error_msgs: Unable to locate a modulefile for"
|
||||
set hide_perms "ugo-rx"
|
||||
|
||||
#
|
||||
# Test enabling modulepath when access not granted to it
|
||||
#
|
||||
|
||||
if { $verbose > 0 } {
|
||||
send_user "\tSetup MODULEPATH = ''\n"
|
||||
}
|
||||
set ::env(MODULEPATH) ""
|
||||
|
||||
change_file_perms $orig_modpath $hide_perms
|
||||
|
||||
# normal enabling, as no directory access
|
||||
testouterr_cmd "sh" "use $orig_modpath" "$use_modshare_sh\n$use_modpath_sh" ""
|
||||
|
||||
|
||||
if { $verbose > 0 } {
|
||||
send_user "\tRestore MODULEPATH = $orig_modpath\n"
|
||||
}
|
||||
set ::env(MODULEPATH) $orig_modpath
|
||||
|
||||
|
||||
#
|
||||
# Test global access to the modulefiles of a modulepath when access not
|
||||
# granted on this modulepath
|
||||
#
|
||||
|
||||
# nothing found
|
||||
testouterr_cmd "sh" "whatis" "" ""
|
||||
testouterr_cmd "sh" "avail" "" ""
|
||||
testouterr_cmd "sh" "aliases" "" ""
|
||||
|
||||
|
||||
#
|
||||
# Test access to modulefile when access not granted on modulepath
|
||||
#
|
||||
|
||||
# nothing found
|
||||
testouterr_cmd "sh" "load $module" "$err_sh" "$locate_msg '$module'"
|
||||
testouterr_cmd "sh" "display $module" "$err_sh" "$locate_msg '$module'"
|
||||
testouterr_cmd "sh" "whatis $module" "$err_sh" "$locate_msg '$module'"
|
||||
testouterr_cmd "sh" "avail -t $module" "" ""
|
||||
|
||||
|
||||
#
|
||||
# Test disabling modulepath when access not granted to it
|
||||
#
|
||||
|
||||
# normal disabling, as no directory access
|
||||
testouterr_cmd "sh" "unuse $orig_modpath" "$unuse_modshare_sh\n$unuse_modpath_sh" ""
|
||||
|
||||
restore_file_perms $orig_modpath
|
||||
|
||||
|
||||
#
|
||||
# Cleanup
|
||||
#
|
||||
|
||||
unset err_sh
|
||||
unset locate_msg
|
||||
unset hide_perms
|
||||
|
||||
unset orig_modpath
|
||||
unset use_modpath_sh
|
||||
unset use_modshare_sh
|
||||
unset unuse_modpath_sh
|
||||
unset unuse_modshare_sh
|
||||
|
||||
unset module
|
||||
@@ -21,35 +21,6 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
#
|
||||
# Procedure for this test
|
||||
#
|
||||
|
||||
proc change_file_perms {name perms} {
|
||||
global verbose file_orig_perms
|
||||
|
||||
# backup original file permission to restore them later
|
||||
set file_orig_perms($name) [file attributes $name -permissions]
|
||||
|
||||
if { $verbose > 0 } {
|
||||
send_user "\tChange permissions of file $name ($perms)\n"
|
||||
}
|
||||
|
||||
# lock file by removing read and execution perms
|
||||
file attributes $name -permissions $perms
|
||||
}
|
||||
|
||||
proc restore_file_perms {name} {
|
||||
global verbose file_orig_perms
|
||||
|
||||
if { $verbose > 0 } {
|
||||
send_user "\tRestore permissions of file $name ($file_orig_perms($name))\n"
|
||||
}
|
||||
|
||||
# restore file original permissions
|
||||
file attributes $name -permissions $file_orig_perms($name)
|
||||
}
|
||||
|
||||
#
|
||||
# Variables for this test
|
||||
#
|
||||
@@ -405,9 +376,3 @@ unset m15
|
||||
unset lmd15
|
||||
unset m16
|
||||
unset lmd16
|
||||
|
||||
unset file_orig_perms
|
||||
|
||||
# remove procs
|
||||
rename change_file_perms {}
|
||||
rename restore_file_perms {}
|
||||
|
||||
@@ -21,35 +21,6 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
#
|
||||
# Procedure for this test
|
||||
#
|
||||
|
||||
proc change_file_perms {name perms} {
|
||||
global verbose file_orig_perms
|
||||
|
||||
# backup original file permission to restore them later
|
||||
set file_orig_perms($name) [file attributes $name -permissions]
|
||||
|
||||
if { $verbose > 0 } {
|
||||
send_user "\tChange permissions of file $name ($perms)\n"
|
||||
}
|
||||
|
||||
# lock file by removing read and execution perms
|
||||
file attributes $name -permissions $perms
|
||||
}
|
||||
|
||||
proc restore_file_perms {name} {
|
||||
global verbose file_orig_perms
|
||||
|
||||
if { $verbose > 0 } {
|
||||
send_user "\tRestore permissions of file $name ($file_orig_perms($name))\n"
|
||||
}
|
||||
|
||||
# restore file original permissions
|
||||
file attributes $name -permissions $file_orig_perms($name)
|
||||
}
|
||||
|
||||
#
|
||||
# Variables for this test
|
||||
#
|
||||
@@ -426,9 +397,3 @@ unset m17
|
||||
unset lmd17
|
||||
unset m18
|
||||
unset lmd18
|
||||
|
||||
unset file_orig_perms
|
||||
|
||||
# remove procs
|
||||
rename change_file_perms {}
|
||||
rename restore_file_perms {}
|
||||
|
||||
Reference in New Issue
Block a user