Skip to content

Commit

Permalink
Get mock interface working better with Identity.UW.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffFranklin committed Feb 5, 2019
1 parent 84b007b commit f3b0bcc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 3 additions & 2 deletions tests/test_mock.py
Expand Up @@ -8,13 +8,14 @@ def flick_mock_flag(monkeypatch):


def test_login_redirect():
expected = ('mock-login?return_to=%2F&force_authn=False'
expected = ('/mock-login?return_to=%2F&force_authn=False'
'&idp=urn%3Amace%3Aincommon%3Awashington.edu')
assert uw_saml2.login_redirect() == expected


def test_process_response():
post = {'idp': 'urn:mace:incommon:washington.edu', 'foo': 'bar'}
post = {'idp': 'urn:mace:incommon:washington.edu',
'remote_user': 'javerage@washington.edu', 'uwnetid': 'javerage'}
expected = {'two_factor': False, **post}
assert uw_saml2.process_response(post) == expected

Expand Down
16 changes: 13 additions & 3 deletions uw_saml2/mock.py
@@ -1,4 +1,6 @@
import urllib.parse
from .idp import uw, federated
MOCK_LOGIN_URL = '/mock-login'


class SamlAuthenticator:
Expand All @@ -10,7 +12,7 @@ def __init__(self, request, old_settings, *args, **kwargs):
def login(self, **kwargs):
kwargs['idp'] = self.idp
qs = urllib.parse.urlencode(kwargs)
return f'mock-login?{qs}'
return f'{MOCK_LOGIN_URL}?{qs}'

def process_response(self):
idp = self.request['post_data'].get('idp')
Expand All @@ -20,8 +22,16 @@ def process_response(self):

def get_attributes(self):
"""Just reflect what's posted right back."""
items = self.request['post_data'].items()
return dict((key, [value]) for key, value in items)
post = self.request['post_data']
remote_user = post.get('remote_user', '')
attributes = {}
if post.get('idp') == uw.UwIdp.entity_id:
uwnetid = remote_user.split('@washington.edu')[0]
attributes['uwnetid'] = [uwnetid]
elif post.get('idp') == federated.CollegenetIdp.entity_id:
attributes['collegenet_userid'] = [remote_user]
attributes.update((key, [value]) for key, value in post.items())
return attributes

def get_errors(self):
return self.errors
Expand Down

0 comments on commit f3b0bcc

Please sign in to comment.