Index: main/waeup.kofa/trunk/src/waeup/kofa/tests/test_authentication.py
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/tests/test_authentication.py	(revision 14511)
+++ main/waeup.kofa/trunk/src/waeup/kofa/tests/test_authentication.py	(revision 14667)
@@ -21,16 +21,22 @@
 import unittest
 from cStringIO import StringIO
-from zope.component import getGlobalSiteManager
+from zope.component import getGlobalSiteManager, queryUtility
 from zope.component.hooks import setSite, clearSite
 from zope.interface.verify import verifyClass, verifyObject
 from zope.password.testing import setUpPasswordManagers
-from zope.pluggableauth.interfaces import IAuthenticatorPlugin
+from zope.pluggableauth import PluggableAuthentication
+from zope.pluggableauth.interfaces import (
+    IAuthenticatorPlugin, ICredentialsPlugin)
+from zope.publisher.browser import TestRequest
 from zope.securitypolicy.interfaces import IPrincipalRoleManager
 from waeup.kofa.testing import FunctionalTestCase, FunctionalLayer
 from waeup.kofa.authentication import (
     UserAuthenticatorPlugin, Account, KofaPrincipalInfo, FailedLoginInfo,
-    get_principal_role_manager, UsersPlugin,)
+    get_principal_role_manager, UsersPlugin, KofaXMLRPCCredentialsPlugin,
+    setup_authentication)
 from waeup.kofa.interfaces import (
-    IUserAccount, IFailedLoginInfo, IKofaPrincipalInfo, IKofaPluggable)
+    IAuthPluginUtility, IUserAccount, IFailedLoginInfo, IKofaPrincipalInfo,
+    IKofaPluggable)
+
 
 class FakeSite(grok.Site, grok.Container):
@@ -39,4 +45,81 @@
     #    return getGlobalSiteManager()
     pass
+
+
+class FakeAuthPlugin(object):
+    def register(self, pau):
+        pau.credentialsPlugins += ('foo', )
+
+
+class Test_setup_authentication(FunctionalTestCase):
+    # Tests for the `setup_authentication` function
+
+    layer = FunctionalLayer
+
+    def tearDown(self):
+        # clean up registry.
+        gsm = getGlobalSiteManager()
+        for iface, name in ((IAuthPluginUtility, 'myauth'), ):
+            to_delete = queryUtility(iface, name=name)
+            if to_delete is not None:
+                gsm.unregisterUtility(provided=iface, name=name)
+        super(Test_setup_authentication, self).tearDown()
+
+    def test_plugins_are_registered(self):
+        # We can populate a PAU with (hardcoded set of) plugins
+        pau = PluggableAuthentication()
+        setup_authentication(pau)
+        for name in (
+                'No Challenge if Authenticated',
+                'xmlrpc-credentials',
+                'credentials'):
+            assert name in pau.credentialsPlugins
+        for name in ('users', ):
+            assert name in pau.authenticatorPlugins
+
+    def test_external_plugins_are_registered(self):
+        # registered plugins are called as well
+        gsm = getGlobalSiteManager()
+        gsm.registerUtility(
+            MyFakeAuthPlugin(), IAuthPluginUtility, name='myauth')
+        pau = PluggableAuthentication()
+        setup_authentication(pau)
+        assert 'foo' in pau.credentialsPlugins
+
+
+class KofaXMLRPCCredentialsPluginTests(FunctionalTestCase):
+    # Test for XMLRPC credentials plugin
+
+    layer = FunctionalLayer
+
+    def test_ifaces(self):
+        # we meet interface requirements
+        plugin = KofaXMLRPCCredentialsPlugin()
+        self.assertTrue(
+            verifyClass(ICredentialsPlugin, KofaXMLRPCCredentialsPlugin))
+
+    def test_util_is_registered(self):
+        # we can query this named utility
+        util = queryUtility(ICredentialsPlugin, name='xmlrpc-credentials')
+        assert util is not None
+
+    def test_can_extract_creds(self):
+        # we can extract credentials from appropriate requests
+        req = TestRequest(
+            environ={'HTTP_AUTHORIZATION': u'Basic bWdyOm1ncnB3'})
+        plugin = KofaXMLRPCCredentialsPlugin()
+        assert plugin.extractCredentials(req) == {
+            'login': 'mgr', 'password': 'mgrpw'}
+
+    def test_challenge_disabled(self):
+        # we will not challenge people
+        plugin = KofaXMLRPCCredentialsPlugin()
+        assert plugin.challenge(TestRequest()) is False
+
+    def test_logout_disabled(self):
+        # we do not support logging out. HTTP basic auth cannot do this.
+        plugin = KofaXMLRPCCredentialsPlugin()
+        assert plugin.logout(TestRequest()) is False
+
 
 class UserAuthenticatorPluginTests(FunctionalTestCase):
