Skip to content

Commit d0be0a2

Browse files
committed
Move decoding logic from saml2 backend to SAMLMirrorFrontend
The SAMLMirrorFrontend is responsible for the encoding and decoding of the value that is given to context. The backend cannot and should not know about it. It expects to use the value from the context/environment as is. Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent f74d737 commit d0be0a2

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

src/satosa/backends/saml2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import functools
66
import json
77
import logging
8-
from base64 import urlsafe_b64encode, urlsafe_b64decode
8+
from base64 import urlsafe_b64encode
99
from urllib.parse import urlparse
1010

1111
from saml2.client_base import Base
@@ -90,7 +90,7 @@ def start_auth(self, context, internal_req):
9090

9191
target_entity_id = context.get_decoration(Context.KEY_TARGET_ENTITYID)
9292
if target_entity_id:
93-
entity_id = urlsafe_b64decode(target_entity_id).decode()
93+
entity_id = target_entity_id
9494
return self.authn_request(context, entity_id)
9595

9696
# if there is only one IdP in the metadata, bypass the discovery service

src/satosa/frontends/saml2.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import functools
66
import json
77
import logging
8+
from base64 import urlsafe_b64decode
89
from urllib.parse import urlparse
910

1011
from saml2 import SAMLError, xmldsig
@@ -534,9 +535,10 @@ def handle_authn_request(self, context, binding_in):
534535
:type binding_in: str
535536
:rtype: satosa.response.Response
536537
"""
537-
context.decorate(
538-
Context.KEY_TARGET_ENTITYID,
539-
context.target_entity_id_from_path())
538+
target_entity_id = context.target_entity_id_from_path()
539+
target_entity_id = urlsafe_b64decode(target_entity_id).decode()
540+
context.decorate(Context.KEY_TARGET_ENTITYID, target_entity_id)
541+
540542
idp = self._load_idp_dynamic_endpoints(context)
541543
return self._handle_authn_request(context, binding_in, idp)
542544

tests/satosa/backends/test_saml2.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,7 @@ def test_full_flow(self, context, idp_conf, sp_conf):
144144
def test_start_auth_redirects_directly_to_mirrored_idp(
145145
self, context, idp_conf):
146146
entityid = idp_conf["entityid"]
147-
entityid_bytes = entityid.encode("utf-8")
148-
entityid_b64_str = urlsafe_b64encode(entityid_bytes).decode("utf-8")
149-
context.decorate(Context.KEY_TARGET_ENTITYID, entityid_b64_str)
147+
context.decorate(Context.KEY_TARGET_ENTITYID, entityid)
150148

151149
resp = self.samlbackend.start_auth(context, InternalRequest(None, None))
152150
self.assert_redirect_to_idp(resp, idp_conf)

0 commit comments

Comments
 (0)