Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.
 

[Redmine][Resolved] Redmine custom plugin authentication problem


#1

Hi!

I’m trying to integrate my TestRail installation with our Redmine issue tracker. I followed the provided tutorials about building custom plugins for integrations but I’m stuck.

You can find the current version of the plugin here.

When I press the push link in the Add Test Result screen I get the following error:

Plugin “Redmine_custom” returned an error: Invalid HTTP code (401).
Please check your user/password and that the API is enabled in Redmine.

The plugin fails to authenticate when it requests the categories (or any request that needs authentication) from Redmine.
I switched the default authention to API key. I had the same error when I was using the username + password combo. The Redmine user has all the priviliges to work with the project. If I try to use this API key in a REST client it works just fine.

I tried many variation of authentication to get it work, but the only time it worked, when I hard coded the admin user and password in the config, but that’s not the best way to do it.

This is the content of the response variable if I execute the public function get_categories($project_id) function:

 stdClass(
code = 401
log = array(
['info'] => array(
['url'] => 'http://10.3.2.1:81/redmine/projects/2/issue_categories.json?limit=100'
['content_type'] => 'application/json; charset=utf-8'
['http_code'] => 401
['header_size'] => 464
['request_size'] => 196
['filetime'] => -1
['ssl_verify_result'] => 0
['redirect_count'] => 0
['total_time'] => 0.019103
['namelookup_time'] => 0.000166
['connect_time'] => 0.000312
['pretransfer_time'] => 0.000394
['size_upload'] => 0
['size_download'] => 1
['speed_download'] => 52
['speed_upload'] => 0
['download_content_length'] => -1
['upload_content_length'] => 0
['starttransfer_time'] => 0.015809
['redirect_time'] => 0
['certinfo'] => 
['request_header'] => 'GET /redmine/projects/2/issue_categories.json?limit=100 HTTP/1.1

Host: 10.3.2.1:81

Accept: */*

Content-Type: application/json

X-Redmine-API-Key: dc420dc3de438c124836b3a0e5091bf40385a019'



'
)
['raw'] => 'HTTP/1.1 401 Unauthorized

Date: Wed, 03 Jun 2015 19:08:04 GMT

Server: Apache

x-rack-cache: miss

cache-control: no-cache

x-ua-compatible: IE=Edge,chrome=1

x-runtime: 0.012831

www-authenticate: Basic realm="Redmine API"

x-request-id: ca9a8ea8e20aa6931c15efd3c551ba7b

Connection: close

X-Powered-By: Phusion Passenger 5.0.6

X-Frame-Options: SAMEORIGIN

Status: 401 Unauthorized

Transfer-Encoding: chunked

Content-Type: application/json; charset=utf-8



 '
)
content =  
headers = array(
['Date'] => 'Wed, 03 Jun 2015 19:08:04 GMT'
['Server'] => 'Apache'
['x-rack-cache'] => 'miss'
['cache-control'] => 'no-cache'
['x-ua-compatible'] => 'IE=Edge,chrome=1'
['x-runtime'] => 0.012831
['www-authenticate'] => 'Basic realm="Redmine API"'
['x-request-id'] => 'ca9a8ea8e20aa6931c15efd3c551ba7b'
['Connection'] => 'close'
['X-Powered-By'] => 'Phusion Passenger 5.0.6'
['X-Frame-Options'] => 'SAMEORIGIN'
['Status'] => '401 Unauthorized'
['Transfer-Encoding'] => 'chunked'
['Content-Type'] => 'application/json; charset=utf-8'
)
cookies = 
)

The logs form Redmine and Testrail:

==> redmine26-logs/access_log <==
10.3.2.1 - - [03/Jun/2015:21:20:27 +0200] "GET /redmine/trackers.json?limit=100 HTTP/1.1" 200 89
10.3.2.1 - - [03/Jun/2015:21:20:27 +0200] "GET /redmine/projects.json?limit=100 HTTP/1.1" 200 633
10.3.2.1 - - [03/Jun/2015:21:20:27 +0200] "GET /redmine/projects/2/issue_categories.json?limit=100 HTTP/1.1" 401 1

==> testrail-log/access_log <==
10.3.2.1 - - [03/Jun/2015:21:20:27 +0200] "POST /testrail/index.php?/defects/ajax_prepare_push HTTP/1.1" 200 169 "http://10.3.2.1:82/testrail/index.php?/tests/view/47&group_by=cases:section_id&group_order=asc&group_id=14" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0 FirePHP/0.7.4"

[E] 2015-06-03 21:20:27 [121ms]: [RedmineException] Invalid HTTP code (401). Please check your user/password and that the API is enabled in Redmine.
---
Details: <missing>
File: /var/www/html/testrail/custom/defects/Redmine_custom.php
Line: 653
Status Code: 500
Host: 10.3.2.1:82
Uri: /testrail/index.php?/defects/ajax_prepare_push (POST)
---
Browser: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0 FirePHP/0.7.4
PHP: 5.3.3
Server: Linux 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64
---
status_id: 1
assignedto: <empty>
comment: <empty>
attachments: <empty>
version: <empty>
elapsed: <empty>
defects: <empty>
project_id: 2
test_ids: 47
_token: OFbgpRTHXfkGlD13Zwou
_version: 4.2.0.3315
---
Trace:
at Redmine_api->_throw_error (Redmine_custom.php:716)
at Redmine_api->_send_request (Redmine_custom.php:665)
at Redmine_api->_send_command (Redmine_custom.php:795)
at Redmine_api->get_categories (Redmine_custom.php:349)
at Redmine_custom_defect_plugin->_get_categories (Redmine_custom.php:450)
at Redmine_custom_defect_plugin->prepare_field (defects.php:625)
at Defects_controller->_prepare_form (defects.php:674)
at Defects_controller->ajax_prepare_push (controller.php:215)
at Controller->_invoke_web_call (controller.php:127)
at Controller->_invoke_web (controller.php:76)
at Controller->_invoke (gizmo.php:107)
at require_once (index.php:106)

I hope some can help me :smile:

Thanks in advance!


#2

If that’s a raw copy-paste, that single quote right after the api key looks suspicious. Basically check the api key entry in your ini file (or whatever — looks like there’s ini file judging by code)


#3

I agree with @Actine, the quote character in that line looks odd. Could you verify that this is correct?


#4

It’s correct. I removed it and it works. Thank you so much!