/** * testing testNormalizeUrl * */ public function testNormalizeUrl() { $url = 'example://a/b/c/%7Bfoo%7D'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'example://a/b/c/%7Bfoo%7D', $url ); $url = 'eXAMPLE://A/./b/../b/%63/%7bfoo%7d'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'example://a/b/c/%7Bfoo%7D', $url ); $url = 'eXAMPLE://A/./b/../b/%63/%bbfoo%Bd'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'example://a/b/c/%BBfoo%BD', $url ); $url = 'example://a/b/c/%1'; $this->assertFalse( OpenId::normalizeUrl($url) ); $url = 'example://a/b/c/%x1'; $this->assertFalse( OpenId::normalizeUrl($url) ); $url = 'example://a/b/c/%1x'; $this->assertFalse( OpenId::normalizeUrl($url) ); $url = 'eXAMPLE://A/b/c/x%20y'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'example://a/b/c/x%20y', $url ); $url = 'example://host/.a/b/c'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'example://host/.a/b/c', $url ); $url = 'a/b/c'; $this->assertFalse( OpenId::normalizeUrl($url) ); $url = 'example://:80/a/b/c'; $this->assertFalse( OpenId::normalizeUrl($url) ); $url = 'example://host/a/.b/c'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'example://host/a/.b/c', $url ); $url = 'example://host/a/b/.c'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'example://host/a/b/.c', $url ); $url = 'example://host/..a/b/c'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'example://host/..a/b/c', $url ); $url = 'example://host/a/..b/c'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'example://host/a/..b/c', $url ); $url = 'example://host/a/b/..c'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'example://host/a/b/..c', $url ); $url = 'example://host/./b/c'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'example://host/b/c', $url ); $url = 'example://host/a/./c'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'example://host/a/c', $url ); $url = 'example://host/a/b/.'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'example://host/a/b', $url ); $url = 'example://host/a/b/./'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'example://host/a/b/', $url ); $url = 'example://host/../b/c'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'example://host/b/c', $url ); $url = 'example://host/a/../c'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'example://host/c', $url ); $url = 'example://host/a/b/..'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'example://host/a', $url ); $url = 'example://host/a/b/../'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'example://host/a/', $url ); $url = 'example://host/a/b/c/..'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'example://host/a/b', $url ); $url = 'example://host/a/b/c/../..'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'example://host/a', $url ); $url = 'example://host/a/b/c/../../..'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'example://host/', $url ); $url = 'example://host///a///b///c///..///../d'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'example://host/a/d', $url ); $url = 'example://host///a///b///c///.///./d'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'example://host/a/b/c/d', $url ); $url = 'example://host///a///b///c///..///./d'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'example://host/a/b/d', $url ); $url = 'example://host///a///b///c///.///../d'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'example://host/a/b/d', $url ); $url = 'http://example.com'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'http://example.com/', $url ); $url = 'http://example.com/'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'http://example.com/', $url ); $url = 'http://example.com:'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'http://example.com/', $url ); $url = 'http://example.com:80/'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'http://example.com/', $url ); $url = 'https://example.com:443/'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'https://example.com/', $url ); $url = 'http://example.com?'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'http://example.com/?', $url ); $url = 'http://example.com/?'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'http://example.com/?', $url ); $url = 'http://example.com/test.php?Foo=Bar#Baz'; $this->assertTrue( OpenId::normalizeUrl($url) ); $this->assertSame( 'http://example.com/test.php?Foo=Bar', $url ); }
/** * Retrieve consumer's root URL from request query. * Returns URL or false in case of failure * * @param array $params query arguments * @return mixed */ public function getSiteRoot($params) { $version = 1.1; if (isset($params['openid_ns']) && $params['openid_ns'] == OpenId\OpenId::NS_2_0) { $version = 2.0; } if ($version >= 2.0 && isset($params['openid_realm'])) { $root = $params['openid_realm']; } elseif ($version < 2.0 && isset($params['openid_trust_root'])) { $root = $params['openid_trust_root']; } elseif (isset($params['openid_return_to'])) { $root = $params['openid_return_to']; } else { return false; } if (OpenId\OpenId::normalizeUrl($root) && !empty($root)) { return $root; } return false; }