Permalink
Browse files

Added 'classifiers.forbidden_challenger'.

The function is a "challenge decider" function for use by ``repoze.who`` with
current versions of ``pyramid``, which now return "403 Forbidden" instead
of "401 Unauthorized" on authorization failures.
  • Loading branch information...
1 parent 678ba90 commit df5949e1eb65242db9c217689e9434c6f18c4100 @tseaver tseaver committed Apr 5, 2011
Showing with 33 additions and 0 deletions.
  1. +7 −0 CHANGES.txt
  2. +6 −0 pyramid_who/classifiers.py
  3. +20 −0 pyramid_who/tests/test_classifiers.py
View
@@ -1,6 +1,13 @@
``pyramid_who`` Changelog
=========================
+Unreleased
+----------
+
+- Added a "challenge decider" function for use by ``repoze.who`` with
+ current versions of ``pyramid``, which now return "403 Forbidden" instead
+ of "401 Unauthorized" on authorization failures.
+
0.2 (2011-03-23)
----------------
@@ -0,0 +1,6 @@
+from zope.interface import directlyProvides
+from repoze.who.interfaces import IChallengeDecider
+
+def forbidden_challenger(environ, status, headers):
+ return status.startswith('403 ')
+directlyProvides(forbidden_challenger, IChallengeDecider)
@@ -0,0 +1,20 @@
+import unittest
+
+class ForbiddenChallengeDeciderTests(unittest.TestCase):
+
+ def _getFUT(self):
+ from pyramid_who.classifiers import forbidden_challenger
+ return forbidden_challenger
+
+ def _callFUT(self, environ, status, headers):
+ return self._getFUT()(environ, status, headers)
+
+ def test_conforms_to_IChallengeDecider(self):
+ from repoze.who.interfaces import IChallengeDecider
+ self.failUnless(IChallengeDecider.providedBy(self._getFUT()))
+
+ def test_miss(self):
+ self.failIf(self._callFUT({}, '200 OK', ()))
+
+ def test_hit(self):
+ self.failUnless(self._callFUT({}, '403 Forbidden', ()))

0 comments on commit df5949e

Please sign in to comment.