summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortailor <cygnus@janrain.com>2007-02-14 22:13:18 +0000
committertailor <cygnus@janrain.com>2007-02-14 22:13:18 +0000
commitda2ec5feccef42c0004bfde3a286d00336a9b052 (patch)
tree9892d325b7e5130bfdba709ef2897d39eb5259f0
parent789e9db7ff45a1942ddcef9931f0b3961f3d3a7d (diff)
downloadphp-openid-da2ec5feccef42c0004bfde3a286d00336a9b052.zip
php-openid-da2ec5feccef42c0004bfde3a286d00336a9b052.tar.gz
php-openid-da2ec5feccef42c0004bfde3a286d00336a9b052.tar.bz2
[project @ Refactored and updated discovery tests]
-rw-r--r--Tests/Auth/OpenID/Discover_OpenID.php705
-rw-r--r--Tests/Auth/OpenID/data/test_discover_openid.html11
-rw-r--r--Tests/Auth/OpenID/data/test_discover_openid2.html11
-rw-r--r--Tests/Auth/OpenID/data/test_discover_openid2_xrds.xml12
-rw-r--r--Tests/Auth/OpenID/data/test_discover_openid2_xrds_no_local_id.xml11
-rw-r--r--Tests/Auth/OpenID/data/test_discover_openid_1_and_2.html11
-rw-r--r--Tests/Auth/OpenID/data/test_discover_openid_1_and_2_xrds.xml16
-rw-r--r--Tests/Auth/OpenID/data/test_discover_openid_1_and_2_xrds_bad_delegate.xml17
-rw-r--r--Tests/Auth/OpenID/data/test_discover_openid_and_yadis.html12
-rw-r--r--Tests/Auth/OpenID/data/test_discover_openid_no_delegate.html10
-rw-r--r--Tests/Auth/OpenID/data/test_discover_yadis_0entries.xml12
-rw-r--r--Tests/Auth/OpenID/data/test_discover_yadis_2_bad_local_id.xml15
-rw-r--r--Tests/Auth/OpenID/data/test_discover_yadis_2entries_delegate.xml22
-rw-r--r--Tests/Auth/OpenID/data/test_discover_yadis_2entries_idp.xml21
-rw-r--r--Tests/Auth/OpenID/data/test_discover_yadis_another_delegate.xml14
-rw-r--r--Tests/Auth/OpenID/data/test_discover_yadis_idp.xml12
-rw-r--r--Tests/Auth/OpenID/data/test_discover_yadis_idp_delegate.xml13
-rw-r--r--Tests/Auth/OpenID/data/test_discover_yadis_idp_last.xml17
-rw-r--r--Tests/Auth/OpenID/data/test_discover_yadis_no_delegate.xml11
19 files changed, 535 insertions, 418 deletions
diff --git a/Tests/Auth/OpenID/Discover_OpenID.php b/Tests/Auth/OpenID/Discover_OpenID.php
index bba84b8..a77cbf1 100644
--- a/Tests/Auth/OpenID/Discover_OpenID.php
+++ b/Tests/Auth/OpenID/Discover_OpenID.php
@@ -1,6 +1,7 @@
<?php
require_once 'PHPUnit.php';
+require_once 'TestUtil.php';
require_once 'Auth/OpenID.php';
require_once 'Auth/OpenID/Discover.php';
@@ -155,516 +156,384 @@ class _DiscoveryMockFetcher {
}
}
-define('DISCOVERYBASE_ID_URL', "http://someuser.unittest/");
-
class _DiscoveryBase extends PHPUnit_TestCase {
- var $id_url = DISCOVERYBASE_ID_URL;
- var $documents = array();
-
- function setUp()
- {
- $this->fetcher = new _DiscoveryMockFetcher($this->documents);
- }
-}
-
-$__yadis_2entries = '<?xml version="1.0" encoding="UTF-8"?>
-<xrds:XRDS xmlns:xrds="xri://$xrds"
- xmlns="xri://$xrd*($v*2.0)"
- xmlns:openid="http://openid.net/xmlns/1.0"
- >
- <XRD>
- <CanonicalID>=!1000</CanonicalID>
-
- <Service priority="10">
- <Type>http://openid.net/signon/1.0</Type>
- <URI>http://www.myopenid.com/server</URI>
- <openid:Delegate>http://smoker.myopenid.com/</openid:Delegate>
- </Service>
-
- <Service priority="20">
- <Type>http://openid.net/signon/1.0</Type>
- <URI>http://www.livejournal.com/openid/server.bml</URI>
- <openid:Delegate>http://frank.livejournal.com/</openid:Delegate>
- </Service>
-
- </XRD>
-</xrds:XRDS>
-';
-
-$__yadis_2entries_flipped_priority = '<?xml version="1.0" encoding="UTF-8"?>
-<xrds:XRDS xmlns:xrds="xri://$xrds"
- xmlns="xri://$xrd*($v*2.0)"
- xmlns:openid="http://openid.net/xmlns/1.0"
- >
- <XRD>
-
- <Service priority="20">
- <Type>http://openid.net/signon/1.0</Type>
- <URI>http://www.myopenid.com/server</URI>
- <openid:Delegate>http://smoker.myopenid.com/</openid:Delegate>
- </Service>
-
- <Service priority="10">
- <Type>http://openid.net/signon/1.0</Type>
- <URI>http://www.livejournal.com/openid/server.bml</URI>
- <openid:Delegate>http://frank.livejournal.com/</openid:Delegate>
- </Service>
-
- </XRD>
-</xrds:XRDS>
-';
-
-$__yadis_another = '<?xml version="1.0" encoding="UTF-8"?>
-<xrds:XRDS xmlns:xrds="xri://$xrds"
- xmlns="xri://$xrd*($v*2.0)"
- xmlns:openid="http://openid.net/xmlns/1.0"
- >
- <XRD>
-
- <Service priority="10">
- <Type>http://openid.net/signon/1.0</Type>
- <URI>http://vroom.unittest/server</URI>
- <openid:Delegate>http://smoker.myopenid.com/</openid:Delegate>
- </Service>
- </XRD>
-</xrds:XRDS>
-';
-
-$__yadis_0entries = '<?xml version="1.0" encoding="UTF-8"?>
-<xrds:XRDS xmlns:xrds="xri://$xrds"
- xmlns="xri://$xrd*($v*2.0)"
- xmlns:openid="http://openid.net/xmlns/1.0"
- >
- <XRD>
- <Service >
- <Type>http://is-not-openid.unittest/</Type>
- <URI>http://noffing.unittest./</URI>
- </Service>
- </XRD>
-</xrds:XRDS>
-';
-
-$__yadis_no_delegate = '<?xml version="1.0" encoding="UTF-8"?>
-<xrds:XRDS xmlns:xrds="xri://$xrds"
- xmlns="xri://$xrd*($v*2.0)"
- >
- <XRD>
- <Service priority="10">
- <Type>http://openid.net/signon/1.0</Type>
- <URI>http://www.myopenid.com/server</URI>
- </Service>
- </XRD>
-</xrds:XRDS>
-';
-
-$__openid_html = '
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html>
- <head>
- <title>Identity Page for Smoker</title>
-<link rel="openid.server" href="http://www.myopenid.com/server" />
-<link rel="openid.delegate" href="http://smoker.myopenid.com/" />
- </head><body><p>foo</p></body></html>
-';
-
-$__openid_html_no_delegate = '
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html>
- <head>
- <title>Identity Page for Smoker</title>
-<link rel="openid.server" href="http://www.myopenid.com/server" />
- </head><body><p>foo</p></body></html>
-';
-
-$__openid_and_yadis_html = '
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html>
- <head>
- <title>Identity Page for Smoker</title>
-<meta http-equiv="X-XRDS-Location" content="http://someuser.unittest/xrds" />
-<link rel="openid.server" href="http://www.myopenid.com/server" />
-<link rel="openid.delegate" href="http://smoker.myopenid.com/" />
- </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 (Services_Yadis_startswith($xri, '/')) {
- $xri = substr($xri, 1);
+ var $id_url = "http://someuser.unittest/";
+ var $fetcherClass = '_DiscoveryMockFetcher';
+
+ function _checkService($s,
+ $server_url,
+ $claimed_id=null,
+ $local_id=null,
+ $canonical_id=null,
+ $types=null,
+ $used_yadis=false)
+ {
+ $this->assertEquals($server_url, $s->server_url);
+ if ($types == array('2.0 OP')) {
+ $this->assertFalse($claimed_id);
+ $this->assertFalse($local_id);
+ $this->assertFalse($s->claimed_id);
+ $this->assertFalse($s->local_id);
+ $this->assertFalse($s->getLocalID());
+ $this->assertFalse($s->compatibilityMode());
+ $this->assertTrue($s->isOPIdentifier());
+ $this->assertEquals($s->preferredNamespace(),
+ Auth_OpenID_TYPE_2_0);
+ } else {
+ $this->assertEquals($claimed_id, $s->claimed_id);
+ $this->assertEquals($local_id, $s->getLocalID());
}
- if (array_key_exists($xri, $this->documents)) {
- list($ctype, $body) = $this->documents[$xri];
- $status = 200;
+ if ($used_yadis) {
+ $this->assertTrue($s->used_yadis, "Expected to use Yadis");
} else {
- $status = 404;
- $ctype = 'text/plain';
- $body = '';
+ $this->assertFalse($s->used_yadis,
+ "Expected to use old-style discovery");
}
- return new Services_Yadis_HTTPResponse($url, $status,
- array('content-type' => $ctype),
- $body);
- }
-}
+ $openid_types = array(
+ '1.1' => Auth_OpenID_TYPE_1_1,
+ '1.0' => Auth_OpenID_TYPE_1_0,
+ '2.0' => Auth_OpenID_TYPE_2_0,
+ '2.0 OP' => Auth_OpenID_TYPE_2_0_IDP);
-class Tests_Auth_OpenID_DiscoverSession {
- function Tests_Auth_OpenID_DiscoverSession()
- {
- $this->data = array();
- }
-
- function set($name, $value)
- {
- $this->data[$name] = $value;
- }
-
- function get($name, $default=null)
- {
- if (array_key_exists($name, $this->data)) {
- return $this->data[$name];
- } else {
- return $default;
+ $type_uris = array();
+ foreach ($types as $t) {
+ $type_uris[] = $openid_types[$t];
}
+
+ $this->assertEquals($type_uris, $s->type_uris);
+ $this->assertEquals($canonical_id, $s->canonicalID);
}
- function del($name)
+ function setUp()
{
- unset($this->data[$name]);
+ $cls = $this->fetcherClass;
+ // D is for Dumb.
+ $d = array();
+ $this->fetcher = new $cls($d);
}
}
-$__Tests_BOGUS_SERVICE = new Auth_OpenID_ServiceEndpoint();
-$__Tests_BOGUS_SERVICE->claimed_id = "=really.bogus.endpoint";
-
-function __serviceCheck_discover_cb($url, $fetcher)
-{
- global $__Tests_BOGUS_SERVICE;
- return array($url, array($__Tests_BOGUS_SERVICE));
-}
-
class Tests_Auth_OpenID_Discover_OpenID extends _DiscoveryBase {
- function _usedYadis($service)
+ function _discover($content_type, $data,
+ $expected_services, $expected_id=null)
{
- $this->assertTrue($service->used_yadis,
- "Expected to use Yadis");
- }
+ if ($expected_id === null) {
+ $expected_id = $this->id_url;
+ }
- function _notUsedYadis($service)
- {
- $this->assertFalse($service->used_yadis,
- "Expected to use old-style discovery");
+ $this->fetcher->documents[$this->id_url] = array($content_type, $data);
+ list($id_url, $services) = Auth_OpenID_discover($this->id_url,
+ $this->fetcher);
+ $this->assertEquals($expected_services, count($services));
+ $this->assertEquals($expected_id, $id_url);
+ return $services;
}
function test_404()
{
- $result = Auth_OpenID_discover($this->id_url . '/404',
- $this->fetcher);
-
- list($id_url, $svclist) = $result;
-
- $this->assertTrue($svclist == array());
- $this->assertTrue($id_url == $this->id_url . '/404');
+ list($url, $services) = Auth_OpenID_discover($this->id_url . '/404',
+ $this->fetcher);
+ $this->assertTrue($services == array());
}
- function test_noYadis()
+ function test_noOpenID()
{
- global $__openid_html;
-
- $this->documents[$this->id_url] = array('text/html', $__openid_html);
-
- list($id_url, $services) =
- Auth_OpenID_discover($this->id_url,
- $this->fetcher);
+ $services = $this->_discover('text/plain',
+ "junk",
+ 0);
- $this->assertEquals($this->id_url, $id_url);
+ $services = $this->_discover(
+ 'text/html',
+ Tests_Auth_OpenID_readdata('test_discover_openid_no_delegate.html'),
+ 1);
- $this->assertEquals(count($services), 1,
- "More than one service");
+ $this->_checkService($services[0],
+ "http://www.myopenid.com/server",
+ $this->id_url,
+ $this->id_url,
+ null,
+ array('1.1'),
+ false);
+ }
- $this->assertEquals($services[0]->server_url,
- "http://www.myopenid.com/server");
+ function test_html1()
+ {
+ $services = $this->_discover('text/html',
+ Tests_Auth_OpenID_readdata('test_discover_openid.html'),
+ 1);
- $this->assertEquals($services[0]->local_id,
- "http://smoker.myopenid.com/");
- $this->assertEquals($services[0]->claimed_id, $this->id_url);
- $this->_notUsedYadis($services[0]);
+ $this->_checkService($services[0],
+ "http://www.myopenid.com/server",
+ $this->id_url,
+ 'http://smoker.myopenid.com/',
+ null,
+ array('1.1'),
+ false);
}
- function test_managerServices()
+ function test_html2()
{
- global $__yadis_2entries_flipped_priority;
+ $services = $this->_discover('text/html',
+ Tests_Auth_OpenID_readdata('test_discover_openid2.html'),
+ 1);
- $url = "http://bogus.xxx/";
- $sess = new Tests_Auth_OpenID_DiscoverSession();
- $m = new Services_Yadis_Discovery($sess, $url);
+ $this->_checkService($services[0],
+ "http://www.myopenid.com/server",
+ $this->id_url,
+ 'http://smoker.myopenid.com/',
+ null,
+ array('2.0'),
+ false);
+ }
- $documents = array(
- $url => array("application/xrds+xml",
- $__yadis_2entries_flipped_priority)
- );
+ function test_html1And2()
+ {
+ $services = $this->_discover('text/html',
+ Tests_Auth_OpenID_readdata('test_discover_openid_1_and_2.html'),
+ 2);
- $fetcher = new _DiscoveryMockFetcher($documents);
+ $types = array('2.0', '1.1');
- $expected = array("http://frank.livejournal.com/",
- "http://smoker.myopenid.com/");
+ for ($i = 0; $i < count($types); $i++) {
+ $t = $types[$i];
+ $s = $services[$i];
- foreach ($expected as $openid) {
- $s = $m->getNextService('Auth_OpenID_discover',
- $fetcher);
- $this->assertEquals($s->local_id, $openid);
+ $this->_checkService(
+ $s,
+ "http://www.myopenid.com/server",
+ $this->id_url,
+ 'http://smoker.myopenid.com/',
+ null,
+ array($t),
+ false);
}
}
- function test_serviceCheck()
+ function test_yadisEmpty()
{
- global $__Tests_BOGUS_SERVICE;
-
- $url = "http://bogus.xxx/";
- $sess =& new Tests_Auth_OpenID_DiscoverSession();
- $disco =& new Services_Yadis_Discovery($sess, $url);
-
- # Set an empty manager to be sure it gets blown away
- $manager =& new Services_Yadis_Manager($url, null, array(),
- $disco->getSessionKey());
-
- $loader =& new Services_Yadis_ManagerLoader();
- $disco->session->set($disco->session_key,
- serialize($loader->toSession($manager)));
-
- $docs = array();
- $fetcher =& new _DiscoveryMockFetcher($docs);
-
- $result = $disco->getNextService('__serviceCheck_discover_cb', $fetcher);
-
- $newMan = $disco->getManager();
-
- $currentService = $newMan->_current;
- $this->assertEquals($currentService->claimed_id,
- $__Tests_BOGUS_SERVICE->claimed_id);
+ $services = $this->_discover('application/xrds+xml',
+ Tests_Auth_OpenID_readdata('test_discover_yadis_0entries.xml'),
+ 0);
}
- function test_noOpenID()
+ function test_htmlEmptyYadis()
{
- $this->fetcher->documents = array(
- $this->id_url => array('text/plain', "junk"));
+ // HTML document has discovery information, but points to an
+ // empty Yadis document.
- list($id_url, $services) = Auth_OpenID_discover($this->id_url,
- $this->fetcher);
+ // The XRDS document pointed to by "openid_and_yadis.html"
+ $this->fetcher->documents[$this->id_url . 'xrds'] =
+ array('application/xrds+xml',
+ Tests_Auth_OpenID_readdata('test_discover_yadis_0entries.xml'));
- $this->assertEquals($this->id_url, $id_url);
+ $services = $this->_discover('text/html',
+ Tests_Auth_OpenID_readdata('test_discover_openid_and_yadis.html'),
+ 1);
- $this->assertFalse(count($services) > 0);
+ $this->_checkService($services[0],
+ "http://www.myopenid.com/server",
+ $this->id_url,
+ 'http://smoker.myopenid.com/',
+ null,
+ array('1.1'),
+ false);
}
- function test_yadis()
+ function test_yadis1NoDelegate()
{
- global $__yadis_2entries;
-
- $this->fetcher->documents = array(
- DISCOVERYBASE_ID_URL => array('application/xrds+xml',
- $__yadis_2entries));
-
- list($id_url, $services) = Auth_OpenID_discover($this->id_url,
- $this->fetcher);
-
- $this->assertEquals($this->id_url, $id_url);
-
- $this->assertEquals(count($services), 2,
- "Not 2 services");
-
- $this->assertEquals($services[0]->server_url,
- "http://www.myopenid.com/server");
-
- $this->_usedYadis($services[0]);
-
- $this->assertEquals($services[1]->server_url,
- "http://www.livejournal.com/openid/server.bml");
+ $services = $this->_discover('application/xrds+xml',
+ Tests_Auth_OpenID_readdata('test_discover_yadis_no_delegate.xml'),
+ 1);
- $this->_usedYadis($services[1]);
+ $this->_checkService(
+ $services[0],
+ "http://www.myopenid.com/server",
+ $this->id_url,
+ $this->id_url,
+ null,
+ array('1.0'),
+ true);
}
- function test_redirect()
+ function test_yadis2NoLocalID()
{
- global $__openid_html;
-
- $expected_final_url = "http://elsewhere.unittest/";
-
- $this->fetcher->redirect = $expected_final_url;
- $this->fetcher->documents = array(
- $this->id_url => array('text/html', $__openid_html));
-
- list($id_url, $services) = Auth_OpenID_discover($this->id_url,
- $this->fetcher);
-
- $this->assertEquals($expected_final_url, $id_url);
-
- $this->assertEquals(count($services), 1,
- "More than one service");
+ $services = $this->_discover('application/xrds+xml',
+ Tests_Auth_OpenID_readdata('test_discover_openid2_xrds_no_local_id.xml'),
+ 1);
- $this->assertEquals($services[0]->server_url,
- "http://www.myopenid.com/server");
-
- $this->assertEquals($services[0]->local_id,
- "http://smoker.myopenid.com/");
-
- $this->assertEquals($services[0]->claimed_id,
- $expected_final_url);
-
- $this->_notUsedYadis($services[0]);
+ $this->_checkService(
+ $services[0],
+ "http://www.myopenid.com/server",
+ $this->id_url,
+ $this->id_url,
+ null,
+ array('2.0'),
+ true);
}
- function test_emptyList()
+ function test_yadis2()
{
- global $__yadis_0entries;
-
- $this->fetcher->documents = array(
- $this->id_url =>
- array('application/xrds+xml', $__yadis_0entries));
-
- list($id_url, $services) = Auth_OpenID_discover($this->id_url,
- $this->fetcher);
+ $services = $this->_discover('application/xrds+xml',
+ Tests_Auth_OpenID_readdata('test_discover_openid2_xrds.xml'),
+ 1);
- $this->assertEquals($this->id_url, $id_url);
-
- $this->assertTrue(count($services) == 0);
+ $this->_checkService($services[0],
+ "http://www.myopenid.com/server",
+ $this->id_url,
+ 'http://smoker.myopenid.com/',
+ null,
+ array('2.0'),
+ true);
}
- function test_emptyListWithLegacy()
+ function test_yadis2OP()
{
- global $__openid_and_yadis_html,
- $__yadis_0entries;
-
- $this->fetcher->documents = array(
- $this->id_url => array('text/html', $__openid_and_yadis_html),
- $this->id_url . 'xrds' => array('application/xrds+xml', $__yadis_0entries));
-
- list($id_url, $services) = Auth_OpenID_discover($this->id_url,
- $this->fetcher);
-
- $this->assertEquals($this->id_url, $id_url);
-
- $this->assertEquals(count($services), 1,
- "Not one service");
+ $services = $this->_discover('application/xrds+xml',
+ Tests_Auth_OpenID_readdata('test_discover_yadis_idp.xml'),
+ 1);
- $this->assertEquals($services[0]->server_url,
- "http://www.myopenid.com/server");
-
- $this->assertEquals($services[0]->claimed_id, $this->id_url);
-
- $this->_notUsedYadis($services[0]);
+ $this->_checkService($services[0],
+ "http://www.myopenid.com/server",
+ null,
+ null,
+ null,
+ array('2.0 OP'),
+ true);
}
- function test_yadisNoDelegate()
+ function test_yadis2OPDelegate()
{
- global $__yadis_no_delegate;
+ // The delegate tag isn't meaningful for OP entries.
+ $services = $this->_discover('application/xrds+xml',
+ Tests_Auth_OpenID_readdata('test_discover_yadis_idp_delegate.xml'),
+ 1);
- $this->fetcher->documents = array(
- $this->id_url => array('application/xrds+xml', $__yadis_no_delegate));
+ $this->_checkService(
+ $services[0],
+ "http://www.myopenid.com/server",
+ null, null, null,
+ array('2.0 OP'),
+ true);
+ }
- list($id_url, $services) = Auth_OpenID_discover($this->id_url,
- $this->fetcher);
+ function test_yadis2BadLocalID()
+ {
+ $services = $this->_discover('application/xrds+xml',
+ Tests_Auth_OpenID_readdata('test_discover_yadis_2_bad_local_id.xml'),
+ 0);
+ }
- $this->assertEquals($this->id_url, $id_url);
+ function test_yadis1And2()
+ {
+ $services = $this->_discover('application/xrds+xml',
+ Tests_Auth_OpenID_readdata('test_discover_openid_1_and_2_xrds.xml'),
+ 1);
- $this->assertEquals(count($services), 1,
- "Not 1 service");
+ $this->_checkService(
+ $services[0],
+ "http://www.myopenid.com/server",
+ $this->id_url,
+ 'http://smoker.myopenid.com/',
+ null,
+ array('2.0', '1.1'),
+ true);
+ }
- $this->assertEquals($services[0]->server_url,
- "http://www.myopenid.com/server");
+ function test_yadis1And2BadLocalID()
+ {
+ $services = $this->_discover('application/xrds+xml',
+ Tests_Auth_OpenID_readdata('test_discover_openid_1_and_2_xrds_bad_delegate.xml'),
+ 0);
+ }
+}
- $this->assertEquals($services[0]->local_id, null,
- 'Delegate should be null');
+class _MockFetcherForXRIProxy {
- $this->_usedYadis($services[0]);
+ function _MockFetcherForXRIProxy($documents)
+ {
+ $this->documents = $documents;
+ $this->fetchlog = array();
}
- function test_openidNoDelegate()
+ function get($url, $headers=null)
{
- global $__openid_html_no_delegate;
+ return $this->fetch($url, $headers);
+ }
- $this->fetcher->documents = array(
- $this->id_url => array('text/html',
- $__openid_html_no_delegate));
+ function post($url, $body)
+ {
+ return $this->fetch($url, $body);
+ }
- list($id_url, $services) = Auth_OpenID_discover($this->id_url,
- $this->fetcher);
+ function fetch($url, $body=null, $headers=null)
+ {
+ $this->fetchlog[] = array($url, $body, $headers);
- $this->assertEquals($this->id_url, $id_url);
+ $u = parse_url($url);
+ $proxy_host = $u['host'];
+ $xri = $u['path'];
+ $query = $u['query'];
- $this->assertEquals($services[0]->server_url,
- "http://www.myopenid.com/server");
+ if ((!$headers) && (!$query)) {
+ trigger_error('Error in mock XRI fetcher: no headers or query');
+ }
- $this->assertEquals($services[0]->claimed_id, $this->id_url);
+ if (Services_Yadis_startswith($xri, '/')) {
+ $xri = substr($xri, 1);
+ }
- $this->assertEquals($services[0]->local_id, null,
- 'Delegate should be null');
+ if (array_key_exists($xri, $this->documents)) {
+ list($ctype, $body) = $this->documents[$xri];
+ $status = 200;
+ } else {
+ $status = 404;
+ $ctype = 'text/plain';
+ $body = '';
+ }
- $this->_notUsedYadis($services[0]);
+ return new Services_Yadis_HTTPResponse($url, $status,
+ array('content-type' => $ctype),
+ $body);
}
+}
- function test_xriDiscovery()
+class Tests_Auth_OpenID_DiscoverSession {
+ function Tests_Auth_OpenID_DiscoverSession()
{
- 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->data = array();
+ }
- $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, Services_Yadis_XRI("=!1000"));
+ function set($name, $value)
+ {
+ $this->data[$name] = $value;
}
- function test_useCanonicalID()
+ function get($name, $default=null)
{
- // When there is no delegate, the CanonicalID should be used
- // with XRI.
+ if (array_key_exists($name, $this->data)) {
+ return $this->data[$name];
+ } else {
+ return $default;
+ }
+ }
- $endpoint = new Auth_OpenID_ServiceEndpoint();
- $endpoint->claimed_id = "=example";
- $endpoint->canonicalID = Services_Yadis_XRI("=!1000");
- $this->assertEquals($endpoint->getLocalID(), Services_Yadis_XRI("=!1000"));
+ function del($name)
+ {
+ unset($this->data[$name]);
}
}
+$__Tests_BOGUS_SERVICE = new Auth_OpenID_ServiceEndpoint();
+$__Tests_BOGUS_SERVICE->claimed_id = "=really.bogus.endpoint";
+
+function __serviceCheck_discover_cb($url, $fetcher)
+{
+ global $__Tests_BOGUS_SERVICE;
+ return array($url, array($__Tests_BOGUS_SERVICE));
+}
+
+
?> \ No newline at end of file
diff --git a/Tests/Auth/OpenID/data/test_discover_openid.html b/Tests/Auth/OpenID/data/test_discover_openid.html
new file mode 100644
index 0000000..1a57d44
--- /dev/null
+++ b/Tests/Auth/OpenID/data/test_discover_openid.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html>
+ <head>
+ <title>Identity Page for Smoker</title>
+ <link rel="openid.server" href="http://www.myopenid.com/server" />
+ <link rel="openid.delegate" href="http://smoker.myopenid.com/" />
+ </head>
+ <body>
+ <p>foo</p>
+ </body>
+</html>
diff --git a/Tests/Auth/OpenID/data/test_discover_openid2.html b/Tests/Auth/OpenID/data/test_discover_openid2.html
new file mode 100644
index 0000000..a74c042
--- /dev/null
+++ b/Tests/Auth/OpenID/data/test_discover_openid2.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html>
+ <head>
+ <title>Identity Page for Smoker</title>
+ <link rel="openid2.provider" href="http://www.myopenid.com/server" />
+ <link rel="openid2.local_id" href="http://smoker.myopenid.com/" />
+ </head>
+ <body>
+ <p>foo</p>
+ </body>
+</html>
diff --git a/Tests/Auth/OpenID/data/test_discover_openid2_xrds.xml b/Tests/Auth/OpenID/data/test_discover_openid2_xrds.xml
new file mode 100644
index 0000000..25ed581
--- /dev/null
+++ b/Tests/Auth/OpenID/data/test_discover_openid2_xrds.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xrds:XRDS xmlns:xrds="xri://$xrds"
+ xmlns="xri://$xrd*($v*2.0)"
+ >
+ <XRD>
+ <Service priority="10">
+ <Type>http://openid.net/signon/2.0</Type>
+ <URI>http://www.myopenid.com/server</URI>
+ <LocalID>http://smoker.myopenid.com/</LocalID>
+ </Service>
+ </XRD>
+</xrds:XRDS>
diff --git a/Tests/Auth/OpenID/data/test_discover_openid2_xrds_no_local_id.xml b/Tests/Auth/OpenID/data/test_discover_openid2_xrds_no_local_id.xml
new file mode 100644
index 0000000..acd08ef
--- /dev/null
+++ b/Tests/Auth/OpenID/data/test_discover_openid2_xrds_no_local_id.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xrds:XRDS xmlns:xrds="xri://$xrds"
+ xmlns="xri://$xrd*($v*2.0)"
+ >
+ <XRD>
+ <Service priority="10">
+ <Type>http://openid.net/signon/2.0</Type>
+ <URI>http://www.myopenid.com/server</URI>
+ </Service>
+ </XRD>
+</xrds:XRDS>
diff --git a/Tests/Auth/OpenID/data/test_discover_openid_1_and_2.html b/Tests/Auth/OpenID/data/test_discover_openid_1_and_2.html
new file mode 100644
index 0000000..5e58128
--- /dev/null
+++ b/Tests/Auth/OpenID/data/test_discover_openid_1_and_2.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html>
+ <head>
+ <title>Identity Page for Smoker</title>
+ <link rel="openid2.provider openid.server" href="http://www.myopenid.com/server" />
+ <link rel="openid2.local_id openid.delegate" href="http://smoker.myopenid.com/" />
+ </head>
+ <body>
+ <p>foo</p>
+ </body>
+</html>
diff --git a/Tests/Auth/OpenID/data/test_discover_openid_1_and_2_xrds.xml b/Tests/Auth/OpenID/data/test_discover_openid_1_and_2_xrds.xml
new file mode 100644
index 0000000..e8a1f5b
--- /dev/null
+++ b/Tests/Auth/OpenID/data/test_discover_openid_1_and_2_xrds.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xrds:XRDS xmlns:xrds="xri://$xrds"
+ xmlns="xri://$xrd*($v*2.0)"
+ xmlns:openid="http://openid.net/xmlns/1.0"
+ >
+ <XRD>
+
+ <Service priority="10">
+ <Type>http://openid.net/signon/2.0</Type>
+ <Type>http://openid.net/signon/1.1</Type>
+ <URI>http://www.myopenid.com/server</URI>
+ <LocalID>http://smoker.myopenid.com/</LocalID>
+ <openid:Delegate>http://smoker.myopenid.com/</openid:Delegate>
+ </Service>
+ </XRD>
+</xrds:XRDS>
diff --git a/Tests/Auth/OpenID/data/test_discover_openid_1_and_2_xrds_bad_delegate.xml b/Tests/Auth/OpenID/data/test_discover_openid_1_and_2_xrds_bad_delegate.xml
new file mode 100644
index 0000000..019cd65
--- /dev/null
+++ b/Tests/Auth/OpenID/data/test_discover_openid_1_and_2_xrds_bad_delegate.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xrds:XRDS xmlns:xrds="xri://$xrds"
+ xmlns="xri://$xrd*($v*2.0)"
+ xmlns:openid="http://openid.net/xmlns/1.0"
+ >
+ <XRD>
+
+ <Service priority="10">
+ <Type>http://openid.net/signon/2.0</Type>
+ <Type>http://openid.net/signon/1.0</Type>
+ <Type>http://openid.net/signon/1.1</Type>
+ <URI>http://www.myopenid.com/server</URI>
+ <LocalID>http://smoker.myopenid.com/</LocalID>
+ <openid:Delegate>http://localid.mismatch.invalid/</openid:Delegate>
+ </Service>
+ </XRD>
+</xrds:XRDS>
diff --git a/Tests/Auth/OpenID/data/test_discover_openid_and_yadis.html b/Tests/Auth/OpenID/data/test_discover_openid_and_yadis.html
new file mode 100644
index 0000000..3befa6f
--- /dev/null
+++ b/Tests/Auth/OpenID/data/test_discover_openid_and_yadis.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html>
+ <head>
+ <title>Identity Page for Smoker</title>
+ <meta http-equiv="X-XRDS-Location" content="http://someuser.unittest/xrds" />
+ <link rel="openid.server" href="http://www.myopenid.com/server" />
+ <link rel="openid.delegate" href="http://smoker.myopenid.com/" />
+ </head>
+ <body>
+ <p>foo</p>
+ </body>
+</html>
diff --git a/Tests/Auth/OpenID/data/test_discover_openid_no_delegate.html b/Tests/Auth/OpenID/data/test_discover_openid_no_delegate.html
new file mode 100644
index 0000000..f5180b3
--- /dev/null
+++ b/Tests/Auth/OpenID/data/test_discover_openid_no_delegate.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html>
+ <head>
+ <title>Identity Page for Smoker</title>
+ <link rel="openid.server" href="http://www.myopenid.com/server" />
+ </head>
+ <body>
+ <p>foo</p>
+ </body>
+</html>
diff --git a/Tests/Auth/OpenID/data/test_discover_yadis_0entries.xml b/Tests/Auth/OpenID/data/test_discover_yadis_0entries.xml
new file mode 100644
index 0000000..f161a0b
--- /dev/null
+++ b/Tests/Auth/OpenID/data/test_discover_yadis_0entries.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xrds:XRDS xmlns:xrds="xri://$xrds"
+ xmlns="xri://$xrd*($v*2.0)"
+ xmlns:openid="http://openid.net/xmlns/1.0"
+ >
+ <XRD>
+ <Service >
+ <Type>http://is-not-openid.unittest/</Type>
+ <URI>http://noffing.unittest./</URI>
+ </Service>
+ </XRD>
+</xrds:XRDS>
diff --git a/Tests/Auth/OpenID/data/test_discover_yadis_2_bad_local_id.xml b/Tests/Auth/OpenID/data/test_discover_yadis_2_bad_local_id.xml
new file mode 100644
index 0000000..b72727c
--- /dev/null
+++ b/Tests/Auth/OpenID/data/test_discover_yadis_2_bad_local_id.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xrds:XRDS xmlns:xrds="xri://$xrds"
+ xmlns="xri://$xrd*($v*2.0)"
+ xmlns:openid="http://openid.net/xmlns/1.0"
+ >
+ <XRD>
+
+ <Service priority="10">
+ <Type>http://openid.net/signon/2.0</Type>
+ <URI>http://www.myopenid.com/server</URI>
+ <LocalID>http://smoker.myopenid.com/</LocalID>
+ <LocalID>http://localid.mismatch.invalid/</LocalID>
+ </Service>
+ </XRD>
+</xrds:XRDS>
diff --git a/Tests/Auth/OpenID/data/test_discover_yadis_2entries_delegate.xml b/Tests/Auth/OpenID/data/test_discover_yadis_2entries_delegate.xml
new file mode 100644
index 0000000..372955b
--- /dev/null
+++ b/Tests/Auth/OpenID/data/test_discover_yadis_2entries_delegate.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xrds:XRDS xmlns:xrds="xri://$xrds"
+ xmlns="xri://$xrd*($v*2.0)"
+ xmlns:openid="http://openid.net/xmlns/1.0"
+ >
+ <XRD>
+ <CanonicalID>=!1000</CanonicalID>
+
+ <Service priority="10">
+ <Type>http://openid.net/signon/1.0</Type>
+ <URI>http://www.myopenid.com/server</URI>
+ <openid:Delegate>http://smoker.myopenid.com/</openid:Delegate>
+ </Service>
+
+ <Service priority="20">
+ <Type>http://openid.net/signon/1.0</Type>
+ <URI>http://www.livejournal.com/openid/server.bml</URI>
+ <openid:Delegate>http://frank.livejournal.com/</openid:Delegate>
+ </Service>
+
+ </XRD>
+</xrds:XRDS>
diff --git a/Tests/Auth/OpenID/data/test_discover_yadis_2entries_idp.xml b/Tests/Auth/OpenID/data/test_discover_yadis_2entries_idp.xml
new file mode 100644
index 0000000..f1714cc
--- /dev/null
+++ b/Tests/Auth/OpenID/data/test_discover_yadis_2entries_idp.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xrds:XRDS xmlns:xrds="xri://$xrds"
+ xmlns="xri://$xrd*($v*2.0)"
+ xmlns:openid="http://openid.net/xmlns/1.0"
+ >
+ <XRD>
+ <CanonicalID>=!1000</CanonicalID>
+
+ <Service priority="10">
+ <Type>http://openid.net/signon/2.0</Type>
+ <URI>http://www.myopenid.com/server</URI>
+ <openid:LocalID>http://smoker.myopenid.com/</openid:LocalID>
+ </Service>
+
+ <Service priority="20">
+ <Type>http://openid.net/server/2.0</Type>
+ <URI>http://www.livejournal.com/openid/server.bml</URI>
+ </Service>
+
+ </XRD>
+</xrds:XRDS>
diff --git a/Tests/Auth/OpenID/data/test_discover_yadis_another_delegate.xml b/Tests/Auth/OpenID/data/test_discover_yadis_another_delegate.xml
new file mode 100644
index 0000000..2f3b9af
--- /dev/null
+++ b/Tests/Auth/OpenID/data/test_discover_yadis_another_delegate.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xrds:XRDS xmlns:xrds="xri://$xrds"
+ xmlns="xri://$xrd*($v*2.0)"
+ xmlns:openid="http://openid.net/xmlns/1.0"
+ >
+ <XRD>
+
+ <Service priority="10">
+ <Type>http://openid.net/signon/1.0</Type>
+ <URI>http://vroom.unittest/server</URI>
+ <openid:Delegate>http://smoker.myopenid.com/</openid:Delegate>
+ </Service>
+ </XRD>
+</xrds:XRDS>
diff --git a/Tests/Auth/OpenID/data/test_discover_yadis_idp.xml b/Tests/Auth/OpenID/data/test_discover_yadis_idp.xml
new file mode 100644
index 0000000..3d7ed98
--- /dev/null
+++ b/Tests/Auth/OpenID/data/test_discover_yadis_idp.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xrds:XRDS xmlns:xrds="xri://$xrds"
+ xmlns="xri://$xrd*($v*2.0)"
+ xmlns:openid="http://openid.net/xmlns/1.0"
+ >
+ <XRD>
+ <Service priority="10">
+ <Type>http://openid.net/server/2.0</Type>
+ <URI>http://www.myopenid.com/server</URI>
+ </Service>
+ </XRD>
+</xrds:XRDS>
diff --git a/Tests/Auth/OpenID/data/test_discover_yadis_idp_delegate.xml b/Tests/Auth/OpenID/data/test_discover_yadis_idp_delegate.xml
new file mode 100644
index 0000000..f94c0df
--- /dev/null
+++ b/Tests/Auth/OpenID/data/test_discover_yadis_idp_delegate.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xrds:XRDS xmlns:xrds="xri://$xrds"
+ xmlns="xri://$xrd*($v*2.0)"
+ xmlns:openid="http://openid.net/xmlns/1.0"
+ >
+ <XRD>
+ <Service>
+ <Type>http://openid.net/server/2.0</Type>
+ <URI>http://www.myopenid.com/server</URI>
+ <openid:Delegate>http://smoker.myopenid.com/</openid:Delegate>
+ </Service>
+ </XRD>
+</xrds:XRDS>
diff --git a/Tests/Auth/OpenID/data/test_discover_yadis_idp_last.xml b/Tests/Auth/OpenID/data/test_discover_yadis_idp_last.xml
new file mode 100644
index 0000000..20d3a19
--- /dev/null
+++ b/Tests/Auth/OpenID/data/test_discover_yadis_idp_last.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xrds:XRDS xmlns:xrds="xri://$xrds"
+ xmlns="xri://$xrd*($v*2.0)"
+ xmlns:openid="http://openid.net/xmlns/1.0"
+ >
+ <XRD>
+ <Service priority="10">
+ <Type>http://openid.net/signon/2.0</Type>
+ <URI>http://www.myopenid.com/server2_0</URI>
+ </Service>
+
+ <Service priority="20">
+ <Type>http://openid.net/server/2.0</Type>
+ <URI>http://www.myopenid.com/server_id</URI>
+ </Service>
+ </XRD>
+</xrds:XRDS>
diff --git a/Tests/Auth/OpenID/data/test_discover_yadis_no_delegate.xml b/Tests/Auth/OpenID/data/test_discover_yadis_no_delegate.xml
new file mode 100644
index 0000000..fbd6734
--- /dev/null
+++ b/Tests/Auth/OpenID/data/test_discover_yadis_no_delegate.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xrds:XRDS xmlns:xrds="xri://$xrds"
+ xmlns="xri://$xrd*($v*2.0)"
+ >
+ <XRD>
+ <Service priority="10">
+ <Type>http://openid.net/signon/1.0</Type>
+ <URI>http://www.myopenid.com/server</URI>
+ </Service>
+ </XRD>
+</xrds:XRDS>