6464import com .onelogin .saml2 .util .Util ;
6565
6666import org .mockito .ArgumentCaptor ;
67+ import org .w3c .dom .Document ;
6768
6869public class AuthTest {
6970
@@ -563,6 +564,38 @@ public void testProcessResponse() throws Exception {
563564 assertEquals (keys , auth2 .getAttributesName ());
564565 }
565566
567+ /**
568+ * Tests the processResponse methods of Auth
569+ * Case: process Response, status code Responder and sub status
570+ *
571+ * @throws Exception
572+ *
573+ * @see com.onelogin.saml2.Auth#processSLO
574+ */
575+ @ Test
576+ public void testProcessResponseStatusResponder () throws Exception {
577+ HttpServletRequest request = mock (HttpServletRequest .class );
578+ HttpServletResponse response = mock (HttpServletResponse .class );
579+ HttpSession session = mock (HttpSession .class );
580+ when (request .getRequestURL ()).thenReturn (new StringBuffer ("https://example.com/opensso/Consumer/metaAlias/sp" ));
581+ when (request .getSession ()).thenReturn (session );
582+
583+ String samlResponseEncoded = Util .getFileAsString ("data/responses/invalids/status_code_and_sub_status_code_responder_and_msg.xml.base64" );
584+ Document samlResponseDoc = Util .loadXML (new String (Util .base64decoder (samlResponseEncoded )));
585+ when (request .getParameterMap ()).thenReturn (singletonMap ("SAMLResponse" , new String []{samlResponseEncoded }));
586+ Saml2Settings settings = new SettingsBuilder ().fromFile ("config/config.min.properties" ).build ();
587+ Auth auth = new Auth (settings , request , response );
588+ assertFalse (auth .isAuthenticated ());
589+ assertTrue (auth .getErrors ().isEmpty ());
590+ auth .processResponse ();
591+ verify (session , times (0 )).invalidate ();
592+ assertFalse (auth .getErrors ().isEmpty ());
593+ assertEquals ("The status code of the Response was not Success, was urn:oasis:names:tc:SAML:2.0:status:Responder -> something_is_wrong" , auth .getLastErrorReason ());
594+ assertTrue (auth .getErrors ().contains ("response_not_success" ));
595+ assertTrue (auth .getErrors ().contains (Constants .STATUS_RESPONDER ));
596+ assertTrue (auth .getErrors ().contains (Constants .STATUS_AUTHNFAILED ));
597+ }
598+
566599 /**
567600 * Tests the processSLO methods of Auth
568601 *
@@ -825,6 +858,7 @@ public void testProcessSLOResponseStatusResponder() throws Exception {
825858 verify (session , times (0 )).invalidate ();
826859 assertFalse (auth .getErrors ().isEmpty ());
827860 assertTrue (auth .getErrors ().contains ("logout_not_success" ));
861+ assertTrue (auth .getErrors ().contains (Constants .STATUS_RESPONDER ));
828862 }
829863
830864 /**
@@ -853,7 +887,6 @@ public void testIsAuthenticated() throws Exception {
853887 assertFalse (auth .getErrors ().isEmpty ());
854888 List <String > expectedErrors = new ArrayList <String >();
855889 expectedErrors .add ("invalid_response" );
856- expectedErrors .add ("urn:oasis:names:tc:SAML:2.0:status:Success" );
857890 assertEquals (expectedErrors , auth .getErrors ());
858891 assertEquals ("SAML Response must contain 1 Assertion." , auth .getLastErrorReason ());
859892 assertTrue (auth .getLastValidationException () instanceof ValidationError );
@@ -868,7 +901,6 @@ public void testIsAuthenticated() throws Exception {
868901 assertFalse (auth2 .getErrors ().isEmpty ());
869902 expectedErrors = new ArrayList <String >();
870903 expectedErrors .add ("invalid_response" );
871- expectedErrors .add ("urn:oasis:names:tc:SAML:2.0:status:Success" );
872904 assertEquals (expectedErrors , auth2 .getErrors ());
873905 assertThat (auth2 .getLastErrorReason (), containsString ("Invalid issuer in the Assertion/Response" ));
874906 assertTrue (auth2 .getLastValidationException () instanceof ValidationError );
0 commit comments