Note: The default ITS GitLab runner is a shared resource and is subject to slowdowns during heavy usage.
You can run your own GitLab runner that is dedicated just to your group if you need to avoid processing delays.

Commit 8cc0bd83 authored by Paul Arthur's avatar Paul Arthur
Browse files

Fix problems encountered in testing CSAM

* Refactor MCommGroup.fetch(), mainly to reduce nesting.

* LDAP attributes are not case sensitive, but we were doing a
  case-sensitive check for the umichGroup object class.

* Centralize defaulting of list attrs to []; the old code was both
  overly duplicated and failed to account for some situations.
parent 397abb8e
Pipeline #8327 passed with stage
in 25 seconds
......@@ -120,32 +120,24 @@ class MCommGroup:
def externalMembers(self):
if not hasattr(self, '_externalMembers'):
if not isinstance(self.memberExternal, list):
self.memberExternal = []
self._externalMembers = [x['dn'] for x in self.memberExternal]
return self._externalMembers
def links(self):
if not hasattr(self, '_links'):
if not isinstance(self.urlLinks, list):
self.urlLinks = []
self._links = [x['labeledUri'] for x in self.urlLinks]
return self._links
def members(self):
if not hasattr(self, '_members'):
if not isinstance(self.memberDn, list):
self.memberDn = []
self._members = [parse_dn(x)[0][1] for x in self.memberDn]
return self._members
def memberGroups(self):
if not hasattr(self, '_memberGroups'):
if not isinstance(self.memberGroupDn, list):
self.memberGroupDn = []
self._memberGroups = [
parse_dn(x)[0][1] for x in self.memberGroupDn
......@@ -154,20 +146,16 @@ class MCommGroup:
def moderators(self):
if not hasattr(self, '_moderators'):
if not isinstance(self.moderator, list):
self.moderator = []
self._moderators = [x['dn'] for x in self.moderator]
return self._moderators
def owners(self):
if not hasattr(self, '_owners'):
if not isinstance(self.ownerDn, list):
self.ownerDn = []
self._owners = [parse_dn(x)[0][1] for x in self.ownerDn]
return self._owners
def fetch(self, targets=False):
def fetch(self, targets=None):
"""Fetch information for an mcommunity group
......@@ -181,41 +169,59 @@ class MCommGroup:
self.dn = core.get_entity_dn(self.client,
if self.dn:
if not self.dn:
raise core.MCommError('Unable to fetch fresh group data')
# Updated data isn't always available immediately, so try to loop
# for a bit if we don't see any change.
# FIXME: people might call fetch when there actually haven't been any
# changes, so this should probably be controlled by a flag.
for i in range(5):
r = self.client.get(
if r.ok:
if not r.ok:
raise core.MCommError('{}: {}'.format(
group = r.json()['group'][0]
group['owners_details'] = group.pop('owners')
tmp_hash = hashlib.md5(json.dumps(group).encode('utf-8'))
if hasattr(self, 'group_hash'):
if tmp_hash.hexdigest() == self.group_hash.hexdigest():
new_hash = hashlib.md5(json.dumps(group).encode('utf-8')).hexdigest()
if getattr(self, 'group_hash', None) != new_hash:
self.group_hash = new_hash
if i < 4:
if 'umichgroup' in group['objectClass']:
self.group_hash = tmp_hash
if targets:
for target in targets:
setattr(self, target, group[target])
group['objectClass'] = [x.lower() for x in group['objectClass']]
if 'umichgroup' not in group['objectClass']:
raise core.MCommError(
'Entity found is {}, not group'.format(
', '.join(group['objectClass'])
raise core.MCommError('{}: {}'.format(
if targets:
for target in targets:
setattr(self, target, group[target])
raise core.MCommError('Unable to fetch fresh group data')
# Make sure that our list attrs are at least empty lists
for attr in [
if not getattr(self, attr, None):
setattr(self, attr, [])
def create(self):
"""Create a new mcommunity group
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment