diff --git a/CHANGELOG.md b/CHANGELOG.md index cfe03a6..997b0e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Search users by fullname and email. @alecghica - Fix login on Volto frontend when already logged-in in Plone Classic. @avoinea - Add the possibility to override the ZopeRequestAdapter. +- Fix the authomatic view when it is reporting an exception that does not have a message attribute ## 1.2.0 (2023-09-13) diff --git a/src/pas/plugins/authomatic/browser/view.py b/src/pas/plugins/authomatic/browser/view.py index 06d1e9f..23f657b 100644 --- a/src/pas/plugins/authomatic/browser/view.py +++ b/src/pas/plugins/authomatic/browser/view.py @@ -123,7 +123,10 @@ def __call__(self): # let authomatic do its work return if result.error: - return result.error.message + try: + return result.error.message + except AttributeError: + return str(result.error) display = cfg[self.provider].get("display", {}) provider_name = display.get("title", self.provider) if not self.is_anon: diff --git a/src/pas/plugins/authomatic/locales/update.py b/src/pas/plugins/authomatic/locales/update.py index 2cb52d2..c10a835 100644 --- a/src/pas/plugins/authomatic/locales/update.py +++ b/src/pas/plugins/authomatic/locales/update.py @@ -1,4 +1,5 @@ """Update locales.""" + from pathlib import Path import logging diff --git a/src/pas/plugins/authomatic/plugin.py b/src/pas/plugins/authomatic/plugin.py index e039ba3..933dccf 100644 --- a/src/pas/plugins/authomatic/plugin.py +++ b/src/pas/plugins/authomatic/plugin.py @@ -267,19 +267,21 @@ def enumerateUsers( identity = self._useridentities_by_userid[userid] search_term = search_id.lower() identity_userid = identity.userid - identity_fullname = identity.propertysheet.getProperty("fullname", "").lower() + identity_fullname = identity.propertysheet.getProperty( + "fullname", "" + ).lower() identity_email = identity.propertysheet.getProperty("email", "").lower() if ( - not search_term in identity_userid - and not search_term in identity_fullname - and not search_term in identity_email + search_term not in identity_userid + and search_term not in identity_fullname # noqa: W503 + and search_term not in identity_email # noqa: W503 ): continue -# if not userid.startswith(search_id): -# continue -# identity = self._useridentities_by_userid[userid] -# identity_userid = identity.userid + # if not userid.startswith(search_id): + # continue + # identity = self._useridentities_by_userid[userid] + # identity_userid = identity.userid ret.append( { "id": identity_userid, diff --git a/src/pas/plugins/authomatic/services/authomatic.py b/src/pas/plugins/authomatic/services/authomatic.py index f57e397..95aaaa2 100644 --- a/src/pas/plugins/authomatic/services/authomatic.py +++ b/src/pas/plugins/authomatic/services/authomatic.py @@ -1,4 +1,3 @@ -import logging from authomatic import Authomatic from pas.plugins.authomatic.integration import RestAPIAdapter from pas.plugins.authomatic.utils import authomatic_cfg @@ -14,7 +13,10 @@ from zope.interface import implementer from zope.publisher.interfaces import IPublishTraverse +import logging import transaction + + logger = logging.getLogger("pas.plugins.authomatic") @@ -169,8 +171,7 @@ def _add_identity(self, result, userid=None): :param result: Authomatic login result. """ aclu = self._get_acl_users() - aclu.authomatic.remember_identity( - result, userid) + aclu.authomatic.remember_identity(result, userid) def _remember_identity(self, result): """Store identity information. @@ -238,7 +239,7 @@ def reply(self) -> dict: } elif result: alsoProvides(self.request, IDisableCSRFProtection) - action = '' + action = "" if api.user.is_anonymous(): self._remember_identity(result) action = "login" diff --git a/src/pas/plugins/authomatic/tests/test_plugin.py b/src/pas/plugins/authomatic/tests/test_plugin.py index defe924..054f5ae 100644 --- a/src/pas/plugins/authomatic/tests/test_plugin.py +++ b/src/pas/plugins/authomatic/tests/test_plugin.py @@ -1,3 +1,4 @@ +from pas.plugins.authomatic.testing import AUTHOMATIC_PLONE_INTEGRATION_TESTING from pas.plugins.authomatic.testing import AUTHOMATIC_ZOPE_FIXTURE from pas.plugins.authomatic.tests.mocks import make_user @@ -56,6 +57,19 @@ def test_authentication_zope_admin(self): self.assertEqual(admin["pluginid"], "users") self.assertEqual(self.aclu.getUserById("admin").getId(), "admin") + +class TestPlonePlugin(unittest.TestCase): + + layer = AUTHOMATIC_PLONE_INTEGRATION_TESTING + + def setUp(self): + # create plugin + from pas.plugins.authomatic.setuphandlers import _add_plugin + + self.aclu = self.layer["app"].acl_users + _add_plugin(self.aclu, "authomatic") + self.plugin = self.aclu["authomatic"] + def test_user_enumaration(self): make_user("123joe", testcase=self) make_user("123jane", testcase=self) diff --git a/src/pas/plugins/authomatic/tests/test_setup.py b/src/pas/plugins/authomatic/tests/test_setup.py index 9cc5a92..cf40b3d 100644 --- a/src/pas/plugins/authomatic/tests/test_setup.py +++ b/src/pas/plugins/authomatic/tests/test_setup.py @@ -1,4 +1,5 @@ """Setup tests for this package.""" + from pas.plugins.authomatic.testing import AUTHOMATIC_PLONE_INTEGRATION_TESTING from Products.CMFPlone.utils import get_installer diff --git a/src/pas/plugins/authomatic/tests/test_upgrades.py b/src/pas/plugins/authomatic/tests/test_upgrades.py index 5b7ac5d..24337d9 100644 --- a/src/pas/plugins/authomatic/tests/test_upgrades.py +++ b/src/pas/plugins/authomatic/tests/test_upgrades.py @@ -1,4 +1,5 @@ """Upgrades tests for this package.""" + from parameterized import parameterized from pas.plugins.authomatic.testing import AUTHOMATIC_PLONE_INTEGRATION_TESTING from plone.app.testing import setRoles