changeset 2503:09afb8020b20

Merge devel.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Sun, 22 Jul 2007 05:11:46 +0200
parents d9e112066a9e (current diff) d9aef892fda8 (diff)
children 426a8cb8e44c
files MoinMoin/xmlrpc/_tests/test_multicall.py
diffstat 6 files changed, 88 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/xmlrpc/__init__.py	Sun Jul 22 04:17:59 2007 +0200
+++ b/MoinMoin/xmlrpc/__init__.py	Sun Jul 22 05:11:46 2007 +0200
@@ -622,11 +622,16 @@
             except caching.CacheError:
                 pass
 
-    def _generate_auth_token(self):
+    def _generate_auth_token(self, usr):
+        """Generate a token that can be used to authorize next requests
+
+        @type usr: MoinMoin.user
+
+        """
         token = random_string(32, 'abcdefghijklmnopqrstuvwxyz0123456789')
         centry = caching.CacheEntry(self.request, 'xmlrpc-session', token,
                                     scope='farm', use_pickle=True)
-        centry.update((time.time() + 15*3600, u.id))
+        centry.update((time.time() + 15*3600, usr.id))
         return token
 
     def xmlrpc_getAuthToken(self, username, password, *args):
@@ -641,7 +646,7 @@
                                      password=password, login=True)
 
         if u and u.valid:
-            return _generate_auth_token()
+            return self._generate_auth_token(u)
         else:
             return ""
 
@@ -663,7 +668,7 @@
         u = self.request.handle_jid_auth(jid)
 
         if u and u.valid:
-            return _generate_auth_token()
+            return self._generate_auth_token(u)
         else:
             return ""
 
--- a/MoinMoin/xmlrpc/_tests/test_multicall.py	Sun Jul 22 04:17:59 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-# -*- coding: iso-8859-1 -*-
-"""
-    MoinMoin - MoinMoin.xmlrpc.xmlrpc_system_multicall Fault serialization
-
-    @copyright: 2007 by Karol Nowak <grywacz@gmail.com>
-    @license: GNU GPL, see COPYING for details.
-"""
-
-from MoinMoin.xmlrpc import XmlRpcBase
-from xmlrpclib import Fault
-
-def xmlrpc_return_fault():
-    return Fault(666, "Fault description")
-
-def test_fault_serialization(request):
-    xmlrpc = XmlRpcBase(request)
-    xmlrpc.xmlrpc_return_fault = xmlrpc_return_fault
-    args = [{'methodName': 'return_fault', 'params': []}]
-
-    print """If a XML RPC method returns a Fault, we should get a failure response
-    instead of a serialized Fault, as it happened in the past. See revision
-    8b7d6d70fc95 for details"""
-
-    result = xmlrpc.xmlrpc_system_multicall(args)
-    assert type(result[0]) == dict
-    assert result[0].has_key("faultCode") and result[0].has_key("faultString")
-
-
-coverage_modules = ['MoinMoin.xmlrpc']
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/xmlrpc/_tests/test_xmlrpc.py	Sun Jul 22 05:11:46 2007 +0200
@@ -0,0 +1,45 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - tests for the xmlrpc module
+
+    @copyright: 2007 by Karol Nowak <grywacz@gmail.com>
+    @license: GNU GPL, see COPYING for details.
+"""
+
+from MoinMoin.user import User
+from MoinMoin.xmlrpc import XmlRpcBase
+from xmlrpclib import Fault
+
+
+def test_fault_serialization(request):
+    """test MoinMoin.xmlrpc.xmlrpc_system_multicall Fault serialization"""
+
+    def xmlrpc_return_fault():
+        return Fault(666, "Fault description")
+
+    xmlrpc = XmlRpcBase(request)
+    xmlrpc.xmlrpc_return_fault = xmlrpc_return_fault
+    args = [{'methodName': 'return_fault', 'params': []}]
+
+    print """If a XML RPC method returns a Fault, we should get a failure response
+    instead of a serialized Fault, as it happened in the past. See revision
+    8b7d6d70fc95 for details"""
+
+    result = xmlrpc.xmlrpc_system_multicall(args)
+    assert type(result[0]) == dict
+    assert result[0].has_key("faultCode") and result[0].has_key("faultString")
+
+def test_generate_auth_token(request):
+    """Check if auth token generation works"""
+
+    usr = User(request)
+    xmlrpc = XmlRpcBase(request)
+    token = xmlrpc._generate_auth_token(usr)
+
+    print "Token should be a string or unicode object and have langth of 32 chars!"
+    assert type(token) == str or type(token) == unicode
+    assert len(token) == 32
+
+
+coverage_modules = ['MoinMoin.xmlrpc']
+
--- a/jabberbot/commands.py	Sun Jul 22 04:17:59 2007 +0200
+++ b/jabberbot/commands.py	Sun Jul 22 05:11:46 2007 +0200
@@ -57,6 +57,11 @@
     parameter_list = u""
 
     def __init__(self, jid):
+        """A constructor
+
+        @param jid: Jabber ID to send the reply to
+        @type jid: unicode
+        """
         self.jid = jid
         self.data = None
 
--- a/jabberbot/xmlrpcbot.py	Sun Jul 22 04:17:59 2007 +0200
+++ b/jabberbot/xmlrpcbot.py	Sun Jul 22 05:11:46 2007 +0200
@@ -82,7 +82,13 @@
         self.commands_out.put_nowait(report)
 
     def get_auth_token(self, jid):
-        token = self.connection.getAuthToken(jid, self.config.secret)
+        """Get an auth token using user's Jabber ID
+
+        @type jid: unicode
+        """
+        # We have to use a bare JID
+        jid = jid.split('/')[0]
+        token = self.connection.getJabberAuthToken(jid, self.config.secret)
         if token:
             self.token = token
 
@@ -139,12 +145,13 @@
 
         if not self.token:
             self.warn_no_credentials(command.jid)
-            getpage_result = self.multicall()
+            getpage_result = self.multicall()[0]
         else:
-            getpage_result, token_result = self.multicall()
+            token_result, getpage_result = self.multicall()
+            if token_result != u"SUCCESS":
+                self.warn_no_credentials(command.jid)
 
-        # FIXME: warn if token turned out being wrong
-        command.data = getpage_result[0]
+        command.data = getpage_result
 
     get_page = _xmlrpc_decorator(get_page)
 
@@ -156,12 +163,13 @@
 
         if not self.token:
             self.warn_no_credentials(command.jid)
-            getpagehtml_result = self.multicall()
+            getpagehtml_result = self.multicall()[0]
         else:
             token_result, getpagehtml_result = self.multicall()
+            if token_result != u"SUCCESS":
+                self.warn_no_credentials(command.jid)
 
-        # FIXME: warn if token turned out being wrong
-        command.data = getpagehtml_result[0]
+        command.data = getpagehtml_result
 
     get_page_html = _xmlrpc_decorator(get_page_html)
 
@@ -177,12 +185,13 @@
 
         if not self.token:
             # FIXME: notify the user that he may not have full rights on the wiki
-            getpagelist_result = self.multicall()
+            getpagelist_result = self.multicall()[0]
         else:
             token_result, getpagelist_result = self.multicall()
+            if token_result != u"SUCCESS":
+                self.warn_no_credentials(command.jid)
 
-        # FIXME: warn if token turned out being wrong
-        command.data = getpagelist_result[0]
+        command.data = getpagelist_result
 
     get_page_list = _xmlrpc_decorator(get_page_list)
 
@@ -193,18 +202,18 @@
         self.multicall.getPageInfo(command.pagename)
 
         if not self.token:
-            # FIXME: notify the user that he may not have full rights on the wiki
-            getpageinfo_result = self.multicall()
+            self.warn_no_credentials(command.jid)
+            getpageinfo_result = self.multicall()[0]
         else:
             token_result, getpageinfo_result = self.multicall()
-
-        # FIXME: warn if token turned out being wrong
+            if token_result != u"SUCCESS":
+                self.warn_no_credentials(jid)
 
-        author = getpageinfo_result[0]['author']
+        author = getpageinfo_result['author']
         if author.startswith("Self:"):
-            author = getpageinfo_result[0]['author'][5:]
+            author = getpageinfo_result['author'][5:]
 
-        datestr = str(getpageinfo_result[0]['lastModified'])
+        datestr = str(getpageinfo_result['lastModified'])
         date = u"%(year)s-%(month)s-%(day)s at %(time)s" % {
                     'year': datestr[:4],
                     'month': datestr[4:6],
@@ -217,7 +226,7 @@
 Current version: %(version)s""") % {
              'author': author,
              'modification': date,
-             'version': getpageinfo_result[0]['version'],
+             'version': getpageinfo_result['version'],
          }
 
         command.data = msg
--- a/jabberbot/xmppbot.py	Sun Jul 22 04:17:59 2007 +0200
+++ b/jabberbot/xmppbot.py	Sun Jul 22 05:11:46 2007 +0200
@@ -292,7 +292,7 @@
             })
 
         elif isinstance(command, cmd.GetPageList):
-            msg = _("uThat's the list of pages accesible to you:\n\n%s")
+            msg = _("That's the list of pages accesible to you:\n\n%s")
             pagelist = u"\n".join(command.data)
 
             self.send_message(command.jid, msg % (pagelist, ))