Skip to content

Commit 09b826d

Browse files
d-w-moorealanking
authored andcommitted
[#431][irods/irods#6921] filter user_id results from R_OBJT_ACCESS through IDs still in R_USER_MAIN
1 parent 03fb36b commit 09b826d

2 files changed

Lines changed: 47 additions & 4 deletions

File tree

irods/manager/access_manager.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,12 @@ def __get_raw(self, target, **kw):
104104
else:
105105
raise TypeError
106106

107-
rows = [ r for r in query_func(target.path) ]
107+
# TODO: remove the filtering through extant_ids on resolution of irods/irods#6921.
108+
# (depending on the nature of the fix we may make it conditional, based on the server --
109+
# if for example in upcoming iRODS 4.2.12 and >=4.3.1 outdated userIDs in R_OBJT_ACCESS
110+
# are guaranteed to be systematically and atomically purged.
111+
extant_ids = set(u[User.id] for u in self.sess.query(User))
112+
rows = [r for r in query_func(target.path) if r[access_column.user_id] in extant_ids]
108113
userids = set( r[access_column.user_id] for r in rows )
109114

110115
user_lookup = { j.id:j for j in users_by_ids(self.sess, userids) }

irods/test/access_test.py

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
#! /usr/bin/env python
22
from __future__ import absolute_import
3+
34
import os
45
import sys
56
import unittest
7+
68
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
713
from irods.user import iRODSUser
814
from irods.session import iRODSSession
9-
from irods.models import User,Collection,DataObject
10-
from irods.collection import iRODSCollection
1115
import irods.test.helpers as helpers
12-
from irods.column import In, Like
1316

1417

1518
class TestAccess(unittest.TestCase):
@@ -332,6 +335,41 @@ def test_ses_acls_data_and_collection_395_396(self):
332335
self.alice.remove()
333336
self.team.remove()
334337

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()
335373

336374
if __name__ == '__main__':
337375
# let the tests find the parent irods lib

0 commit comments

Comments
 (0)