Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WSGIPublisher: set REMOTE_USER even in case of error #1156

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ https://github.com/zopefoundation/Zope/blob/4.x/CHANGES.rst
- Added image dimensions to SVG file properties
`#1146 <https://github.com/zopefoundation/Zope/pull/1146>`_.

- Fix username not in access log for error requests, see issue
`#1155 <https://github.com/zopefoundation/Zope/issues/1155>`_.

5.8.4 (2023-09-06)
------------------

Expand Down
13 changes: 7 additions & 6 deletions src/ZPublisher/WSGIPublisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,13 @@ def publish_module(environ, start_response,
try:
with load_app(module_info) as new_mod_info:
with transaction_pubevents(request, response):
response = _publish(request, new_mod_info)

user = getSecurityManager().getUser()
if user is not None and \
user.getUserName() != 'Anonymous User':
environ['REMOTE_USER'] = user.getUserName()
try:
response = _publish(request, new_mod_info)
finally:
user = getSecurityManager().getUser()
if user is not None and \
user.getUserName() != 'Anonymous User':
environ['REMOTE_USER'] = user.getUserName()
break
except TransientError:
if request.supports_retry():
Expand Down
9 changes: 9 additions & 0 deletions src/ZPublisher/tests/test_WSGIPublisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,15 @@ def test_set_REMOTE_USER_environ(self):
self._callFUT(environ, start_response, _publish)
self.assertFalse('REMOTE_USER' in environ)

def test_set_REMOTE_USER_environ_error(self):
environ = self._makeEnviron()
start_response = DummyCallable()
_publish = DummyCallable()
_publish._raise = ValueError()
with self.assertRaises(ValueError):
self._callFUT(environ, start_response, _publish)
self.assertEqual(environ['REMOTE_USER'], user_name)

def test_webdav_source_port(self):
from ZPublisher import WSGIPublisher
old_webdav_source_port = WSGIPublisher._WEBDAV_SOURCE_PORT
Expand Down