summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortailor <cygnus@janrain.com>2006-01-02 18:32:07 +0000
committertailor <cygnus@janrain.com>2006-01-02 18:32:07 +0000
commit7640a5e5c993d30ec6c6f830ff68016244d68e45 (patch)
tree75cf311d087b213ae1adacaa380bdcbb63c44613
parent71f475c7553901a774355e21a25c2eb451a417ab (diff)
downloadphp-openid-7640a5e5c993d30ec6c6f830ff68016244d68e45.zip
php-openid-7640a5e5c993d30ec6c6f830ff68016244d68e45.tar.gz
php-openid-7640a5e5c993d30ec6c6f830ff68016244d68e45.tar.bz2
[project @ Added oidutil test for base64 functions and updated test driver.]
-rw-r--r--Tests/Net/OpenID/OIDUtil.php60
-rw-r--r--Tests/TestDriver.php1
2 files changed, 61 insertions, 0 deletions
diff --git a/Tests/Net/OpenID/OIDUtil.php b/Tests/Net/OpenID/OIDUtil.php
new file mode 100644
index 0000000..1c26206
--- /dev/null
+++ b/Tests/Net/OpenID/OIDUtil.php
@@ -0,0 +1,60 @@
+<?php
+
+require_once('PHPUnit.php');
+require_once('Net/OpenID/OIDUtil.php');
+
+class Tests_Net_OpenID_OIDUtil extends PHPUnit_TestCase {
+ function test_base64() {
+
+ // This is not good for international use, but PHP doesn't
+ // appear to provide access to the local alphabet.
+ $letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ $digits = "0123456789";
+ $extra = "+/=";
+ $allowed_s = $letters . $digits . $extra;
+ $allowed_d = array();
+
+ for ($i = 0; $i < strlen($allowed_s); $i++) {
+ $c = $allowed_s[$i];
+ $allowed_d[$c] = null;
+ }
+
+ function checkEncoded($obj, $str, $allowed_array) {
+ for ($i = 0; $i < strlen($str); $i++) {
+ $obj->assertTrue(array_key_exists($str[$i], $allowed_array));
+ }
+ }
+
+ $cases = array(
+ "",
+ "x",
+ "\x00",
+ "\x01",
+ str_repeat("\x00", 100),
+ implode("", array_map('chr', range(0, 255)))
+ );
+
+ foreach ($cases as $s) {
+ $b64 = Net_OpenID_toBase64($s);
+ checkEncoded($this, $b64, $allowed_d);
+ $s_prime = Net_OpenID_fromBase64($b64);
+ $this->assertEquals($s_prime, $s);
+ }
+
+ function random_ordinal($unused) {
+ return rand(0, 255);
+ }
+
+ // Randomized test
+ foreach (range(0, 49) as $i) {
+ $n = rand(0, 2048);
+ $s = implode("", array_map('chr', array_map('random_ordinal', range(0, $n))));
+ $b64 = Net_OpenID_toBase64($s);
+ checkEncoded($this, $b64, $allowed_d);
+ $s_prime = Net_OpenID_fromBase64($b64);
+ $this->assertEquals($s_prime, $s);
+ }
+ }
+}
+
+?> \ No newline at end of file
diff --git a/Tests/TestDriver.php b/Tests/TestDriver.php
index 1cd3ca0..cc78e5a 100644
--- a/Tests/TestDriver.php
+++ b/Tests/TestDriver.php
@@ -40,6 +40,7 @@ $_test_dir = 'Tests/Net/OpenID/';
$_test_names = array(
'KVForm',
'CryptUtil',
+ 'OIDUtil',
'DiffieHellman',
'HMACSHA1',
);