summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortailor <cygnus@janrain.com>2007-02-09 00:37:09 +0000
committertailor <cygnus@janrain.com>2007-02-09 00:37:09 +0000
commitafa11e752d2215ed4a85b06b0e61677a6ca5edb5 (patch)
tree0bd51b83922d5a8d02cc9114498caf7b917fc8fe
parentabc240e35e4620e57a020fc1a26110e5c52d95e0 (diff)
downloadphp-openid-afa11e752d2215ed4a85b06b0e61677a6ca5edb5.zip
php-openid-afa11e752d2215ed4a85b06b0e61677a6ca5edb5.tar.gz
php-openid-afa11e752d2215ed4a85b06b0e61677a6ca5edb5.tar.bz2
[project @ Update tests and stub discovery object creation]
-rw-r--r--Auth/OpenID/Consumer.php19
-rw-r--r--Tests/Auth/OpenID/Consumer.php73
2 files changed, 36 insertions, 56 deletions
diff --git a/Auth/OpenID/Consumer.php b/Auth/OpenID/Consumer.php
index 84985a9..d2d1fa0 100644
--- a/Auth/OpenID/Consumer.php
+++ b/Auth/OpenID/Consumer.php
@@ -263,6 +263,13 @@ class Auth_OpenID_Consumer {
$this->_token_key = $this->session_key_prefix . $this->_token_suffix;
}
+ function getDiscoveryObject(&$session, $openid_url,
+ $session_key_prefix)
+ {
+ return new Services_Yadis_Discovery($session, $openid_url,
+ $session_key_prefix);
+ }
+
/**
* Start the OpenID authentication process. See steps 1-2 in the
* overview at the top of this file.
@@ -285,9 +292,9 @@ class Auth_OpenID_Consumer {
$discoverMethod = 'Auth_OpenID_discover';
$openid_url = $user_url;
- $disco =& new Services_Yadis_Discovery($this->session,
- $openid_url,
- $this->session_key_prefix);
+ $disco =& $this->getDiscoveryObject($this->session,
+ $openid_url,
+ $this->session_key_prefix);
// Set the 'stale' attribute of the manager. If discovery
// fails in a fatal way, the stale flag will cause the manager
@@ -380,9 +387,9 @@ class Auth_OpenID_Consumer {
if (in_array($response->status, array(Auth_OpenID_SUCCESS,
Auth_OpenID_CANCEL))) {
if ($response->identity_url !== null) {
- $disco = new Services_Yadis_Discovery($this->session,
- $response->identity_url,
- $this->session_key_prefix);
+ $disco = $this->getDiscoveryObject($this->session,
+ $response->identity_url,
+ $this->session_key_prefix);
$disco->cleanup();
}
}
diff --git a/Tests/Auth/OpenID/Consumer.php b/Tests/Auth/OpenID/Consumer.php
index 826f116..c4217eb 100644
--- a/Tests/Auth/OpenID/Consumer.php
+++ b/Tests/Auth/OpenID/Consumer.php
@@ -1548,6 +1548,29 @@ class _StubConsumer {
}
}
+class Tests_Auth_OpenID_DiscoFailure extends PHPUnit_TestCase {
+ var $consumerClass = null;
+
+ function setUp()
+ {
+ foreach ($_SESSION as $k => $v) {
+ unset($_SESSION[$k]);
+ }
+
+ $this->endpoint = new Auth_OpenID_ServiceEndpoint();
+ $this->claimed_id = 'http://identity.url/';
+ $this->endpoint->claimed_id = $this->claimed_id;
+ $this->store = null;
+ $this->session = new Services_Yadis_PHPSession();
+ $cls = $this->consumerClass;
+ $this->consumer =& new $cls($this->store, &$this->session);
+ $this->consumer->consumer =& new _StubConsumer();
+ $this->discovery =& new Services_Yadis_Discovery(&$this->session,
+ $this->claimed_id,
+ $this->consumer->session_key_prefix);
+ }
+}
+
class Tests_Auth_OpenID_ConsumerTest2 extends PHPUnit_TestCase {
function setUp()
{
@@ -1567,56 +1590,6 @@ class Tests_Auth_OpenID_ConsumerTest2 extends PHPUnit_TestCase {
$this->consumer->session_key_prefix);
}
- /*
- function withDummyDiscovery(self, callable, dummy_getNextService):
- class DummyDisco(object):
- function __init__(self, *ignored):
- pass
-
- getNextService = dummy_getNextService
-
- import openid.consumer.consumer
- old_discovery = openid.consumer.consumer.Discovery
- try:
- openid.consumer.consumer.Discovery = DummyDisco
- callable()
- finally:
- openid.consumer.consumer.Discovery = old_discovery
-
- function test_beginHTTPError(self):
- """Make sure that the discovery HTTP failure case behaves properly
- """
- function getNextService(self, ignored):
- raise HTTPFetchingError("Unit test")
-
- function test():
- try:
- $this->consumer.begin('unused in this test')
- except DiscoveryFailure, why:
- $this->assertTrue(why[0].startswith('Error fetching'))
- $this->assertFalse(why[0].find('Unit test') == -1)
- else:
- $this->fail('Expected DiscoveryFailure')
-
- $this->withDummyDiscovery(test, getNextService)
-
- function test_beginNoServices(self):
- function getNextService(self, ignored):
- return None
-
- url = 'http://a.user.url/'
- function test():
- try:
- $this->consumer.begin(url)
- except DiscoveryFailure, why:
- $this->assertTrue(why[0].startswith('No usable OpenID'))
- $this->assertFalse(why[0].find(url) == -1)
- else:
- $this->fail('Expected DiscoveryFailure')
-
- $this->withDummyDiscovery(test, getNextService)
- */
-
function test_beginWithoutDiscovery()
{
// Does this really test anything non-trivial?