@@ -1196,6 +1196,90 @@ public function testLoginNameIDPolicy()
11961196 }
11971197 }
11981198
1199+ /**
1200+ * Tests the login method of the OneLogin_Saml2_Auth class
1201+ * Case Login with no parameters. A AuthN Request is built with and without Subject
1202+ *
1203+ * @covers OneLogin_Saml2_Auth::login
1204+ * @runInSeparateProcess
1205+ */
1206+ public function testLoginSubject ()
1207+ {
1208+ $ settingsDir = TEST_ROOT .'/settings/ ' ;
1209+ include $ settingsDir .'settings1.php ' ;
1210+
1211+ $ auth = new OneLogin_Saml2_Auth ($ settingsInfo );
1212+
1213+ try {
1214+ // The Header of the redirect produces an Exception
1215+ $ returnTo = 'http://example.com/returnto ' ;
1216+ $ auth ->login ($ returnTo );
1217+ // Do not ever get here
1218+ $ this ->assertFalse (true );
1219+ } catch (Exception $ e ) {
1220+ $ this ->assertContains ('Cannot modify header information ' , $ e ->getMessage ());
1221+ $ trace = $ e ->getTrace ();
1222+ $ targetUrl = getUrlFromRedirect ($ trace );
1223+ $ parsedQuery = getParamsFromUrl ($ targetUrl );
1224+
1225+ $ ssoUrl = $ settingsInfo ['idp ' ]['singleSignOnService ' ]['url ' ];
1226+ $ this ->assertContains ($ ssoUrl , $ targetUrl );
1227+ $ this ->assertArrayHasKey ('SAMLRequest ' , $ parsedQuery );
1228+ $ encodedRequest = $ parsedQuery ['SAMLRequest ' ];
1229+ $ decoded = base64_decode ($ encodedRequest );
1230+ $ request = gzinflate ($ decoded );
1231+ $ this ->assertNotContains ('<saml:Subject ' , $ request );
1232+ }
1233+
1234+ try {
1235+ // The Header of the redirect produces an Exception
1236+ $ returnTo = 'http://example.com/returnto ' ;
1237+ $ auth ->login ($ returnTo , array (), false , false , false , true , "testuser@example.com " );
1238+ // Do not ever get here
1239+ $ this ->assertFalse (true );
1240+ } catch (Exception $ e ) {
1241+ $ this ->assertContains ('Cannot modify header information ' , $ e ->getMessage ());
1242+ $ trace2 = $ e ->getTrace ();
1243+ $ targetUrl2 = getUrlFromRedirect ($ trace2 );
1244+ $ parsedQuery2 = getParamsFromUrl ($ targetUrl2 );
1245+
1246+ $ ssoUrl2 = $ settingsInfo ['idp ' ]['singleSignOnService ' ]['url ' ];
1247+ $ this ->assertContains ($ ssoUrl2 , $ targetUrl2 );
1248+ $ this ->assertArrayHasKey ('SAMLRequest ' , $ parsedQuery2 );
1249+ $ encodedRequest2 = $ parsedQuery2 ['SAMLRequest ' ];
1250+ $ decoded2 = base64_decode ($ encodedRequest2 );
1251+ $ request2 = gzinflate ($ decoded2 );
1252+ $ this ->assertContains ('<saml:Subject ' , $ request2 );
1253+ $ this ->assertContains ('Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified">testuser@example.com</saml:NameID> ' , $ request2 );
1254+ $ this ->assertContains ('<saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"> ' , $ request2 );
1255+ }
1256+
1257+ try {
1258+ // The Header of the redirect produces an Exception
1259+ $ returnTo = 'http://example.com/returnto ' ;
1260+ $ settingsInfo ['sp ' ]['NameIDFormat ' ] = "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress " ;
1261+ $ auth2 = new OneLogin_Saml2_Auth ($ settingsInfo );
1262+ $ auth2 ->login ($ returnTo );
1263+ // Do not ever get here
1264+ $ this ->assertFalse (true );
1265+ } catch (Exception $ e ) {
1266+ $ this ->assertContains ('Cannot modify header information ' , $ e ->getMessage ());
1267+ $ trace3 = $ e ->getTrace ();
1268+ $ targetUrl3 = getUrlFromRedirect ($ trace3 );
1269+ $ parsedQuery3 = getParamsFromUrl ($ targetUrl3 );
1270+
1271+ $ ssoUrl3 = $ settingsInfo ['idp ' ]['singleSignOnService ' ]['url ' ];
1272+ $ this ->assertContains ($ ssoUrl3 , $ targetUrl3 );
1273+ $ this ->assertArrayHasKey ('SAMLRequest ' , $ parsedQuery3 );
1274+ $ encodedRequest3 = $ parsedQuery3 ['SAMLRequest ' ];
1275+ $ decoded3 = base64_decode ($ encodedRequest3 );
1276+ $ request3 = gzinflate ($ decoded3 );
1277+ $ this ->assertContains ('<saml:Subject ' , $ request3 );
1278+ $ this ->assertContains ('Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress">testuser@example.com</saml:NameID> ' , $ request3 );
1279+ $ this ->assertContains ('<saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"> ' , $ request3 );
1280+ }
1281+ }
1282+
11991283 /**
12001284 * Tests the logout method of the OneLogin_Saml2_Auth class
12011285 * Case Logout with no parameters. A logout Request is built and redirect executed
0 commit comments