Skip to content

Commit b89977e

Browse files
d-w-moorealanking
authored andcommitted
[#290][#315] tests
1 parent 490b155 commit b89977e

1 file changed

Lines changed: 85 additions & 1 deletion

File tree

irods/test/login_auth_test.py

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,28 @@
33
from __future__ import absolute_import
44
import os
55
import sys
6+
import tempfile
67
import unittest
78
import textwrap
89
import json
910
import shutil
1011
import ssl
1112
import irods.test.helpers as helpers
1213
from irods.connection import Connection
13-
from irods.session import iRODSSession
14+
from irods.session import iRODSSession, NonAnonymousLoginWithoutPassword
1415
from irods.rule import Rule
1516
from irods.models import User
1617
from socket import gethostname
1718
from irods.password_obfuscation import (encode as pw_encode)
1819
from irods.connection import PlainTextPAMPasswordError
1920
from irods.access import iRODSAccess
21+
import irods.exception as ex
2022
import contextlib
2123
import socket
2224
from re import compile as regex
25+
import gc
26+
import six
27+
2328
try:
2429
from re import _pattern_type as regex_type
2530
except ImportError:
@@ -385,6 +390,85 @@ def test_login_from_environment(self):
385390
os.environ.clear()
386391
os.environ.update( orig_env )
387392

393+
class TestMiscellaneous(unittest.TestCase):
394+
395+
def test_nonanonymous_login_without_auth_file_fails__290(self):
396+
ses = self.admin
397+
if ses.users.get( ses.username ).type != 'rodsadmin':
398+
self.skipTest( 'Only a rodsadmin may run this test.')
399+
try:
400+
ENV_DIR = tempfile.mkdtemp()
401+
ses.users.create('bob', 'rodsuser')
402+
ses.users.modify('bob', 'password', 'bpass')
403+
d = dict(password = 'bpass', user = 'bob', host = ses.host, port = ses.port, zone = ses.zone)
404+
(bob_env, bob_auth) = helpers.make_environment_and_auth_files(ENV_DIR, **d)
405+
login_options = { 'irods_env_file': bob_env, 'irods_authentication_file': bob_auth }
406+
with helpers.make_session(**login_options) as s:
407+
s.users.get('bob')
408+
os.unlink(bob_auth)
409+
# -- Check that we raise an appropriate exception pointing to the missing auth file path --
410+
with self.assertRaisesRegexp(NonAnonymousLoginWithoutPassword, bob_auth):
411+
with helpers.make_session(**login_options) as s:
412+
s.users.get('bob')
413+
finally:
414+
try:
415+
shutil.rmtree(ENV_DIR,ignore_errors=True)
416+
ses.users.get('bob').remove()
417+
except ex.UserDoesNotExist:
418+
pass
419+
420+
421+
def setUp(self):
422+
admin = self.admin = helpers.make_session()
423+
if admin.users.get(admin.username).type != 'rodsadmin':
424+
self.skipTest('need admin privilege')
425+
admin.users.create('alice','rodsuser')
426+
427+
def tearDown(self):
428+
self.admin.users.remove('alice')
429+
self.admin.cleanup()
430+
431+
@unittest.skipUnless(six.PY3, "Skipping in Python2 because it doesn't reliably do cyclic GC.")
432+
def test_destruct_session_with_no_pool_315(self):
433+
434+
destruct_flag = [False]
435+
436+
class mySess( iRODSSession ):
437+
def __del__(self):
438+
self.pool = None
439+
super(mySess,self).__del__() # call parent destructor(s) - will raise
440+
# an error before the #315 fix
441+
destruct_flag[:] = [True]
442+
443+
admin = self.admin
444+
admin.users.modify('alice','password','apass')
445+
446+
my_sess = mySess( user = 'alice',
447+
password = 'apass',
448+
host = admin.host,
449+
port = admin.port,
450+
zone = admin.zone)
451+
my_sess.cleanup()
452+
del my_sess
453+
gc.collect()
454+
self.assertEqual( destruct_flag, [True] )
455+
456+
def test_non_anon_native_login_omitting_password_fails_1__290(self):
457+
# rodsuser with password unset
458+
with self.assertRaises(ex.CAT_INVALID_USER):
459+
self._non_anon_native_login_omitting_password_fails_N__290()
460+
461+
def test_non_anon_native_login_omitting_password_fails_2__290(self):
462+
# rodsuser with a password set
463+
self.admin.users.modify('alice','password','apass')
464+
with self.assertRaises(ex.CAT_INVALID_AUTHENTICATION):
465+
self._non_anon_native_login_omitting_password_fails_N__290()
466+
467+
def _non_anon_native_login_omitting_password_fails_N__290(self):
468+
admin = self.admin
469+
with iRODSSession(zone = admin.zone, port = admin.port, host = admin.host, user = 'alice') as alice:
470+
alice.collections.get(helpers.home_collection(alice))
471+
388472
class TestWithSSL(unittest.TestCase):
389473
'''
390474
The tests within this class should be run by an account other than the

0 commit comments

Comments
 (0)