diff options
author | tailor <cygnus@janrain.com> | 2007-02-13 00:37:37 +0000 |
---|---|---|
committer | tailor <cygnus@janrain.com> | 2007-02-13 00:37:37 +0000 |
commit | a7f5afca8fd3e5e7de9fad3f031f2e174e304679 (patch) | |
tree | 1bdb54c81351c9aadb1a362fc038e116cd2f73ae | |
parent | c938d68a94682d720e109abcb627da6fc325621d (diff) | |
download | php-openid-a7f5afca8fd3e5e7de9fad3f031f2e174e304679.zip php-openid-a7f5afca8fd3e5e7de9fad3f031f2e174e304679.tar.gz php-openid-a7f5afca8fd3e5e7de9fad3f031f2e174e304679.tar.bz2 |
[project @ Fixed Message->delArg and added more tests]
-rw-r--r-- | Auth/OpenID/Message.php | 21 | ||||
-rw-r--r-- | Tests/Auth/OpenID/Consumer.php | 142 |
2 files changed, 108 insertions, 55 deletions
diff --git a/Auth/OpenID/Message.php b/Auth/OpenID/Message.php index b930379..3dd919c 100644 --- a/Auth/OpenID/Message.php +++ b/Auth/OpenID/Message.php @@ -102,6 +102,7 @@ class Auth_OpenID_Mapping { function items() { $temp = array(); + for ($i = 0; $i < count($this->keys); $i++) { $temp[] = array($this->keys[$i], $this->values[$i]); @@ -149,6 +150,25 @@ class Auth_OpenID_Mapping { } } + function _reflow() + { + // PHP is broken yet again. Sort the arrays to remove the + // hole in the numeric indexes that make up the array. + $old_keys = $this->keys; + $old_values = $this->values; + + $this->keys = array(); + $this->values = array(); + + foreach ($old_keys as $k) { + $this->keys[] = $k; + } + + foreach ($old_values as $v) { + $this->values[] = $v; + } + } + /** * Deletes a key-value pair from the mapping with the specified * key. @@ -160,6 +180,7 @@ class Auth_OpenID_Mapping { if ($index !== false) { unset($this->keys[$index]); unset($this->values[$index]); + $this->_reflow(); return true; } return false; diff --git a/Tests/Auth/OpenID/Consumer.php b/Tests/Auth/OpenID/Consumer.php index cfbf04f..aeeeda5 100644 --- a/Tests/Auth/OpenID/Consumer.php +++ b/Tests/Auth/OpenID/Consumer.php @@ -1924,73 +1924,104 @@ class TestDiscoveryVerification extends PHPUnit_TestCase { } } -/* -class TestCreateAssociationRequest(unittest.TestCase): - function setUp(self): - class DummyEndpoint(object): - use_compatibility = False - - function compatibilityMode(self): - return $this->use_compatibility - - $this->endpoint = DummyEndpoint() - $this->consumer = GenericConsumer(store=None) - $this->assoc_type = 'HMAC-SHA1' - - function test_noEncryptionSendsType(self): - session_type = 'no-encryption' - session, args = $this->consumer._createAssociateRequest( - $this->endpoint, $this->assoc_type, session_type) - - $this->failUnless(isinstance(session, PlainTextConsumerSession)) - expected = Message.fromOpenIDArgs( - {'ns'=>Auth_OpenID_OPENID2_NS, - 'session_type'=>session_type, - 'mode'=>'associate', - 'assoc_type'=>$this->assoc_type, - }) - - $this->assertEquals(expected, args) - - function test_noEncryptionCompatibility(self): - $this->endpoint.use_compatibility = True - session_type = 'no-encryption' - session, args = $this->consumer._createAssociateRequest( - $this->endpoint, $this->assoc_type, session_type) - - $this->failUnless(isinstance(session, PlainTextConsumerSession)) - $this->assertEquals(Message.fromOpenIDArgs({'mode'=>'associate', - 'assoc_type'=>$this->assoc_type, - }), args) - - function test_dhSHA1Compatibility(self): +class DummyEndpoint { + var $use_compatibility = false; + + function compatibilityMode() + { + return $this->use_compatibility; + } +} + +class FastConsumerSession extends Auth_OpenID_DiffieHellmanSHA1ConsumerSession { + function FastConsumerSession($dh = null) + { + if ($dh === null) { + $dh = new Auth_OpenID_DiffieHellman(100389557, 2); + } + + $this->dh = $dh; + } +} + +function setConsumerSession(&$con) +{ + $con->session_types = array('DH-SHA1' => 'FastConsumerSession'); +} + +class TestCreateAssociationRequest extends PHPUnit_TestCase { + function setUp() + { + $this->endpoint = new DummyEndpoint(); + $s = null; + $this->consumer = new Auth_OpenID_GenericConsumer($s); + $this->assoc_type = 'HMAC-SHA1'; + } + + function test_noEncryptionSendsType() + { + $session_type = 'no-encryption'; + list($session, $args) = $this->consumer->_createAssociateRequest( + $this->endpoint, $this->assoc_type, $session_type); + + $this->assertTrue(is_a($session, 'Auth_OpenID_PlainTextConsumerSession')); + + $expected = Auth_OpenID_Message::fromOpenIDArgs( + array('ns' => Auth_OpenID_OPENID2_NS, + 'session_type'=>$session_type, + 'mode'=>'associate', + 'assoc_type'=>$this->assoc_type)); + + $this->assertEquals($expected->toPostArgs(), + $args->toPostArgs()); + } + + function test_noEncryptionCompatibility() + { + $this->endpoint->use_compatibility = true; + $session_type = 'no-encryption'; + list($session, $args) = $this->consumer->_createAssociateRequest( + $this->endpoint, $this->assoc_type, $session_type); + + $this->assertTrue(is_a($session, 'Auth_OpenID_PlainTextConsumerSession')); + $this->assertEquals(Auth_OpenID_Message::fromOpenIDArgs(array('mode'=>'associate', + 'assoc_type'=>$this->assoc_type)), + $args); + } + + function test_dhSHA1Compatibility() + { // Set the consumer's session type to a fast session since we // need it here. - setConsumerSession($this->consumer) + setConsumerSession($this->consumer); - $this->endpoint.use_compatibility = True - session_type = 'DH-SHA1' - session, args = $this->consumer._createAssociateRequest( - $this->endpoint, $this->assoc_type, session_type) + $this->endpoint->use_compatibility = true; + $session_type = 'DH-SHA1'; + list($session, $args) = $this->consumer->_createAssociateRequest( + $this->endpoint, $this->assoc_type, $session_type); - $this->failUnless(isinstance(session, DiffieHellmanSHA1ConsumerSession)) + $this->assertTrue(is_a($session, + 'Auth_OpenID_DiffieHellmanSHA1ConsumerSession')); // This is a random base-64 value, so just check that it's // present. - $this->failUnless(args.getArg(Auth_OpenID_OPENID1_NS, 'dh_consumer_public')) - args.delArg(Auth_OpenID_OPENID1_NS, 'dh_consumer_public') + $this->assertTrue($args->hasKey(Auth_OpenID_OPENID1_NS, 'dh_consumer_public')); + $args->delArg(Auth_OpenID_OPENID1_NS, 'dh_consumer_public'); // OK, session_type is set here and not for no-encryption // compatibility - expected = Message.fromOpenIDArgs({'mode'=>'associate', - 'session_type'=>'DH-SHA1', - 'assoc_type'=>$this->assoc_type, - 'dh_modulus'=> 'BfvStQ==', - 'dh_gen'=> 'Ag==', - }) + $expected = Auth_OpenID_Message::fromOpenIDArgs(array('mode'=>'associate', + 'session_type'=>'DH-SHA1', + 'assoc_type'=>$this->assoc_type, + 'dh_modulus'=> 'BfvStQ==', + 'dh_gen'=> 'Ag==')); - $this->assertEquals(expected, args) + $this->assertEquals($expected->toPostArgs(), + $args->toPostArgs()); + } +} +/* class TestDiffieHellmanResponseParameters(object): session_cls = None message_namespace = None @@ -2078,6 +2109,7 @@ $Tests_Auth_OpenID_Consumer_other = array( new TestReturnToArgs(), new IDPDrivenTest(), new TestDiscoveryVerification(), + new TestCreateAssociationRequest(), ); ?>
\ No newline at end of file |