[Checkins] SVN: PluggableAuthService/trunk/ Extended the
DomainAuthHelper to function as its own extraction plugin
Tres Seaver
tseaver at palladion.com
Mon Aug 28 23:21:16 EDT 2006
Log message for revision 69827:
Extended the DomainAuthHelper to function as its own extraction plugin
o This change allows for the case that another extractor is registered,
but does not return any credentials.
Resolves http://www.zope.org/Collectors/PAS/46
Changed:
U PluggableAuthService/trunk/doc/CHANGES.txt
U PluggableAuthService/trunk/interfaces/plugins.py
U PluggableAuthService/trunk/plugins/DomainAuthHelper.py
A PluggableAuthService/trunk/plugins/tests/test_DomainAuthHelper.py
-=-
Modified: PluggableAuthService/trunk/doc/CHANGES.txt
===================================================================
--- PluggableAuthService/trunk/doc/CHANGES.txt 2006-08-29 00:49:57 UTC (rev 69826)
+++ PluggableAuthService/trunk/doc/CHANGES.txt 2006-08-29 03:21:16 UTC (rev 69827)
@@ -1,5 +1,18 @@
PluggableAuthService changelog
+ After PluggableAuthService 1.4-beta
+
+ Bugs Fixed
+
+ - Extended the DomainAuthHelper to function as its own extraction
+ plugin, to allow for the case that another extractor is registered,
+ but does not return any credentials.
+ (http://www.zope.org/Collectors/PAS/46)
+
+ - Re-worded parts of the README so they don't point to specific or
+ non-existing files (http://www.zope.org/Collectors/PAS/6 and
+ http://www.zope.org/Collectors/PAS/47)
+
PluggableAuthService 1.4-beta (2006/08/07)
Features Added
@@ -37,11 +50,6 @@
- Added a DEPENDENCIES.txt. (http://www.zope.org/Collectors/PAS/44)
- - Re-worded parts of the README so they don't point to specific or
- non-existing files (http://www.zope.org/Collectors/PAS/6 and
- http://www.zope.org/Collectors/PAS/47)
-
-
PluggableAuthService 1.3 (2006/06/09)
No changes from version 1.3-beta
Modified: PluggableAuthService/trunk/interfaces/plugins.py
===================================================================
--- PluggableAuthService/trunk/interfaces/plugins.py 2006-08-29 00:49:57 UTC (rev 69826)
+++ PluggableAuthService/trunk/interfaces/plugins.py 2006-08-29 03:21:16 UTC (rev 69827)
@@ -29,9 +29,12 @@
def extractCredentials( request ):
- """ request -> {}
+ """ request -> {...}
o Return a mapping of any derived credentials.
+
+ o Return an empty mapping to indicate that the plugin found no
+ appropriate credentials.
"""
class ILoginPasswordExtractionPlugin( IExtractionPlugin ):
@@ -46,10 +49,13 @@
, k1 : v1
, ...
, kN : vN
- }
+ } | {}
- o Returned mapping will contain at least 'login' and 'password'
- keys, with the password in plaintext.
+ o If credentials are found, the returned mapping will contain at
+ least 'login' and 'password' keys, with the password in plaintext.
+
+ o Return an empty mapping to indicate that the plugin found no
+ appropriate credentials.
"""
class ILoginPasswordHostExtractionPlugin( ILoginPasswordExtractionPlugin ):
@@ -66,11 +72,14 @@
, k1 : v1
, ...
, kN : vN
- }
+ } | {}
- o Returned mapping will contain at least 'login', 'password',
- 'remote_host' and 'remote_addr' keys, with the password in
- plaintext.
+ o If credentials are found, the returned mapping will contain at
+ least 'login', 'password', 'remote_host' and 'remote_addr' keys,
+ with the password in plaintext.
+
+ o Return an empty mapping to indicate that the plugin found no
+ appropriate credentials.
"""
class IAuthenticationPlugin( Interface ):
Modified: PluggableAuthService/trunk/plugins/DomainAuthHelper.py
===================================================================
--- PluggableAuthService/trunk/plugins/DomainAuthHelper.py 2006-08-29 00:49:57 UTC (rev 69826)
+++ PluggableAuthService/trunk/plugins/DomainAuthHelper.py 2006-08-29 03:21:16 UTC (rev 69827)
@@ -32,6 +32,8 @@
from Products.PluggableAuthService.interfaces.plugins import \
IAuthenticationPlugin
from Products.PluggableAuthService.interfaces.plugins import \
+ IExtractionPlugin
+from Products.PluggableAuthService.interfaces.plugins import \
IRolesPlugin
from Products.PluggableAuthService.plugins.BasePlugin import BasePlugin
from Products.PluggableAuthService.utils import classImplements
@@ -91,6 +93,23 @@
self._domain_map = OOBTree()
+ security.declarePrivate('extractCredentials')
+ def extractCredentials(self, request):
+ """ Extract credentials from 'request'.
+ """
+ creds = {}
+
+ remote_host = request.get('REMOTE_HOST', '')
+ if remote_host:
+ creds['remote_host'] = request.get('REMOTE_HOST', '')
+
+ try:
+ creds['remote_address'] = request.getClientAddr()
+ except AttributeError:
+ creds['remote_address'] = request.get('REMOTE_ADDR', '')
+
+ return creds
+
security.declarePrivate('authenticateCredentials')
def authenticateCredentials(self, credentials):
""" Fulfill AuthenticationPlugin requirements """
@@ -300,6 +319,7 @@
classImplements( DomainAuthHelper
, IDomainAuthHelper
+ , IExtractionPlugin
, IAuthenticationPlugin
, IRolesPlugin
)
Added: PluggableAuthService/trunk/plugins/tests/test_DomainAuthHelper.py
===================================================================
--- PluggableAuthService/trunk/plugins/tests/test_DomainAuthHelper.py 2006-08-29 00:49:57 UTC (rev 69826)
+++ PluggableAuthService/trunk/plugins/tests/test_DomainAuthHelper.py 2006-08-29 03:21:16 UTC (rev 69827)
@@ -0,0 +1,100 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors. All Rights
+# Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this
+# distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+import unittest
+
+from Products.PluggableAuthService.tests.conformance \
+ import IExtractionPlugin_conformance
+from Products.PluggableAuthService.tests.conformance \
+ import IAuthenticationPlugin_conformance
+from Products.PluggableAuthService.tests.conformance \
+ import IRolesPlugin_conformance
+
+class FauxRequest:
+
+ def __init__(self, **kw):
+ self._data = dict(kw)
+
+ def get(self, key, default=None):
+ return self._data.get(key, default)
+
+class FauxRequestWithClientAddr(FauxRequest):
+
+ def getClientAddr(self):
+ return self._data.get('CLIENT_ADDR')
+
+class DomainAuthHelperTests( unittest.TestCase
+ , IExtractionPlugin_conformance
+ , IAuthenticationPlugin_conformance
+ , IRolesPlugin_conformance
+ ):
+
+ def _getTargetClass( self ):
+
+ from Products.PluggableAuthService.plugins.DomainAuthHelper \
+ import DomainAuthHelper
+
+ return DomainAuthHelper
+
+ def _makeOne( self, id='test', *args, **kw ):
+
+ return self._getTargetClass()( id=id, *args, **kw )
+
+ def test_extractCredentials_no_creds( self ):
+
+ helper = self._makeOne()
+ request = FauxRequest()
+
+ self.assertEqual( helper.extractCredentials( request ), {} )
+
+ def test_extractCredentials_with_getClientAddr( self ):
+
+ helper = self._makeOne()
+ request = FauxRequestWithClientAddr(REMOTE_HOST='foo',
+ CLIENT_ADDR='bar')
+
+ self.assertEqual(helper.extractCredentials(request),
+ {'remote_host': 'foo',
+ 'remote_address': 'bar'})
+
+ def test_extractCredentials_no_getClientAddr_with_REMOTE_ADDR( self ):
+
+ helper = self._makeOne()
+ request = FauxRequest(REMOTE_HOST='foo',
+ REMOTE_ADDR='bam')
+
+ self.assertEqual(helper.extractCredentials(request),
+ {'remote_host': 'foo',
+ 'remote_address': 'bam'})
+
+ def test_extractCredentials_no_getClientAddr_no_REMOTE_ADDR( self ):
+
+ helper = self._makeOne()
+ request = FauxRequest(REMOTE_HOST='foo')
+
+ self.assertEqual(helper.extractCredentials(request),
+ {'remote_host': 'foo',
+ 'remote_address': ''})
+
+ # TODO add tests for authenticateCredentials, getRolesForPrincipal, etc.
+
+
+if __name__ == "__main__":
+ unittest.main()
+
+def test_suite():
+ return unittest.TestSuite((
+ unittest.makeSuite( DomainAuthHelperTests ),
+ ))
+
Property changes on: PluggableAuthService/trunk/plugins/tests/test_DomainAuthHelper.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
More information about the Checkins
mailing list