@@ -557,9 +557,10 @@ def testQuery(self):
557557 signature_nodes_5 = OneLogin_Saml2_Utils .query (dom , './/ds:SignatureValue' , assertion )
558558 self .assertEqual (1 , len (signature_nodes_5 ))
559559
560- def testGenerateNameId (self ):
560+ def testGenerateNameIdWithSPNameQualifier (self ):
561561 """
562562 Tests the generateNameId method of the OneLogin_Saml2_Utils
563+ Adding a SPNameQualifier
563564 """
564565 name_id_value = 'ONELOGIN_ce998811003f4e60f8b07a311dc641621379cfde'
565566 entity_id = 'http://stuff.com/endpoints/metadata.php'
@@ -577,6 +578,25 @@ def testGenerateNameId(self):
577578 expected_name_id_enc = '<saml:EncryptedID><xenc:EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"><xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"/><dsig:KeyInfo xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"><xenc:EncryptedKey><xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"/><xenc:CipherData><xenc:CipherValue>'
578579 self .assertIn (expected_name_id_enc , name_id_enc )
579580
581+ def testGenerateNameIdWithoutSPNameQualifier (self ):
582+ """
583+ Tests the generateNameId method of the OneLogin_Saml2_Utils
584+ """
585+ name_id_value = 'ONELOGIN_ce998811003f4e60f8b07a311dc641621379cfde'
586+ name_id_format = 'urn:oasis:names:tc:SAML:2.0:nameid-format:unspecified'
587+
588+ name_id = OneLogin_Saml2_Utils .generate_name_id (name_id_value , None , name_id_format )
589+ expected_name_id = '<saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:unspecified">ONELOGIN_ce998811003f4e60f8b07a311dc641621379cfde</saml:NameID>'
590+ self .assertEqual (name_id , expected_name_id )
591+
592+ settings_info = self .loadSettingsJSON ()
593+ x509cert = settings_info ['idp' ]['x509cert' ]
594+ key = OneLogin_Saml2_Utils .format_cert (x509cert )
595+
596+ name_id_enc = OneLogin_Saml2_Utils .generate_name_id (name_id_value , None , name_id_format , key )
597+ expected_name_id_enc = '<saml:EncryptedID><xenc:EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"><xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"/><dsig:KeyInfo xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"><xenc:EncryptedKey><xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"/><xenc:CipherData><xenc:CipherValue>'
598+ self .assertIn (expected_name_id_enc , name_id_enc )
599+
580600 def testCalculateX509Fingerprint (self ):
581601 """
582602 Tests the calculateX509Fingerprint method of the OneLogin_Saml2_Utils
0 commit comments