|
3 | 3 | from __future__ import absolute_import |
4 | 4 | import os |
5 | 5 | import sys |
| 6 | +import tempfile |
6 | 7 | import unittest |
7 | 8 | import textwrap |
8 | 9 | import json |
9 | 10 | import shutil |
10 | 11 | import ssl |
11 | 12 | import irods.test.helpers as helpers |
12 | 13 | from irods.connection import Connection |
13 | | -from irods.session import iRODSSession |
| 14 | +from irods.session import iRODSSession, NonAnonymousLoginWithoutPassword |
14 | 15 | from irods.rule import Rule |
15 | 16 | from irods.models import User |
16 | 17 | from socket import gethostname |
17 | 18 | from irods.password_obfuscation import (encode as pw_encode) |
18 | 19 | from irods.connection import PlainTextPAMPasswordError |
19 | 20 | from irods.access import iRODSAccess |
| 21 | +import irods.exception as ex |
20 | 22 | import contextlib |
21 | 23 | import socket |
22 | 24 | from re import compile as regex |
| 25 | +import gc |
| 26 | +import six |
| 27 | + |
23 | 28 | try: |
24 | 29 | from re import _pattern_type as regex_type |
25 | 30 | except ImportError: |
@@ -385,6 +390,85 @@ def test_login_from_environment(self): |
385 | 390 | os.environ.clear() |
386 | 391 | os.environ.update( orig_env ) |
387 | 392 |
|
| 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 | + |
388 | 472 | class TestWithSSL(unittest.TestCase): |
389 | 473 | ''' |
390 | 474 | The tests within this class should be run by an account other than the |
|
0 commit comments