Always return authenticationDate, longTermAuthenticationRequestTokenUsed and isFromNewLogin attributes
As specified in the CAS response XML schema (see Appendix A). Fix #37 as returned attributes are now never empty.
This commit is contained in:
@ -149,15 +149,23 @@ class XmlContent(object):
|
||||
namespaces={'cas': "http://www.yale.edu/tp/cas"}
|
||||
)
|
||||
self.assertEqual(len(attributes), 1)
|
||||
ignore_attrs = {"authenticationDate", "longTermAuthenticationRequestTokenUsed", "isFromNewLogin"}
|
||||
ignored_attrs = 0
|
||||
attrs1 = set()
|
||||
for attr in attributes[0]:
|
||||
attrs1.add((attr.tag[len("http://www.yale.edu/tp/cas")+2:], attr.text))
|
||||
name = attr.tag[len("http://www.yale.edu/tp/cas")+2:]
|
||||
if not name in ignore_attrs:
|
||||
attrs1.add((name, attr.text))
|
||||
else:
|
||||
ignored_attrs += 1
|
||||
|
||||
attributes = root.xpath("//cas:attribute", namespaces={'cas': "http://www.yale.edu/tp/cas"})
|
||||
self.assertEqual(len(attributes), len(attrs1))
|
||||
self.assertEqual(len(attributes), len(attrs1) + ignored_attrs)
|
||||
attrs2 = set()
|
||||
for attr in attributes:
|
||||
attrs2.add((attr.attrib['name'], attr.attrib['value']))
|
||||
name = attr.attrib['name']
|
||||
if not name in ignore_attrs:
|
||||
attrs2.add((name, attr.attrib['value']))
|
||||
original = set()
|
||||
for key, value in original_attributes.items():
|
||||
if isinstance(value, list):
|
||||
|
@ -1907,9 +1907,11 @@ class SamlValidateTestCase(TestCase, BaseServicePattern, XmlContent):
|
||||
"//samla:AttributeStatement/samla:Attribute",
|
||||
namespaces={'samla': "urn:oasis:names:tc:SAML:1.0:assertion"}
|
||||
)
|
||||
ignore_attrs = {"authenticationDate", "longTermAuthenticationRequestTokenUsed", "isFromNewLogin"} - set(original_attributes.keys())
|
||||
attrs = set()
|
||||
for attr in attributes:
|
||||
attrs.add((attr.attrib['AttributeName'], attr.getchildren()[0].text))
|
||||
if not attr.attrib['AttributeName'] in ignore_attrs:
|
||||
attrs.add((attr.attrib['AttributeName'], attr.getchildren()[0].text))
|
||||
original = set()
|
||||
for key, value in original_attributes.items():
|
||||
if isinstance(value, list):
|
||||
|
@ -264,7 +264,9 @@ class DummyCAS(BaseHTTPServer.BaseHTTPRequestHandler):
|
||||
template = loader.get_template('cas_server/serviceValidate.xml')
|
||||
context = Context({
|
||||
'username': self.server.username,
|
||||
'attributes': self.server.attributes
|
||||
'attributes': self.server.attributes,
|
||||
'auth_date': timezone.now().replace(microsecond=0).isoformat(),
|
||||
'is_new_login': 'true',
|
||||
})
|
||||
self.wfile.write(return_bytes(template.render(context), "utf8"))
|
||||
else:
|
||||
@ -301,6 +303,8 @@ class DummyCAS(BaseHTTPServer.BaseHTTPRequestHandler):
|
||||
'ResponseID': utils.gen_saml_id(),
|
||||
'username': self.server.username,
|
||||
'attributes': self.server.attributes,
|
||||
'auth_date': timezone.now().replace(microsecond=0).isoformat(),
|
||||
'is_new_login': 'true',
|
||||
})
|
||||
self.wfile.write(return_bytes(template.render(context), "utf8"))
|
||||
else:
|
||||
|
Reference in New Issue
Block a user