Skip to content

Commit

Permalink
fixes for reverse proxies
Browse files Browse the repository at this point in the history
When buildbot sits behind reverse proxies:

- fonts where fetched using /fonts instead of /proxypath/fonts
- selforigin was miscaculated. /proxypath/ should be dropped from buildbotURL=http://server/proxypath -> origin is http://server

Signed-off-by: Pierre Tardy <pierre.tardy@intel.com>
  • Loading branch information
Pierre Tardy committed Feb 27, 2015
1 parent 6589418 commit 28bbb69
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
19 changes: 18 additions & 1 deletion master/buildbot/test/unit/test_www_rest.py
Expand Up @@ -59,7 +59,7 @@ def test_versions_limited(self):
class V2RootResource(www.WwwTestMixin, unittest.TestCase):

def setUp(self):
self.master = self.make_master(url='h:/')
self.master = self.make_master(url='http://server/path/')
self.master.data._scanModule(endpoint)
self.rsrc = rest.V2RootResource(self.master)
self.rsrc.reconfigResource(self.master.config)
Expand All @@ -80,6 +80,23 @@ def test_invalid_http_method(self):
yield self.render_resource(self.rsrc, '/', method='PATCH')
self.assertSimpleError('invalid HTTP method', 400)

def test_default_origin(self):
self.master.config.buildbotURL = 'http://server/path/'
self.rsrc.reconfigResource(self.master.config)
self.assertEqual([r.pattern for r in self.rsrc.origins], ['http\\:\\/\\/server\\Z(?ms)'])

self.master.config.buildbotURL = 'http://server/'
self.rsrc.reconfigResource(self.master.config)
self.assertEqual([r.pattern for r in self.rsrc.origins], ['http\\:\\/\\/server\\Z(?ms)'])

self.master.config.buildbotURL = 'http://server:8080/'
self.rsrc.reconfigResource(self.master.config)
self.assertEqual([r.pattern for r in self.rsrc.origins], ['http\\:\\/\\/server\\:8080\\Z(?ms)'])

self.master.config.buildbotURL = 'https://server:8080/'
self.rsrc.reconfigResource(self.master.config)
self.assertEqual([r.pattern for r in self.rsrc.origins], ['https\\:\\/\\/server\\:8080\\Z(?ms)'])


class V2RootResource_CORS(www.WwwTestMixin, unittest.TestCase):

Expand Down
6 changes: 4 additions & 2 deletions master/buildbot/www/rest.py
Expand Up @@ -29,6 +29,7 @@
from twisted.internet import defer
from twisted.python import log
from twisted.web.error import Error
from urlparse import urlparse


class BadRequest(Exception):
Expand Down Expand Up @@ -370,8 +371,9 @@ def writeError(msg, errcode=404, jsonrpccode=None):
request.write(data)

def reconfigResource(self, new_config):
# buildbotURL will always ends with a '/', not the Origin header.
origin_self = new_config.buildbotURL.rstrip('/')
# buildbotURL may contain reverse proxy path, Origin header is just scheme + host + port
buildbotURL = urlparse(new_config.buildbotURL)
origin_self = buildbotURL.scheme + "://" + buildbotURL.netloc
# pre-translate the origin entries in the config
self.origins = [re.compile(fnmatch.translate(o.lower()))
for o in new_config.www.get('allowed_origins',
Expand Down
1 change: 1 addition & 0 deletions www/base/src/styles/styles.less
Expand Up @@ -2,6 +2,7 @@
@import "../../libs/bootstrap/less/bootstrap.less";
@import "../../libs/font-awesome/less/font-awesome.less";
@import (inline) "../../libs/guanlecoja-ui/styles.css";
@fa-font-path: "./fonts";

// Import colors and animation stylesheet
@import "animations.less";
Expand Down

0 comments on commit 28bbb69

Please sign in to comment.