Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix WantAuthnRequestsSigned parser. #338

Merged
merged 1 commit into from
Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/onelogin/saml2/idp_metadata_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def parse(

idp_entity_id = entity_descriptor_node.get('entityID', None)

want_authn_requests_signed = entity_descriptor_node.get('WantAuthnRequestsSigned', None)
want_authn_requests_signed = idp_descriptor_node.get('WantAuthnRequestsSigned', None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this causes a regression, because idp_descriptor_node.get('WantAuthnRequestsSigned', None) returns the string 'false' for my config (and probably others as well) which gets later evaluated to True in

authn_sign = bool(security.get('authnRequestsSigned'))


name_id_format_nodes = OneLogin_Saml2_XML.query(idp_descriptor_node, './md:NameIDFormat')
if len(name_id_format_nodes) > 0:
Expand Down
2 changes: 1 addition & 1 deletion tests/data/metadata/idp_multiple_descriptors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</md:IDPSSODescriptor>
</md:EntityDescriptor>
<md:EntityDescriptor entityID="https://bar.example.com/access/saml/idp.xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="md:EntityDescriptorType">
<md:IDPSSODescriptor WantAuthnRequestsSigned="true" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
<md:IDPSSODescriptor WantAuthnRequestsSigned="false" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
<md:KeyDescriptor use="signing">
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:X509Data>
Expand Down
31 changes: 28 additions & 3 deletions tests/src/OneLogin/saml2_tests/idp_metadata_parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,37 @@ def test_parse_with_entity_id(self):
data = OneLogin_Saml2_IdPMetadataParser.parse(xml_idp_metadata)
self.assertEqual("https://foo.example.com/access/saml/idp.xml", data["idp"]["entityId"])

expected_settings_json = """
{
"security": {"authnRequestsSigned": "true"},
"sp": {
"NameIDFormat": "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified"
},
"idp": {
"singleLogoutService": {
"url": "https://hello.example.com/access/saml/logout",
"binding": "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
},
"entityId": "https://foo.example.com/access/saml/idp.xml",
"x509cert": "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURxekNDQXhTZ0F3SUJBZ0lCQVRBTkJna3Foa2lHOXcwQkFRc0ZBRENCaGpFTE1Ba0dBMVVFQmhNQ1FWVXgKRERBS0JnTlZCQWdUQTA1VFZ6RVBNQTBHQTFVRUJ4TUdVM2xrYm1WNU1Rd3dDZ1lEVlFRS0RBTlFTVlF4Q1RBSApCZ05WQkFzTUFERVlNQllHQTFVRUF3d1BiR0YzY21WdVkyVndhWFF1WTI5dE1TVXdJd1lKS29aSWh2Y05BUWtCCkRCWnNZWGR5Wlc1alpTNXdhWFJBWjIxaGFXd3VZMjl0TUI0WERURXlNRFF4T1RJeU5UUXhPRm9YRFRNeU1EUXgKTkRJeU5UUXhPRm93Z1lZeEN6QUpCZ05WQkFZVEFrRlZNUXd3Q2dZRFZRUUlFd05PVTFjeER6QU5CZ05WQkFjVApCbE41Wkc1bGVURU1NQW9HQTFVRUNnd0RVRWxVTVFrd0J3WURWUVFMREFBeEdEQVdCZ05WQkFNTUQyeGhkM0psCmJtTmxjR2wwTG1OdmJURWxNQ01HQ1NxR1NJYjNEUUVKQVF3V2JHRjNjbVZ1WTJVdWNH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ZET2dpQzhic2ZmUzgKQkptb3VscnJaRE5OVmpHOG1XNmNMeHJZdlZRT3JSVmVjQ0ZJZ3NzQ2JBPT0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=",
"singleSignOnService": {
"url": "https://hello.example.com/access/saml/login",
"binding": "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
}
}
}
"""
expected_settings = json.loads(expected_settings_json)
self.assertEqual(expected_settings, data)


# should find desired descriptor
data2 = OneLogin_Saml2_IdPMetadataParser.parse(xml_idp_metadata, entity_id="https://bar.example.com/access/saml/idp.xml")
self.assertEqual("https://bar.example.com/access/saml/idp.xml", data2["idp"]["entityId"])

expected_settings_json = """
expected_settings_json2 = """
{
"security": {"authnRequestsSigned": "false"},
"sp": {
"NameIDFormat": "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified"
},
Expand All @@ -314,8 +339,8 @@ def test_parse_with_entity_id(self):
}
}
"""
expected_settings = json.loads(expected_settings_json)
self.assertEqual(expected_settings, data2)
expected_settings2 = json.loads(expected_settings_json2)
self.assertEqual(expected_settings2, data2)

def test_parse_multi_certs(self):
"""
Expand Down