summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorJosh Hoyt <josh@janrain.com>2006-09-08 22:56:12 +0000
committerJosh Hoyt <josh@janrain.com>2006-09-08 22:56:12 +0000
commit9371604f7b7e4a1691afc90a4f3ba9e83777d2af (patch)
tree0c5c813bc69deec509045ca42c9bf8449987adc9 /Tests
parent9588223f3465c362171cdcab5101feca2a3b0412 (diff)
downloadphp-openid-9371604f7b7e4a1691afc90a4f3ba9e83777d2af.zip
php-openid-9371604f7b7e4a1691afc90a4f3ba9e83777d2af.tar.gz
php-openid-9371604f7b7e4a1691afc90a4f3ba9e83777d2af.tar.bz2
[project @ Make MySQL and PostGreSQL store tests work; make NO_MATH_SUPPORT work]
Diffstat (limited to 'Tests')
-rw-r--r--Tests/Auth/OpenID/Consumer.php89
-rw-r--r--Tests/Auth/OpenID/Server.php40
-rw-r--r--Tests/Auth/OpenID/StoreTest.php11
3 files changed, 104 insertions, 36 deletions
diff --git a/Tests/Auth/OpenID/Consumer.php b/Tests/Auth/OpenID/Consumer.php
index 1e9311c..190b23a 100644
--- a/Tests/Auth/OpenID/Consumer.php
+++ b/Tests/Auth/OpenID/Consumer.php
@@ -57,22 +57,30 @@ function Auth_OpenID_associate($qs, $assoc_secret, $assoc_handle)
{
$query_data = Auth_OpenID_parse($qs);
- assert((count($query_data) == 6) || (count($query_data) == 4));
assert($query_data['openid.mode'] == 'associate');
assert($query_data['openid.assoc_type'] == 'HMAC-SHA1');
- assert($query_data['openid.session_type'] == 'DH-SHA1');
$reply_dict = array(
- 'assoc_type' => 'HMAC-SHA1',
- 'assoc_handle' => $assoc_handle,
- 'expires_in' => '600',
- );
-
- $dh_args = Auth_OpenID_DiffieHellman::
- serverAssociate($query_data, $assoc_secret);
-
- $reply_dict = array_merge($reply_dict, $dh_args);
-
+ 'assoc_type' => 'HMAC-SHA1',
+ 'assoc_handle' => $assoc_handle,
+ 'expires_in' => '600',
+ );
+
+ if (defined('Auth_OpenID_NO_MATH_SUPPORT')) {
+ assert(count($query_data) == 2);
+ $reply_dict['mac_key'] = $assoc_secret;
+ } else {
+ assert((count($query_data) == 6) || (count($query_data) == 4));
+ assert($query_data['openid.mode'] == 'associate');
+ assert($query_data['openid.session_type'] == 'DH-SHA1');
+ $dh_args = Auth_OpenID_DiffieHellman::
+ serverAssociate($query_data, $assoc_secret);
+
+ $reply_dict = array_merge($reply_dict, $dh_args);
+
+ }
+
+
return Auth_OpenID_KVForm::fromArray($reply_dict);
}
@@ -870,8 +878,27 @@ class Tests_Auth_OpenID_ParseAssociation extends _TestIdRes {
return array($sess, $server_resp);
}
- function test_success()
+ function test_plainSuccess()
+ {
+ $sess = new Auth_OpenID_PlainTextConsumerSession();
+ $server_resp = array('mac_key' => 'AAAAAAAAAAAAAAAAAAAAAAAAAAA=',
+ 'assoc_type' => 'HMAC-SHA1',
+ 'assoc_handle' => 'ahandle',
+ 'expires_in' => '1000'
+ );
+ $ret = $this->consumer->_parseAssociation($server_resp, $sess,
+ 'server_url');
+ $this->assertEquals($ret->secret,
+ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
+ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00");
+ }
+
+ function test_DHSuccess()
{
+ if (defined('Auth_OpenID_NO_MATH_SUPPORT')) {
+ print "No math support: not running test_DHSuccess\n";
+ return;
+ }
list($sess, $server_resp) = $this->_setUpDH();
$ret = $this->consumer->_parseAssociation($server_resp, $sess,
'server_url');
@@ -884,8 +911,12 @@ class Tests_Auth_OpenID_ParseAssociation extends _TestIdRes {
function test_badAssocType()
{
- list($sess, $server_resp) = $this->_setUpDH();
- $server_resp['assoc_type'] = 'Crazy Low Prices!!!';
+ $sess = new Auth_OpenID_PlainTextConsumerSession();
+ $server_resp = array('mac_key' => 'XXXXXXXXXXXXXXXXXXXX',
+ 'assoc_handle' => 'ahandle',
+ 'assoc_type' => 'Crazy Low Prices!!!',
+ 'expires_in' => '1000'
+ );
$ret = $this->consumer->_parseAssociation($server_resp, $sess,
'server_url');
$this->assertTrue($ret === null);
@@ -893,8 +924,12 @@ class Tests_Auth_OpenID_ParseAssociation extends _TestIdRes {
function test_badExpiresIn()
{
- list($sess, $server_resp) = $this->_setUpDH();
- $server_resp['expires_in'] = 'Crazy Low Prices!!!';
+ $sess = new Auth_OpenID_PlainTextConsumerSession();
+ $server_resp = array('mac_key' => 'XXXXXXXXXXXXXXXXXXXX',
+ 'assoc_handle' => 'ahandle',
+ 'assoc_type' => 'HMAC-SHA1',
+ 'expires_in' => 'Crazy Low Prices!!!'
+ );
$ret = $this->consumer->_parseAssociation($server_resp, $sess,
'server_url');
$this->assertTrue($ret === null);
@@ -902,8 +937,13 @@ class Tests_Auth_OpenID_ParseAssociation extends _TestIdRes {
function test_badSessionType()
{
- list($sess, $server_resp) = $this->_setUpDH();
- $server_resp['session_type'] = '|/iA6rA';
+ $sess = new Auth_OpenID_PlainTextConsumerSession();
+ $server_resp = array('mac_key' => 'XXXXXXXXXXXXXXXXXXXX',
+ 'assoc_handle' => 'ahandle',
+ 'assoc_type' => 'HMAC-SHA1',
+ 'expires_in' => '1000',
+ 'session_type' => '|/iA6rA'
+ );
$ret = $this->consumer->_parseAssociation($server_resp, $sess,
'server_url');
$this->assertTrue($ret === null);
@@ -911,6 +951,10 @@ class Tests_Auth_OpenID_ParseAssociation extends _TestIdRes {
function test_plainFallback()
{
+ if (defined('Auth_OpenID_NO_MATH_SUPPORT')) {
+ print "No math support: not running test_plainFallback\n";
+ return;
+ }
$sess = new Auth_OpenID_DiffieHellmanConsumerSession();
$server_resp = array(
'assoc_type' => 'HMAC-SHA1',
@@ -929,6 +973,10 @@ class Tests_Auth_OpenID_ParseAssociation extends _TestIdRes {
function test_plainFallbackFailure()
{
+ if (defined('Auth_OpenID_NO_MATH_SUPPORT')) {
+ print "No math support: not running test_plainFallbackFailure\n";
+ return;
+ }
$sess = new Auth_OpenID_DiffieHellmanConsumerSession();
// missing mac_key
$server_resp = array(
@@ -943,6 +991,9 @@ class Tests_Auth_OpenID_ParseAssociation extends _TestIdRes {
function test_badDHValues()
{
+ if (defined('Auth_OpenID_NO_MATH_SUPPORT')) {
+ return;
+ }
list($sess, $server_resp) = $this->_setUpDH();
$server_resp['enc_mac_key'] = "\x00\x00\x00";
$ret = $this->consumer->_parseAssociation($server_resp, $sess,
diff --git a/Tests/Auth/OpenID/Server.php b/Tests/Auth/OpenID/Server.php
index 231272b..452a663 100644
--- a/Tests/Auth/OpenID/Server.php
+++ b/Tests/Auth/OpenID/Server.php
@@ -293,23 +293,29 @@ class Tests_Auth_OpenID_Test_Decode extends PHPUnit_TestCase {
function test_associateDH()
{
- if (!defined('Auth_OpenID_NO_MATH_SUPPORT')) {
- $args = array(
- 'openid.mode' => 'associate',
- 'openid.session_type' => 'DH-SHA1',
- 'openid.dh_consumer_public' => "Rzup9265tw==");
-
- $r = $this->decoder->decode($args);
- $this->assertTrue(is_a($r, 'Auth_OpenID_AssociateRequest'));
- $this->assertEquals($r->mode, "associate");
- $this->assertEquals($r->session->session_type, "DH-SHA1");
- $this->assertEquals($r->assoc_type, "HMAC-SHA1");
- $this->assertTrue($r->session->consumer_pubkey);
+ if (defined('Auth_OpenID_NO_MATH_SUPPORT')) {
+ print "Warning: not testing associateDH\n";
+ return;
}
+ $args = array(
+ 'openid.mode' => 'associate',
+ 'openid.session_type' => 'DH-SHA1',
+ 'openid.dh_consumer_public' => "Rzup9265tw==");
+
+ $r = $this->decoder->decode($args);
+ $this->assertTrue(is_a($r, 'Auth_OpenID_AssociateRequest'));
+ $this->assertEquals($r->mode, "associate");
+ $this->assertEquals($r->session->session_type, "DH-SHA1");
+ $this->assertEquals($r->assoc_type, "HMAC-SHA1");
+ $this->assertTrue($r->session->consumer_pubkey);
}
function test_associateDHMissingKey()
{
+ if (defined('Auth_OpenID_NO_MATH_SUPPORT')) {
+ print "Warning: not testing associateDHMissingKey\n";
+ return;
+ }
$args = array(
'openid.mode' => 'associate',
'openid.session_type' => 'DH-SHA1');
@@ -338,6 +344,11 @@ class Tests_Auth_OpenID_Test_Decode extends PHPUnit_TestCase {
function test_associateDHModGen()
{
+ if (defined('Auth_OpenID_NO_MATH_SUPPORT')) {
+ print "No math support: not running test_associateDHModGen\n";
+ return;
+ }
+
global $ALT_GEN;
// test dh with non-default but valid values for dh_modulus
@@ -385,6 +396,11 @@ class Tests_Auth_OpenID_Test_Decode extends PHPUnit_TestCase {
function test_associateDHMissingModGen()
{
+ if (defined('Auth_OpenID_NO_MATH_SUPPORT')) {
+ print "No math support: not running test_associateDHModGen\n";
+ return;
+ }
+
// test dh with non-default but valid values for dh_modulus
// and dh_gen
$args = array(
diff --git a/Tests/Auth/OpenID/StoreTest.php b/Tests/Auth/OpenID/StoreTest.php
index 57f5be7..e27b726 100644
--- a/Tests/Auth/OpenID/StoreTest.php
+++ b/Tests/Auth/OpenID/StoreTest.php
@@ -308,15 +308,13 @@ explicitly');
// Random nonce (not in store)
$nonce1 = Auth_OpenID_mkNonce();
- // A nonce is not allowed by default
+ // A nonce is not by default
$this->_checkUseNonce($store, $nonce1, true, $url, 1);
- // Storing once causes useNonce to return true the first,
- // and only the first, time it is called after the
- // $store->
+ // Once stored, cannot be stored again
$this->_checkUseNonce($store, $nonce1, false, $url, 2);
- // Storing twice has the same effect as storing once.
+ // And using again has the same effect
$this->_checkUseNonce($store, $nonce1, false, $url, 3);
}
@@ -366,6 +364,7 @@ explicitly');
// because we can't run the test.
if (!(extension_loaded('pgsql') ||
@dl('pgsql.' . PHP_SHLIB_SUFFIX))) {
+ print "Warning: not testing PostGreSQL store";
$this->pass();
return;
}
@@ -475,6 +474,7 @@ explicitly');
// because we can't run the test.
if (!(extension_loaded('sqlite') ||
@dl('sqlite.' . PHP_SHLIB_SUFFIX))) {
+ print "Warning: not testing SQLite store";
$this->pass();
return;
}
@@ -517,6 +517,7 @@ explicitly');
// because we can't run the test.
if (!(extension_loaded('mysql') ||
@dl('mysql.' . PHP_SHLIB_SUFFIX))) {
+ print "Warning: not testing MySQL store";
$this->pass();
return;
}