Tuesday, January 13, 2009

Trac, Testlink and XML-RPC


Trac is a web-based project and defect management system that has gained considerable market share for a wide range of commercial and open-source projects. Easy to set up, configure and maintain, it's rich feature set offers some surprisingly advanced capabilities. It's highly configurable without being overly complex - in a word, elegant. And if the default functionality of Trac isn't enough, there's a trove of 3rd-party plugins available for it, including the XML-RPC plugin, which makes the Trac database queriable via -- you guessed it -- XML-RPC.

Testlink is a testcase management software bit. To be honest I don't like it because it's bloated and clunky. There, I've said it. But its probably one of the better open-source solutions for testcase management out there, so I won't complain too much.

Testlink offers some limited support for integration with Trac using the XML-RPC plugin. Unfortunately, if you're using authenticated XML-RPC in Trac, Testlink can't handle it. I don't know too many people who would want to put an unauthenticated XML-RPC interface to their defects database on a network, private or public. Anyway, I hacked some support for authenticated XML-RPC into the Testlink code. It's pretty easy, so if anyone is having this problem getting Testlink to talk to Trac over authenticated XML-RPC, here's what you do. Changes are in bold red.

[Note: please don't ask me how to set up Trac, the XML-RPC plugin or Testlink.]


modified /opt/lampp/htdocs/testlink/cfg/trac.cfg.php, added:
define('BUG_TRACK_XMLRPC_HOST', 'http://username:password@192.168.0.123');

modified /opt/lampp/htdocs/testlink_18RC1/lib/bugtracking/int_trac.php:
$this->m_xmlrpcClient = new IXR_Client(BUG_TRACK_XMLRPC_HOST.$tracProjectName.'/login/xmlrpc');

modified /opt/lampp/htdocs/testlink_18RC1/third_party/xml-rpc/class-IXR.php

function query() {
$args = func_get_args();
$method = array_shift($args);
$request = new IXR_Request($method, $args);
$length = $request->getLength();
$xml = $request->getXml();
$r = "\r\n";
$credentials = "";
if ($this->user != "") {
$credentials = base64_encode($this->user . ":" . $this->pass);
}

$request = "POST {$this->path} HTTP/1.0$r";
$request .= "Host: {$this->server}$r";
if ($credentials != "") {
$request .= "Authorization: Basic {$credentials}$r";
}

function IXR_Client($server, $path = false, $port = 80, $timeout = false) {
if (!$path) {
// Assume we have been given a URL instead
$bits = parse_url($server);
$this->server = $bits['host'];
$this->port = isset($bits['port']) ? $bits['port'] : 80;
$this->user = isset($bits['user']) ? $bits['user'] : '';
$this->pass = isset($bits['pass']) ? $bits['pass'] : '';

12 comments:

protonic said...

Thanks a lot for your work and spend time for solve it problem. All work as you write.


But what need change if for trac used another auth.
for example 'trac':
tracd -s -p 8080 --auth=trac,D:\SVN\repo\trac\auth.txt,trac D:\SVN\repo\trac

my problem consist of that trac do not give access when using standart url http://user:password@www.trac

only by fill and send special login fields in login page.

Early I think that it's not so importance because of xml-rpc must have ability to login of itself in trac. But now I don't understand how it happens.

Darren said...

Hi protonic,

Use the TracHTTPAuth plugin to use htaccess as the underlayment for the web login form. http://trac-hacks.org/wiki/HttpAuthPlugin

cheers,
Darren

Unknown said...

Looks pretty cool. Just so I'm clear, this code will take the credentials being used for testlink and pass them to trac? If so, that's pretty awesome, and exactly what I need.

- qthatswho

Darren said...

Not exactly, whatever you specify for username / password in the trac.cfg.php file gets passed to Trac. You can set up a testlink user and password in Trac so Testlink can then log in, providing a very basic level of integration.

Sven said...

I needed Digest support so I used http://phpxmlrpc.sourceforge.net/ instead of the Incutio lib shipped with TestLink.

I put phpxmlrpc in the third_party directory and and modified .../lib/bugtracking/int_trac.php and .../cfg/trac.cfg.php

Thanks for the inspiration!

Unknown said...

Hi Darren,
I am using tracd and testlink and wanted to connect with authentication. For this i have created a user in trac and configuring the same in testlink side.
tracd is started as below;
C:\Python25\Scripts>tracd -p 8000 --basic-auth=*,D:\00_Gopi\Projects\trac\cd-fda\passwordByhtpasswd.
txt,trac D:\00_Gopi\Projects\trac\cd-fda --hostname=cd-fda.is.olympus.co.jp

On testlink side, i have configured as per the description given by you.
But i am getting fault code 1 with error message as "XML_RPC privileges are required to perform this operation"
Any pointer would be of a great help?

Regards
Baral.

Darren said...

Hi Baral.

Check the configuration of your xml-rpc plugin in trac.

"Note: please don't ask me how to set up Trac, the XML-RPC plugin or Testlink."

Good luck!

Unknown said...

Hi Darren,
Thanks for your input. I have not configured authmanager plugin in TRAC and after changing trac.ini as below, i could able to connect TRAC from Testlink.

[account-manager]
password_file = D:\00_Gopi\Projects\trac\cd-fda\passwordByhtpasswd.txt
password_format = htpasswd
password_store = HtPasswdStore

Thanks again.

Regards
Baral

Anonymous said...

Thanks a lot. This works for me!!

Guilherme said...

I've followed all steps and looks like that it's OK, but how can i test if it's working, once that my agilo trac interface doesn't change?

Thanks a lot, really good tutorial!

Anonymous said...

1Hi Darren,

Maybe you can help me.

I've installed the Testlink 1.9.7 (ghost) and Agilo Trac 0.9.10 and I'm not sure how I can check if the XML-RPC plugin is working. I mean, is any way to check this via front end? or how the plug in manage this connection? sorry but i didnt find anything about this.
I have this 2 tools in the same server and the OS is Ubuntu.

Thanks in Advance!

Regards,

Fer

Unknown said...

Hi Darren,

Maybe you can help me.

I've installed the Testlink 1.9.7 (ghost) and Agilo Trac 0.9.10 and I'm not sure how I can check if the XML-RPC plugin is working. I mean, is any way to check this via front end? or how the plug in manage this connection? sorry but i didnt find anything about this.
I have this 2 tools in the same server and the OS is Ubuntu.

Thanks in Advance!

Regards,

Fer

Productivity and Note-taking

I told a friend of mine that I wasn't really happy with the amount of time that gets taken up by Slack and "communication and sched...