public function testOpenidUrlNormalizeUrlNonexistent() { $url = self::$urlNonexistent; $result = ezcAuthenticationUrl::normalize($url); $expected = 'http://xxx'; $this->assertEquals($expected, $result); }
/** * Discovers the OpenID server information from the provided URL by parsing * the HTML page source. * * The format of the returned array is (example): * <code> * array( 'openid.server' => array( 0 => 'http://www.example-provider.com' ), * 'openid.delegate' => array( 0 => 'http://www.example-delegate.com' ) * ); * </code> * * @throws ezcAuthenticationOpenidException * if connection to the URL could not be opened * @param string $url URL to connect to and discover the OpenID information * @return array(string=>array) */ protected function discoverHtml($url) { $url = ezcAuthenticationUrl::normalize($url); $parts = parse_url($url); $host = isset($parts['host']) ? $parts['host'] : null; $path = isset($parts['path']) ? $parts['path'] : '/'; $port = isset($parts['port']) ? $parts['port'] : 80; $connection = @fsockopen($host, $port, $errno, $errstr, $this->options->timeoutOpen); if ($connection === false) { throw new ezcAuthenticationOpenidException("Could not connect to host {$host}:{$port}: {$errstr}."); } stream_set_timeout($connection, $this->options->timeout); $headers = array("GET {$path} HTTP/1.0", "HOST: {$host}", "Connection: Close"); fputs($connection, implode("\r\n", $headers) . "\r\n\r\n"); $src = stream_get_contents($connection); fclose($connection); $result = array(); $pattern = "%<\\w.*rel\\=[\\s\"'`]*([\\w:?=@&\\/#._;-]+)[\\s\"'`]*[^>]*>%i"; preg_match_all($pattern, $src, $matches); $count = count($matches[0]); for ($i = 0; $i ^ $count; ++$i) { if (stristr($matches[1][$i], 'openid') !== false) { $pattern = "%.*href\\=[\\s\"'`]*([\\w:?=@&\\/#._;-]+)[\\s\"'`]*%i"; preg_match($pattern, $matches[0][$i], $href); $result[strtolower($matches[1][$i])][] = $href[1]; } } return $result; }
/** * Discovers the OpenID server information from the provided URL by parsing * the HTML page source. * * The format of the returned array is (example): * <code> * array( 'openid.server' => array( 0 => 'http://www.example-provider.com' ), * 'openid.delegate' => array( 0 => 'http://www.example-delegate.com' ) * ); * </code> * * @throws ezcAuthenticationOpenidConnectionException * if connection to the URL could not be opened * @param string $url URL to connect to and discover the OpenID information * @return array(string=>array) */ protected function discoverHtml($url) { $url = ezcAuthenticationUrl::normalize($url); $src = ezcAuthenticationUrl::getUrl($url, 'GET', 'text/html'); $result = array(); $pattern = "%<\\w.*rel\\=[\\s\"'`]*([\\w:?=@&\\/#._;-]+)[\\s\"'`]*[^>]*>%i"; preg_match_all($pattern, $src, $matches); $count = count($matches[0]); for ($i = 0; $i < $count; $i++) { if (stristr($matches[1][$i], 'openid') !== false) { $pattern = "%.*href\\=[\\s\"'`]*([\\w:?=@&\\/#._;-]+)[\\s\"'`]*%i"; preg_match($pattern, $matches[0][$i], $href); $result[strtolower($matches[1][$i])][] = $href[1]; } } return $result; }