Commit a1929c9d authored by Denis Laxalde's avatar Denis Laxalde
Browse files

[server] Drop update_config method of source

It does not make sense anymore to update the config of a source instance
(subclass of cubicweb.server.sources.AbstractSource) now that they are always
built from database information (CWSource). In datafeed and ldapfeed, we
move all code from "update_config" method in "init" method.

This changeset fixes LDAPFeedUserDeletionTC.test_a_filter_inactivate() failure
(unittest_ldapsource.py) introduces in previous changeset.

--HG--
branch : 3.25
parent db2fc87348ab
......@@ -99,8 +99,8 @@ class AbstractSource(object):
# on logging
set_log_methods(self, getLogger('cubicweb.sources.' + unormalize(text_type(self.uri))))
source_config.pop('type')
self.update_config(None, self.check_conf_dict(eid, source_config,
fail_if_unknown=False))
self.config = self.check_conf_dict(
eid, source_config, fail_if_unknown=False)
def __repr__(self):
return '<%s %s source %s @%#x>' % (self.uri, self.__class__.__name__,
......@@ -176,14 +176,6 @@ class AbstractSource(object):
return cls.check_conf_dict(source_entity.eid, source_entity.host_config,
_=source_entity._cw._)
def update_config(self, source_entity, typedconfig):
"""update configuration from source entity. `typedconfig` is config
properly typed with defaults set
"""
if source_entity is not None:
self._entity_update(source_entity)
self.config = typedconfig
def _entity_update(self, source_entity):
source_entity.complete()
if source_entity.url:
......
......@@ -112,11 +112,10 @@ class DataFeedSource(AbstractSource):
self.parser_id = source_entity.parser
self.latest_retrieval = source_entity.latest_retrieval
def update_config(self, source_entity, typed_config):
"""update configuration from source entity. `typed_config` is config
properly typed with defaults set
"""
super(DataFeedSource, self).update_config(source_entity, typed_config)
def init(self, activated, source_entity):
super(DataFeedSource, self).init(activated, source_entity)
self.parser_id = source_entity.parser
typed_config = self.config
self.synchro_interval = timedelta(seconds=typed_config['synchronization-interval'])
self.max_lock_lifetime = timedelta(seconds=typed_config['max-lock-lifetime'])
self.http_timeout = typed_config['http-timeout']
......@@ -127,10 +126,6 @@ class DataFeedSource(AbstractSource):
self.use_cwuri_as_url = typed_config['use-cwuri-as-url']
self.public_config['use-cwuri-as-url'] = self.use_cwuri_as_url
def init(self, activated, source_entity):
super(DataFeedSource, self).init(activated, source_entity)
self.parser_id = source_entity.parser
def _get_parser(self, cnx, **kwargs):
if self.parser_id is None:
self.warning('No parser defined on source %r', self)
......
......@@ -176,11 +176,9 @@ You can set multiple groups by separating them by a comma.',
_conn = None
def update_config(self, source_entity, typedconfig):
"""update configuration from source entity. `typedconfig` is config
properly typed with defaults set
"""
super(LDAPFeedSource, self).update_config(source_entity, typedconfig)
def init(self, activated, source_entity):
super(LDAPFeedSource, self).init(activated, source_entity)
typedconfig = self.config
self.authmode = typedconfig['auth-mode']
self._authenticate = getattr(self, '_auth_%s' % self.authmode)
self.cnx_dn = typedconfig['data-cnx-dn']
......
......@@ -115,6 +115,12 @@ def ldapsource(cnx):
return cnx.find('CWSource', type=u'ldapfeed').one()
def update_source_config(source, options):
config = source.dictconfig
config.update(options)
source.cw_set(config=u'\n'.join('%s=%s' % x for x in config.items()))
class LDAPFeedTestBase(CubicWebTC):
test_db_id = 'ldap-feed'
loglevel = 'ERROR'
......@@ -222,10 +228,9 @@ class CheckWrongGroup(LDAPFeedTestBase):
def test_wrong_group(self):
with self.admin_access.repo_cnx() as cnx:
source = ldapsource(cnx)
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)
options = {'use-default-group': 'thisgroupdoesnotexists,users'}
update_source_config(source, options)
cnx.commit()
# here we emitted an error log entry
source.repo_source.pull_data(cnx, force=True, raise_on_error=True)
......@@ -329,16 +334,15 @@ class LDAPFeedUserDeletionTC(LDAPFeedTestBase):
def test_a_filter_inactivate(self):
""" filtered out people should be deactivated, unable to authenticate """
repo_source = self.repo.sources_by_uri['ldap']
with self.admin_access.repo_cnx() as cnx:
source = ldapsource(cnx)
config = repo_source.check_config(source)
# filter with adim's phone number
config['user-filter'] = u'(%s=%s)' % ('telephoneNumber', '109')
repo_source.update_config(source, config)
options = {'user-filter': '(%s=%s)' % ('telephonenumber', '109')}
update_source_config(source, options)
cnx.commit()
with self.repo.internal_cnx() as cnx:
self.pull(cnx)
repo_source = self.repo.sources_by_uri['ldap']
self.assertRaises(AuthenticationError,
repo_source.authenticate, cnx, 'syt', 'syt')
with self.admin_access.repo_cnx() as cnx:
......@@ -349,8 +353,9 @@ class LDAPFeedUserDeletionTC(LDAPFeedTestBase):
'U in_state S, S name N').rows[0][0],
'activated')
# unfilter, syt should be activated again
config['user-filter'] = u''
repo_source.update_config(source, config)
source = ldapsource(cnx)
options = {'user-filter': u''}
update_source_config(source, options)
cnx.commit()
with self.repo.internal_cnx() as cnx:
self.pull(cnx)
......
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