Skip to content

Commit

Permalink
Hide "username" field when HTTP authentication is enabled
Browse files Browse the repository at this point in the history
In case if username is already known from HTTP request headers, there
is no sense to ask user to enter it again. This adds needUserForm
method to Authz class and modifies the authFormIfNeeded template to
hide the username field if not needed.
  • Loading branch information
paroga committed Oct 6, 2011
1 parent 0ec7159 commit 31ff088
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
12 changes: 12 additions & 0 deletions master/buildbot/status/web/authz.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ def needAuthForm(self, action):
return True
return False

def needUserForm(self, action):
"""Does this action require an user form?"""
if action not in self.knownActions:
raise KeyError("unknown action")
if self.useHttpHeader:
# TODO: show the form when Authorization header is missing?
return False
cfg = self.config.get(action, False)
if cfg:
return True
return False

def actionAllowed(self, action, request, *args):
"""Is this ACTION allowed, given this http REQUEST?"""
if action not in self.knownActions:
Expand Down
4 changes: 2 additions & 2 deletions master/buildbot/status/web/templates/forms.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<span class="label">Your username:</span>
<input type="text" name="username"/>
</div>

<div class="row">
<span class="label">Your password:</span>
<input type="password" name="passwd"/>
</div>
{% else %}
{% elif authz.needUserForm(action) %}
<div class="row">
<span class="label">Your name:</span>
<input type="text" name="username"/>
Expand Down
16 changes: 16 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 @@ -171,6 +171,22 @@ def test_needAuthForm_callable(self):
z = Authz(stopAllBuilds = lambda u : False)
assert z.needAuthForm('stopAllBuilds')

def test_needUserForm_False(self):
z = Authz(forceBuild = False)
assert not z.needUserForm('forceBuild')

def test_needUserForm_Ture(self):
z = Authz(forceBuild = True)
assert z.needUserForm('forceBuild')

def test_needUserForm_http_False(self):
z = Authz(useHttpHeader = True, forceBuild = False)
assert not z.needUserForm('forceBuild')

def test_needUserForm_http_True(self):
z = Authz(useHttpHeader = True, forceBuild = True)
assert not z.needUserForm('forceBuild')

def test_constructor_invalidAction(self):
self.assertRaises(ValueError, Authz, someRandomAction=3)

Expand Down

0 comments on commit 31ff088

Please sign in to comment.