Skip to content

Commit

Permalink
Merge branch 'username' of git://github.com/paroga/buildbot
Browse files Browse the repository at this point in the history
* 'username' of git://github.com/paroga/buildbot:
  Unify username handling
  • Loading branch information
djmitche committed Oct 5, 2011
2 parents 139c4ca + 9b7d091 commit 1eaaf8b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
10 changes: 8 additions & 2 deletions master/buildbot/status/web/authz.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ def __init__(self,
if kwargs:
raise ValueError("unknown authorization action(s) " + ", ".join(kwargs.keys()))

def getUsername(self, request):
return request.args.get("username", ["<unknown>"])[0]

def getPassword(self, request):
return request.args.get("passwd", ["<no-password>"])[0]

def advertiseAction(self, action):
"""Should the web interface even show the form for ACTION?"""
if action not in self.knownActions:
Expand Down Expand Up @@ -78,8 +84,8 @@ def actionAllowed(self, action, request, *args):
if cfg == 'auth' or callable(cfg):
if not self.auth:
return defer.succeed(False)
user = request.args.get("username", ["<unknown>"])[0]
passwd = request.args.get("passwd", ["<no-password>"])[0]
user = self.getUsername(request)
passwd = self.getPassword(request)
if user == "<unknown>" or passwd == "<no-password>":
return defer.succeed(False)

Expand Down
13 changes: 7 additions & 6 deletions master/buildbot/status/web/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def __init__(self, build_status, builder):
@defer.deferredGenerator
def performAction(self, req):
url = None
d = self.getAuthz(req).actionAllowed(self.action, req, self.builder)
authz = self.getAuthz(req)
d = authz.actionAllowed(self.action, req, self.builder)
wfd = defer.waitForDeferred(d)
yield wfd
res = wfd.getResult()
Expand All @@ -53,7 +54,7 @@ def performAction(self, req):
b = self.build_status
builder_name = self.builder.getName()
log.msg("web rebuild of build %s:%s" % (builder_name, b.getNumber()))
name = req.args.get("username", ["<unknown>"])[0]
name = authz.getUsername(req)
comments = req.args.get("comments", ["<no reason specified>"])[0]
reason = ("The web-page 'rebuild' button was pressed by "
"'%s': %s\n" % (name, comments))
Expand Down Expand Up @@ -93,8 +94,8 @@ def __init__(self, build_status):

@defer.deferredGenerator
def performAction(self, req):
d = self.getAuthz(req).actionAllowed(self.action, req,
self.build_status)
authz = self.getAuthz(req)
d = authz.actionAllowed(self.action, req, self.build_status)
wfd = defer.waitForDeferred(d)
yield wfd
res = wfd.getResult()
Expand All @@ -106,7 +107,7 @@ def performAction(self, req):
b = self.build_status
log.msg("web stopBuild of build %s:%s" % \
(b.getBuilder().getName(), b.getNumber()))
name = req.args.get("username", ["<unknown>"])[0]
name = authz.getUsername(req)
comments = req.args.get("comments", ["<no reason specified>"])[0]
# html-quote both the username and comments, just to be safe
reason = ("The web-page 'stop build' button was pressed by "
Expand Down Expand Up @@ -249,7 +250,7 @@ def stop(self, req, auth_ok=False):
b = self.build_status
log.msg("web stopBuild of build %s:%s" % \
(b.getBuilder().getName(), b.getNumber()))
name = req.args.get("username", ["<unknown>"])[0]
name = self.getAuthz(req).getUsername(req)
comments = req.args.get("comments", ["<no reason specified>"])[0]
# html-quote both the username and comments, just to be safe
reason = ("The web-page 'stop build' button was pressed by "
Expand Down
2 changes: 1 addition & 1 deletion master/buildbot/status/web/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def content(self, req, cxt):
yield template.render(**cxt)

def force(self, req, auth_ok=False):
name = req.args.get("username", ["<unknown>"])[0]
name = self.getAuthz(req).getUsername(req)
reason = req.args.get("comments", ["<no reason specified>"])[0]
branch = req.args.get("branch", [""])[0]
revision = req.args.get("revision", [""])[0]
Expand Down
8 changes: 8 additions & 0 deletions master/buildbot/test/unit/test_status_web_authz_Authz.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ def test_needAuthForm_callable(self):
def test_constructor_invalidAction(self):
self.assertRaises(ValueError, Authz, someRandomAction=3)

def test_getUsername_request(self):
z = Authz()
assert z.getUsername(StubRequest('foo', 'bar')) == 'foo'

def test_getPassword_request(self):
z = Authz()
assert z.getPassword(StubRequest('foo', 'bar')) == 'bar'

def test_advertiseAction_invalidAction(self):
z = Authz()
self.assertRaises(KeyError, z.advertiseAction, 'someRandomAction')
Expand Down

0 comments on commit 1eaaf8b

Please sign in to comment.