@@ -813,51 +813,29 @@ def testAddSign(self):
813
813
814
814
xml_authn = b64decode (self .file_contents (join (self .data_path , 'requests' , 'authn_request.xml.base64' )))
815
815
xml_authn_signed = OneLogin_Saml2_Utils .add_sign (xml_authn , key , cert )
816
- self .assertIn ('<ds:SignatureValue>' , xml_authn_signed )
817
-
818
- res = parseString (xml_authn_signed )
819
- ds_signature = res .firstChild .firstChild .nextSibling .nextSibling .nextSibling
820
- self .assertEqual ('ds:Signature' , ds_signature .tagName )
821
816
822
817
xml_authn_dom = parseString (xml_authn )
823
818
xml_authn_signed_2 = OneLogin_Saml2_Utils .add_sign (xml_authn_dom , key , cert )
824
- self .assertIn ('<ds:SignatureValue>' , xml_authn_signed_2 )
825
- res_2 = parseString (xml_authn_signed_2 )
826
- ds_signature_2 = res_2 .firstChild .firstChild .nextSibling .nextSibling .nextSibling
827
- self .assertEqual ('ds:Signature' , ds_signature_2 .tagName )
828
-
829
819
xml_authn_signed_3 = OneLogin_Saml2_Utils .add_sign (xml_authn_dom .firstChild , key , cert )
830
- self .assertIn ('<ds:SignatureValue>' , xml_authn_signed_3 )
831
- res_3 = parseString (xml_authn_signed_3 )
832
- ds_signature_3 = res_3 .firstChild .firstChild .nextSibling .nextSibling .nextSibling
833
- self .assertEqual ('ds:Signature' , ds_signature_3 .tagName )
834
820
835
821
xml_authn_etree = etree .fromstring (xml_authn )
836
822
xml_authn_signed_4 = OneLogin_Saml2_Utils .add_sign (xml_authn_etree , key , cert )
837
- self .assertIn ('<ds:SignatureValue>' , xml_authn_signed_4 )
838
- res_4 = parseString (xml_authn_signed_4 )
839
- ds_signature_4 = res_4 .firstChild .firstChild .nextSibling .nextSibling .nextSibling
840
- self .assertEqual ('ds:Signature' , ds_signature_4 .tagName )
841
-
842
- xml_authn_signed_5 = OneLogin_Saml2_Utils .add_sign (xml_authn_etree , key , cert )
843
- self .assertIn ('<ds:SignatureValue>' , xml_authn_signed_5 )
844
- res_5 = parseString (xml_authn_signed_5 )
845
- ds_signature_5 = res_5 .firstChild .firstChild .nextSibling .nextSibling .nextSibling
846
- self .assertEqual ('ds:Signature' , ds_signature_5 .tagName )
847
823
848
824
xml_logout_req = b64decode (self .file_contents (join (self .data_path , 'logout_requests' , 'logout_request.xml.base64' )))
849
825
xml_logout_req_signed = OneLogin_Saml2_Utils .add_sign (xml_logout_req , key , cert )
850
- self .assertIn ('<ds:SignatureValue>' , xml_logout_req_signed )
851
- res_6 = parseString (xml_logout_req_signed )
852
- ds_signature_6 = res_6 .firstChild .firstChild .nextSibling .nextSibling .nextSibling
853
- self .assertEqual ('ds:Signature' , ds_signature_6 .tagName )
854
826
855
827
xml_logout_res = b64decode (self .file_contents (join (self .data_path , 'logout_responses' , 'logout_response.xml.base64' )))
856
828
xml_logout_res_signed = OneLogin_Saml2_Utils .add_sign (xml_logout_res , key , cert )
857
- self .assertIn ('<ds:SignatureValue>' , xml_logout_res_signed )
858
- res_7 = parseString (xml_logout_res_signed )
859
- ds_signature_7 = res_7 .firstChild .firstChild .nextSibling .nextSibling .nextSibling
860
- self .assertEqual ('ds:Signature' , ds_signature_7 .tagName )
829
+
830
+ xml_signed_saml_messages = [xml_authn_signed , xml_authn_signed_2 , xml_authn_signed_3 , xml_authn_signed_4 , xml_logout_req_signed , xml_logout_res_signed ]
831
+
832
+ for xml_signed_saml_message in xml_signed_saml_messages :
833
+ self .assertIn ('<ds:SignatureValue>' , xml_signed_saml_message )
834
+ signed_saml_message = parseString (xml_signed_saml_message )
835
+ ds_signature = signed_saml_message .firstChild .firstChild .nextSibling .nextSibling
836
+ if ds_signature .tagName != 'ds:Signature' :
837
+ ds_signature = ds_signature .nextSibling
838
+ self .assertEqual ('ds:Signature' , ds_signature .tagName )
861
839
862
840
xml_metadata = self .file_contents (join (self .data_path , 'metadata' , 'metadata_settings1.xml' ))
863
841
xml_metadata_signed = OneLogin_Saml2_Utils .add_sign (xml_metadata , key , cert )
0 commit comments