diff options
author | tailor <cygnus@janrain.com> | 2006-08-18 17:23:33 +0000 |
---|---|---|
committer | tailor <cygnus@janrain.com> | 2006-08-18 17:23:33 +0000 |
commit | e864c7aa4f77b774cdc3fe64baf7a1533a4828b8 (patch) | |
tree | 6c1e9af34d180672c81fa9b8279d1a7d5290b52c | |
parent | d3943515a5b13059844b0b23b21dfb2ced50f055 (diff) | |
download | php-openid-e864c7aa4f77b774cdc3fe64baf7a1533a4828b8.zip php-openid-e864c7aa4f77b774cdc3fe64baf7a1533a4828b8.tar.gz php-openid-e864c7aa4f77b774cdc3fe64baf7a1533a4828b8.tar.bz2 |
[project @ Added XRI discovery tests and added canonicalID to OpenID service endpoints]
-rw-r--r-- | Auth/OpenID/Discover.php | 18 | ||||
-rw-r--r-- | Services/Yadis/XRIRes.php | 5 | ||||
-rw-r--r-- | Tests/Auth/OpenID/Discover.php | 74 |
3 files changed, 94 insertions, 3 deletions
diff --git a/Auth/OpenID/Discover.php b/Auth/OpenID/Discover.php index 61ab7f8..16c36a6 100644 --- a/Auth/OpenID/Discover.php +++ b/Auth/OpenID/Discover.php @@ -28,6 +28,7 @@ class Auth_OpenID_ServiceEndpoint { $this->server_url = null; $this->type_uris = array(); $this->delegate = null; + $this->canonicalID = null; $this->used_yadis = false; // whether this came from an XRDS } @@ -119,6 +120,10 @@ function Auth_OpenID_makeOpenIDEndpoints($uri, $endpoints) { $s = array(); + if (!$endpoints) { + return $s; + } + foreach ($endpoints as $service) { $type_uris = $service->getTypes(); $uris = $service->getURIs(); @@ -229,11 +234,18 @@ function Auth_OpenID_discoverWithoutYadis($uri, &$fetcher) function _Auth_OpenID_discoverXRI($iname, &$fetcher) { $services = new Services_Yadis_ProxyResolver($fetcher); - $service_list = $services->query($iname, array(_OPENID_1_0_TYPE, - _OPENID_1_1_TYPE, - _OPENID_1_2_TYPE), + list($canonicalID, $service_list) = $services->query($iname, + array(_OPENID_1_0_TYPE, + _OPENID_1_1_TYPE, + _OPENID_1_2_TYPE), array('filter_MatchesAnyOpenIDType')); + $endpoints = Auth_OpenID_makeOpenIDEndpoints($iname, $service_list); + + for ($i = 0; $i < count($endpoints); $i++) { + $endpoints[$i]->canonicalID = $canonicalID; + } + // FIXME: returned xri should probably be in some normal form return array($iname, $endpoints, null); } diff --git a/Services/Yadis/XRIRes.php b/Services/Yadis/XRIRes.php index 688349c..5db35fc 100644 --- a/Services/Yadis/XRIRes.php +++ b/Services/Yadis/XRIRes.php @@ -51,6 +51,11 @@ class Services_Yadis_ProxyResolver { } $canonicalID = Services_Yadis_getCanonicalID($xri, $xrds); + + if ($canonicalID === false) { + return null; + } + $some_services = $xrds->services($filters); $services = array_merge($services, $some_services); // TODO: diff --git a/Tests/Auth/OpenID/Discover.php b/Tests/Auth/OpenID/Discover.php index 43161a5..22cd434 100644 --- a/Tests/Auth/OpenID/Discover.php +++ b/Tests/Auth/OpenID/Discover.php @@ -5,6 +5,7 @@ require_once 'PHPUnit.php'; require_once 'Auth/OpenID.php'; require_once 'Auth/OpenID/Discover.php'; require_once 'Services/Yadis/Manager.php'; +require_once 'Services/Yadis/Misc.php'; /** * Tests for the core of the PHP Yadis library discovery logic. @@ -171,6 +172,7 @@ $__yadis_2entries = '<?xml version="1.0" encoding="UTF-8"?> xmlns:openid="http://openid.net/xmlns/1.0" > <XRD> + <CanonicalID>=!1000</CanonicalID> <Service priority="10"> <Type>http://openid.net/signon/1.0</Type> @@ -284,6 +286,56 @@ $__openid_and_yadis_html = ' </head><body><p>foo</p></body></html> '; +class _MockFetcherForXRIProxy { + + function _MockFetcherForXRIProxy($documents) + { + $this->documents = $documents; + $this->fetchlog = array(); + } + + function get($url, $headers=null) + { + return $this->fetch($url, $headers); + } + + function post($url, $body) + { + return $this->fetch($url, $body); + } + + function fetch($url, $body=null, $headers=null) + { + $this->fetchlog[] = array($url, $body, $headers); + + $u = parse_url($url); + $proxy_host = $u['host']; + $xri = $u['path']; + $query = $u['query']; + + if ((!$headers) && (!$query)) { + trigger_error('Error in mock XRI fetcher: no headers or query'); + } + + if (_startswith($xri, '/')) { + $xri = substr($xri, 1); + } + + if (array_key_exists($xri, $this->documents)) { + list($ctype, $body) = $this->documents[$xri]; + $status = 200; + } else { + $status = 404; + $ctype = 'text/plain'; + $body = ''; + } + + return new Services_Yadis_HTTPResponse($url, $status, + array('content-type' => $ctype), + $body); + } +} + class Tests_Auth_OpenID_DiscoverSession { function Tests_Auth_OpenID_DiscoverSession() { @@ -542,6 +594,28 @@ class Tests_Auth_OpenID_Discover extends _DiscoveryBase { $this->_notUsedYadis($services[0]); } + + function test_xriDiscovery() + { + global $__yadis_2entries; + + $documents = array( + '=smoker' => array('application/xrds+xml', + $__yadis_2entries) + ); + + $fetcher = new _MockFetcherForXRIProxy($documents); + + list($user_xri, $services) = _Auth_OpenID_discoverXRI('=smoker', + $fetcher); + $this->assertTrue($services); + + $this->assertEquals($services[0]->server_url, + "http://www.myopenid.com/server"); + $this->assertEquals($services[1]->server_url, + "http://www.livejournal.com/openid/server.bml"); + $this->assertEquals($services[0]->canonicalID, "=!1000"); + } } ?>
\ No newline at end of file |