Пример #1
0
 /**
  * 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'];
     } else {
         if ($version < 2.0 && isset($params['openid_trust_root'])) {
             $root = $params['openid_trust_root'];
         } else {
             if (isset($params['openid_return_to'])) {
                 $root = $params['openid_return_to'];
             } else {
                 return false;
             }
         }
     }
     if (OpenID\OpenID::normalizeUrl($root) && !empty($root)) {
         return $root;
     }
     return false;
 }
Пример #2
0
 /**
  * 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);
 }