/** * Tests the getSelfURLhost method of the OneLogin_Saml2_Utils * * @covers OneLogin_Saml2_Utils::getSelfURLhost */ public function testGetSelfURLhost() { $hostname = OneLogin_Saml2_Utils::getSelfHost(); $this->assertEquals("http://{$hostname}", OneLogin_Saml2_Utils::getSelfURLhost()); $_SERVER['SERVER_PORT'] = '80'; $this->assertEquals("http://{$hostname}", OneLogin_Saml2_Utils::getSelfURLhost()); $_SERVER['SERVER_PORT'] = '81'; $this->assertEquals("http://{$hostname}:81", OneLogin_Saml2_Utils::getSelfURLhost()); $_SERVER['SERVER_PORT'] = '443'; $this->assertEquals("https://{$hostname}", OneLogin_Saml2_Utils::getSelfURLhost()); unset($_SERVER['SERVER_PORT']); $_SERVER['HTTPS'] = 'on'; $this->assertEquals("https://{$hostname}", OneLogin_Saml2_Utils::getSelfURLhost()); $_SERVER['SERVER_PORT'] = '444'; $this->assertEquals("https://{$hostname}:444", OneLogin_Saml2_Utils::getSelfURLhost()); $_SERVER['SERVER_PORT'] = '443'; $_SERVER['REQUEST_URI'] = '/onelogin'; $this->assertEquals("https://{$hostname}", OneLogin_Saml2_Utils::getSelfURLhost()); $_SERVER['REQUEST_URI'] = 'https://$hostname/onelogin/sso'; $this->assertEquals("https://{$hostname}", OneLogin_Saml2_Utils::getSelfURLhost()); }
/** * Tests the logout method of the OneLogin_Saml2_Auth class * Case Logout with no parameters. A logout Request is built and redirect executed * * @covers OneLogin_Saml2_Auth::logout * @runInSeparateProcess */ public function testLogout() { try { // The Header of the redirect produces an Exception $this->_auth->logout(); // Do not ever get here $this->assertFalse(true); } catch (Exception $e) { $this->assertContains('Cannot modify header information', $e->getMessage()); $trace = $e->getTrace(); $targetUrl = getUrlFromRedirect($trace); $parsedQuery = getParamsFromUrl($targetUrl); $sloUrl = $this->_settingsInfo['idp']['singleLogoutService']['url']; $this->assertContains($sloUrl, $targetUrl); $this->assertArrayHasKey('SAMLRequest', $parsedQuery); $this->assertArrayHasKey('RelayState', $parsedQuery); $hostname = OneLogin_Saml2_Utils::getSelfHost(); $this->assertEquals($parsedQuery['RelayState'], "http://{$hostname}" . $_SERVER["PHP_SELF"]); } }