Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

unauthenticated_user() #11

Merged
merged 5 commits into from

3 participants

Bruk Habtu Chris McDonough Tres Seaver
Bruk Habtu

Added unauthenticated_user() to the pyramid_exclog output when the extra_info key is set to True.

Chris McDonough
Owner

I hesitate to ask because I dont know whether this code already has unit tests, but it'd be nice if this was accompanied by some sort of test.

Systems added some commits
Systems The message that is used when extra_info key is set to true is wrapped
in dedent so the message is no longer indented.
The user name displayed in the message no longer shows up as None when
there is no user, it is now an empty string.
037a79b
Systems Added tests for checking that the user name is added to the message when
extra_info is set to True.
1a86b63
Systems Documented adding the user in the message. 0d218ad
Systems Added name to contributorsw: d817226
Bruk Habtu

Unit tests are now commited along with changes to the documentation. Also added name to contributor's list.

Tres Seaver tseaver merged commit d817226 into from
Tres Seaver
Owner

Thank you!

Tres Seaver tseaver referenced this pull request from a commit
Tres Seaver tseaver Changelog for PR #11. 5d2004e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 23, 2012
  1. Added unauthenticated_user() output to the pyramid_exclog when extra_…

    Bruk Habtu authored
    …info key is true
Commits on Nov 23, 2012
  1. The message that is used when extra_info key is set to true is wrapped

    Systems authored
    in dedent so the message is no longer indented.
    The user name displayed in the message no longer shows up as None when
    there is no user, it is now an empty string.
  2. Added tests for checking that the user name is added to the message when

    Systems authored
    extra_info is set to True.
  3. Documented adding the user in the message.

    Systems authored
  4. Added name to contributorsw:

    Systems authored
This page is out of date. Refresh to see the latest.
1  CONTRIBUTORS.txt
View
@@ -100,3 +100,4 @@ Contributors
- Chris McDonough, 2011/08/11
- Jason McKellar, 2012/01/09
- Rob Miller, 2012/04/24
+- Bruk Habtu, 2012/11/23
3  docs/index.rst
View
@@ -290,7 +290,8 @@ section of your Pyramid's ``.ini`` file. These are:
If ``exclog.extra_info`` is true the error message will also include
the environ and params attributes of ``pyramid.request.Request`` formatted
- using ``pprint.pformat``.
+ using ``pprint.pformat()``. The output from
+ ``pyramid.security.unauthenticated_id()`` is also included.
This setting defaults to false
22 pyramid_exclog/__init__.py
View
@@ -7,6 +7,7 @@
from pyramid.settings import asbool
from pyramid.util import DottedNameResolver
from pyramid.httpexceptions import WSGIHTTPException
+from pyramid.security import unauthenticated_userid
resolver = DottedNameResolver(None)
@@ -14,7 +15,7 @@
if PY3: # pragma: no cover
import builtins
-else:
+else:
import __builtin__ as builtins
def as_globals_list(value):
@@ -47,10 +48,10 @@ def exclog_tween(request, getLogger=getLogger):
raise
except:
logger = getLogger('exc_logger')
-
-
+ unauth = unauthenticated_userid(request)
+
if extra_info:
- message = dedent("""\n
+ message = dedent("""\
%(url)s
ENVIRONMENT
@@ -61,13 +62,20 @@ def exclog_tween(request, getLogger=getLogger):
PARAMETERS
%(params)s
+
+
+ UNAUTHENTICATED USER
-
- """ % dict(url=request.url,
+ %(usr)s
+
+ """) % dict(url=request.url,
env=pformat(request.environ),
- params=pformat(request.params)))
+ params=pformat(request.params),
+ usr=unauth if unauth else '')
+
else:
message = request.url
+
logger.exception(message)
raise
19 pyramid_exclog/tests.py
View
@@ -64,7 +64,24 @@ def test_extra_info(self):
self.assertEqual(len(self.logger.exceptions), 1)
msg = self.logger.exceptions[0]
self.assertTrue('ENVIRONMENT' in msg)
-
+
+ def test_user_info_user(self):
+ self.config.testing_securitypolicy(
+ userid='hank',
+ permissive=True)
+ self.registry.settings['exclog.extra_info'] = True
+ self.assertRaises(NotImplementedError, self._callFUT)
+ self.assertEqual(len(self.logger.exceptions), 1)
+ msg = self.logger.exceptions[0]
+ self.assertTrue('UNAUTHENTICATED USER\n\nhank' in msg)
+
+ def test_user_info_no_user(self):
+ self.registry.settings['exclog.extra_info'] = True
+ self.assertRaises(NotImplementedError, self._callFUT)
+ self.assertEqual(len(self.logger.exceptions), 1)
+ msg = self.logger.exceptions[0]
+ self.assertTrue('UNAUTHENTICATED USER\n\n\n' in msg)
+
class Test_includeme(unittest.TestCase):
def _callFUT(self, config):
from pyramid_exclog import includeme
Something went wrong with that request. Please try again.