@@ -1274,6 +1274,89 @@ public function testLoginNameIDPolicy()
12741274 }
12751275 }
12761276
1277+ /**
1278+ * Tests the login method of the Auth class
1279+ * Case Login with no parameters. A AuthN Request is built with and without Subject
1280+ *
1281+ * @covers OneLogin\Saml2\Auth::login
1282+ * @runInSeparateProcess
1283+ */
1284+ public function testLoginSubject ()
1285+ {
1286+ $ settingsDir = TEST_ROOT .'/settings/ ' ;
1287+ include $ settingsDir .'settings1.php ' ;
1288+ $ auth = new Auth ($ settingsInfo );
1289+
1290+ try {
1291+ // The Header of the redirect produces an Exception
1292+ $ returnTo = 'http://example.com/returnto ' ;
1293+ $ auth ->login ($ returnTo );
1294+ // Do not ever get here
1295+ $ this ->assertFalse (true );
1296+ } catch (Exception $ e ) {
1297+ $ this ->assertContains ('Cannot modify header information ' , $ e ->getMessage ());
1298+ $ trace = $ e ->getTrace ();
1299+ $ targetUrl = getUrlFromRedirect ($ trace );
1300+ $ parsedQuery = getParamsFromUrl ($ targetUrl );
1301+
1302+ $ ssoUrl = $ settingsInfo ['idp ' ]['singleSignOnService ' ]['url ' ];
1303+ $ this ->assertContains ($ ssoUrl , $ targetUrl );
1304+ $ this ->assertArrayHasKey ('SAMLRequest ' , $ parsedQuery );
1305+ $ encodedRequest = $ parsedQuery ['SAMLRequest ' ];
1306+ $ decoded = base64_decode ($ encodedRequest );
1307+ $ request = gzinflate ($ decoded );
1308+ $ this ->assertNotContains ('<saml:Subject ' , $ request );
1309+ }
1310+
1311+ try {
1312+ // The Header of the redirect produces an Exception
1313+ $ returnTo = 'http://example.com/returnto ' ;
1314+ $ auth ->login ($ returnTo , array (), false , false , false , true , "testuser@example.com " );
1315+ // Do not ever get here
1316+ $ this ->assertFalse (true );
1317+ } catch (Exception $ e ) {
1318+ $ this ->assertContains ('Cannot modify header information ' , $ e ->getMessage ());
1319+ $ trace2 = $ e ->getTrace ();
1320+ $ targetUrl2 = getUrlFromRedirect ($ trace2 );
1321+ $ parsedQuery2 = getParamsFromUrl ($ targetUrl2 );
1322+
1323+ $ ssoUrl2 = $ settingsInfo ['idp ' ]['singleSignOnService ' ]['url ' ];
1324+ $ this ->assertContains ($ ssoUrl2 , $ targetUrl2 );
1325+ $ this ->assertArrayHasKey ('SAMLRequest ' , $ parsedQuery2 );
1326+ $ encodedRequest2 = $ parsedQuery2 ['SAMLRequest ' ];
1327+ $ decoded2 = base64_decode ($ encodedRequest2 );
1328+ $ request2 = gzinflate ($ decoded2 );
1329+ $ this ->assertContains ('<saml:Subject ' , $ request2 );
1330+ $ this ->assertContains ('Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified">testuser@example.com</saml:NameID> ' , $ request2 );
1331+ $ this ->assertContains ('<saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"> ' , $ request2 );
1332+ }
1333+
1334+ try {
1335+ // The Header of the redirect produces an Exception
1336+ $ returnTo = 'http://example.com/returnto ' ;
1337+ $ settingsInfo ['sp ' ]['NameIDFormat ' ] = "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress " ;
1338+ $ auth2 = new Auth ($ settingsInfo );
1339+ $ auth2 ->login ($ returnTo );
1340+ // Do not ever get here
1341+ $ this ->assertFalse (true );
1342+ } catch (Exception $ e ) {
1343+ $ this ->assertContains ('Cannot modify header information ' , $ e ->getMessage ());
1344+ $ trace3 = $ e ->getTrace ();
1345+ $ targetUrl3 = getUrlFromRedirect ($ trace3 );
1346+ $ parsedQuery3 = getParamsFromUrl ($ targetUrl3 );
1347+
1348+ $ ssoUrl3 = $ settingsInfo ['idp ' ]['singleSignOnService ' ]['url ' ];
1349+ $ this ->assertContains ($ ssoUrl3 , $ targetUrl3 );
1350+ $ this ->assertArrayHasKey ('SAMLRequest ' , $ parsedQuery3 );
1351+ $ encodedRequest3 = $ parsedQuery3 ['SAMLRequest ' ];
1352+ $ decoded3 = base64_decode ($ encodedRequest3 );
1353+ $ request3 = gzinflate ($ decoded3 );
1354+ $ this ->assertContains ('<saml:Subject ' , $ request3 );
1355+ $ this ->assertContains ('Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress">testuser@example.com</saml:NameID> ' , $ request3 );
1356+ $ this ->assertContains ('<saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"> ' , $ request3 );
1357+ }
1358+ }
1359+
12771360 /**
12781361 * Tests the logout method of the Auth class
12791362 * Case Logout with no parameters. A logout Request is built and redirect executed
0 commit comments