@@ -435,11 +435,40 @@ def testIsInValidNoStatement(self):
435435
436436 settings .set_strict (True )
437437 response_2 = OneLogin_Saml2_Response (settings , xml )
438- try :
439- valid = response_2 .is_valid (self .get_request_data ())
440- self .assertFalse (valid )
441- except Exception as e :
442- self .assertEqual ('There is no AttributeStatement on the Response' , str (e ))
438+ self .assertFalse (response_2 .is_valid (self .get_request_data ()))
439+ self .assertEqual ('There is no AttributeStatement on the Response' , response_2 .get_error ())
440+
441+ def testIsValidOptionalStatement (self ):
442+ """
443+ Tests the is_valid method of the OneLogin_Saml2_Response
444+ Case AttributeStatement is optional
445+ """
446+ # shortcut
447+ json_settings = self .loadSettingsJSON ()
448+ settings = OneLogin_Saml2_Settings (json_settings )
449+ settings .set_strict (True )
450+
451+ # want AttributeStatement True by default
452+ self .assertTrue (settings .get_security_data ()['wantAttributeStatement' ])
453+
454+ xml = self .file_contents (join (self .data_path , 'responses' , 'invalids' , 'signed_assertion_response.xml.base64' ))
455+
456+ response = OneLogin_Saml2_Response (settings , xml )
457+ self .assertFalse (response .is_valid (self .get_request_data ()))
458+ self .assertEqual ('There is no AttributeStatement on the Response' , response .get_error ())
459+
460+ security = settings .get_security_data ()
461+ # change wantAttributeStatement to optional
462+ json_settings ['security' ]['wantAttributeStatement' ] = False
463+ settings = OneLogin_Saml2_Settings (json_settings )
464+
465+ # check settings
466+ self .assertFalse (settings .get_security_data ()['wantAttributeStatement' ])
467+
468+ response = OneLogin_Saml2_Response (settings , xml )
469+ response .is_valid (self .get_request_data ())
470+ self .assertNotEqual ('There is no AttributeStatement on the Response' , response .get_error ())
471+ self .assertEqual ('Signature validation failed. SAML Response rejected' , response .get_error ())
443472
444473 def testIsInValidNoKey (self ):
445474 """
0 commit comments