[ldapfeed] don't crash if one specify an unexisting group in the configuration. Closes #2538399
--- a/server/test/unittest_ldapuser.py Wed Jan 09 14:27:51 2013 +0100
+++ b/server/test/unittest_ldapuser.py Tue Dec 18 12:25:08 2012 +0100
@@ -95,6 +95,23 @@
def tearDownClass(cls):
terminate_slapd(cls)
+class CheckWrongGroup(LDAPTestBase):
+
+ def test_wrong_group(self):
+ self.session.create_entity('CWSource', name=u'ldapuser', type=u'ldapfeed', parser=u'ldapfeed',
+ url=URL, config=CONFIG)
+ self.commit()
+ with self.session.repo.internal_session(safe=True) as session:
+ source = self.session.execute('CWSource S WHERE S type="ldapfeed"').get_entity(0,0)
+ config = source.repo_source.check_config(source)
+ # inject a bogus group here, along with at least a valid one
+ config['user-default-group'] = ('thisgroupdoesnotexists','users')
+ source.repo_source.update_config(source, config)
+ session.commit(free_cnxset=False)
+ # here we emitted an error log entry
+ stats = source.repo_source.pull_data(session, force=True, raise_on_error=True)
+ session.commit()
+
class DeleteStuffFromLDAPFeedSourceTC(LDAPTestBase):
test_db_id = 'ldap-feed'
--- a/sobjects/ldapparser.py Wed Jan 09 14:27:51 2013 +0100
+++ b/sobjects/ldapparser.py Tue Dec 18 12:25:08 2012 +0100
@@ -130,8 +130,10 @@
super(DataFeedLDAPAdapter, self).after_entity_copy(entity, sourceparams)
if entity.__regid__ == 'EmailAddress':
return
- groups = [self._get_group(n) for n in self.source.user_default_groups]
- entity.set_relations(in_group=groups)
+ groups = filter(None, [self._get_group(name)
+ for name in self.source.user_default_groups])
+ if groups:
+ entity.set_relations(in_group=groups)
self._process_email(entity, sourceparams)
def is_deleted(self, extidplus, etype, eid):
@@ -172,5 +174,11 @@
@cached
def _get_group(self, name):
- return self._cw.execute('Any X WHERE X is CWGroup, X name %(name)s',
- {'name': name}).get_entity(0, 0)
+ try:
+ return self._cw.execute('Any X WHERE X is CWGroup, X name %(name)s',
+ {'name': name}).get_entity(0, 0)
+ except IndexError:
+ self.error('group %r referenced by source configuration %r does not exist'
+ % (name, self.source.uri))
+ return None
+