diff options
-rw-r--r-- | Auth/OpenID/Discover.php | 15 | ||||
-rw-r--r-- | Tests/Auth/OpenID/Discover_OpenID.php | 32 |
2 files changed, 46 insertions, 1 deletions
diff --git a/Auth/OpenID/Discover.php b/Auth/OpenID/Discover.php index 4e8e402..1bdfa26 100644 --- a/Auth/OpenID/Discover.php +++ b/Auth/OpenID/Discover.php @@ -52,7 +52,20 @@ class Auth_OpenID_ServiceEndpoint { if ($this->display_identifier) { return $this->display_identifier; } - return $this->claimed_id; + if (! $this->claimed_id) { + return $this->claimed_id; + } + $parsed = parse_url($this->claimed_id); + $scheme = $parsed['scheme']; + $host = $parsed['host']; + $path = $parsed['path']; + if (array_key_exists('query', $parsed)) { + $query = $parsed['query']; + $no_frag = "$scheme://$host$path?$query"; + } else { + $no_frag = "$scheme://$host$path"; + } + return $no_frag; } function usesExtension($extension_uri) diff --git a/Tests/Auth/OpenID/Discover_OpenID.php b/Tests/Auth/OpenID/Discover_OpenID.php index ccfe61d..a00873f 100644 --- a/Tests/Auth/OpenID/Discover_OpenID.php +++ b/Tests/Auth/OpenID/Discover_OpenID.php @@ -27,6 +27,38 @@ class _SimpleMockFetcher { } } +class Tests_Auth_OpenID_ServiceEndpoint extends PHPUnit_TestCase { + function setUp() { + $this->endpoint = new Auth_OpenID_ServiceEndpoint(); + } + + function test_getDisplayIdentifier_noFragment() { + $urls = array("http://foo.bar.com/something", + "http://foo.bar.com/something?else=what¬hing=0", + "https://smoker.myopenid.com/" + ); + + foreach ($urls as $url) { + $this->endpoint->claimed_id = $url; + $this->assertEquals($url, $this->endpoint->getDisplayIdentifier()); + } + } + + function test_getDisplayIdentifier_withFragment() { + $urls = array("http://foo.bar.com/something#fragged", + "http://foo.bar.com/something?else=what¬hing=0#ow", + "https://smoker.myopenid.com/#myentirelife" + ); + + foreach ($urls as $url) { + $this->endpoint->claimed_id = $url; + $split = explode('#', $url); + $this->assertEquals($split[0], + $this->endpoint->getDisplayIdentifier()); + } + } +} + class Tests_Auth_OpenID_DiscoveryFailure extends PHPUnit_TestCase { function Tests_Auth_OpenID_DiscoveryFailure($responses) |