def test_ee_6(): ee = saml2_tophat.extension_element_from_string( """<?xml version='1.0' encoding='UTF-8'?> <foo xmlns="urn:mace:example.com:saml:ns">bar</foo>""") ce = saml2_tophat.extension_element_from_string( """<?xml version='1.0' encoding='UTF-8'?> <educause xmlns="urn:mace:example.com:saml:cu">rev</educause>""") et = ee.transfer_to_element_tree() ce.become_child_element_of(et) pee = saml2_tophat._extension_element_from_element_tree(et) assert pee != None print(pee.__dict__) assert pee.attributes == {} assert pee.tag == "foo" assert pee.namespace == "urn:mace:example.com:saml:ns" assert len(pee.children) == 1 assert pee.text.strip() == "bar" c = pee.children[0] print(c.__dict__) child = pee.find_children(namespace="urn:mace:example.com:saml:cu") assert len(child) == 1 child = pee.find_children(namespace="urn:mace:example.com:saml:ns") assert len(child) == 0 child = pee.find_children("educause", "urn:mace:example.com:saml:cu") assert len(child) == 1 child = pee.find_children("edugain", "urn:mace:example.com:saml:cu") assert len(child) == 0 print(pee.to_string())
def test_ee_5(): ee = saml2_tophat.extension_element_from_string( """<?xml version='1.0' encoding='UTF-8'?> <foo xmlns="urn:mace:example.com:saml:ns">bar</foo>""") ce = saml2_tophat.extension_element_from_string( """<?xml version='1.0' encoding='UTF-8'?> <educause xmlns="urn:mace:example.com:saml:cu">rev</educause>""") ee.children.append(ce) assert ee != None print(ee.__dict__) assert ee.attributes == {} assert ee.tag == "foo" assert ee.namespace == "urn:mace:example.com:saml:ns" assert len(ee.children) == 1 assert ee.text.strip() == "bar" c = ee.children[0] print(c.__dict__) child = ee.find_children(namespace="urn:mace:example.com:saml:cu") assert len(child) == 1 child = ee.find_children(namespace="urn:mace:example.com:saml:ns") assert len(child) == 0 child = ee.find_children("educause", "urn:mace:example.com:saml:cu") assert len(child) == 1 child = ee.find_children("edugain", "urn:mace:example.com:saml:cu") assert len(child) == 0 print(ee.to_string())
def test_ee_xxe(): xml = """<?xml version="1.0"?> <!DOCTYPE lolz [ <!ENTITY lol "lol"> <!ELEMENT lolz (#PCDATA)> <!ENTITY lol1 "&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;"> ]> <lolz>&lol1;</lolz> """ with raises(EntitiesForbidden): saml2_tophat.extension_element_from_string(xml)
def test_ee_7(): ee = saml2_tophat.extension_element_from_string( """<?xml version='1.0' encoding='UTF-8'?> <ExternalEntityAttributeAuthority xmlns="urn:oasis:names:tc:SAML:metadata:dynamicsaml"> <AssertingEntity> <NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity"> http://federationX.org </NameID> </AssertingEntity> <RetrievalEndpoint> https://federationX.org/?ID=a87s76a5765da76576a57as </RetrievalEndpoint> </ExternalEntityAttributeAuthority> """) print(ee.__dict__) assert len(ee.children) == 2 for child in ee.children: assert child.namespace == "urn:oasis:names:tc:SAML:metadata:dynamicsaml" assert _eq(["AssertingEntity", "RetrievalEndpoint"], [c.tag for c in ee.children]) aes = [c for c in ee.children if c.tag == "AssertingEntity"] assert len(aes) == 1 assert len(aes[0].children) == 1 assert _eq(aes[0].attributes.keys(), []) nid = aes[0].children[0] assert nid.tag == "NameID" assert nid.namespace == "urn:oasis:names:tc:SAML:metadata:dynamicsaml" assert len(nid.children) == 0 assert _eq(nid.attributes.keys(), ["Format"]) assert nid.text.strip() == "http://federationX.org"
def test_ee_2(): ee = saml2_tophat.extension_element_from_string( """<?xml version='1.0' encoding='UTF-8'?><foo id="xyz">bar</foo>""") assert ee != None print(ee.__dict__) assert ee.attributes == {"id": "xyz"} assert ee.tag == "foo" assert ee.namespace == None assert ee.children == [] assert ee.text == "bar"
def test_ee_4(): ee = saml2_tophat.extension_element_from_string( """<?xml version='1.0' encoding='UTF-8'?> <foo xmlns="urn:mace:example.com:saml:ns"> <id>xyz</id><bar>tre</bar></foo>""") assert ee != None print(ee.__dict__) assert ee.attributes == {} assert ee.tag == "foo" assert ee.namespace == "urn:mace:example.com:saml:ns" assert len(ee.children) == 2 assert ee.text.strip() == "" cid = ee.find_children("id", "urn:mace:example.com:saml:namespace") assert cid == [] ids = ee.find_children("id", "urn:mace:example.com:saml:ns") assert ids != [] cid = ids[0] print(cid.__dict__) assert cid.attributes == {} assert cid.tag == "id" assert cid.namespace == "urn:mace:example.com:saml:ns" assert cid.children == [] assert cid.text.strip() == "xyz"