@@ -64,7 +64,9 @@ def testReturnNameId(self):
6464 """
6565 Tests the get_nameid method of the OneLogin_Saml2_Response
6666 """
67- settings = OneLogin_Saml2_Settings (self .loadSettingsJSON ())
67+ json_settings = self .loadSettingsJSON ()
68+
69+ settings = OneLogin_Saml2_Settings (json_settings )
6870 xml = self .file_contents (join (self .data_path , 'responses' , 'response1.xml.base64' ))
6971 response = OneLogin_Saml2_Response (settings , xml )
7072 self .assertEqual ('support@onelogin.com' , response .get_nameid ())
@@ -85,10 +87,39 @@ def testReturnNameId(self):
8587 except Exception as e :
8688 self .assertIn ('Not NameID found in the assertion of the Response' , e .message )
8789
90+ json_settings ['security' ]['wantNameId' ] = True
91+ settings = OneLogin_Saml2_Settings (json_settings )
92+
93+ response_5 = OneLogin_Saml2_Response (settings , xml_4 )
94+ try :
95+ response_5 .get_nameid ()
96+ self .assertTrue (False )
97+ except Exception as e :
98+ self .assertIn ('Not NameID found in the assertion of the Response' , e .message )
99+
100+ json_settings ['security' ]['wantNameId' ] = False
101+ settings = OneLogin_Saml2_Settings (json_settings )
102+
103+ response_6 = OneLogin_Saml2_Response (settings , xml_4 )
104+ nameid_6 = response_6 .get_nameid ()
105+ self .assertIsNone (nameid_6 )
106+
107+ del json_settings ['security' ]['wantNameId' ]
108+ settings = OneLogin_Saml2_Settings (json_settings )
109+
110+ response_7 = OneLogin_Saml2_Response (settings , xml_4 )
111+ try :
112+ response_7 .get_nameid ()
113+ self .assertTrue (False )
114+ except Exception as e :
115+ self .assertIn ('Not NameID found in the assertion of the Response' , e .message )
116+
88117 def testGetNameIdData (self ):
89118 """
90119 Tests the get_nameid_data method of the OneLogin_Saml2_Response
91120 """
121+ json_settings = self .loadSettingsJSON ()
122+
92123 settings = OneLogin_Saml2_Settings (self .loadSettingsJSON ())
93124 xml = self .file_contents (join (self .data_path , 'responses' , 'response1.xml.base64' ))
94125 response = OneLogin_Saml2_Response (settings , xml )
@@ -127,6 +158,33 @@ def testGetNameIdData(self):
127158 except Exception as e :
128159 self .assertIn ('Not NameID found in the assertion of the Response' , e .message )
129160
161+ json_settings ['security' ]['wantNameId' ] = True
162+ settings = OneLogin_Saml2_Settings (json_settings )
163+
164+ response_5 = OneLogin_Saml2_Response (settings , xml_4 )
165+ try :
166+ response_5 .get_nameid_data ()
167+ self .assertTrue (False )
168+ except Exception as e :
169+ self .assertIn ('Not NameID found in the assertion of the Response' , e .message )
170+
171+ json_settings ['security' ]['wantNameId' ] = False
172+ settings = OneLogin_Saml2_Settings (json_settings )
173+
174+ response_6 = OneLogin_Saml2_Response (settings , xml_4 )
175+ nameid_data_6 = response_6 .get_nameid_data ()
176+ self .assertEqual ({}, nameid_data_6 )
177+
178+ del json_settings ['security' ]['wantNameId' ]
179+ settings = OneLogin_Saml2_Settings (json_settings )
180+
181+ response_7 = OneLogin_Saml2_Response (settings , xml_4 )
182+ try :
183+ response_7 .get_nameid_data ()
184+ self .assertTrue (False )
185+ except Exception as e :
186+ self .assertIn ('Not NameID found in the assertion of the Response' , e .message )
187+
130188 def testCheckStatus (self ):
131189 """
132190 Tests the check_status method of the OneLogin_Saml2_Response
0 commit comments