def test_server_config_environment_variables(self): # set log level to get all the things os.environ['spLogLevel'] = '11' # set a random environment value to find in the log svr_cfg_file = get_irods_config_dir() + "/server_config.json" os.system("cp %s %sOrig" % (svr_cfg_file, svr_cfg_file)) with open(svr_cfg_file) as f: svr_cfg = json.load(f) the_value = 'THIS_IS_THE_VALUE' svr_cfg['environment_variables']['foo_bar'] = the_value mod_json_file(svr_cfg_file, svr_cfg) # bounce the server to get the new env variable os.system(get_irods_top_level_dir() + "/iRODS/irodsctl stop") os.system(get_irods_top_level_dir() + "/iRODS/irodsctl start") assertiCmd(s.adminsession, "ils", "LIST", "tempZone") # look for the error "unable to read session variable $userNameClient." p = subprocess.Popen( ['grep "' + the_value + '" ../../iRODS/server/log/rodsLog.*'], shell=True, stdout=subprocess.PIPE) result = p.communicate()[0] del os.environ['spLogLevel'] os.system("mv %sOrig %s" % (svr_cfg_file, svr_cfg_file)) os.system(get_irods_top_level_dir() + "/iRODS/irodsctl stop") os.system(get_irods_top_level_dir() + "/iRODS/irodsctl start") # check the results for the error assert(-1 != result.find(the_value))
def test_issue_2420(self): # manipulate the core.re to enable host access control corefile = get_irods_config_dir() + "/core.re" backupcorefile = corefile + "--" + self._testMethodName shutil.copy(corefile, backupcorefile) os.system( '''sed -e '/^acAclPolicy {msiAclPolicy("STRICT"); }/iacAclPolicy {ON($userNameClient == "quickshare") { } }' /etc/irods/core.re > /tmp/irods/core.re''') time.sleep(1) # remove once file hash fix is commited #2279 os.system("cp /tmp/irods/core.re /etc/irods/core.re") time.sleep(1) # remove once file hash fix is commited #2279 # restart the server to reread the new core.re os.system(get_irods_top_level_dir() + "/iRODS/irodsctl stop") os.system(get_irods_top_level_dir() + "/iRODS/irodsctl start") assertiCmd(s.adminsession, "ils", "LIST", "tempZone") # look for the error "unable to read session variable $userNameClient." p = subprocess.Popen( ['grep "unable to read session variable $userNameClient." ../../iRODS/server/log/rodsLog.*'], shell=True, stdout=subprocess.PIPE) result = p.communicate()[0] # restore the original core.re shutil.copy(backupcorefile, corefile) os.remove(backupcorefile) # check the results for the error assert(-1 == result.find("userNameClient"))
def test_ssl_iput_small_and_large_files(self): # set up client and server side for ssl handshake # server side certificate setup os.system("openssl genrsa -out server.key 2> /dev/null") os.system("openssl req -batch -new -key server.key -out server.csr") os.system( "openssl req -batch -new -x509 -key server.key -out server.crt -days 365" ) os.system("mv server.crt chain.pem") os.system("openssl dhparam -2 -out dhparams.pem 100 2> /dev/null" ) # normally 2048, but smaller size here for speed # server side environment variables os.environ['irodsSSLCertificateChainFile'] = get_irods_top_level_dir( ) + "/tests/pydevtest/chain.pem" os.environ['irodsSSLCertificateKeyFile'] = get_irods_top_level_dir( ) + "/tests/pydevtest/server.key" os.environ['irodsSSLDHParamsFile'] = get_irods_top_level_dir( ) + "/tests/pydevtest/dhparams.pem" # client side environment variables os.environ['irodsSSLVerifyServer'] = "none" # add client irodsEnv settings clientEnvFile = s.adminsession.sessionDir + "/.irodsEnv" os.system("cp %s %sOrig" % (clientEnvFile, clientEnvFile)) os.system("echo \"irodsClientServerPolicy 'CS_NEG_REQUIRE'\" >> %s" % clientEnvFile) # server reboot to pick up new irodsEnv settings os.system(get_irods_top_level_dir() + "/iRODS/irodsctl restart") # do the encrypted put filename = "encryptedfile.txt" filepath = create_local_testfile(filename) assertiCmd(s.adminsession, "iinit rods") # reinitialize # small file assertiCmd(s.adminsession, "iput " + filename) # encrypted put - small file assertiCmd(s.adminsession, "ils -L " + filename, "LIST", filename) # should be listed # large file largefilename = "BIGencryptedfile.txt" output = commands.getstatusoutput('dd if=/dev/zero of=' + largefilename + ' bs=1M count=60') assert output[0] == 0, "dd did not successfully exit" #os.system("ls -al "+largefilename) assertiCmd(s.adminsession, "iput " + largefilename) # encrypted put - large file assertiCmd(s.adminsession, "ils -L " + largefilename, "LIST", largefilename) # should be listed # reset client environment to not require SSL os.system("mv %sOrig %s" % (clientEnvFile, clientEnvFile)) # clean up os.system("rm server.key server.csr chain.pem dhparams.pem") os.remove(filename) os.remove(largefilename)
def test_authentication_PAM_without_negotiation(self): # add auth test user authTestUser = "******" authTestPass = "******" assertiCmd(s.adminsession, "iadmin mkuser %s rodsuser" % authTestUser) # set up client and server side for ssl handshake # server side certificate setup os.system("openssl genrsa -out server.key") # os.system("openssl req -batch -new -key server.key -out server.csr") # if use external CA # self-signed certificate os.system("openssl req -batch -new -x509 -key server.key -out server.crt -days 365") os.system("mv server.crt chain.pem") os.system("openssl dhparam -2 -out dhparams.pem 100") # normally 2048, but smaller size here for speed # server side environment variables os.environ['irodsSSLCertificateChainFile'] = get_irods_top_level_dir() + "/tests/pydevtest/chain.pem" os.environ['irodsSSLCertificateKeyFile'] = get_irods_top_level_dir() + "/tests/pydevtest/server.key" os.environ['irodsSSLDHParamsFile'] = get_irods_top_level_dir() + "/tests/pydevtest/dhparams.pem" # client side environment variables os.environ['irodsSSLVerifyServer'] = "none" # add client irodsEnv settings clientEnvFile = s.adminsession._session_dir + "/irods_environment.json" os.system("cp %s %sOrig" % (clientEnvFile, clientEnvFile)) # does not use our SSL to test legacy SSL code path env = {} env['irods_authentication_scheme'] = "PaM" env['irods_user_name'] = authTestUser env['irods_home'] = '/tempZone/home/' + authTestUser env['irods_cwd'] = '/tempZone/home/' + authTestUser update_json_file_from_dict(clientEnvFile, env) # server reboot to pick up new irodsEnv settings os.system(get_irods_top_level_dir() + "/iRODS/irodsctl restart") # do the reauth assertiCmd(s.adminsession, "iinit %s" % authTestPass) # reinitialize # connect and list some files assertiCmd(s.adminsession, "icd") # home directory assertiCmd(s.adminsession, "ils -L", "LIST", "home") # should be listed # reset client environment to original os.system("mv %sOrig %s" % (clientEnvFile, clientEnvFile)) # reconnect as admin assertiCmd(s.adminsession, "iinit %s" % s.adminsession._password) # reinitialize # remove auth test user assertiCmd(s.adminsession, "iadmin rmuser %s" % authTestUser) # clean up os.system("rm server.key chain.pem dhparams.pem")
def test_authentication_PAM_without_negotiation(self): # add auth test user authTestUser = "******" authTestPass = "******" assertiCmd(s.adminsession, "iadmin mkuser %s rodsuser" % authTestUser) # set up client and server side for ssl handshake # server side certificate setup os.system("openssl genrsa -out server.key") # os.system("openssl req -batch -new -key server.key -out server.csr") # if use external CA # self-signed certificate os.system("openssl req -batch -new -x509 -key server.key -out server.crt -days 365") os.system("mv server.crt chain.pem") os.system("openssl dhparam -2 -out dhparams.pem 100") # normally 2048, but smaller size here for speed # server side environment variables os.environ['irodsSSLCertificateChainFile'] = get_irods_top_level_dir() + "/tests/pydevtest/chain.pem" os.environ['irodsSSLCertificateKeyFile'] = get_irods_top_level_dir() + "/tests/pydevtest/server.key" os.environ['irodsSSLDHParamsFile'] = get_irods_top_level_dir() + "/tests/pydevtest/dhparams.pem" # client side environment variables os.environ['irodsSSLVerifyServer'] = "none" # add client irodsEnv settings clientEnvFile = s.adminsession.sessionDir + "/irods_environment.json" os.system("cp %s %sOrig" % (clientEnvFile, clientEnvFile)) # does not use our SSL to test legacy SSL code path env = {} env['irods_authentication_scheme'] = "PaM" env['irods_user_name'] = authTestUser env['irods_home'] = '/tempZone/home/' + authTestUser env['irods_cwd'] = '/tempZone/home/' + authTestUser mod_json_file(clientEnvFile, env) # server reboot to pick up new irodsEnv settings os.system(get_irods_top_level_dir() + "/iRODS/irodsctl restart") # do the reauth assertiCmd(s.adminsession, "iinit %s" % authTestPass) # reinitialize # connect and list some files assertiCmd(s.adminsession, "icd") # home directory assertiCmd(s.adminsession, "ils -L", "LIST", "home") # should be listed # reset client environment to original os.system("mv %sOrig %s" % (clientEnvFile, clientEnvFile)) # reconnect as admin assertiCmd(s.adminsession, "iinit %s" % s.users[0]['passwd']) # reinitialize # remove auth test user assertiCmd(s.adminsession, "iadmin rmuser %s" % authTestUser) # clean up os.system("rm server.key chain.pem dhparams.pem")
def test_ssl_iput_small_and_large_files(self): # set up client and server side for ssl handshake # server side certificate setup os.system("openssl genrsa -out server.key 2> /dev/null") os.system("openssl req -batch -new -key server.key -out server.csr") os.system("openssl req -batch -new -x509 -key server.key -out server.crt -days 365") os.system("mv server.crt chain.pem") os.system("openssl dhparam -2 -out dhparams.pem 100 2> /dev/null") # normally 2048, but smaller size here for speed # server side environment variables os.environ['irodsSSLCertificateChainFile'] = get_irods_top_level_dir() + "/tests/pydevtest/chain.pem" os.environ['irodsSSLCertificateKeyFile'] = get_irods_top_level_dir() + "/tests/pydevtest/server.key" os.environ['irodsSSLDHParamsFile'] = get_irods_top_level_dir() + "/tests/pydevtest/dhparams.pem" # client side environment variables os.environ['irodsSSLVerifyServer'] = "none" # add client irodsEnv settings clientEnvFile = s.adminsession.sessionDir+"/irods_environment.json" os.system("cp %s %sOrig" % (clientEnvFile, clientEnvFile)) env = {} env['irods_client_server_policy'] = 'CS_NEG_REQUIRE' mod_json_file(clientEnvFile, env) # server reboot to pick up new irodsEnv settings os.system(get_irods_top_level_dir() + "/iRODS/irodsctl restart") # do the encrypted put filename = "encryptedfile.txt" filepath = create_local_testfile(filename) assertiCmd(s.adminsession,"iinit rods") # reinitialize # small file assertiCmd(s.adminsession,"iput "+filename) # encrypted put - small file assertiCmd(s.adminsession,"ils -L "+filename,"LIST",filename) # should be listed # large file largefilename = "BIGencryptedfile.txt" output = commands.getstatusoutput( 'dd if=/dev/zero of='+largefilename+' bs=1M count=60' ) assert output[0] == 0, "dd did not successfully exit" #os.system("ls -al "+largefilename) assertiCmd(s.adminsession,"iput "+largefilename) # encrypted put - large file assertiCmd(s.adminsession,"ils -L "+largefilename,"LIST",largefilename) # should be listed # reset client environment to not require SSL os.system("mv %sOrig %s" % (clientEnvFile, clientEnvFile)) # clean up os.system("rm server.key server.csr chain.pem dhparams.pem") os.remove(filename) os.remove(largefilename)
class Test_MS_Plugin_CURL(unittest.TestCase): rules_dir = c.get_irods_top_level_dir( ) + "/iRODS/clients/icommands/test/rules3.0/" dest_obj = "/tempZone/home/public/ferrari.art" # will need to be passed to curlGetObj.r def setUp(self): s.admin_up() def tearDown(self): s.adminsession.runCmd('irm', ['-f', self.dest_obj]) s.admin_down() def test_curl_get_obj(self): rule_file = self.rules_dir + "curlGetObj.r" print "-- running " + rule_file c.assertiCmd(s.adminsession, "irule -vF " + rule_file, "LIST", "completed successfully") def test_curl_get_str(self): rule_file = self.rules_dir + "curlGetStr.r" print "-- running " + rule_file c.assertiCmd(s.adminsession, "irule -vF " + rule_file, "LIST", "completed successfully") def test_curl_post(self): rule_file = self.rules_dir + "curlPost.r" print "-- running " + rule_file # will have to dynamically pass form_data to the rule once that's fixed form_data = "Sent from iRODS" c.assertiCmd(s.adminsession, "irule -F " + rule_file, "LIST", form_data)
def write_to_server_log(message): server_log_dir = os.path.join(pydevtest_common.get_irods_top_level_dir(), 'iRODS/server/log') proc = subprocess.Popen('ls -t ' + server_log_dir + '/rodsLog* | head -n1', stdout=subprocess.PIPE, shell=True) log_file_path, err = proc.communicate() with open(log_file_path.rstrip(), 'a') as f: f.write(message)
def test_host_access_control(self): my_ip = socket.gethostbyname(socket.gethostname()) # manipulate the core.re to enable host access control corefile = get_irods_config_dir() + "/core.re" backupcorefile = corefile + "--" + self._testMethodName shutil.copy(corefile, backupcorefile) os.system( '''sed -e '/^acChkHostAccessControl { }/i acChkHostAccessControl { msiCheckHostAccessControl; }' /etc/irods/core.re > /tmp/irods/core.re''') time.sleep(1) # remove once file hash fix is commited #2279 os.system("cp /tmp/irods/core.re /etc/irods/core.re") time.sleep(1) # remove once file hash fix is commited #2279 # restart the server to reread the new core.re os.system(get_irods_top_level_dir() + "/iRODS/irodsctl stop") os.system(get_irods_top_level_dir() + "/iRODS/irodsctl start") host_access_control = '' if os.path.isfile('/etc/irods/host_access_control.json'): host_access_control = '/etc/irods/host_access_control.json' else: install_dir = os.path.dirname( os.path.dirname( os.path.realpath(__file__))) host_access_control = install_dir + '/iRODS/server/config/host_access_control.json' orig_file = host_access_control + '.orig' os.system('cp %s %s' % (host_access_control, orig_file)) write_host_access_control(host_access_control, 'nope', 'nope', '', '') assertiCmdFail(s.adminsession, "ils", "ERROR", "SYS_AGENT_INIT_ERR") write_host_access_control(host_access_control, 'all', 'all', my_ip, '255.255.255.255') assertiCmd(s.adminsession, "ils", "LIST", "tempZone") # restore the original host_access_control.json os.system('mv %s %s' % (orig_file, host_access_control)) # restore the original core.re shutil.copy(backupcorefile, corefile) os.remove(backupcorefile)
def tearDown(self): # revert to original server.config os.system("mv -f %s_orig %s" % (self.serverConfigFile, self.serverConfigFile)) # restart server my_env = os.environ.copy() args = [get_irods_top_level_dir() + '/iRODS/irodsctl', 'restart'] subprocess.Popen(args, env=my_env).communicate() # Close admin session s.admin_down()
def tearDown(self): # revert to original server_config.json os.system("mv -f %s_orig %s" % (self.serverConfigFile, self.serverConfigFile)) # restart server my_env = os.environ.copy() args = [get_irods_top_level_dir() + '/iRODS/irodsctl', 'restart'] subprocess.Popen(args, env=my_env).communicate() # Close admin session s.admin_down()
def test_local_iput_physicalpath(self): # local setup datafilename = "newfile.txt" f = open(datafilename,'wb') f.write("TESTFILE -- ["+datafilename+"]") f.close() # assertions fullpath = get_irods_top_level_dir() + "/newphysicalpath.txt" assertiCmd(s.adminsession,"iput -p "+fullpath+" "+datafilename) # should complete assertiCmd(s.adminsession,"ils -L "+datafilename,"LIST",datafilename) # should be listed assertiCmd(s.adminsession,"ils -L "+datafilename,"LIST",fullpath) # should be listed # local cleanup output = commands.getstatusoutput( 'rm '+datafilename )
def test_local_iput_physicalpath(self): # local setup datafilename = "newfile.txt" f = open(datafilename, 'wb') f.write("TESTFILE -- [" + datafilename + "]") f.close() # assertions fullpath = get_irods_top_level_dir() + "/newphysicalpath.txt" assertiCmd(s.adminsession, "iput -p " + fullpath + " " + datafilename) # should complete assertiCmd(s.adminsession, "ils -L " + datafilename, "LIST", datafilename) # should be listed assertiCmd(s.adminsession, "ils -L " + datafilename, "LIST", fullpath) # should be listed # local cleanup output = commands.getstatusoutput('rm ' + datafilename)
def setUp(self): # Set up admin session s.admin_up() # add Xmsg settings to server.config os.system("cp %s %s_orig" % (self.serverConfigFile, self.serverConfigFile)) os.system('echo "xmsgHost %s" >> %s' % (self.xmsgHost, self.serverConfigFile)) os.system('echo "xmsgPort %s" >> %s' % (self.xmsgPort, self.serverConfigFile)) # apparently needed by the server too... my_env = os.environ.copy() my_env['xmsgHost'] = self.xmsgHost my_env['xmsgPort'] = self.xmsgPort # restart server with Xmsg args = [get_irods_top_level_dir() + '/iRODS/irodsctl', 'restart'] subprocess.Popen(args, env=my_env).communicate()
def setUp(self): # Set up admin session s.admin_up() # add Xmsg settings to server.config os.system("cp %s %s_orig" % (self.serverConfigFile, self.serverConfigFile)) os.system('echo "xmsgHost %s" >> %s' % (self.xmsgHost, self.serverConfigFile)) os.system('echo "xmsgPort %s" >> %s' % (self.xmsgPort, self.serverConfigFile)) # apparently needed by the server too... my_env = os.environ.copy() my_env['xmsgHost'] = self.xmsgHost my_env['xmsgPort'] = self.xmsgPort # restart server with Xmsg args = [get_irods_top_level_dir() + '/iRODS/irodsctl', 'restart'] subprocess.Popen(args, env=my_env).communicate()
def setUp(self): # Set up admin session s.admin_up() # add Xmsg settings to server_config.json with open(self.serverConfigFile) as f: contents = json.load(f) os.system("cp %s %s_orig" % (self.serverConfigFile, self.serverConfigFile)) contents["xmsg_host"] = self.xmsgHost contents["xmsg_port"] = self.xmsgPort with open(self.serverConfigFile, 'w') as f: json.dump(contents, f) # apparently needed by the server too... my_env = os.environ.copy() my_env['XMSG_HOST'] = self.xmsgHost my_env['XMSG_PORT'] = str(self.xmsgPort) # restart server with Xmsg args = [get_irods_top_level_dir() + '/iRODS/irodsctl', 'restart'] subprocess.Popen(args, env=my_env).communicate()
def setUp(self): # Set up admin session s.admin_up() # add Xmsg settings to server_config.json with open(self.serverConfigFile) as f: contents = json.load(f) os.system("cp %s %s_orig" % (self.serverConfigFile, self.serverConfigFile)) contents["xmsg_host"] = self.xmsgHost contents["xmsg_port"] = self.xmsgPort with open(self.serverConfigFile, 'w') as f: json.dump(contents, f) # apparently needed by the server too... my_env = os.environ.copy() my_env['XMSG_HOST'] = self.xmsgHost my_env['XMSG_PORT'] = str(self.xmsgPort) # restart server with Xmsg args = [get_irods_top_level_dir() + '/iRODS/irodsctl', 'restart'] subprocess.Popen(args, env=my_env).communicate()
def test_authentication_PAM_without_negotiation(self): # add auth test user authTestUser = "******" authTestPass = "******" assertiCmd(s.adminsession, "iadmin mkuser %s rodsuser" % authTestUser) # set up client and server side for ssl handshake # server side certificate setup os.system("openssl genrsa -out server.key") #os.system("openssl req -batch -new -key server.key -out server.csr") # if use external CA os.system( "openssl req -batch -new -x509 -key server.key -out server.crt -days 365" ) # self-signed certificate os.system("mv server.crt chain.pem") os.system("openssl dhparam -2 -out dhparams.pem 100" ) # normally 2048, but smaller size here for speed # server side environment variables os.environ['irodsSSLCertificateChainFile'] = get_irods_top_level_dir( ) + "/tests/pydevtest/chain.pem" os.environ['irodsSSLCertificateKeyFile'] = get_irods_top_level_dir( ) + "/tests/pydevtest/server.key" os.environ['irodsSSLDHParamsFile'] = get_irods_top_level_dir( ) + "/tests/pydevtest/dhparams.pem" # client side environment variables os.environ['irodsSSLVerifyServer'] = "none" # add client irodsEnv settings clientEnvFile = s.adminsession.sessionDir + "/.irodsEnv" os.system("cp %s %sOrig" % (clientEnvFile, clientEnvFile)) # os.system("echo \"irodsClientServerPolicy 'CS_NEG_REQUIRE'\" >> %s" % clientEnvFile) # commented out to test legacy SSL path os.system("echo \"irodsAuthScheme 'PaM'\" >> %s" % clientEnvFile) # check for auth to_lower os.system("echo \"irodsUserName '%s'\" >> %s" % (authTestUser, clientEnvFile)) os.system("echo \"irodsHome '/tempZone/home/%s'\" >> %s" % (authTestUser, clientEnvFile)) os.system("echo \"irodsCwd '/tempZone/home/%s'\" >> %s" % (authTestUser, clientEnvFile)) # server reboot to pick up new irodsEnv settings os.system(get_irods_top_level_dir() + "/iRODS/irodsctl restart") # do the reauth assertiCmd(s.adminsession, "iinit %s" % authTestPass) # reinitialize # connect and list some files assertiCmd(s.adminsession, "icd") # home directory assertiCmd(s.adminsession, "ils -L", "LIST", "home") # should be listed # reset client environment to original os.system("mv %sOrig %s" % (clientEnvFile, clientEnvFile)) # reconnect as admin assertiCmd(s.adminsession, "iinit %s" % s.users[0]['passwd']) # reinitialize # remove auth test user assertiCmd(s.adminsession, "iadmin rmuser %s" % authTestUser) # clean up os.system("rm server.key chain.pem dhparams.pem")
from __future__ import with_statement import os import shutil import subprocess import datetime import time import psutil import sys import json from pydevtest_common import get_irods_top_level_dir '''Originally written by Antoine de Torcy''' RODSLOGDIR = get_irods_top_level_dir() + "/iRODS/server/log" class RodsEnv(object): '''Contains Env/Auth variables. Used as argument for RodsSession.createEnvFiles(). ''' def __init__(self, host, port, defRes, homeColl, cwd, username, zone, auth, csnegotiation, cspolicy, enckeysize, encsaltsize, encnumhashrounds, encalgorithm, defaulthashscheme): self.host = host self.port = port self.defRes = defRes self.homeColl = homeColl self.cwd = cwd self.username = username self.zone = zone
import os if (sys.version_info >= (2, 7)): import unittest else: import unittest2 as unittest from resource_suite import ResourceBase from pydevtest_common import assertiCmd, assertiCmdFail, interruptiCmd, getiCmdOutput, get_irods_top_level_dir import pydevtest_sessions as s import commands import os import shlex import datetime import time import socket RODSHOME = get_irods_top_level_dir() + "/iRODS/" ABSPATHTESTDIR = os.path.abspath(os.path.dirname(sys.argv[0])) RODSHOME = ABSPATHTESTDIR + "/../../iRODS" class Test_ireg_Suite(unittest.TestCase, ResourceBase): my_test_resource = {"setup": [], "teardown": []} def setUp(self): ResourceBase.__init__(self) s.twousers_up() shutil.copy2(ABSPATHTESTDIR + '/test_ireg_suite.py', ABSPATHTESTDIR + '/file0') shutil.copy2(ABSPATHTESTDIR + '/test_ireg_suite.py', ABSPATHTESTDIR + '/file1') shutil.copy2(ABSPATHTESTDIR + '/test_ireg_suite.py', ABSPATHTESTDIR + '/file2') shutil.copy2(ABSPATHTESTDIR + '/test_ireg_suite.py', ABSPATHTESTDIR + '/file3')
from __future__ import with_statement import os import shutil import subprocess import datetime import time import psutil import sys import json from pydevtest_common import get_irods_top_level_dir '''Originally written by Antoine de Torcy''' RODSLOGDIR = get_irods_top_level_dir() + "/iRODS/server/log" class RodsEnv(object): '''Contains Env/Auth variables. Used as argument for RodsSession.createEnvFiles(). ''' def __init__(self, host, port, defRes, homeColl, cwd, username, zone, auth, csnegotiation, cspolicy, enckeysize, encsaltsize, encnumhashrounds, encalgorithm, defaulthashscheme): self.host = host self.port = port self.defRes = defRes self.homeColl = homeColl self.cwd = cwd self.username = username self.zone = zone self.auth = auth
def test_authentication_PAM_with_server_params(self): # add auth test user authTestUser = "******" authTestPass = "******" assertiCmd(s.adminsession,"iadmin mkuser %s rodsuser" % authTestUser) # set up client and server side for ssl handshake # server side certificate setup os.system("openssl genrsa -out server.key") # os.system("openssl req -batch -new -key server.key -out server.csr") # if use external CA os.system("openssl req -batch -new -x509 -key server.key -out server.crt -days 365") # self-signed certificate os.system("mv server.crt chain.pem") os.system("openssl dhparam -2 -out dhparams.pem 100") # normally 2048, but smaller size here for speed # server side environment variables os.environ['irodsSSLCertificateChainFile'] = get_irods_top_level_dir() + "/tests/pydevtest/chain.pem" os.environ['irodsSSLCertificateKeyFile'] = get_irods_top_level_dir() + "/tests/pydevtest/server.key" os.environ['irodsSSLDHParamsFile'] = get_irods_top_level_dir() + "/tests/pydevtest/dhparams.pem" # client side environment variables os.environ['irodsSSLVerifyServer'] = "none" # add client irodsEnv settings clientEnvFile = s.adminsession.sessionDir+"/.irodsEnv" os.system("cp %s %sOrig" % (clientEnvFile, clientEnvFile)) os.system("echo \"irodsClientServerPolicy 'CS_NEG_REQUIRE'\" >> %s" % clientEnvFile) os.system("echo \"irodsAuthScheme 'PaM'\" >> %s" % clientEnvFile) # check for auth to_lower os.system("echo \"irodsUserName '%s'\" >> %s" % (authTestUser, clientEnvFile)) os.system("echo \"irodsHome '/tempZone/home/%s'\" >> %s" % (authTestUser, clientEnvFile)) os.system("echo \"irodsCwd '/tempZone/home/%s'\" >> %s" % (authTestUser, clientEnvFile)) # add server.config settings serverConfigFile = get_irods_config_dir() + "/server.config" os.system("cp %s %sOrig" % (serverConfigFile, serverConfigFile)) os.system("echo \"pam_password_length 20\" >> %s" % serverConfigFile) os.system("echo \"pam_no_extend false\" >> %s" % serverConfigFile) os.system("echo \"pam_password_min_time 121\" >> %s" % serverConfigFile) os.system("echo \"pam_password_max_time 1209600\" >> %s" % serverConfigFile) # server reboot to pick up new irodsEnv and server settings os.system(get_irods_top_level_dir() + "/iRODS/irodsctl restart") # do the reauth assertiCmd(s.adminsession,"iinit %s" % authTestPass) # reinitialize # connect and list some files assertiCmd(s.adminsession,"icd") # home directory assertiCmd(s.adminsession,"ils -L","LIST","home") # should be listed # reset client environment to original os.system("mv %sOrig %s" % (clientEnvFile, clientEnvFile)) # reconnect as admin assertiCmd(s.adminsession,"iinit %s" % s.users[0]['passwd']) # reinitialize # remove auth test user assertiCmd(s.adminsession,"iadmin rmuser %s" % authTestUser) # clean up os.system("rm server.key chain.pem dhparams.pem") # reset server.config to original os.system("mv %sOrig %s" % (serverConfigFile, serverConfigFile)) # server reboot to revert to previous server configuration os.system(get_irods_top_level_dir() + "/iRODS/irodsctl stop") os.system(get_irods_top_level_dir() + "/tests/zombiereaper.sh") os.system(get_irods_top_level_dir() + "/iRODS/irodsctl start")
def test_authentication_PAM_with_server_params(self): # add auth test user authTestUser = "******" authTestPass = "******" assertiCmd(s.adminsession, "iadmin mkuser %s rodsuser" % authTestUser) # set up client and server side for ssl handshake # server side certificate setup os.system("openssl genrsa -out server.key") # os.system("openssl req -batch -new -key server.key -out server.csr") # if use external CA # self-signed certificate os.system("openssl req -batch -new -x509 -key server.key -out server.crt -days 365") os.system("mv server.crt chain.pem") os.system("openssl dhparam -2 -out dhparams.pem 100") # normally 2048, but smaller size here for speed # server side environment variables os.environ['irodsSSLCertificateChainFile'] = get_irods_top_level_dir() + "/tests/pydevtest/chain.pem" os.environ['irodsSSLCertificateKeyFile'] = get_irods_top_level_dir() + "/tests/pydevtest/server.key" os.environ['irodsSSLDHParamsFile'] = get_irods_top_level_dir() + "/tests/pydevtest/dhparams.pem" # client side environment variables os.environ['irodsSSLVerifyServer'] = "none" # add client irodsEnv settings clientEnvFile = s.adminsession._session_dir + "/irods_environment.json" os.system("cp %s %sOrig" % (clientEnvFile, clientEnvFile)) env = {} env['irods_client_server_policy'] = 'CS_NEG_REQUIRE' env['irods_authentication_scheme'] = "PaM" env['irods_user_name'] = authTestUser env['irods_home'] = '/tempZone/home/' + authTestUser env['irods_cwd'] = '/tempZone/home/' + authTestUser update_json_file_from_dict(clientEnvFile, env) # add server_config.json settings serverConfigFile = get_irods_config_dir() + "/server_config.json" with open(serverConfigFile) as f: contents = json.load(f) os.system("cp %s %sOrig" % (serverConfigFile, serverConfigFile)) contents['pam_password_length'] = 20 contents['pam_no_extend'] = False contents['pam_password_min_time'] = 121 contents['pam_password_max_time'] = 1209600 with open(serverConfigFile, 'w') as f: json.dump(contents, f) # server reboot to pick up new irodsEnv and server settings os.system(get_irods_top_level_dir() + "/iRODS/irodsctl restart") # do the reauth assertiCmd(s.adminsession, "iinit %s" % authTestPass) # reinitialize # connect and list some files assertiCmd(s.adminsession, "icd") # home directory assertiCmd(s.adminsession, "ils -L", "LIST", "home") # should be listed # reset client environment to original os.system("mv %sOrig %s" % (clientEnvFile, clientEnvFile)) # reconnect as admin assertiCmd(s.adminsession, "iinit %s" % s.adminsession._password) # reinitialize # remove auth test user assertiCmd(s.adminsession, "iadmin rmuser %s" % authTestUser) # clean up os.system("rm server.key chain.pem dhparams.pem") # reset server_config.json to original os.system("mv %sOrig %s" % (serverConfigFile, serverConfigFile)) # server reboot to revert to previous server configuration os.system(get_irods_top_level_dir() + "/iRODS/irodsctl stop") os.system(get_irods_top_level_dir() + "/tests/zombiereaper.sh") os.system(get_irods_top_level_dir() + "/iRODS/irodsctl start")
class Test_MSOSuite(unittest.TestCase, ResourceBase): hostname = socket.gethostname() my_test_resource = { "setup": [ "iadmin modresc demoResc name origResc", "iadmin mkresc demoResc compound", "iadmin mkresc cacheResc 'unix file system' " + hostname + ":" + get_irods_top_level_dir() + "/cacheRescVault", "iadmin mkresc archiveResc mso " + hostname + ":/fake/vault/", "iadmin addchildtoresc demoResc cacheResc cache", "iadmin addchildtoresc demoResc archiveResc archive", ], "teardown": [ "iadmin rmchildfromresc demoResc archiveResc", "iadmin rmchildfromresc demoResc cacheResc", "iadmin rmresc archiveResc", "iadmin rmresc cacheResc", "iadmin rmresc demoResc", "iadmin modresc origResc name demoResc", "rm -rf " + get_irods_top_level_dir() + "/archiveRescVault", "rm -rf " + get_irods_top_level_dir() + "/cacheRescVault", ], } def setUp(self): ResourceBase.__init__(self) s.twousers_up() self.run_resource_setup() def tearDown(self): self.run_resource_teardown() s.twousers_down() def test_mso_http(self): test_file_path = "/" + s.adminsession.get_zone_name() + "/home/" + s.adminsession.get_username() + \ "/" + s.adminsession._session_id assertiCmd(s.adminsession, 'ireg -D mso -R archiveResc "//http://people.renci.org/~jasonc/irods/http_mso_test_file.txt" ' + test_file_path + '/test_file.txt') assertiCmd(s.adminsession, 'iget -f ' + test_file_path + '/test_file.txt') assertiCmdFail(s.adminsession, 'ils -L ' + test_file_path + '/test_file.txt', 'STDOUT', ' -99 ') os.remove('test_file.txt') # unregister the object assertiCmd(s.adminsession, 'irm -U ' + test_file_path + '/test_file.txt') assertiCmd(s.adminsession, 'ils -L', 'STDOUT', 'tempZone') def test_mso_slink(self): test_file_path = "/" + s.adminsession.get_zone_name() + "/home/" + s.adminsession.get_username() + \ "/" + s.adminsession._session_id assertiCmd(s.adminsession, 'iput -fR origResc ../zombiereaper.sh src_file.txt') assertiCmd(s.adminsession, 'ireg -D mso -R archiveResc "//slink:' + test_file_path + '/src_file.txt" ' + test_file_path + '/test_file.txt') assertiCmd(s.adminsession, 'iget -f ' + test_file_path + '/test_file.txt') result = os.system("diff %s %s" % ('./test_file.txt', '../zombiereaper.sh')) assert result == 0 assertiCmd(s.adminsession, 'iput -f ../zombiereaper.sh ' + test_file_path + '/test_file.txt') # unregister the object assertiCmd(s.adminsession, 'irm -U ' + test_file_path + '/test_file.txt') def test_mso_irods(self): hostname = socket.gethostname() test_file_path = "/" + s.adminsession.get_zone_name() + "/home/" + s.adminsession.get_username() + \ "/" + s.adminsession._session_id assertiCmd(s.adminsession, 'iput -fR pydevtest_AnotherResc ../zombiereaper.sh src_file.txt') assertiCmd(s.adminsession, 'ireg -D mso -R archiveResc "//irods:' + hostname + ':1247:rods@tempZone' + test_file_path + '/src_file.txt" ' + test_file_path + '/test_file.txt') assertiCmd(s.adminsession, 'iget -f ' + test_file_path + '/test_file.txt') result = os.system("diff %s %s" % ('./test_file.txt', '../zombiereaper.sh')) assert result == 0 assertiCmd(s.adminsession, 'iput -f ../zombiereaper.sh ' + test_file_path + '/test_file.txt') # unregister the object assertiCmd(s.adminsession, 'irm -U ' + test_file_path + '/test_file.txt') assertiCmd(s.adminsession, 'irm -f src_file.txt')
import os if (sys.version_info >= (2, 7)): import unittest else: import unittest2 as unittest from resource_suite import ResourceBase from pydevtest_common import assertiCmd, assertiCmdFail, interruptiCmd, getiCmdOutput, get_irods_top_level_dir import pydevtest_sessions as s import commands import os import shlex import datetime import time import socket RODSHOME = get_irods_top_level_dir() + "/iRODS/" ABSPATHTESTDIR = os.path.abspath(os.path.dirname(sys.argv[0])) RODSHOME = ABSPATHTESTDIR + "/../../iRODS" FILESDIR = ABSPATHTESTDIR + '/workflow_testfiles' class Test_ireg_Suite(unittest.TestCase, ResourceBase): my_test_resource = {"setup": [], "teardown": []} def setUp(self): ResourceBase.__init__(self) s.twousers_up() shutil.copy2(ABSPATHTESTDIR + '/test_ireg_suite.py', ABSPATHTESTDIR + '/file0') shutil.copy2(ABSPATHTESTDIR + '/test_ireg_suite.py', ABSPATHTESTDIR + '/file1') shutil.copy2(ABSPATHTESTDIR + '/test_ireg_suite.py', ABSPATHTESTDIR + '/file2')
def test_authentication_PAM_with_server_params(self): # add auth test user authTestUser = "******" authTestPass = "******" assertiCmd(s.adminsession,"iadmin mkuser %s rodsuser" % authTestUser) # set up client and server side for ssl handshake # server side certificate setup os.system("openssl genrsa -out server.key") # os.system("openssl req -batch -new -key server.key -out server.csr") # if use external CA os.system("openssl req -batch -new -x509 -key server.key -out server.crt -days 365") # self-signed certificate os.system("mv server.crt chain.pem") os.system("openssl dhparam -2 -out dhparams.pem 100") # normally 2048, but smaller size here for speed # server side environment variables os.environ['irodsSSLCertificateChainFile'] = get_irods_top_level_dir() + "/tests/pydevtest/chain.pem" os.environ['irodsSSLCertificateKeyFile'] = get_irods_top_level_dir() + "/tests/pydevtest/server.key" os.environ['irodsSSLDHParamsFile'] = get_irods_top_level_dir() + "/tests/pydevtest/dhparams.pem" # client side environment variables os.environ['irodsSSLVerifyServer'] = "none" # add client irodsEnv settings clientEnvFile = s.adminsession.sessionDir+"/irods_environment.json" os.system("cp %s %sOrig" % (clientEnvFile, clientEnvFile)) env = {} env['irods_client_server_policy'] = 'CS_NEG_REQUIRE' env['irods_authentication_scheme'] = "PaM" env['irods_user_name'] = authTestUser env['irods_home'] = '/tempZone/home/'+authTestUser env['irods_cwd'] = '/tempZone/home/'+authTestUser mod_json_file(clientEnvFile,env); # add server_config.json settings serverConfigFile = get_irods_config_dir() + "/server_config.json" with open(serverConfigFile) as f: contents = json.load(f) os.system("cp %s %sOrig" % (serverConfigFile, serverConfigFile)) contents['pam_password_length'] = 20; contents['pam_no_extend'] = False; contents['pam_password_min_time'] = 121; contents['pam_password_max_time'] = 1209600; with open(serverConfigFile, 'w') as f: json.dump(contents, f) # server reboot to pick up new irodsEnv and server settings os.system(get_irods_top_level_dir() + "/iRODS/irodsctl restart") # do the reauth assertiCmd(s.adminsession,"iinit %s" % authTestPass) # reinitialize # connect and list some files assertiCmd(s.adminsession,"icd") # home directory assertiCmd(s.adminsession,"ils -L","LIST","home") # should be listed # reset client environment to original os.system("mv %sOrig %s" % (clientEnvFile, clientEnvFile)) # reconnect as admin assertiCmd(s.adminsession,"iinit %s" % s.users[0]['passwd']) # reinitialize # remove auth test user assertiCmd(s.adminsession,"iadmin rmuser %s" % authTestUser) # clean up os.system("rm server.key chain.pem dhparams.pem") # reset server_config.json to original os.system("mv %sOrig %s" % (serverConfigFile, serverConfigFile)) # server reboot to revert to previous server configuration os.system(get_irods_top_level_dir() + "/iRODS/irodsctl stop") os.system(get_irods_top_level_dir() + "/tests/zombiereaper.sh") os.system(get_irods_top_level_dir() + "/iRODS/irodsctl start")
class Test_MSOSuite(unittest.TestCase, ResourceBase): hostname = socket.gethostname() my_test_resource = { "setup" : [ "iadmin modresc demoResc name origResc", "iadmin mkresc demoResc compound", "iadmin mkresc cacheResc 'unix file system' "+hostname+":" + get_irods_top_level_dir() + "/cacheRescVault", "iadmin mkresc archiveResc mso "+hostname+":/fake/vault/", "iadmin addchildtoresc demoResc cacheResc cache", "iadmin addchildtoresc demoResc archiveResc archive", ], "teardown" : [ "iadmin rmchildfromresc demoResc archiveResc", "iadmin rmchildfromresc demoResc cacheResc", "iadmin rmresc archiveResc", "iadmin rmresc cacheResc", "iadmin rmresc demoResc", "iadmin modresc origResc name demoResc", "rm -rf " + get_irods_top_level_dir() + "/archiveRescVault", "rm -rf " + get_irods_top_level_dir() + "/cacheRescVault", ], } def setUp(self): ResourceBase.__init__(self) s.twousers_up() self.run_resource_setup() def tearDown(self): self.run_resource_teardown() s.twousers_down() def test_mso_http(self): test_file_path = "/"+s.adminsession.getZoneName()+"/home/"+s.adminsession.getUserName()+"/"+s.adminsession.sessionId assertiCmd( s.adminsession, 'ireg -D mso -R archiveResc "//http://people.renci.org/~jasonc/irods/http_mso_test_file.txt" '+test_file_path+'/test_file.txt') assertiCmd( s.adminsession, 'iget -f '+test_file_path+'/test_file.txt') shutil.copy( 'test_file.txt', 'backup_test_file.txt' ) myfile = open( 'test_file.txt', "a") myfile.write('THIS IS A NEW LINE\n') myfile.close() assertiCmd( s.adminsession, 'iput -f test_file.txt '+test_file_path+'/test_file.txt') os.remove( 'test_file.txt' ) assertiCmd( s.adminsession, 'iget -f '+test_file_path+'/test_file.txt') result = os.system("diff %s %s" % ( 'test_file.txt', 'backup_test_file.txt' )) assert result != 0 # repave remote file with old copy of the file assertiCmd( s.adminsession, 'iput -f backup_test_file.txt '+test_file_path+'/test_file.txt') # unregister the object assertiCmd( s.adminsession, 'irm -U '+test_file_path+'/test_file.txt') os.remove( 'test_file.txt' ) os.remove( 'backup_test_file.txt' ) def test_mso_slink(self): test_file_path = "/"+s.adminsession.getZoneName()+"/home/"+s.adminsession.getUserName()+"/"+s.adminsession.sessionId assertiCmd( s.adminsession, 'iput -fR origResc ../zombiereaper.sh src_file.txt' ) assertiCmd( s.adminsession, 'ireg -D mso -R archiveResc "//slink:'+test_file_path+'/src_file.txt" '+test_file_path+'/test_file.txt') assertiCmd( s.adminsession, 'iget -f '+test_file_path+'/test_file.txt') result = os.system("diff %s %s" % ( './test_file.txt', '../zombiereaper.sh' )) assert result == 0 assertiCmd( s.adminsession, 'iput -f ../zombiereaper.sh '+test_file_path+'/test_file.txt') # unregister the object assertiCmd( s.adminsession, 'irm -U '+test_file_path+'/test_file.txt') def test_mso_irods(self): hostname = socket.gethostname() test_file_path = "/"+s.adminsession.getZoneName()+"/home/"+s.adminsession.getUserName()+"/"+s.adminsession.sessionId assertiCmd( s.adminsession, 'iput -fR origResc ../zombiereaper.sh src_file.txt' ) assertiCmd( s.adminsession, 'ireg -D mso -R archiveResc "//irods:'+hostname+':1247:rods@tempZone'+test_file_path+'/src_file.txt" '+test_file_path+'/test_file.txt') assertiCmd( s.adminsession, 'iget -f '+test_file_path+'/test_file.txt') result = os.system("diff %s %s" % ( './test_file.txt', '../zombiereaper.sh' )) assert result == 0 assertiCmd( s.adminsession, 'iput -f ../zombiereaper.sh '+test_file_path+'/test_file.txt') # unregister the object assertiCmd( s.adminsession, 'irm -U '+test_file_path+'/test_file.txt')
class Test_LoadBalanced_Resource(unittest.TestCase, ResourceBase): hostname = socket.gethostname() my_test_resource = { "setup": [ "iadmin modresc demoResc name origResc", "iadmin mkresc demoResc load_balanced", "iadmin mkresc rescA 'unix file system' " + hostname + ":" + get_irods_top_level_dir() + "/rescAVault", "iadmin mkresc rescB 'unix file system' " + hostname + ":" + get_irods_top_level_dir() + "/rescBVault", "iadmin mkresc rescC 'unix file system' " + hostname + ":" + get_irods_top_level_dir() + "/rescCVault", "iadmin addchildtoresc demoResc rescA", "iadmin addchildtoresc demoResc rescB", "iadmin addchildtoresc demoResc rescC", ], "teardown": [ "iadmin rmchildfromresc demoResc rescA", "iadmin rmchildfromresc demoResc rescB", "iadmin rmchildfromresc demoResc rescC", "iadmin rmresc rescA", "iadmin rmresc rescB", "iadmin rmresc rescC", "iadmin rmresc demoResc", "iadmin modresc origResc name demoResc", "rm -rf " + get_irods_top_level_dir() + "/rescAVault", "rm -rf " + get_irods_top_level_dir() + "/rescBVault", "rm -rf " + get_irods_top_level_dir() + "/rescCVault", ], } def setUp(self): ResourceBase.__init__(self) s.twousers_up() self.run_resource_setup() def tearDown(self): self.run_resource_teardown() s.twousers_down() def test_load_balanced(self): # =-=-=-=-=-=-=- # read server.config and .odbc.ini cfg = Server_Config() if cfg.values['catalog_database_type'] == "postgres": # =-=-=-=-=-=-=- # seed load table with fake values - rescA should win secs = int(time.time()) cfg.exec_sql_cmd( "insert into r_server_load_digest values ('rescA', 50, %s)" % secs) cfg.exec_sql_cmd( "insert into r_server_load_digest values ('rescB', 75, %s)" % secs) cfg.exec_sql_cmd( "insert into r_server_load_digest values ('rescC', 95, %s)" % secs) # =-=-=-=-=-=-=- # build a logical path for putting a file test_file_path = "/" + s.adminsession.getZoneName( ) + "/home/" + s.adminsession.getUserName( ) + "/" + s.adminsession.sessionId test_file = test_file_path + "/test_file.txt" # =-=-=-=-=-=-=- # put a test_file.txt - should be on rescA given load table values assertiCmd(s.adminsession, "iput -f ./test_load_balanced_suite.py " + test_file) assertiCmd(s.adminsession, "ils -L " + test_file, "LIST", "rescA") assertiCmd(s.adminsession, "irm -f " + test_file) # =-=-=-=-=-=-=- # drop rescC to a load of 15 - this should now win cfg.exec_sql_cmd( "update r_server_load_digest set load_factor=15 where resc_name='rescC'" ) # =-=-=-=-=-=-=- # put a test_file.txt - should be on rescC given load table values assertiCmd(s.adminsession, "iput -f ./test_load_balanced_suite.py " + test_file) assertiCmd(s.adminsession, "ils -L " + test_file, "LIST", "rescC") assertiCmd(s.adminsession, "irm -f " + test_file) # =-=-=-=-=-=-=- # clean up our alterations to the load table cfg.exec_sql_cmd( "delete from r_server_load_digest where resc_name='rescA'") cfg.exec_sql_cmd( "delete from r_server_load_digest where resc_name='rescB'") cfg.exec_sql_cmd( "delete from r_server_load_digest where resc_name='rescC'") else: print 'skipping test_load_balanced due to unsupported database for this test.'
def write_to_server_log(message): server_log_dir = os.path.join(pydevtest_common.get_irods_top_level_dir(), 'iRODS/server/log') proc = subprocess.Popen('ls -t ' + server_log_dir + '/rodsLog* | head -n1', stdout=subprocess.PIPE, shell=True) log_file_path, err = proc.communicate() with open(log_file_path.rstrip(), 'a') as f: f.write(message)