[PATCH] bugzilla: support Bugzilla 4.4.3+ API login token authentication (issue4257)

Jim Hague jim.hague at acm.org
Fri May 23 11:42:51 CDT 2014


# HG changeset patch
# User Jim Hague <jim.hague at acm.org>
# Date 1400862544 -3600
#      Fri May 23 17:29:04 2014 +0100
# Branch stable
# Node ID 1522f121693156c814fd1d037c3dbc57a3639030
# Parent  54d7657d7d1e6a62315eea53f4498657e766bb60
bugzilla: support Bugzilla 4.4.3+ API login token authentication (issue4257)

Bugzilla 4.4.3 and later remove the old cookie based session authentication
from the Web Services API and replace it with a login token. The session
can now also be restricted to the originating IP.

Add the necessary to the extension so it works with 4.4.3 and later.

diff -r 54d7657d7d1e -r 1522f1216931 hgext/bugzilla.py
--- a/hgext/bugzilla.py	Mon May 05 16:54:15 2014 +0200
+++ b/hgext/bugzilla.py	Fri May 23 17:29:04 2014 +0100
@@ -1,7 +1,7 @@
 # bugzilla.py - bugzilla integration for mercurial
 #
 # Copyright 2006 Vadim Gelfer <vadim.gelfer at gmail.com>
-# Copyright 2011-2 Jim Hague <jim.hague at acm.org>
+# Copyright 2011-4 Jim Hague <jim.hague at acm.org>
 #
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
@@ -523,7 +523,7 @@
 
     The regular xmlrpclib transports ignore cookies. Which causes
     a bit of a problem when you need a cookie-based login, as with
-    the Bugzilla XMLRPC interface.
+    the Bugzilla XMLRPC interface prior to 4.4.3.
 
     So this is a helper for defining a Transport which looks for
     cookies being set in responses and saves them to add to all future
@@ -620,7 +620,9 @@
         ver = self.bzproxy.Bugzilla.version()['version'].split('.')
         self.bzvermajor = int(ver[0])
         self.bzverminor = int(ver[1])
-        self.bzproxy.User.login({'login': user, 'password': passwd})
+        login = self.bzproxy.User.login({'login': user, 'password': passwd,
+                                         'restrict_login': True})
+        self.bztoken = login.get('token', '')
 
     def transport(self, uri):
         if urlparse.urlparse(uri, "http")[0] == "https":
@@ -631,13 +633,15 @@
     def get_bug_comments(self, id):
         """Return a string with all comment text for a bug."""
         c = self.bzproxy.Bug.comments({'ids': [id],
-                                       'include_fields': ['text']})
+                                       'include_fields': ['text'],
+                                       'token': self.bztoken})
         return ''.join([t['text'] for t in c['bugs'][str(id)]['comments']])
 
     def filter_real_bug_ids(self, bugs):
         probe = self.bzproxy.Bug.get({'ids': sorted(bugs.keys()),
                                       'include_fields': [],
                                       'permissive': True,
+                                      'token': self.bztoken,
                                       })
         for badbug in probe['faults']:
             id = badbug['id']
@@ -662,6 +666,7 @@
             if 'fix' in newstate:
                 args['status'] = self.fixstatus
                 args['resolution'] = self.fixresolution
+            args['token'] = self.bztoken
             self.bzproxy.Bug.update(args)
         else:
             if 'fix' in newstate:
@@ -719,10 +724,12 @@
         than the subject line, and leave a blank line after it.
         '''
         user = self.map_committer(committer)
-        matches = self.bzproxy.User.get({'match': [user]})
+        matches = self.bzproxy.User.get({'match': [user],
+                                         'token': self.bztoken})
         if not matches['users']:
             user = self.ui.config('bugzilla', 'user', 'bugs')
-            matches = self.bzproxy.User.get({'match': [user]})
+            matches = self.bzproxy.User.get({'match': [user],
+                                             'token': self.bztoken})
             if not matches['users']:
                 raise util.Abort(_("default bugzilla user %s email not found") %
                                  user)


More information about the Mercurial-devel mailing list