@@ -746,6 +746,168 @@ public function testLoginSigned()
746746 }
747747 }
748748
749+ /**
750+ * Tests the login method of the OneLogin_Saml2_Auth class
751+ * Case Logout with no parameters. A AuthN Request is built with ForceAuthn and redirect executed
752+ *
753+ * @covers OneLogin_Saml2_Auth::login
754+ * @runInSeparateProcess
755+ */
756+ public function testLoginForceAuthN ()
757+ {
758+ $ settingsDir = TEST_ROOT .'/settings/ ' ;
759+ include $ settingsDir .'settings1.php ' ;
760+
761+ $ settingsInfo ['security ' ]['authnRequestsSigned ' ] = true ;
762+
763+ $ auth = new OneLogin_Saml2_Auth ($ settingsInfo );
764+
765+ try {
766+ // The Header of the redirect produces an Exception
767+ $ returnTo = 'http://example.com/returnto ' ;
768+ $ auth ->login ($ returnTo );
769+ // Do not ever get here
770+ $ this ->assertFalse (true );
771+ } catch (Exception $ e ) {
772+ $ this ->assertContains ('Cannot modify header information ' , $ e ->getMessage ());
773+ $ trace = $ e ->getTrace ();
774+ $ targetUrl = getUrlFromRedirect ($ trace );
775+ $ parsedQuery = getParamsFromUrl ($ targetUrl );
776+
777+ $ ssoUrl = $ settingsInfo ['idp ' ]['singleSignOnService ' ]['url ' ];
778+ $ this ->assertContains ($ ssoUrl , $ targetUrl );
779+ $ this ->assertArrayHasKey ('SAMLRequest ' , $ parsedQuery );
780+ $ encodedRequest = $ parsedQuery ['SAMLRequest ' ];
781+ $ decoded = base64_decode ($ encodedRequest );
782+ $ request = gzinflate ($ decoded );
783+ $ this ->assertNotContains ('ForceAuthn="true" ' , $ request );
784+ }
785+
786+ try {
787+ // The Header of the redirect produces an Exception
788+ $ returnTo = 'http://example.com/returnto ' ;
789+
790+ $ auth ->login ($ returnTo , array (), false , false );
791+ // Do not ever get here
792+ $ this ->assertFalse (true );
793+ } catch (Exception $ e ) {
794+ $ this ->assertContains ('Cannot modify header information ' , $ e ->getMessage ());
795+ $ trace2 = $ e ->getTrace ();
796+ $ targetUrl2 = getUrlFromRedirect ($ trace2 );
797+ $ parsedQuery2 = getParamsFromUrl ($ targetUrl2 );
798+
799+ $ ssoUrl2 = $ settingsInfo ['idp ' ]['singleSignOnService ' ]['url ' ];
800+ $ this ->assertContains ($ ssoUrl2 , $ targetUrl2 );
801+ $ this ->assertArrayHasKey ('SAMLRequest ' , $ parsedQuery2 );
802+ $ encodedRequest2 = $ parsedQuery2 ['SAMLRequest ' ];
803+ $ decoded2 = base64_decode ($ encodedRequest2 );
804+ $ request2 = gzinflate ($ decoded2 );
805+ $ this ->assertNotContains ('ForceAuthn="true" ' , $ request2 );
806+ }
807+
808+ try {
809+ // The Header of the redirect produces an Exception
810+ $ returnTo = 'http://example.com/returnto ' ;
811+ $ auth ->login ($ returnTo , array (), true , false );
812+ // Do not ever get here
813+ $ this ->assertFalse (true );
814+ } catch (Exception $ e ) {
815+ $ this ->assertContains ('Cannot modify header information ' , $ e ->getMessage ());
816+ $ trace3 = $ e ->getTrace ();
817+ $ targetUrl3 = getUrlFromRedirect ($ trace3 );
818+ $ parsedQuery3 = getParamsFromUrl ($ targetUrl3 );
819+
820+ $ ssoUrl3 = $ settingsInfo ['idp ' ]['singleSignOnService ' ]['url ' ];
821+ $ this ->assertContains ($ ssoUrl3 , $ targetUrl3 );
822+ $ this ->assertArrayHasKey ('SAMLRequest ' , $ parsedQuery3 );
823+ $ encodedRequest3 = $ parsedQuery3 ['SAMLRequest ' ];
824+ $ decoded3 = base64_decode ($ encodedRequest3 );
825+ $ request3 = gzinflate ($ decoded3 );
826+ $ this ->assertContains ('ForceAuthn="true" ' , $ request3 );
827+ }
828+
829+ }
830+
831+ /**
832+ * Tests the login method of the OneLogin_Saml2_Auth class
833+ * Case Logout with no parameters. A AuthN Request is built with IsPassive and redirect executed
834+ *
835+ * @covers OneLogin_Saml2_Auth::login
836+ * @runInSeparateProcess
837+ */
838+ public function testLoginIsPassive ()
839+ {
840+ $ settingsDir = TEST_ROOT .'/settings/ ' ;
841+ include $ settingsDir .'settings1.php ' ;
842+
843+ $ settingsInfo ['security ' ]['authnRequestsSigned ' ] = true ;
844+
845+ $ auth = new OneLogin_Saml2_Auth ($ settingsInfo );
846+
847+ try {
848+ // The Header of the redirect produces an Exception
849+ $ returnTo = 'http://example.com/returnto ' ;
850+ $ auth ->login ($ returnTo );
851+ // Do not ever get here
852+ $ this ->assertFalse (true );
853+ } catch (Exception $ e ) {
854+ $ this ->assertContains ('Cannot modify header information ' , $ e ->getMessage ());
855+ $ trace = $ e ->getTrace ();
856+ $ targetUrl = getUrlFromRedirect ($ trace );
857+ $ parsedQuery = getParamsFromUrl ($ targetUrl );
858+
859+ $ ssoUrl = $ settingsInfo ['idp ' ]['singleSignOnService ' ]['url ' ];
860+ $ this ->assertContains ($ ssoUrl , $ targetUrl );
861+ $ this ->assertArrayHasKey ('SAMLRequest ' , $ parsedQuery );
862+ $ encodedRequest = $ parsedQuery ['SAMLRequest ' ];
863+ $ decoded = base64_decode ($ encodedRequest );
864+ $ request = gzinflate ($ decoded );
865+ $ this ->assertNotContains ('IsPassive="true" ' , $ request );
866+ }
867+
868+ try {
869+ // The Header of the redirect produces an Exception
870+ $ returnTo = 'http://example.com/returnto ' ;
871+ $ auth ->login ($ returnTo , array (), false , false );
872+ // Do not ever get here
873+ $ this ->assertFalse (true );
874+ } catch (Exception $ e ) {
875+ $ this ->assertContains ('Cannot modify header information ' , $ e ->getMessage ());
876+ $ trace2 = $ e ->getTrace ();
877+ $ targetUrl2 = getUrlFromRedirect ($ trace2 );
878+ $ parsedQuery2 = getParamsFromUrl ($ targetUrl2 );
879+
880+ $ ssoUrl2 = $ settingsInfo ['idp ' ]['singleSignOnService ' ]['url ' ];
881+ $ this ->assertContains ($ ssoUrl2 , $ targetUrl2 );
882+ $ this ->assertArrayHasKey ('SAMLRequest ' , $ parsedQuery2 );
883+ $ encodedRequest2 = $ parsedQuery2 ['SAMLRequest ' ];
884+ $ decoded2 = base64_decode ($ encodedRequest2 );
885+ $ request2 = gzinflate ($ decoded2 );
886+ $ this ->assertNotContains ('IsPassive="true" ' , $ request2 );
887+ }
888+
889+ try {
890+ // The Header of the redirect produces an Exception
891+ $ returnTo = 'http://example.com/returnto ' ;
892+ $ auth ->login ($ returnTo , array (), false , true );
893+ // Do not ever get here
894+ $ this ->assertFalse (true );
895+ } catch (Exception $ e ) {
896+ $ this ->assertContains ('Cannot modify header information ' , $ e ->getMessage ());
897+ $ trace3 = $ e ->getTrace ();
898+ $ targetUrl3 = getUrlFromRedirect ($ trace3 );
899+ $ parsedQuery3 = getParamsFromUrl ($ targetUrl3 );
900+
901+ $ ssoUrl3 = $ settingsInfo ['idp ' ]['singleSignOnService ' ]['url ' ];
902+ $ this ->assertContains ($ ssoUrl3 , $ targetUrl3 );
903+ $ this ->assertArrayHasKey ('SAMLRequest ' , $ parsedQuery3 );
904+ $ encodedRequest3 = $ parsedQuery3 ['SAMLRequest ' ];
905+ $ decoded3 = base64_decode ($ encodedRequest3 );
906+ $ request3 = gzinflate ($ decoded3 );
907+ $ this ->assertContains ('IsPassive="true" ' , $ request3 );
908+ }
909+ }
910+
749911 /**
750912 * Tests the logout method of the OneLogin_Saml2_Auth class
751913 * Case Logout with no parameters. A logout Request is built and redirect executed
0 commit comments