Skip to content

Commit

Permalink
fix(log): Log error conditions in the server logs
Browse files Browse the repository at this point in the history
An error that indicates incorrect configuration, set up, or otherwise something an
administrator would probably want to know, should also be logged to the server logs.
Those log messages should including enough information for an administrator to find the
specific instance of the issue (e.g. which Plone portal in a multi-portal ZODB).
  • Loading branch information
rpatterson committed Feb 14, 2022
1 parent 1228b58 commit 68e9cdb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/plone/restapi/services/auth/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
from zope.interface import alsoProvides
from zope import component

import logging
import plone.protect.interfaces

logger = logging.getLogger(__name__)


class Login(Service):
"""Handles login and returns a JSON web token (JWT)."""
Expand Down Expand Up @@ -45,10 +48,16 @@ def reply(self):

if plugin is None:
self.request.response.setStatus(501)
message = "JWT authentication plugin not installed"
logger.error(
"%s: %s",
message,
"/".join(uf.getPhysicalPath()),
)
return dict(
error=dict(
type="Login failed",
message="JWT authentication plugin not installed.",
message=message,
)
)

Expand Down
3 changes: 2 additions & 1 deletion src/plone/restapi/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ def test_login_with_zope_user_fails_without_pas_plugin(self):
res = service.reply()
self.assertIn("error", res)
self.assertEqual(
"JWT authentication plugin not installed.", res["error"]["message"]
"jwt authentication plugin not installed",
res["error"]["message"].lower(),
)
self.assertNotIn("token", res)

Expand Down

0 comments on commit 68e9cdb

Please sign in to comment.