Skip to content

Commit b278c15

Browse files
committed
Allow cascadia employee to have either employee or student ID.
1 parent 2958c20 commit b278c15

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

tests/test_federated.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
"""Just importing federated boosts our coverage."""
2-
from uw_saml2.idp import federated
2+
from uw_saml2.idp import federated, attribute
3+
import pytest
34

45

5-
def test_cascadia_employee():
6-
id_attribute = 'urn:mace:washington.edu:dir:attribute-def:stu-validationID'
7-
assert federated.CascadiaEmployeeIdp.id_attribute == id_attribute
6+
@pytest.mark.parametrize('student,employee', [
7+
(['loser'], ['winner']),
8+
(['winner'], None),
9+
(None, ['winner']),
10+
([], ['winner']),
11+
(['winner'], [])
12+
])
13+
def test_cascadia_employee_attributes(student, employee):
14+
"""
15+
Cascadia Employees should come across as such, but our test one comes
16+
through as a student. This checks that if either one is set, we get
17+
a value for remote_user. It's still entirely possible for student to
18+
win out.
19+
"""
20+
prefix = 'urn:mace:washington.edu:dir:attribute-def'
21+
attrs = {}
22+
if student is not None:
23+
attrs[f'{prefix}:stu-validationID'] = student
24+
if employee is not None:
25+
attrs[f'{prefix}:emp-validationID'] = employee
26+
mapped_attrs = dict(attribute.map(attrs, federated.CascadiaEmployeeIdp))
27+
assert mapped_attrs['remote_user'] == 'winner'
828

929

1030
def test_scca_dynamic_entity_id():

uw_saml2/idp/attribute.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ def __init__(self, name):
2424

2525
def map(self, values):
2626
"""Return only the first value in a list of values."""
27-
return values and values[0]
27+
if not values:
28+
return None
29+
return values[0]
2830

2931

3032
class List(Attribute):

uw_saml2/idp/federated.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ class CascadiaEmployeeIdp(CascadiaStudentIdp):
3232
The only difference between an Cascadia Employee and a Student are the
3333
IdP's endpoint. Even the id_attribute of 'stu-validationID' remains.
3434
"""
35-
sso_url = ('https://idp.employee.cascadia.edu'
36-
'/idp/profile/SAML2/Redirect/SSO')
35+
_idp_url = 'https://idp.employee.cascadia.edu'
36+
_attribute_prefix = 'urn:mace:washington.edu:dir:attribute-def'
37+
sso_url = f'{_idp_url}/idp/profile/SAML2/Redirect/SSO'
38+
attribute_map = {
39+
f'{_attribute_prefix}:emp-validationID': 'remote_user'
40+
}
3741

3842

3943
class CollegenetIdp(IdpConfig):

0 commit comments

Comments
 (0)