Skip to content

Commit

Permalink
test-backend: Raise zerver/views/zephyr.py test coverage to 100%.
Browse files Browse the repository at this point in the history
  • Loading branch information
robot-dreams authored and timabbott committed Feb 27, 2017
1 parent 132534b commit 6bdefb9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
1 change: 0 additions & 1 deletion tools/test-backend
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ not_yet_fully_covered = {
'zerver/views/integrations.py',
'zerver/views/messages.py',
'zerver/views/report.py',
'zerver/views/zephyr.py',
'zerver/views/home.py',
'zerver/views/registration.py',
'zerver/views/events_register.py',
Expand Down
26 changes: 26 additions & 0 deletions zerver/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,32 @@ def logging_mock():
get_user_profile_by_email(email).api_key,
'MTIzNA=='])

# Accounts whose Kerberos usernames are known not to match their
# zephyr accounts are hardcoded, and should be handled properly.

def kerberos_alter_egos_mock():
# type: () -> Any
return patch(
'zerver.views.zephyr.kerberos_alter_egos',
{'kerberos_alter_ego': 'starnine'})

cred = dict(cname=dict(nameString=['kerberos_alter_ego']))
with \
ccache_mock(return_value=b'1234'), \
mirror_mock(), \
ssh_mock() as ssh, \
kerberos_alter_egos_mock():
result = post(cred=cred)

self.assert_json_success(result)
ssh.assert_called_with([
'ssh',
'server',
'--',
'/home/zulip/zulip/bots/process_ccache',
'starnine',
get_user_profile_by_email(email).api_key,
'MTIzNA=='])

class AdminCreateUserTest(ZulipTestCase):
def test_create_user_backend(self):
Expand Down
13 changes: 9 additions & 4 deletions zerver/views/zephyr.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@
import ujson


# Hack for mit.edu users whose Kerberos usernames don't match what they zephyr
# as. The key is for Kerberos and the value is for zephyr.
kerberos_alter_egos = {
'golem': 'ctl',
}

@authenticated_json_view
@has_request_variables
def webathena_kerberos_login(request, user_profile,
cred=REQ(default=None)):
# type: (HttpRequest, UserProfile, Text) -> HttpResponse
global kerberos_alter_egos
if cred is None:
return json_error(_("Could not find Kerberos credential"))
if not user_profile.realm.webathena_enabled:
Expand All @@ -30,10 +37,8 @@ def webathena_kerberos_login(request, user_profile,
try:
parsed_cred = ujson.loads(cred)
user = parsed_cred["cname"]["nameString"][0]
if user == "golem":
# Hack for an mit.edu user whose Kerberos username doesn't
# match what he zephyrs as
user = "ctl"
if user in kerberos_alter_egos:
user = kerberos_alter_egos[user]
assert(user == user_profile.email.split("@")[0])
ccache = make_ccache(parsed_cred)
except Exception:
Expand Down

0 comments on commit 6bdefb9

Please sign in to comment.