Skip to content

Commit

Permalink
Merge pull request #77 from collective/fix-tests
Browse files Browse the repository at this point in the history
Fix the tests
  • Loading branch information
jensens authored Nov 11, 2024
2 parents 4caae86 + 7ae25e5 commit 6486108
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion src/pas/plugins/authomatic/browser/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions src/pas/plugins/authomatic/locales/update.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Update locales."""

from pathlib import Path

import logging
Expand Down
18 changes: 10 additions & 8 deletions src/pas/plugins/authomatic/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 5 additions & 4 deletions src/pas/plugins/authomatic/services/authomatic.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")


Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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"
Expand Down
14 changes: 14 additions & 0 deletions src/pas/plugins/authomatic/tests/test_plugin.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/pas/plugins/authomatic/tests/test_setup.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 1 addition & 0 deletions src/pas/plugins/authomatic/tests/test_upgrades.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 6486108

Please sign in to comment.