@@ -63,7 +63,8 @@ def testReturnNameId(self):
6363 """
6464 Tests the get_nameid method of the OneLogin_Saml2_Response
6565 """
66- settings = OneLogin_Saml2_Settings (self .loadSettingsJSON ())
66+ json_settings = self .loadSettingsJSON ()
67+ settings = OneLogin_Saml2_Settings (json_settings )
6768 xml = self .file_contents (join (self .data_path , 'responses' , 'response1.xml.base64' ))
6869 response = OneLogin_Saml2_Response (settings , xml )
6970 self .assertEqual ('support@onelogin.com' , response .get_nameid ())
@@ -84,11 +85,39 @@ def testReturnNameId(self):
8485 except Exception as e :
8586 self .assertIn ('Not NameID found in the assertion of the Response' , str (e ))
8687
88+ json_settings ['security' ]['wantNameId' ] = True
89+ settings = OneLogin_Saml2_Settings (json_settings )
90+
91+ response_5 = OneLogin_Saml2_Response (settings , xml_4 )
92+ try :
93+ response_5 .get_nameid ()
94+ self .assertTrue (False )
95+ except Exception as e :
96+ self .assertIn ('Not NameID found in the assertion of the Response' , e .message )
97+
98+ json_settings ['security' ]['wantNameId' ] = False
99+ settings = OneLogin_Saml2_Settings (json_settings )
100+
101+ response_6 = OneLogin_Saml2_Response (settings , xml_4 )
102+ nameid_6 = response_6 .get_nameid ()
103+ self .assertIsNone (nameid_6 )
104+
105+ del json_settings ['security' ]['wantNameId' ]
106+ settings = OneLogin_Saml2_Settings (json_settings )
107+
108+ response_7 = OneLogin_Saml2_Response (settings , xml_4 )
109+ try :
110+ response_7 .get_nameid ()
111+ self .assertTrue (False )
112+ except Exception as e :
113+ self .assertIn ('Not NameID found in the assertion of the Response' , e .message )
114+
87115 def testGetNameIdData (self ):
88116 """
89117 Tests the get_nameid_data method of the OneLogin_Saml2_Response
90118 """
91- settings = OneLogin_Saml2_Settings (self .loadSettingsJSON ())
119+ json_settings = self .loadSettingsJSON ()
120+ settings = OneLogin_Saml2_Settings (json_settings )
92121 xml = self .file_contents (join (self .data_path , 'responses' , 'response1.xml.base64' ))
93122 response = OneLogin_Saml2_Response (settings , xml )
94123 expected_nameid_data = {
@@ -126,6 +155,33 @@ def testGetNameIdData(self):
126155 except Exception as e :
127156 self .assertIn ('Not NameID found in the assertion of the Response' , str (e ))
128157
158+ json_settings ['security' ]['wantNameId' ] = True
159+ settings = OneLogin_Saml2_Settings (json_settings )
160+
161+ response_5 = OneLogin_Saml2_Response (settings , xml_4 )
162+ try :
163+ response_5 .get_nameid_data ()
164+ self .assertTrue (False )
165+ except Exception as e :
166+ self .assertIn ('Not NameID found in the assertion of the Response' , e .message )
167+
168+ json_settings ['security' ]['wantNameId' ] = False
169+ settings = OneLogin_Saml2_Settings (json_settings )
170+
171+ response_6 = OneLogin_Saml2_Response (settings , xml_4 )
172+ nameid_data_6 = response_6 .get_nameid_data ()
173+ self .assertEqual ({}, nameid_data_6 )
174+
175+ del json_settings ['security' ]['wantNameId' ]
176+ settings = OneLogin_Saml2_Settings (json_settings )
177+
178+ response_7 = OneLogin_Saml2_Response (settings , xml_4 )
179+ try :
180+ response_7 .get_nameid_data ()
181+ self .assertTrue (False )
182+ except Exception as e :
183+ self .assertIn ('Not NameID found in the assertion of the Response' , e .message )
184+
129185 def testCheckStatus (self ):
130186 """
131187 Tests the check_status method of the OneLogin_Saml2_Response
0 commit comments