Brian Sutherland
2010-12-16 cfe26c0de34069c37ab0fb40b87d96f65d5c4e44
Fix bug in repoze.who.api where the remember() or forget() methods could 
return a None if the identifier plugin returned a None. According to the
interfaces in repoze.who.interfaces the API methods cannot return None while
the plugin methods can.

I'm not entirely sure this fix is right. I'm assuming that the interface
documentation is more correct than the code in this case.

3 files modified
30 ■■■■ changed files
CHANGES.txt 5 ●●●●● patch | view | raw | blame | history
repoze/who/api.py 10 ●●●●● patch | view | raw | blame | history
repoze/who/tests/test_api.py 15 ●●●●● patch | view | raw | blame | history
CHANGES.txt
@@ -4,6 +4,11 @@
After 2.0a3 (unreleased)
------------------------
- Fix bug in repoze.who.api where the remember() or forget() methods could
  return a None if the identifier plugin returned a None. According to the
  interfaces in repoze.who.interfaces the API methods cannot return None while
  the plugin methods can.
- Fix auth_tkt plugin to not hand over tokens as strings to paste. See
  http://lists.repoze.org/pipermail/repoze-dev/2010-November/003680.html
repoze/who/api.py
@@ -208,8 +208,9 @@
            identity = self.environ.get('repoze.who.identity', {})
        identifier = identity.get('identifier')
        if identifier:
            headers = identifier.remember(self.environ, identity)
            if headers:
            got_headers = identifier.remember(self.environ, identity)
            if got_headers:
                headers = got_headers
                logger = self.logger
                logger and logger.info('remembering via headers from %s: %s'
                                        % (identifier, headers))
@@ -223,8 +224,9 @@
            identity = self.environ.get('repoze.who.identity', {})
        identifier = identity.get('identifier')
        if identifier:
            headers = identifier.forget(self.environ, identity)
            if headers:
            got_headers = identifier.forget(self.environ, identity)
            if got_headers:
                headers = got_headers
                logger = self.logger
                logger and logger.info('forgetting via headers from %s: %s'
                                        % (identifier, headers))
repoze/who/tests/test_api.py
@@ -626,6 +626,21 @@
        self.assertEqual(identity['repoze.who.userid'], 'chrisid')
        self.assertEqual(headers, REMEMBER_HEADERS)
    def test_identifier_plugin_returns_none(self):
        class _Identifier:
            def identify(self, environ):
                return None
            def remember(self, environ, identity):
                return None
            def forget(self, environ, identity):
                return None
        identity = {'identifier': _Identifier()}
        api = self._makeOne()
        headers = api.remember(identity=identity)
        self.assertEqual(tuple(headers), ())
        headers = api.forget(identity=identity)
        self.assertEqual(tuple(headers), ())
    def test_login_wo_identifier_name_hit(self):
        REMEMBER_HEADERS = [('Foo', 'Bar'), ('Baz', 'Qux')]
        FORGET_HEADERS = [('Spam', 'Blah')]