Skip to content

Commit 1f1d656

Browse files
authored
Merge pull request #22 from its-dirg/saml-metadata-logo
Fix #19: don't assume 'lang' is specified in logo.
2 parents 666bfa6 + 2dfab4c commit 1f1d656

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed

src/satosa/backends/saml2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def get_metadata_desc(self):
297297
for name in ui_info.get("display_name", []):
298298
ui_info_desc.add_display_name(name["text"], name["lang"])
299299
for logo in ui_info.get("logo", []):
300-
ui_info_desc.add_logo(logo["text"], logo["width"], logo["height"], logo["lang"])
300+
ui_info_desc.add_logo(logo["text"], logo["width"], logo["height"], logo.get("lang"))
301301
description.ui_info = ui_info_desc
302302

303303
entity_descriptions.append(description)

src/satosa/metadata_creation/description.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,24 @@ def add_display_name(self, text, lang):
7777
"""
7878
self._display_name.append({"text": text, "lang": lang})
7979

80-
def add_logo(self, text, width, height, lang):
80+
def add_logo(self, text, width, height, lang=None):
8181
"""
8282
Binds a logo to the given language
8383
:type text: str
8484
:type width: str
8585
:type height: str
86-
:type lang: str
86+
:type lang: Optional[str]
8787
8888
:param text: Path to logo
8989
:param width: width of logo
9090
:param height: height of logo
9191
:param lang: language
9292
"""
93-
self._logos.append({"text": text, "width": width, "height": height, "lang": lang})
93+
94+
logo_entry ={"text": text, "width": width, "height": height}
95+
if lang:
96+
logo_entry["lang"] = lang
97+
self._logos.append(logo_entry)
9498

9599
def to_dict(self):
96100
"""

tests/satosa/backends/test_saml2.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,31 @@ def test_get_metadata_desc(self, sp_conf, idp_conf):
205205
assert ui_info["display_name"] == expected_ui_info["display_name"]
206206
assert ui_info["description"] == expected_ui_info["description"]
207207
assert ui_info["logo"] == expected_ui_info["logo"]
208+
209+
def test_get_metadata_desc_with_logo_without_lang(self, sp_conf, idp_conf):
210+
# add logo without 'lang'
211+
idp_conf["service"]["idp"]["ui_info"]["logo"] = [{"text": "https://idp.example.com/static/logo.png",
212+
"width": "120", "height": "60"}]
213+
214+
sp_conf["metadata"]["inline"] = [create_metadata_from_config_dict(idp_conf)]
215+
# instantiate new backend, with a single backing IdP
216+
samlbackend = SAMLBackend(None, INTERNAL_ATTRIBUTES, {"sp_config": sp_conf}, "base_url", "saml_backend")
217+
entity_descriptions = samlbackend.get_metadata_desc()
218+
219+
assert len(entity_descriptions) == 1
220+
221+
idp_desc = entity_descriptions[0].to_dict()
222+
223+
assert idp_desc["entityid"] == urlsafe_b64encode(idp_conf["entityid"].encode("utf-8")).decode("utf-8")
224+
assert idp_desc["contact_person"] == idp_conf["contact_person"]
225+
226+
assert idp_desc["organization"]["name"][0] == tuple(idp_conf["organization"]["name"][0])
227+
assert idp_desc["organization"]["display_name"][0] == tuple(idp_conf["organization"]["display_name"][0])
228+
assert idp_desc["organization"]["url"][0] == tuple(idp_conf["organization"]["url"][0])
229+
230+
expected_ui_info = idp_conf["service"]["idp"]["ui_info"]
231+
ui_info = idp_desc["service"]["idp"]["ui_info"]
232+
assert ui_info["display_name"] == expected_ui_info["display_name"]
233+
assert ui_info["description"] == expected_ui_info["description"]
234+
assert ui_info["logo"] == expected_ui_info["logo"]
235+

tests/satosa/metadata_creation/test_description.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ def test_to_dict(self):
3333
assert ui_info["display_name"] == [{"text": "my company", "lang": "en"}]
3434
assert ui_info["logo"] == [{"text": "logo.jpg", "width": 80, "height": 80, "lang": "en"}]
3535

36+
def test_to_dict_for_logo_without_lang(self):
37+
desc = UIInfoDesc()
38+
desc.add_logo("logo.jpg", 80, 80, None)
39+
40+
serialized = desc.to_dict()
41+
ui_info = serialized["service"]["idp"]["ui_info"]
42+
assert ui_info["logo"] == [{"text": "logo.jpg", "width": 80, "height": 80}]
43+
3644
def test_to_dict_with_empty(self):
3745
desc = UIInfoDesc()
3846
assert desc.to_dict() == {}
@@ -69,13 +77,10 @@ def test_to_dict(self):
6977
contact_desc.sur_name = "Tester"
7078
contact_desc.add_email_address("[email protected]")
7179

72-
logo_data = "test data".encode("utf-8")
73-
7480
ui_desc = UIInfoDesc()
7581
ui_desc.add_description("test", "en")
7682
ui_desc.add_display_name("my company", "en")
77-
with patch("builtins.open", mock_open(read_data=logo_data)):
78-
ui_desc.add_logo("logo.jpg", 80, 80, "en")
83+
ui_desc.add_logo("http://example.com/logo.jpg", 80, 80, "en")
7984

8085
desc = MetadataDescription("my_entity")
8186
desc.organization = org_desc

0 commit comments

Comments
 (0)