From aa514ba896636a5d430467600ce77a8c64af0448 Mon Sep 17 00:00:00 2001 From: jens Date: Sun, 30 May 2010 11:33:45 +0000 Subject: [PATCH] - Bug: Demangling user prefix could not deal with non-string user ids, which may appear in certain cases. (https://bugs.launchpad.net/bugs/586931) git-svn-id: http://svn.dataflake.org/svn/Products.LDAPMultiPlugins/trunk@1969 835909ba-7c00-0410-bfa4-884f43845301 --- Products/LDAPMultiPlugins/CHANGES.txt | 4 +++ Products/LDAPMultiPlugins/LDAPPluginBase.py | 4 +++ .../tests/test_LDAPMultiPlugins.py | 31 ++++++++++++------- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/Products/LDAPMultiPlugins/CHANGES.txt b/Products/LDAPMultiPlugins/CHANGES.txt index 89b31a7..127ae08 100644 --- a/Products/LDAPMultiPlugins/CHANGES.txt +++ b/Products/LDAPMultiPlugins/CHANGES.txt @@ -6,6 +6,10 @@ To see earlier changes please see HISTORY.txt. 2.0 (unreleased) ---------------- +- Bug: Demangling user prefix could not deal with non-string user + ids, which may appear in certain cases. + (https://bugs.launchpad.net/bugs/586931) + - Bug: Added GenericSetup magic to fully provide the INode interface for the exporter and importer classes, making it easier to nest within other importers. diff --git a/Products/LDAPMultiPlugins/LDAPPluginBase.py b/Products/LDAPMultiPlugins/LDAPPluginBase.py index 702f6e9..62971ab 100644 --- a/Products/LDAPMultiPlugins/LDAPPluginBase.py +++ b/Products/LDAPMultiPlugins/LDAPPluginBase.py @@ -153,6 +153,10 @@ class LDAPPluginBase(Folder, BasePlugin, Cacheable): security.declarePrivate('_demangle') def _demangle(self, princid): + # Sanity check + if not isinstance(princid, basestring): + return None + # User must start with our prefix (which is likely to be blank anyway) if not princid.startswith(self.prefix): return None diff --git a/Products/LDAPMultiPlugins/tests/test_LDAPMultiPlugins.py b/Products/LDAPMultiPlugins/tests/test_LDAPMultiPlugins.py index 2572b77..fd7b54b 100644 --- a/Products/LDAPMultiPlugins/tests/test_LDAPMultiPlugins.py +++ b/Products/LDAPMultiPlugins/tests/test_LDAPMultiPlugins.py @@ -17,25 +17,26 @@ $Id$ import unittest -from Products.PluggableAuthService.interfaces.plugins import \ - IUserEnumerationPlugin -from Products.PluggableAuthService.interfaces.plugins import \ - IGroupsPlugin -from Products.PluggableAuthService.interfaces.plugins import \ - IGroupEnumerationPlugin -from Products.PluggableAuthService.interfaces.plugins import \ - IRoleEnumerationPlugin - -from Products.LDAPMultiPlugins.interfaces import ILDAPMultiPlugin - class LMPBaseTests(unittest.TestCase): + def _makeOne(self): + return self._getTargetClass()('testplugin') + def _getTargetClass(self): from Products.LDAPMultiPlugins.LDAPPluginBase import LDAPPluginBase return LDAPPluginBase def test_interfaces(self): + from Products.LDAPMultiPlugins.interfaces import ILDAPMultiPlugin + from Products.PluggableAuthService.interfaces.plugins import \ + IUserEnumerationPlugin + from Products.PluggableAuthService.interfaces.plugins import \ + IGroupsPlugin + from Products.PluggableAuthService.interfaces.plugins import \ + IGroupEnumerationPlugin + from Products.PluggableAuthService.interfaces.plugins import \ + IRoleEnumerationPlugin from zope.interface.verify import verifyClass verifyClass(ILDAPMultiPlugin, self._getTargetClass()) @@ -45,6 +46,14 @@ class LMPBaseTests(unittest.TestCase): verifyClass(IGroupEnumerationPlugin, self._getTargetClass()) verifyClass(IRoleEnumerationPlugin, self._getTargetClass()) + def test_demangle_invalid_userid(self): + plugin = self._makeOne() + plugin.prefix = 'prefix_' + + self.assertEquals(plugin._demangle(None), None) + self.assertEquals(plugin._demangle('incorrectprefix'), None) + self.assertEquals(plugin._demangle('prefix_user1'), 'user1') + class ADMPTests(LMPBaseTests):