Skip to content

Commit f53bbd4

Browse files
Merge pull request #246 from skoranda/saml_co_frontend_04
Add SAMLVirtualCoFrontend IdP entityID to state
2 parents f7bb955 + efe9d08 commit f53bbd4

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/satosa/frontends/saml2.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,7 @@ class SAMLVirtualCoFrontend(SAMLFrontend):
700700
"""
701701
KEY_CO = 'collaborative_organizations'
702702
KEY_CO_NAME = 'co_name'
703+
KEY_CO_ENTITY_ID = 'co_entity_id'
703704
KEY_CO_ATTRIBUTES = 'co_static_saml_attributes'
704705
KEY_CONTACT_PERSON = 'contact_person'
705706
KEY_ENCODEABLE_NAME = 'encodeable_name'
@@ -770,6 +771,8 @@ def _create_state_data(self, context, resp_args, relay_state):
770771
"""
771772
state = super()._create_state_data(context, resp_args, relay_state)
772773
state[self.KEY_CO_NAME] = context.get_decoration(self.KEY_CO_NAME)
774+
state[self.KEY_CO_ENTITY_ID] = context.get_decoration(
775+
self.KEY_CO_ENTITY_ID)
773776

774777
return state
775778

@@ -869,19 +872,22 @@ def _add_endpoints_to_config(self, config, co_name, backend_name):
869872

870873
return config
871874

872-
def _add_entity_id(self, config, co_name):
875+
def _add_entity_id(self, context, config, co_name):
873876
"""
874877
Use the CO name to construct the entity ID for the virtual IdP
875-
for the CO.
878+
for the CO and add it to the config. Also add it to the
879+
context.
876880
877881
The entity ID has the form
878882
879883
{base_entity_id}/{co_name}
880884
885+
:type context: The current context
881886
:type config: satosa.satosa_config.SATOSAConfig
882887
:type co_name: str
883888
:rtype: satosa.satosa_config.SATOSAConfig
884889
890+
:param context:
885891
:param config: satosa proxy config
886892
:param co_name: CO name
887893
@@ -890,6 +896,7 @@ def _add_entity_id(self, config, co_name):
890896
base_entity_id = config['entityid']
891897
co_entity_id = "{}/{}".format(base_entity_id, quote_plus(co_name))
892898
config['entityid'] = co_entity_id
899+
context.decorate(self.KEY_CO_ENTITY_ID, co_entity_id)
893900

894901
return config
895902

@@ -910,7 +917,8 @@ def _overlay_for_saml_metadata(self, config, co_name):
910917
"""
911918
all_co_configs = self.config[self.KEY_CO]
912919
co_config = next(
913-
item for item in all_co_configs if item[self.KEY_ENCODEABLE_NAME] == co_name
920+
item for item in all_co_configs
921+
if item[self.KEY_ENCODEABLE_NAME] == co_name
914922
)
915923

916924
key = self.KEY_ORGANIZATION
@@ -974,7 +982,7 @@ def _create_co_virtual_idp(self, context):
974982
idp_config = self._add_endpoints_to_config(idp_config,
975983
co_name,
976984
backend_name)
977-
idp_config = self._add_entity_id(idp_config, co_name)
985+
idp_config = self._add_entity_id(context, idp_config, co_name)
978986

979987
# Use the overwritten IdP config to generate a pysaml2 config object
980988
# and from it a server object.

tests/satosa/frontends/test_saml2.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,11 +483,14 @@ def context(self, context):
483483

484484
return context
485485

486-
def test_create_state_data(self, frontend, context):
487-
context.decorate(frontend.KEY_CO_NAME, self.CO)
486+
def test_create_state_data(self, frontend, context, idp_conf):
487+
frontend._create_co_virtual_idp(context)
488488
state = frontend._create_state_data(context, {}, "")
489489
assert state[frontend.KEY_CO_NAME] == self.CO
490490

491+
expected_entityid = "{}/{}".format(idp_conf['entityid'], self.CO)
492+
assert state[frontend.KEY_CO_ENTITY_ID] == expected_entityid
493+
491494
def test_get_co_name(self, frontend, context):
492495
co_name = frontend._get_co_name(context)
493496
assert co_name == self.CO
@@ -534,7 +537,7 @@ def test_co_static_attributes(self, frontend, context, internal_response,
534537
backend_name = context.target_backend
535538
idp_conf = frontend._add_endpoints_to_config(idp_conf, co_name,
536539
backend_name)
537-
idp_conf = frontend._add_entity_id(idp_conf, co_name)
540+
idp_conf = frontend._add_entity_id(context, idp_conf, co_name)
538541

539542
# Use a utility function to serialize the idp_conf IdP configuration
540543
# fixture to a string and then dynamically update the sp_conf

0 commit comments

Comments
 (0)