summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortailor <cygnus@janrain.com>2007-02-01 21:54:36 +0000
committertailor <cygnus@janrain.com>2007-02-01 21:54:36 +0000
commit85e4a9af86fb53edc838c3693345b57c95fa3fa8 (patch)
tree62c1400fa8110f8f0a07653a990768eb72f11a91
parentfc6af05b581732bef9f4bd8da9feef5d008be350 (diff)
downloadphp-openid-85e4a9af86fb53edc838c3693345b57c95fa3fa8.zip
php-openid-85e4a9af86fb53edc838c3693345b57c95fa3fa8.tar.gz
php-openid-85e4a9af86fb53edc838c3693345b57c95fa3fa8.tar.bz2
[project @ Added no-return-to, no-realm tests for OpenID2]
-rw-r--r--Auth/OpenID/Server.php11
-rw-r--r--Tests/Auth/OpenID/Server.php43
2 files changed, 49 insertions, 5 deletions
diff --git a/Auth/OpenID/Server.php b/Auth/OpenID/Server.php
index 9bb14f3..35fb120 100644
--- a/Auth/OpenID/Server.php
+++ b/Auth/OpenID/Server.php
@@ -629,7 +629,8 @@ class Auth_OpenID_CheckIDRequest extends Auth_OpenID_Request {
"server must not be null");
}
- if (!Auth_OpenID_TrustRoot::_parse($return_to)) {
+ if ($return_to &&
+ !Auth_OpenID_TrustRoot::_parse($return_to)) {
return new Auth_OpenID_MalformedReturnURL($message, $return_to);
}
@@ -776,8 +777,12 @@ class Auth_OpenID_CheckIDRequest extends Auth_OpenID_Request {
return new Auth_OpenID_MalformedTrustRoot(null, $this->trust_root);
}
- return Auth_OpenID_TrustRoot::match($this->trust_root,
- $this->return_to);
+ if ($this->return_to !== null) {
+ return Auth_OpenID_TrustRoot::match($this->trust_root,
+ $this->return_to);
+ } else {
+ return true;
+ }
}
function answer($allow, $server_url = null, $identity = null,
diff --git a/Tests/Auth/OpenID/Server.php b/Tests/Auth/OpenID/Server.php
index 66c2ef2..59534bb 100644
--- a/Tests/Auth/OpenID/Server.php
+++ b/Tests/Auth/OpenID/Server.php
@@ -246,7 +246,7 @@ class Tests_Auth_OpenID_Test_Decode extends PHPUnit_TestCase {
$this->assertEquals($r->return_to, $this->rt_url);
}
- function test_checkidSetupNoReturn()
+ function test_checkidSetupNoReturnOpenID1()
{
$args = array(
'openid.mode' => 'checkid_setup',
@@ -256,10 +256,49 @@ class Tests_Auth_OpenID_Test_Decode extends PHPUnit_TestCase {
$result = $this->decoder->decode($args);
if (!Auth_OpenID_isError($result)) {
- $this->fail("Expected Auth_OpenID_Error");
+ $this->fail("Expected Auth_OpenID_ServerError");
}
}
+ function test_checkidSetupNoReturnOpenID2()
+ {
+ // Make sure an OpenID 2 request with no return_to can be
+ // decoded, and make sure a response to such a request raises
+ // NoReturnToError.
+ $args = array(
+ 'openid.ns' => Auth_OpenID_OPENID2_NS,
+ 'openid.mode' => 'checkid_setup',
+ 'openid.identity' => $this->id_url,
+ 'openid.claimed_id' => $this->id_url,
+ 'openid.assoc_handle' => $this->assoc_handle,
+ 'openid.realm' => $this->tr_url);
+
+ $req = $this->decoder->decode($args);
+
+ $this->assertTrue(is_a($req,
+ 'Auth_OpenID_CheckIDRequest'));
+
+ $this->assertTrue(is_a($req->answer(false), 'Auth_OpenID_NoReturnToError'));
+ $this->assertTrue(is_a($req->encodeToURL('bogus'), 'Auth_OpenID_NoReturnToError'));
+ $this->assertTrue(is_a($req->getCancelURL(), 'Auth_OpenID_NoReturnToError'));
+ }
+
+ function test_checkidSetupRealmRequiredOpenID2()
+ {
+ // Make sure that an OpenID 2 request which lacks return_to
+ // cannot be decoded if it lacks a realm. Spec: This value
+ // (openid.realm) MUST be sent if openid.return_to is omitted.
+
+ $args = array(
+ 'openid.ns' => Auth_OpenID_OPENID2_NS,
+ 'openid.mode' => 'checkid_setup',
+ 'openid.identity' => $this->id_url,
+ 'openid.assoc_handle' => $this->assoc_handle);
+
+ $this->assertTrue(is_a($this->decoder->decode($args),
+ 'Auth_OpenID_ServerError'));
+ }
+
function test_checkidSetupBadReturn()
{
$args = array(