Skip to content

Commit c8b5735

Browse files
committed
[_519][_3] updated tests including for irods_ssl_verify_server = "none"
1 parent 198b283 commit c8b5735

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

irods/test/login_auth_test.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from re import compile as regex
2525
import gc
2626
import six
27+
from irods.test.setupssl import create_ssl_dir
2728

2829
#
2930
# Allow override to specify the PAM password in effect for the test rodsuser.
@@ -57,7 +58,7 @@ def env_dir_fullpath(authtype): return os.path.join( os.environ['HOME'] , '.iro
5758
def json_env_fullpath(authtype): return os.path.join( env_dir_fullpath(authtype), 'irods_environment.json')
5859
def secrets_fullpath(authtype): return os.path.join( env_dir_fullpath(authtype), '.irodsA')
5960

60-
SERVER_ENV_PATH = os.path.expanduser('~irods/.irods/irods_environment.json')
61+
RODSADMIN_ENV_PATH = os.path.expanduser('~/.irods/irods_environment.json')
6162

6263
SERVER_ENV_SSL_SETTINGS = {
6364
"irods_ssl_certificate_chain_file": "/etc/irods/ssl/irods.crt",
@@ -67,9 +68,6 @@ def secrets_fullpath(authtype): return os.path.join( env_dir_fullpath(authtype
6768
"irods_ssl_verify_server": "cert"
6869
}
6970

70-
def update_service_account_for_SSL():
71-
json_file_update( SERVER_ENV_PATH, **SERVER_ENV_SSL_SETTINGS )
72-
7371
CLIENT_OPTIONS_FOR_SSL = {
7472
"irods_client_server_policy": "CS_NEG_REQUIRE",
7573
"irods_client_server_negotiation": "request_server_negotiation",
@@ -82,9 +80,9 @@ def update_service_account_for_SSL():
8280
}
8381

8482

85-
def client_env_from_server_env(user_name, auth_scheme=""):
83+
def client_env_keys_from_admin_env(user_name, auth_scheme=""):
8684
cli_env = {}
87-
with open(SERVER_ENV_PATH) as f:
85+
with open(RODSADMIN_ENV_PATH) as f:
8886
srv_env = json.load(f)
8987
for k in [ "irods_host", "irods_zone_name", "irods_port" ]:
9088
cli_env [k] = srv_env[k]
@@ -163,7 +161,7 @@ def create_env_dirs(self):
163161
# -- create environment configurations and secrets
164162
with pam_password_in_plaintext():
165163
for dirname,lookup in self.user_auth_envs.items():
166-
if lookup['AUTH'] == 'pam':
164+
if lookup['AUTH'] in ('pam','pam_password'):
167165
ses = iRODSSession( host=gethostname(),
168166
user=lookup['USER'],
169167
zone='tempZone',
@@ -179,7 +177,7 @@ def create_env_dirs(self):
179177
#elif lookup['AUTH'] == 'XXXXXX': # TODO: insert other authentication schemes here
180178
elif lookup['AUTH'] in ('native', '',None):
181179
scrambled_pw = pw_encode( lookup['PASSWORD'] )
182-
cl_env = client_env_from_server_env(TEST_RODS_USER)
180+
cl_env = client_env_keys_from_admin_env(TEST_RODS_USER)
183181
if lookup.get('AUTH',None) is not None: # - specify auth scheme only if given
184182
cl_env['irods_authentication_scheme'] = lookup['AUTH']
185183
dirbase = os.path.join(os.environ['HOME'],dirname)
@@ -199,18 +197,19 @@ def create_env_dirs(self):
199197
retval = dirs.keys()
200198
return retval
201199

200+
PAM_SCHEME_STRING = 'pam'
202201

203202
@classmethod
204203
def setUpClass(cls):
205204
cls.admin = helpers.make_session()
205+
if cls.admin.server_version > (4,3):
206+
cls.PAM_SCHEME_STRING = cls.user_auth_envs['.irods.pam']['AUTH'] = 'pam_password'
206207

207208
@classmethod
208209
def tearDownClass(cls):
209210
cls.admin.cleanup()
210211

211212
def setUp(self):
212-
if os.environ['HOME'] != '/var/lib/irods':
213-
self.skipTest('Must be run as irods')
214213
super(TestLogins,self).setUp()
215214

216215
def tearDown(self):
@@ -244,12 +243,14 @@ def _setup_rodsuser_and_optional_pw(self, name, make_irods_pw = False):
244243
self.admin.users.remove( name )
245244

246245
def tst0(self, ssl_opt, auth_opt, env_opt, name = TEST_RODS_USER, make_irods_pw = False):
247-
246+
_auth_opt = auth_opt
247+
if auth_opt.startswith('pam'):
248+
auth_opt = self.PAM_SCHEME_STRING
248249
with self._setup_rodsuser_and_optional_pw(name = name, make_irods_pw = make_irods_pw):
249250
self.envdirs = self.create_env_dirs()
250251
if not self.envdirs:
251252
raise RuntimeError('Could not create one or more client environments')
252-
auth_opt_explicit = 'native' if auth_opt=='' else auth_opt
253+
auth_opt_explicit = 'native' if _auth_opt=='' else _auth_opt
253254
verbosity=False
254255
#verbosity='' # -- debug - sanity check by printing out options applied
255256
out = {'':''}
@@ -282,7 +283,7 @@ def tst0(self, ssl_opt, auth_opt, env_opt, name = TEST_RODS_USER, make_irods_pw
282283
cadata = None,
283284
cafile = SSL_cert),
284285
**CLIENT_OPTIONS_FOR_SSL )
285-
lookup = self.user_auth_envs ['.irods.'+('native' if not(auth_opt) else auth_opt)]
286+
lookup = self.user_auth_envs ['.irods.'+('native' if not(_auth_opt) else _auth_opt)]
286287
session = iRODSSession ( host=gethostname(),
287288
user=lookup['USER'],
288289
zone='tempZone',
@@ -327,7 +328,7 @@ def test_4(self):
327328
self.tst0 ( ssl_opt = False, auth_opt = 'native' , env_opt = True, make_irods_pw = True)
328329

329330
# == test explicit scheme 'pam'
330-
331+
331332
def test_5(self):
332333
self.tst0 ( ssl_opt = True, auth_opt = 'pam' , env_opt = False )
333334

@@ -511,20 +512,18 @@ def test_ssl_with_server_verify_set_to_none_281(self):
511512
with helpers.file_backed_up(env_file):
512513
with open(env_file) as env_file_handle:
513514
env = json.load( env_file_handle )
514-
env.update({ "irods_client_server_negotiation": "request_server_negotiation",
515-
"irods_client_server_policy": "CS_NEG_REQUIRE",
516-
"irods_ssl_ca_certificate_file": "/path/to/some/file.crt", # does not need to exist
517-
"irods_ssl_verify_server": "none",
518-
"irods_encryption_key_size": 32,
519-
"irods_encryption_salt_size": 8,
520-
"irods_encryption_num_hash_rounds": 16,
521-
"irods_encryption_algorithm": "AES-256-CBC" })
515+
my_ssl_directory = os.path.expanduser("~/some")
516+
# Elect for efficiency in DH param generation, eg. when setting up for testing.
517+
create_ssl_dir(ssl_dir = my_ssl_directory, use_strong_primes_for_dh_generation = False)
518+
keys_to_update = {key:value.replace("/etc/irods/ssl",my_ssl_directory)
519+
for key,value in env.items() if type(value) is str and value.startswith("/etc/irods/ssl")}
520+
keys_to_update["irods_ssl_verify_server"] = "none"
521+
env.update( keys_to_update )
522522
with open(env_file,'w') as f:
523523
json.dump(env,f)
524524
with helpers.make_session() as session:
525525
session.collections.get('/{session.zone}/home/{session.username}'.format(**locals()))
526526

527-
528527
if __name__ == '__main__':
529528
# let the tests find the parent irods lib
530529
sys.path.insert(0, os.path.abspath('../..'))

0 commit comments

Comments
 (0)