Skip to content

Commit defb5df

Browse files
committed
fix(auth): Zope root logout Basic auth assumptions
See also [the PAS issue](zopefoundation/Products.PluggableAuthService#107 (comment)).
1 parent a91a194 commit defb5df

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def read(filename):
8484
"plone.schema >= 1.2.1", # new/fixed json field
8585
"PyJWT",
8686
"pytz",
87+
"collective.monkeypatcher",
8788
],
8889
extras_require={"test": TEST_REQUIRES},
8990
entry_points="""

src/plone/restapi/configure.zcml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
<include package=".deserializer" />
9292
<include package=".types" />
9393
<include package=".search" />
94+
<include package=".pas" />
9495

9596
<include package=".upgrades" />
9697

src/plone/restapi/pas/__init__.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
A JWT token authentication plugin for PluggableAuthService.
3+
"""
4+
5+
from App import Management
6+
from Products import PluggableAuthService # noqa, Ensure PAS patch in place
7+
8+
9+
_orig_manage_zmi_logout = Management.Navigation.manage_zmi_logout
10+
11+
12+
# BBB: Maybe remove depending on the outcome of the PAS issue:
13+
# https://github.com/zopefoundation/Products.PluggableAuthService/issues/107#issue-1090137890
14+
def manage_zmi_logout(self, REQUEST, RESPONSE):
15+
"""
16+
Logout the current ZMI user without re-challenging for login credentials.
17+
"""
18+
_orig_manage_zmi_logout(self, REQUEST, RESPONSE)
19+
20+
# Undo the HTTP `Authorization: Basic ...` assumptions
21+
RESPONSE.deleteHeader("WWW-Authenticate")
22+
RESPONSE.setStatus(200)

src/plone/restapi/pas/configure.zcml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<configure
2+
xmlns="http://namespaces.zope.org/zope"
3+
xmlns:monkey="http://namespaces.plone.org/monkey"
4+
xmlns:zcml="http://namespaces.zope.org/zcml"
5+
i18n_domain="plone.volto"
6+
>
7+
8+
<include package="collective.monkeypatcher" />
9+
10+
<monkey:patch
11+
original="manage_zmi_logout"
12+
replacement=".manage_zmi_logout"
13+
class="App.Management.Navigation"
14+
description="Patch ZMI logout to remove Basic auth assumptions"
15+
/>
16+
17+
</configure>

src/plone/restapi/tests/test_functional_auth.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,21 @@ def test_root_zmi_logout_expires_api_token(self):
382382
logout_link = browser.getLink(url="manage_zmi_logout")
383383
logout_link.click()
384384
browser.raiseHttpErrors = True
385+
self.assertEqual(
386+
browser.headers["Status"].lower(),
387+
"200 ok",
388+
"Wrong Zope root `/acl_users` logout response status",
389+
)
390+
self.assertEqual(
391+
browser.url,
392+
self.app.absolute_url() + "/manage_zmi_logout",
393+
"Wrong Zope root `/acl_users` logout response URL",
394+
)
395+
self.assertIn(
396+
"You have been logged out",
397+
browser.contents,
398+
"Zope root `/acl_users` logout response missing confirmation message",
399+
)
385400
self.assertNotIn(
386401
"__ac",
387402
browser.cookies,

0 commit comments

Comments
 (0)