|
1 | 1 | #! /usr/bin/env python |
2 | 2 | from __future__ import absolute_import |
| 3 | + |
3 | 4 | import os |
4 | 5 | import sys |
5 | 6 | import unittest |
| 7 | + |
6 | 8 | from irods.access import iRODSAccess |
| 9 | +from irods.collection import iRODSCollection |
| 10 | +from irods.column import In, Like |
| 11 | +from irods.exception import UserDoesNotExist |
| 12 | +from irods.models import User,Collection,DataObject |
7 | 13 | from irods.user import iRODSUser |
8 | 14 | from irods.session import iRODSSession |
9 | | -from irods.models import User,Collection,DataObject |
10 | | -from irods.collection import iRODSCollection |
11 | 15 | import irods.test.helpers as helpers |
12 | | -from irods.column import In, Like |
13 | 16 |
|
14 | 17 |
|
15 | 18 | class TestAccess(unittest.TestCase): |
@@ -332,6 +335,41 @@ def test_ses_acls_data_and_collection_395_396(self): |
332 | 335 | self.alice.remove() |
333 | 336 | self.team.remove() |
334 | 337 |
|
| 338 | + def test_removed_user_does_not_affect_raw_ACL_queries__issue_431(self): |
| 339 | + user_name = "testuser" |
| 340 | + session = self.sess |
| 341 | + try: |
| 342 | + # Create user and collection. |
| 343 | + user = session.users.create(user_name, 'rodsuser') |
| 344 | + coll_path = "/{0.zone}/home/test".format(session) |
| 345 | + coll = session.collections.create(coll_path) |
| 346 | + |
| 347 | + # Give user access to collection. |
| 348 | + access = iRODSAccess('read', coll.path, user.name) |
| 349 | + session.acls.set(access) |
| 350 | + |
| 351 | + # We can get permissions from collection, and the test user's entry is there. |
| 352 | + perms = session.acls.get(coll) |
| 353 | + self.assertTrue(any(p for p in perms if p.user_name == user_name)) |
| 354 | + |
| 355 | + # Now we remove the user and try again. |
| 356 | + user.remove() |
| 357 | + |
| 358 | + # The following line threw a KeyError prior to the issue #431 fix, |
| 359 | + # as already-deleted users' IDs were being returned in the raw ACL queries. |
| 360 | + # It appears iRODS as of 4.2.11 and 4.3.0 does not purge R_OBJT_ACCESS of old |
| 361 | + # user IDs. (See: https://github.com/irods/irods/issues/6921) |
| 362 | + perms = session.acls.get(coll) |
| 363 | + |
| 364 | + # As an extra test, make sure the removed user is gone from the list. |
| 365 | + self.assertFalse(any(p for p in perms if p.user_name == user_name)) |
| 366 | + finally: |
| 367 | + try: |
| 368 | + u = session.users.get(user_name) |
| 369 | + except UserDoesNotExist: |
| 370 | + pass |
| 371 | + else: |
| 372 | + u.remove() |
335 | 373 |
|
336 | 374 | if __name__ == '__main__': |
337 | 375 | # let the tests find the parent irods lib |
|
0 commit comments