[Checkins] SVN: zope.login/trunk/s Copy over code and tests from zope.publisher
Hanno Schlichting
hannosch at hannosch.eu
Thu Dec 31 11:57:17 EST 2009
Log message for revision 107455:
Copy over code and tests from zope.publisher
Changed:
U zope.login/trunk/setup.py
U zope.login/trunk/src/zope/login/__init__.py
A zope.login/trunk/src/zope/login/configure.zcml
A zope.login/trunk/src/zope/login/ftp.py
A zope.login/trunk/src/zope/login/http.py
A zope.login/trunk/src/zope/login/tests/
A zope.login/trunk/src/zope/login/tests/__init__.py
A zope.login/trunk/src/zope/login/tests/test_basicauth.py
A zope.login/trunk/src/zope/login/tests/test_ftpauth.py
-=-
Modified: zope.login/trunk/setup.py
===================================================================
--- zope.login/trunk/setup.py 2009-12-31 16:32:53 UTC (rev 107454)
+++ zope.login/trunk/setup.py 2009-12-31 16:57:16 UTC (rev 107455)
@@ -46,6 +46,7 @@
namespace_packages=['zope'],
install_requires=['setuptools',
'zope.authentication',
+ 'zope.component',
'zope.interface',
'zope.publisher',
],
Modified: zope.login/trunk/src/zope/login/__init__.py
===================================================================
--- zope.login/trunk/src/zope/login/__init__.py 2009-12-31 16:32:53 UTC (rev 107454)
+++ zope.login/trunk/src/zope/login/__init__.py 2009-12-31 16:57:16 UTC (rev 107455)
@@ -0,0 +1 @@
+#
\ No newline at end of file
Copied: zope.login/trunk/src/zope/login/configure.zcml (from rev 107454, zope.publisher/trunk/src/zope/publisher/configure.zcml)
===================================================================
--- zope.login/trunk/src/zope/login/configure.zcml (rev 0)
+++ zope.login/trunk/src/zope/login/configure.zcml 2009-12-31 16:57:16 UTC (rev 107455)
@@ -0,0 +1,15 @@
+<configure xmlns="http://namespaces.zope.org/zope">
+
+ <adapter
+ factory=".http.BasicAuthAdapter"
+ provides="zope.authentication.interfaces.ILoginPassword"
+ for="zope.publisher.interfaces.http.IHTTPCredentials"
+ />
+
+ <adapter
+ factory=".ftp.FTPAuth"
+ provides="zope.authentication.interfaces.ILoginPassword"
+ for="zope.publisher.interfaces.ftp.IFTPCredentials"
+ />
+
+</configure>
Copied: zope.login/trunk/src/zope/login/ftp.py (from rev 107454, zope.publisher/trunk/src/zope/publisher/ftp.py)
===================================================================
--- zope.login/trunk/src/zope/login/ftp.py (rev 0)
+++ zope.login/trunk/src/zope/login/ftp.py 2009-12-31 16:57:16 UTC (rev 107455)
@@ -0,0 +1,34 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 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
+#
+##############################################################################
+
+from zope.authentication.loginpassword import LoginPassword
+from zope.component import adapts
+from zope.publisher.interfaces.ftp import IFTPCredentials
+
+class FTPAuth(LoginPassword):
+ """ILoginPassword adapter for handling common FTP authentication."""
+
+ adapts(IFTPCredentials)
+
+ def __init__(self, request):
+ self.__request = request
+ lpw = request._authUserPW()
+ if lpw is None:
+ login, password = None, None
+ else:
+ login, password = lpw
+ super(FTPAuth, self).__init__(login, password)
+
+ def needLogin(self, realm):
+ self.__request.unauthorized("Did not work")
Copied: zope.login/trunk/src/zope/login/http.py (from rev 107454, zope.publisher/trunk/src/zope/publisher/http.py)
===================================================================
--- zope.login/trunk/src/zope/login/http.py (rev 0)
+++ zope.login/trunk/src/zope/login/http.py 2009-12-31 16:57:16 UTC (rev 107455)
@@ -0,0 +1,36 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 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.
+#
+##############################################################################
+
+from zope.authentication.loginpassword import LoginPassword
+from zope.component import adapts
+from zope.publisher.interfaces.http import IHTTPCredentials
+
+
+class BasicAuthAdapter(LoginPassword):
+ """ILoginPassword adapter for handling HTTP Basic authentication"""
+
+ adapts(IHTTPCredentials)
+
+ def __init__(self, request):
+ self.__request = request
+ # TODO base64 decoding should be done here, not in request
+ lpw = request._authUserPW()
+ if lpw is None:
+ login, password = None, None
+ else:
+ login, password = lpw
+ super(BasicAuthAdapter, self).__init__(login, password)
+
+ def needLogin(self, realm):
+ self.__request.unauthorized('basic realm="%s"' % realm)
Property changes on: zope.login/trunk/src/zope/login/tests/__init__.py
___________________________________________________________________
Added: svn:eol-style
+ native
Copied: zope.login/trunk/src/zope/login/tests/test_basicauth.py (from rev 107454, zope.publisher/trunk/src/zope/publisher/tests/test_basicauthadapter.py)
===================================================================
--- zope.login/trunk/src/zope/login/tests/test_basicauth.py (rev 0)
+++ zope.login/trunk/src/zope/login/tests/test_basicauth.py 2009-12-31 16:57:16 UTC (rev 107455)
@@ -0,0 +1,58 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 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.
+#
+##############################################################################
+"""Test Basic Authentication Adapter
+
+$Id$
+"""
+import unittest
+
+from zope.publisher.http import BasicAuthAdapter
+
+class Request(object):
+
+ def __init__(self, lpw):
+ self.lpw = lpw
+
+ def _authUserPW(self):
+ return self.lpw
+
+ challenge = None
+ def unauthorized(self, challenge):
+ self.challenge = challenge
+
+
+class Test(unittest.TestCase):
+
+ def testBasicAuthAdapter(self):
+ r = Request(None)
+ a = BasicAuthAdapter(r)
+ self.assertEqual(a.getLogin(), None)
+ self.assertEqual(a.getPassword(), None)
+ r = Request(("tim", "123"))
+ a = BasicAuthAdapter(r)
+ self.assertEqual(a.getLogin(), "tim")
+ self.assertEqual(a.getPassword(), "123")
+
+ def testUnauthorized(self):
+ r = Request(None)
+ a = BasicAuthAdapter(r)
+ a.needLogin("tim")
+ self.assertEqual(r.challenge, 'basic realm="tim"')
+
+def test_suite():
+ loader=unittest.TestLoader()
+ return loader.loadTestsFromTestCase(Test)
+
+if __name__=='__main__':
+ unittest.TextTestRunner().run(test_suite())
Copied: zope.login/trunk/src/zope/login/tests/test_ftpauth.py (from rev 107454, zope.publisher/trunk/src/zope/publisher/tests/test_ftpauth.py)
===================================================================
--- zope.login/trunk/src/zope/login/tests/test_ftpauth.py (rev 0)
+++ zope.login/trunk/src/zope/login/tests/test_ftpauth.py 2009-12-31 16:57:16 UTC (rev 107455)
@@ -0,0 +1,63 @@
+##############################################################################
+#
+# Copyright (c) 2003 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.
+#
+##############################################################################
+"""FTP Authentication Test
+
+$Id$
+"""
+from unittest import TestCase, TestSuite, main, makeSuite
+from zope.publisher.interfaces.ftp import IFTPCredentials
+from zope.interface import implements
+
+from zope.publisher.ftp import FTPAuth
+
+class FTPCredentials(object):
+ __doc__ = IFTPCredentials.__doc__
+
+ implements(IFTPCredentials)
+
+ def __init__(self, credentials):
+ self.credentials = credentials
+
+ def _authUserPW(self):
+ return self.credentials
+
+ unauth = 0
+ def unauthorized(self, challenge):
+ self.unauth += 1
+
+
+class Test(TestCase):
+
+ def test(self):
+ request = FTPCredentials(('bob', '123'))
+ auth = FTPAuth(request)
+ self.assertEqual(auth.getLogin(), 'bob')
+ self.assertEqual(auth.getPassword(), '123')
+
+ unauth = request.unauth
+ auth.needLogin('xxx')
+ self.assertEqual(request.unauth, unauth+1)
+
+ request = FTPCredentials(None)
+ auth = FTPAuth(request)
+ self.assertEqual(auth.getLogin(), None)
+ self.assertEqual(auth.getPassword(), None)
+
+def test_suite():
+ return TestSuite((
+ makeSuite(Test),
+ ))
+
+if __name__=='__main__':
+ main(defaultTest='test_suite')
More information about the checkins
mailing list