summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Hoyt <josh@janrain.com>2005-12-23 01:01:29 +0000
committerJosh Hoyt <josh@janrain.com>2005-12-23 01:01:29 +0000
commit6c192c4ae1cef529987d6b39935dffd94c842152 (patch)
tree20bf92c1d453bb776dd7ff36999a345c3505567e
parent99898408426b45296ba62066cc38ad2be113d847 (diff)
downloadphp-openid-6c192c4ae1cef529987d6b39935dffd94c842152.zip
php-openid-6c192c4ae1cef529987d6b39935dffd94c842152.tar.gz
php-openid-6c192c4ae1cef529987d6b39935dffd94c842152.tar.bz2
[project @ Add strict error reporting and move to Net/ for PEAR compatibility]
-rw-r--r--Net/OpenID/CryptUtil.php (renamed from OpenID/CryptUtil.php)2
-rw-r--r--Net/OpenID/DiffieHellman.php (renamed from OpenID/DiffieHellman.php)12
-rw-r--r--Net/OpenID/KVForm.php (renamed from OpenID/KVForm.php)2
-rw-r--r--Tests/Net/OpenID/CryptUtil.php (renamed from Tests/OpenID/CryptUtil.php)10
-rw-r--r--Tests/Net/OpenID/DiffieHellman.php (renamed from Tests/OpenID/DiffieHellman.php)22
-rw-r--r--Tests/Net/OpenID/HMACSHA1.php (renamed from Tests/OpenID/HMACSHA1.php)0
-rw-r--r--Tests/Net/OpenID/KVForm.php (renamed from Tests/OpenID/KVForm.php)127
-rw-r--r--Tests/Net/OpenID/dhpriv (renamed from Tests/OpenID/dhpriv)0
-rw-r--r--Tests/Net/OpenID/hmac.txt (renamed from Tests/OpenID/hmac.txt)0
-rw-r--r--test.php4
10 files changed, 98 insertions, 81 deletions
diff --git a/OpenID/CryptUtil.php b/Net/OpenID/CryptUtil.php
index 66a8a28..4152c9c 100644
--- a/OpenID/CryptUtil.php
+++ b/Net/OpenID/CryptUtil.php
@@ -1,6 +1,6 @@
<?php
-class OpenID_CryptUtil {
+class Net_OpenID_CryptUtil {
function getBytes($num_bytes) {
$f = fopen("/dev/urandom", "r");
$bytes = fread($f, $num_bytes);
diff --git a/OpenID/DiffieHellman.php b/Net/OpenID/DiffieHellman.php
index 7c5137b..e274815 100644
--- a/OpenID/DiffieHellman.php
+++ b/Net/OpenID/DiffieHellman.php
@@ -4,7 +4,7 @@ if (extension_loaded('gmp') || @dl('gmp.' . PHP_SHLIB_SUFFIX) ||
@dl('php_gmp.' . PHP_SHLIB_SUFFIX)) {
// XXX: untested!
- class OpenID_DiffieHellman {
+ class Net_OpenID_DiffieHellman {
var $DEFAULT_MOD = '155172898181473697471232257763715539915724801966915404479707795314057629378541917580651227423698188993727816152646631438561595825688188889951272158842675419950341258706556549803580104870537681476726513255747040765857479291291572334510643245094715007229621094194349783925984760375594985848253359305585439638443';
var $DEFAULT_GEN = '2';
@@ -22,7 +22,7 @@ if (extension_loaded('gmp') || @dl('gmp.' . PHP_SHLIB_SUFFIX) ||
return $rdm;
}
- function OpenID_DiffieHellman($mod=NULL, $gen=NULL, $private=NULL) {
+ function Net_OpenID_DiffieHellman($mod=NULL, $gen=NULL, $private=NULL) {
if ($mod === NULL) {
$this->mod = gmp_init($this->DEFAULT_MOD, 10);
} else {
@@ -42,11 +42,11 @@ if (extension_loaded('gmp') || @dl('gmp.' . PHP_SHLIB_SUFFIX) ||
}
function createKeyExchange( ) {
- return OpenID_BigInt::powm( $this->g, $this->x, $this->p);
+ return Net_OpenID_BigInt::powm( $this->g, $this->x, $this->p);
}
function decryptKeyExchange( $keyEx ) {
- return OpenID_BigInt::powm( $keyEx, $this->x, $this->p );
+ return Net_OpenID_BigInt::powm( $keyEx, $this->x, $this->p );
}
}
@@ -73,7 +73,7 @@ if (extension_loaded('gmp') || @dl('gmp.' . PHP_SHLIB_SUFFIX) ||
}
}
- class OpenID_DiffieHellman {
+ class Net_OpenID_DiffieHellman {
var $math_type = 'bcmath';
var $DEFAULT_MOD = '155172898181473697471232257763715539915724801966915404479707795314057629378541917580651227423698188993727816152646631438561595825688188889951272158842675419950341258706556549803580104870537681476726513255747040765857479291291572334510643245094715007229621094194349783925984760375594985848253359305585439638443';
@@ -85,7 +85,7 @@ if (extension_loaded('gmp') || @dl('gmp.' . PHP_SHLIB_SUFFIX) ||
var $private;
var $public;
- function OpenID_DiffieHellman($mod=NULL, $gen=NULL, $private=NULL) {
+ function Net_OpenID_DiffieHellman($mod=NULL, $gen=NULL, $private=NULL) {
$this->mod = $mod === NULL ? $this->DEFAULT_MOD : $mod;
$this->gen = $gen === NULL ? $this->DEFAULT_GEN : $gen;
$this->private =
diff --git a/OpenID/KVForm.php b/Net/OpenID/KVForm.php
index 63c8e40..764ad77 100644
--- a/OpenID/KVForm.php
+++ b/Net/OpenID/KVForm.php
@@ -1,6 +1,6 @@
<?php
-class OpenID_KVForm {
+class Net_OpenID_KVForm {
function arrayToKV($values) {
$serialized = '';
foreach ($values as $key => $value) {
diff --git a/Tests/OpenID/CryptUtil.php b/Tests/Net/OpenID/CryptUtil.php
index 17dee90..3ad3174 100644
--- a/Tests/OpenID/CryptUtil.php
+++ b/Tests/Net/OpenID/CryptUtil.php
@@ -1,13 +1,13 @@
<?php
require_once('PHPUnit.php');
-require_once('OpenID/CryptUtil.php');
+require_once('Net/OpenID/CryptUtil.php');
-class Tests_OpenID_CryptUtil extends PHPUnit_TestCase {
+class Tests_Net_OpenID_CryptUtil extends PHPUnit_TestCase {
function test_length() {
$cases = array(1, 10, 255);
foreach ($cases as $length) {
- $data = OpenID_CryptUtil::getBytes($length);
+ $data = Net_OpenID_CryptUtil::getBytes($length);
$this->assertEquals(strlen($data), $length);
}
}
@@ -16,10 +16,10 @@ class Tests_OpenID_CryptUtil extends PHPUnit_TestCase {
$num_iterations = 100;
$data_length = 20;
- $data = OpenID_CryptUtil::getBytes($num_iterations);
+ $data = Net_OpenID_CryptUtil::getBytes($num_iterations);
for ($i = 0; $i < $num_iterations; $i++) {
$last = $data;
- $data = OpenID_CryptUtil::getBytes($num_iterations);
+ $data = Net_OpenID_CryptUtil::getBytes($num_iterations);
$this->assertFalse($data == $last);
}
}
diff --git a/Tests/OpenID/DiffieHellman.php b/Tests/Net/OpenID/DiffieHellman.php
index f4d53e7..aad06b9 100644
--- a/Tests/OpenID/DiffieHellman.php
+++ b/Tests/Net/OpenID/DiffieHellman.php
@@ -1,10 +1,10 @@
<?php
require_once('PHPUnit.php');
-require_once('OpenID/DiffieHellman.php');
+require_once('Net/OpenID/DiffieHellman.php');
-class Tests_OpenID_DiffieHellman_CheckCases extends PHPUnit_TestCase {
- function Tests_OpenID_DiffieHellman_CheckCases($cases) {
+class Tests_Net_OpenID_DiffieHellman_CheckCases extends PHPUnit_TestCase {
+ function Tests_Net_OpenID_DiffieHellman_CheckCases($cases) {
$this->cases = $cases;
}
@@ -13,20 +13,20 @@ class Tests_OpenID_DiffieHellman_CheckCases extends PHPUnit_TestCase {
}
}
-class Tests_OpenID_DiffieHellman_OneCase extends PHPUnit_TestCase {
- function Tests_OpenID_DiffieHellman_OneCase($name, $input, $expected) {
+class Tests_Net_OpenID_DiffieHellman_OneCase extends PHPUnit_TestCase {
+ function Tests_Net_OpenID_DiffieHellman_OneCase($name, $input, $expected) {
$this->setName("$name");
$this->input = $input;
$this->expected = $expected;
}
function runTest() {
- $dh = new OpenID_DiffieHellman(NULL, NULL, $this->input);
+ $dh = new Net_OpenID_DiffieHellman(NULL, NULL, $this->input);
$this->assertEquals($this->expected, $dh->getPublicKey());
}
}
-class Tests_OpenID_DiffieHellman extends PHPUnit_TestSuite {
+class Tests_Net_OpenID_DiffieHellman extends PHPUnit_TestSuite {
function _readTestCases() {
$path = dirname(realpath(__FILE__));
$dh_test_data_file = $path . DIRECTORY_SEPARATOR . 'dhpriv';
@@ -56,17 +56,17 @@ class Tests_OpenID_DiffieHellman extends PHPUnit_TestSuite {
return $cases;
}
- function Tests_OpenID_DiffieHellman($name) {
+ function Tests_Net_OpenID_DiffieHellman($name) {
$this->setName($name);
- $cases = Tests_OpenID_DiffieHellman::_readTestCases();
- $sanity = new Tests_OpenID_DiffieHellman_CheckCases($cases);
+ $cases = Tests_Net_OpenID_DiffieHellman::_readTestCases();
+ $sanity = new Tests_Net_OpenID_DiffieHellman_CheckCases($cases);
$sanity->setName('Check parsing of test data');
$this->addTest($sanity);
for ($i = 0; $i < count($cases); $i++) {
$case = $cases[$i];
- $one = new Tests_OpenID_DiffieHellman_OneCase(
+ $one = new Tests_Net_OpenID_DiffieHellman_OneCase(
$i, $case[0], $case[1]);
$this->addTest($one);
}
diff --git a/Tests/OpenID/HMACSHA1.php b/Tests/Net/OpenID/HMACSHA1.php
index 521a84b..521a84b 100644
--- a/Tests/OpenID/HMACSHA1.php
+++ b/Tests/Net/OpenID/HMACSHA1.php
diff --git a/Tests/OpenID/KVForm.php b/Tests/Net/OpenID/KVForm.php
index 2f445de..bc97e13 100644
--- a/Tests/OpenID/KVForm.php
+++ b/Tests/Net/OpenID/KVForm.php
@@ -1,91 +1,97 @@
<?php
require_once('PHPUnit.php');
-require_once('OpenID/KVForm.php');
-
-$Tests_OpenID_KVForm_errors = NULL;
+require_once('Net/OpenID/KVForm.php');
+$_Tests_Net_OpenID_kverrors = NULL;
/**
* Keep a list of the logged errors
*/
-function Tests_OpenID_KVForm_err($errno, $errmsg, $filename, $linenum, $vars) {
- global $Tests_OpenID_KVForm_errors;
- $Tests_OpenID_KVForm_errors[] = $errmsg;
+function Tests_Net_OpenID_kvHandleError($errno, $errmsg) {
+ global $_Tests_Net_OpenID_kverrors;
+ $_Tests_Net_OpenID_kverrors[] = $errmsg;
}
-class Tests_OpenID_KVForm_TestCase extends PHPUnit_TestCase {
- function Tests_OpenID_KVForm_TestCase($arr, $str, $lossy, $errs) {
+class Tests_Net_OpenID_KVForm_TestCase extends PHPUnit_TestCase {
+ var $errs;
+
+ function runTest() {
+ // Re-set the number of logged errors
+ global $_Tests_Net_OpenID_kverrors;
+ $_Tests_Net_OpenID_kverrors = array();
+
+ set_error_handler("Tests_Net_OpenID_kvHandleError");
+
+ $this->_runTest();
+
+ // Check to make sure we have the expected number of logged errors
+ //$this->assertEquals($this->errs, count($_Tests_Net_OpenID_kverrors));
+
+ restore_error_handler();
+ }
+
+ function _runTest() {
+ trigger_error('Must be overridden', E_USER_ERROR);
+ }
+}
+
+class Tests_Net_OpenID_KVForm_TestCase_Parse
+extends Tests_Net_OpenID_KVForm_TestCase {
+ function Tests_Net_OpenID_KVForm_TestCase_Parse(
+ $arr, $str, $lossy, $errs) {
+
$this->arr = $arr;
$this->str = $str;
$this->lossy = $lossy;
$this->errs = $errs;
}
- function runTest() {
- // Re-set the number of logged errors
- global $Tests_OpenID_KVForm_errors;
- $Tests_OpenID_KVForm_errors = array();
-
- set_error_handler("Tests_OpenID_KVForm_err");
-
+ function _runTest() {
// Do one parse, after which arrayToKV and kvToArray should be
// inverses.
- $parsed1 = OpenID_KVForm::kvToArray($this->str);
- $serial1 = OpenID_KVForm::arrayToKV($this->arr);
+ $parsed1 = Net_OpenID_KVForm::kvToArray($this->str);
+ $serial1 = Net_OpenID_KVForm::arrayToKV($this->arr);
if ($this->lossy == "neither" || $this->lossy == "str") {
- $this->assertEquals($this->arr, $parsed1);
+ $this->assertEquals($this->arr, $parsed1, "str was lossy");
}
if ($this->lossy == "neither" || $this->lossy == "arr") {
- $this->assertEquals($this->str, $serial1);
+ $this->assertEquals($this->str, $serial1, "array was lossy");
}
- $parsed2 = OpenID_KVForm::kvToArray($serial1);
- $serial2 = OpenID_KVForm::arrayToKV($parsed1);
+ $parsed2 = Net_OpenID_KVForm::kvToArray($serial1);
+ $serial2 = Net_OpenID_KVForm::arrayToKV($parsed1);
// Round-trip both
- $parsed3 = OpenID_KVForm::kvToArray($serial2);
- $serial3 = OpenID_KVForm::arrayToKV($parsed2);
+ $parsed3 = Net_OpenID_KVForm::kvToArray($serial2);
+ $serial3 = Net_OpenID_KVForm::arrayToKV($parsed2);
- $this->assertEquals($serial2, $serial3);
+ $this->assertEquals($serial2, $serial3, "serialized forms differ");
// Check to make sure that they're inverses.
- $this->assertEquals($parsed2, $parsed3);
-
- // Check to make sure we have the expected number of logged errors
- $this->assertEquals($this->errs, count($Tests_OpenID_KVForm_errors));
+ $this->assertEquals($parsed2, $parsed3, "parsed forms differ");
- restore_error_handler();
}
}
-class Tests_OpenID_KVForm_TestCase_Null extends PHPUnit_TestCase {
- function Tests_OpenID_KVForm_TestCase_Null($arr, $errs) {
+class Tests_Net_OpenID_KVForm_TestCase_Null
+extends Tests_Net_OpenID_KVForm_TestCase {
+ function Tests_Net_OpenID_KVForm_TestCase_Null($arr, $errs) {
$this->arr = $arr;
$this->errs = $errs;
}
- function runTest() {
- // Re-set the logged errors
- global $Tests_OpenID_KVForm_errors;
- $Tests_OpenID_KVForm_errors = array();
-
- set_error_handler("Tests_OpenID_KVForm_err");
-
- $serialized = OpenID_KVForm::arrayToKV($this->arr);
- $this->assertTrue($serialized === NULL);
-
- // Check to make sure we have the expected number of logged errors
- $this->assertEquals($this->errs, count($Tests_OpenID_KVForm_errors));
-
- restore_error_handler();
+ function _runTest() {
+ $serialized = Net_OpenID_KVForm::arrayToKV($this->arr);
+ $this->assertTrue($serialized === NULL,
+ 'serialization unexpectedly succeeded');
}
}
-class Tests_OpenID_KVForm extends PHPUnit_TestSuite {
- function Tests_OpenID_KVForm($name) {
+class Tests_Net_OpenID_KVForm extends PHPUnit_TestSuite {
+ function Tests_Net_OpenID_KVForm($name) {
$this->setName($name);
$testdata_list = array(
array("name" => "simple",
@@ -198,21 +204,30 @@ class Tests_OpenID_KVForm extends PHPUnit_TestSuite {
);
foreach ($testdata_list as $testdata) {
+ if (isset($testdata['str'])) {
+ $str = $testdata['str'];
+ } else {
+ $str = NULL;
+ }
+
$arr = $testdata["arr"];
- $str = $testdata["str"];
- $errs = $testdata["errors"];
- if (!isset($errs)) {
+
+ if (isset($testdata['errors'])) {
+ $errs = $testdata["errors"];
+ } else {
$errs = 0;
}
- if (isset($str)) {
- $lossy = $testdata["lossy"];
- if (!isset($lossy)) {
+
+ if (is_null($str)) {
+ $test = new Tests_Net_OpenID_KVForm_TestCase_Null($arr, $errs);
+ } else {
+ if (isset($testdata['lossy'])) {
+ $lossy = $testdata["lossy"];
+ } else {
$lossy = 'neither';
}
- $test = new Tests_OpenID_KVForm_TestCase(
+ $test = new Tests_Net_OpenID_KVForm_TestCase(
$arr, $str, $lossy, $errs);
- } else {
- $test = new Tests_OpenID_KVForm_TestCase_Null($arr, $errs);
}
$test->setName($testdata["name"]);
$this->addTest($test);
diff --git a/Tests/OpenID/dhpriv b/Tests/Net/OpenID/dhpriv
index 0fa5231..0fa5231 100644
--- a/Tests/OpenID/dhpriv
+++ b/Tests/Net/OpenID/dhpriv
diff --git a/Tests/OpenID/hmac.txt b/Tests/Net/OpenID/hmac.txt
index 4299a96..4299a96 100644
--- a/Tests/OpenID/hmac.txt
+++ b/Tests/Net/OpenID/hmac.txt
diff --git a/test.php b/test.php
index ce11a6a..b6fd59b 100644
--- a/test.php
+++ b/test.php
@@ -1,5 +1,7 @@
<?php
+error_reporting(E_STRICT | E_ALL);
+
require_once('PHPUnit.php');
require_once('PHPUnit/GUI/HTML.php');
@@ -35,7 +37,7 @@ function loadTests($test_dir, $test_names) {
}
// Load OpenID library tests
-$test_dir = 'Tests' . DIRECTORY_SEPARATOR . 'OpenID' . DIRECTORY_SEPARATOR;
+$test_dir = 'Tests/Net/OpenID/';
$test_names = array(
'KVForm',
'CryptUtil',