summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Auth/OpenID/SReg.php48
-rw-r--r--Auth/OpenID/Server.php5
-rw-r--r--Tests/Auth/OpenID/SReg.php55
3 files changed, 59 insertions, 49 deletions
diff --git a/Auth/OpenID/SReg.php b/Auth/OpenID/SReg.php
index 208a6ab..e1222aa 100644
--- a/Auth/OpenID/SReg.php
+++ b/Auth/OpenID/SReg.php
@@ -175,9 +175,10 @@ class Auth_OpenID_SRegRequest extends Auth_OpenID_SRegBase {
*/
function build($required=null, $optional=null,
$policy_url=null,
- $sreg_ns_uri=Auth_OpenID_SREG_NS_URI)
+ $sreg_ns_uri=Auth_OpenID_SREG_NS_URI,
+ $cls='Auth_OpenID_SRegRequest')
{
- $obj = new Auth_OpenID_SRegRequest();
+ $obj = new $cls();
$obj->required = array();
$obj->optional = array();
@@ -204,18 +205,23 @@ class Auth_OpenID_SRegRequest extends Auth_OpenID_SRegBase {
* that were requested in the OpenID request with the given
* arguments
*
- * $message: The arguments that were given for this OpenID
- * authentication request
+ * $request: The OpenID authentication request from which to
+ * extract an sreg request.
+ *
+ * $cls: name of class to use when creating sreg request object.
+ * Used for testing.
*
* Returns the newly created simple registration request
*/
- function fromOpenIDRequest($message)
+ function fromOpenIDRequest($request, $cls='Auth_OpenID_SRegRequest')
{
- $obj = Auth_OpenID_SRegRequest::build();
+
+ $obj = call_user_func_array(array($cls, 'build'),
+ array(null, null, null, Auth_OpenID_SREG_NS_URI, $cls));
// Since we're going to mess with namespace URI mapping, don't
// mutate the object that was passed in.
- $m = $message;
+ $m = $request->message;
$obj->ns_uri = $obj->_getSRegNS($m);
$args = $m->getArgs($obj->ns_uri);
@@ -512,30 +518,4 @@ class Auth_OpenID_SRegResponse extends Auth_OpenID_SRegBase {
}
}
-/**
- * Convenience function for copying all the sreg data that was
- * requested from a supplied set of sreg data into the response
- * message. If no data were requested, no data will be sent.
- *
- * openid_request: The OpenID (checkid_*) request that may be
- * requesting sreg data.
- *
- * data: The simple registration data to send. All requested fields
- * that are present in this dictionary will be added to the response
- * message.
- *
- * openid_response: The OpenID C{id_res} response to which the simple
- * registration data should be added
- *
- * Does not return a value; updates the openid_response instead.
- */
-function Auth_OpenID_sendSRegFields(&$openid_request, $data, &$openid_response)
-{
- $sreg_request = Auth_OpenID_SRegRequest::fromOpenIDRequest(
- $openid_request->message);
- $sreg_response = Auth_OpenID_SRegResponse::extractResponse(
- $sreg_request, $data);
- $sreg_response->toMessage($openid_response->fields);
-}
-
-?> \ No newline at end of file
+?>
diff --git a/Auth/OpenID/Server.php b/Auth/OpenID/Server.php
index 1308b2b..6e67e65 100644
--- a/Auth/OpenID/Server.php
+++ b/Auth/OpenID/Server.php
@@ -1153,6 +1153,11 @@ class Auth_OpenID_ServerResponse {
return $this->fields->toURL($this->request->return_to);
}
+ function addExtension($extension_response)
+ {
+ $extension_response->toMessage($this->fields);
+ }
+
function needsSigning()
{
return $this->fields->getArg(Auth_OpenID_OPENID_NS,
diff --git a/Tests/Auth/OpenID/SReg.php b/Tests/Auth/OpenID/SReg.php
index 395daf1..5142b63 100644
--- a/Tests/Auth/OpenID/SReg.php
+++ b/Tests/Auth/OpenID/SReg.php
@@ -176,38 +176,59 @@ class GetNSTest extends PHPUnit_TestCase {
}
}
-class SentinelFakeMessage {
- var $args_sentinel = 'args_sentinel';
+global $__args_sentinel;
+global $__ns_sentinel;
+$__args_sentinel = 'args_sentinel';
+$__ns_sentinel = 'ns_sentinel';
+class SentinelFakeMessage {
function SentinelFakeMessage(&$test_case)
{
$this->test_case =& $test_case;
+ $this->message = new Auth_OpenID_Message();
}
function getArgs($ns_uri)
{
- $this->test_case->assertEquals($ns_sentinel, $ns_uri);
- return $this->args_sentinel;
+ global $__ns_sentinel, $__args_sentinel;
+ $this->test_case->assertEquals($__ns_sentinel, $ns_uri);
+ return $__args_sentinel;
}
}
-class TestingReq extends Auth_OpenID_SRegRequest {
- var $ns_sentinel = 'ns_sentinel';
+// XXX Ugly hack. Thanks, PHP.
+global $__TestingReq_TEST_CASE;
+$__TestingReq_TEST_CASE = "FLUB";
- function fromOpenIDRequest($message, &$test_case)
+function __setTestCase(&$thing) {
+ global $__TestingReq_TEST_CASE;
+ $__TestingReq_TEST_CASE = $thing;
+}
+
+function &__getTestCase() {
+ global $__TestingReq_TEST_CASE;
+ return $__TestingReq_TEST_CASE;
+}
+
+class TestingReq extends Auth_OpenID_SRegRequest {
+ function fromOpenIDRequest(&$thing, &$test_case)
{
- parent::fromOpenIDRequest($message);
- $this->test_case =& $test_case;
+ __setTestCase($test_case);
+ $obj = parent::fromOpenIDRequest($thing, 'TestingReq');
+ return $obj;
}
function _getSRegNS($unused)
{
- return $this->ns_sentinel;
+ global $__ns_sentinel;
+ return $__ns_sentinel;
}
function parseExtensionArgs($args)
{
- $this->test_case->assertEquals($args_sentinel, $args);
+ global $__args_sentinel;
+ $tc =& __getTestCase();
+ $tc->assertEquals($__args_sentinel, $args);
}
}
@@ -239,13 +260,16 @@ class SRegRequestTest extends PHPUnit_TestCase {
$this->assertTrue(Auth_OpenID_SRegRequest::build(array('elvis')) === null);
}
- /*
function test_fromOpenIDResponse()
{
+ $openid_req = new Auth_OpenID_Request();
+
$msg = new SentinelFakeMessage($this);
- $req = TestingReq::fromOpenIDRequest($msg, $this);
+ $openid_req->message =& $msg;
+
+ $req = TestingReq::fromOpenIDRequest($openid_req, $this);
+ $this->assertTrue(is_a($req, 'TestingReq'));
}
- */
function test_parseExtensionArgs_empty()
{
@@ -607,7 +631,8 @@ class SendFieldsTest extends PHPUnit_TestCase {
'language' => 'en-us');
// Put the requested data fields in the response message
- Auth_OpenID_sendSRegFields($req, $data, $resp);
+ $sreg_resp = Auth_OpenID_SRegResponse::extractResponse($sreg_req, $data);
+ $resp->addExtension($sreg_resp);
// <- send id_res response