2430: post-review fails to post diff to reviewboard server if anonymous access disabled

stid*****@gmai***** (Google Code) (Is this you? Claim this profile.)
Sept. 29, 2012
What version are you running?
reviewboard 1.6.2, rbtools 0.3.2_1

What's the URL of the page containing the problem?
http://<review-board-url>/api/repositories

What steps will reproduce the problem?
1. Checkout source code and make some changes
2. Specify the url for reviewboard server in .reviewboardrc file
3. Run post-review to post the diff to the server

What is the expected output? What do you see instead?
User/password should be prompted to the user and diff is posted to the server. But actually I see the following error messages:
$ post-review
Traceback (most recent call last):
  File "/usr/local/bin/post-review", line 8, in <module>
    load_entry_point('RBTools==0.3.2', 'console_scripts', 'post-review')()
  File "build/bdist.freebsd-8.2-RELEASE-amd64/egg/rbtools/postreview.py", line 3741, in main
  File "build/bdist.freebsd-8.2-RELEASE-amd64/egg/rbtools/postreview.py", line 434, in check_api_version
  File "build/bdist.freebsd-8.2-RELEASE-amd64/egg/rbtools/postreview.py", line 876, in api_get
  File "build/bdist.freebsd-8.2-RELEASE-amd64/egg/rbtools/postreview.py", line 846, in http_get
  File "/usr/local/lib/python2.7/urllib2.py", line 126, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/local/lib/python2.7/urllib2.py", line 400, in open
    response = meth(req, response)
  File "build/bdist.freebsd-8.2-RELEASE-amd64/egg/rbtools/postreview.py", line 317, in http_response
  File "/usr/local/lib/python2.7/urllib2.py", line 432, in error
    result = self._call_chain(*args)
  File "/usr/local/lib/python2.7/urllib2.py", line 372, in _call_chain
    result = func(*args)
  File "/usr/local/lib/python2.7/urllib2.py", line 884, in http_error_401
    url, req, headers)
  File "/usr/local/lib/python2.7/urllib2.py", line 859, in http_error_auth_reqed
    response = self.retry_http_basic_auth(host, req, realm)
  File "build/bdist.freebsd-8.2-RELEASE-amd64/egg/rbtools/postreview.py", line 342, in retry_http_basic_auth
AttributeError: 'NoneType' object has no attribute 'code'

What operating system are you using? What browser?
FreeBSD 8.2 Release. It's rbtools issue.

Please provide any additional information below.
It seems that the post-review tool will first try to access the URL
http://<review-board-url>/api/repositories before user login.
But if the administrator has disabled anonymous access of the reviewboard site, the URL above is not allowed to access until the user logs in.
So I guess that the post-review tool should try to authenticate the user before visiting '/api/repositories' URL.

The apache configuration is as follows:

        DocumentRoot "/usr/local/www/reviewboard/htdocs"

        # Error handlers
        ErrorDocument 500 /errordocs/500.html

        WSGIPassAuthorization On
        WSGIScriptAlias "/" "/usr/local/www/reviewboard/htdocs/reviewboard.wsgi/"

        <Directory "/usr/local/www/reviewboard/htdocs">
                AllowOverride All
                Options -Indexes FollowSymLinks
                Allow from all
        </Directory>

        # Alias static media requests to filesystem
        Alias /media "/usr/local/www/reviewboard/htdocs/media"
        Alias /errordocs "/usr/local/www/reviewboard/htdocs/errordocs"
        Alias /favicon.ico "/usr/local/www/reviewboard/htdocs/media/rbcommons/images/favicon.png"
#2 stid*****@gmai***** (Google Code) (Is this you? Claim this profile.)
Now it comes out it's because I use Nginx as a reverse proxy in front of the uWSGI server, and all the URLs I get from the API info is 'localhost' instead of the actual URL requested.

I've submitted a patch for post-review tool at http://reviews.reviewboard.org/r/2776/
#4 stid*****@gmai***** (Google Code) (Is this you? Claim this profile.)
The way in issue 2279 doesn't work. The only way is to add a line to nginx configuration:

proxy_set_header Host $http_host;

And it doesn't support https.
#5 stid*****@gmai***** (Google Code) (Is this you? Claim this profile.)
OK, here is the workaround:

1. In Nginx (front end) configuration, add the following:
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Forwarded-Proto $scheme;

2. In Apache (back end) configuration, add the following:
SetEnvIf X-Forwarded-Proto "^https$" HTTPS=on

3. In reviewboard local configuration file (conf/settings_local.py), add the following:
USE_X_FORWARDED_HOST = True

Now it works for both http and https.
david
#6 david
Pushed patch to master (7d0026f).
  • +Fixed