Skip to content

Commit efedc56

Browse files
author
Rebecka Gulliksson
committed
Make sure InternalRequest.user_id_hash_type always is set.
Use default values instead of None: * transient identifier for SAML, * pairwise identifier for OIDC.
1 parent c84bbd7 commit efedc56

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

src/satosa/frontends/openid_connect.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@
2525

2626

2727
def oidc_subject_type_to_hash_type(subject_type):
28-
if subject_type == "pairwise":
29-
return UserIdHashType.pairwise
30-
elif subject_type == "public":
28+
if subject_type == "public":
3129
return UserIdHashType.public
32-
return None
30+
31+
return UserIdHashType.pairwise
3332

3433

3534
class OpenIDConnectFrontend(FrontendModule):

src/satosa/frontends/saml2.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,17 @@
2727

2828
def saml_name_id_format_to_hash_type(name_format):
2929
"""
30-
Translate pySAML2 name format to statosa format
30+
Translate pySAML2 name format to satosa format
3131
3232
:type name_format: str
3333
:rtype: satosa.internal_data.UserIdHashType
3434
:param name_format: SAML2 name format
3535
:return: satosa format
3636
"""
37-
if name_format == NAMEID_FORMAT_TRANSIENT:
38-
return UserIdHashType.transient
39-
elif name_format == NAMEID_FORMAT_PERSISTENT:
37+
if name_format == NAMEID_FORMAT_PERSISTENT:
4038
return UserIdHashType.persistent
41-
return None
39+
40+
return UserIdHashType.transient
4241

4342

4443
def hash_type_to_saml_name_id_format(hash_type):

tests/satosa/frontends/test_openid_connect.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
from satosa.attribute_mapping import AttributeMapper
1313
from satosa.exception import SATOSAAuthenticationError
14-
from satosa.frontends.openid_connect import OpenIDConnectFrontend
15-
from satosa.internal_data import InternalResponse, AuthenticationInformation
14+
from satosa.frontends.openid_connect import OpenIDConnectFrontend, oidc_subject_type_to_hash_type
15+
from satosa.internal_data import InternalResponse, AuthenticationInformation, UserIdHashType
1616
from tests.users import USERS
1717

1818
INTERNAL_ATTRIBUTES = {
@@ -154,3 +154,14 @@ def test_provider_configuration_endpoint(self, context):
154154
assert all(
155155
item in provider_config.to_dict().items() for item in expected_capabilities.items())
156156
assert provider_config["authorization_endpoint"] == "{}/foo_backend/authorization".format(BASE_URL)
157+
158+
159+
class TestOidcSubjectTypeToHashType:
160+
def test_should_default_to_pairwise(self):
161+
assert oidc_subject_type_to_hash_type("foobar") == UserIdHashType.pairwise
162+
163+
def test_should_map_pairwise(self):
164+
assert oidc_subject_type_to_hash_type("pairwise") == UserIdHashType.pairwise
165+
166+
def test_should_map_pairwise(self):
167+
assert oidc_subject_type_to_hash_type("public") == UserIdHashType.public

tests/satosa/frontends/test_saml2.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from satosa.attribute_mapping import AttributeMapper
2424
from satosa.frontends.saml2 import SAMLFrontend, saml_name_id_format_to_hash_type, SAMLMirrorFrontend
2525
from satosa.internal_data import InternalResponse, AuthenticationInformation, InternalRequest
26+
from satosa.internal_data import UserIdHashType
2627
from satosa.state import State
2728
from tests.users import USERS
2829
from tests.util import FakeSP, create_metadata_from_config_dict
@@ -397,4 +398,15 @@ def test_load_idp_dynamic_entity_id(self, idp_conf):
397398
state = State()
398399
state[self.frontend.name] = {"target_entity_id": self.TARGET_ENTITY_ID}
399400
idp = self.frontend._load_idp_dynamic_entity_id(state)
400-
assert idp.config.entityid == "{}/{}".format(idp_conf["entityid"], self.TARGET_ENTITY_ID)
401+
assert idp.config.entityid == "{}/{}".format(idp_conf["entityid"], self.TARGET_ENTITY_ID)
402+
403+
404+
class TestSamlNameIdFormatToHashType:
405+
def test_should_default_to_transient(self):
406+
assert saml_name_id_format_to_hash_type("foobar") == UserIdHashType.transient
407+
408+
def test_should_map_transient(self):
409+
assert saml_name_id_format_to_hash_type(NAMEID_FORMAT_TRANSIENT) == UserIdHashType.transient
410+
411+
def test_should_map_persistent(self):
412+
assert saml_name_id_format_to_hash_type(NAMEID_FORMAT_PERSISTENT) == UserIdHashType.persistent

0 commit comments

Comments
 (0)