summaryrefslogtreecommitdiffstats
path: root/Tests/Auth/OpenID
diff options
context:
space:
mode:
authorJosh Hoyt <josh@janrain.com>2006-01-28 00:25:15 +0000
committerJosh Hoyt <josh@janrain.com>2006-01-28 00:25:15 +0000
commit82ada6dd9395d0a3ad44710e313eee63e1671c1c (patch)
treea620ecead8d250843faca4d9cf4ade782aa8d733 /Tests/Auth/OpenID
parenta6e4a1af65b4343218b4e0d54c9d5f1a8831c41f (diff)
downloadphp-openid-82ada6dd9395d0a3ad44710e313eee63e1671c1c.zip
php-openid-82ada6dd9395d0a3ad44710e313eee63e1671c1c.tar.gz
php-openid-82ada6dd9395d0a3ad44710e313eee63e1671c1c.tar.bz2
[project @ OIDUtil -> Util]
Diffstat (limited to 'Tests/Auth/OpenID')
-rw-r--r--Tests/Auth/OpenID/BigMath.php2
-rw-r--r--Tests/Auth/OpenID/Consumer.php2
-rw-r--r--Tests/Auth/OpenID/DiffieHellman.php2
-rw-r--r--Tests/Auth/OpenID/HMACSHA1.php2
-rw-r--r--Tests/Auth/OpenID/OIDUtil.php260
-rw-r--r--Tests/Auth/OpenID/Parse.php2
-rw-r--r--Tests/Auth/OpenID/StoreTest.php2
-rw-r--r--Tests/Auth/OpenID/TestUtil.php28
-rw-r--r--Tests/Auth/OpenID/TrustRoot.php2
-rw-r--r--Tests/Auth/OpenID/Util.php270
10 files changed, 286 insertions, 286 deletions
diff --git a/Tests/Auth/OpenID/BigMath.php b/Tests/Auth/OpenID/BigMath.php
index a9bb11b..cae983e 100644
--- a/Tests/Auth/OpenID/BigMath.php
+++ b/Tests/Auth/OpenID/BigMath.php
@@ -15,7 +15,7 @@
require_once 'PHPUnit.php';
require_once 'Auth/OpenID/BigMath.php';
-require_once 'Tests/Auth/OpenID/Util.php';
+require_once 'Tests/Auth/OpenID/TestUtil.php';
class Tests_Auth_OpenID_BinLongConvertRnd extends PHPUnit_TestCase {
var $lib;
diff --git a/Tests/Auth/OpenID/Consumer.php b/Tests/Auth/OpenID/Consumer.php
index 9134876..857cb8b 100644
--- a/Tests/Auth/OpenID/Consumer.php
+++ b/Tests/Auth/OpenID/Consumer.php
@@ -16,7 +16,7 @@
require_once 'Auth/OpenID/CryptUtil.php';
require_once 'Auth/OpenID/DiffieHellman.php';
require_once 'Auth/OpenID/Store/FileStore.php';
-require_once 'Auth/OpenID/OIDUtil.php';
+require_once 'Auth/OpenID/Util.php';
require_once 'Auth/OpenID/KVForm.php';
require_once 'Auth/OpenID/Consumer/Consumer.php';
require_once 'PHPUnit.php';
diff --git a/Tests/Auth/OpenID/DiffieHellman.php b/Tests/Auth/OpenID/DiffieHellman.php
index 2cb8b94..011857c 100644
--- a/Tests/Auth/OpenID/DiffieHellman.php
+++ b/Tests/Auth/OpenID/DiffieHellman.php
@@ -16,7 +16,7 @@
require_once 'PHPUnit.php';
require_once 'Auth/OpenID/DiffieHellman.php';
-require_once 'Tests/Auth/OpenID/Util.php';
+require_once 'Tests/Auth/OpenID/TestUtil.php';
class Tests_Auth_OpenID_DiffieHellman_CheckCases extends PHPUnit_TestCase {
function Tests_Auth_OpenID_DiffieHellman_CheckCases($cases, $n)
diff --git a/Tests/Auth/OpenID/HMACSHA1.php b/Tests/Auth/OpenID/HMACSHA1.php
index 4c532a0..07fd4cb 100644
--- a/Tests/Auth/OpenID/HMACSHA1.php
+++ b/Tests/Auth/OpenID/HMACSHA1.php
@@ -16,7 +16,7 @@
require_once 'PHPUnit.php';
require_once 'Auth/OpenID/HMACSHA1.php';
-require_once 'Tests/Auth/OpenID/Util.php';
+require_once 'Tests/Auth/OpenID/TestUtil.php';
class Tests_Auth_OpenID_HMACSHA1_TestCase extends PHPUnit_TestCase {
function Tests_Auth_OpenID_HMACSHA1_TestCase(
diff --git a/Tests/Auth/OpenID/OIDUtil.php b/Tests/Auth/OpenID/OIDUtil.php
deleted file mode 100644
index 1719fb2..0000000
--- a/Tests/Auth/OpenID/OIDUtil.php
+++ /dev/null
@@ -1,260 +0,0 @@
-<?php
-
-/**
- * Tests for utility functions used by the OpenID library.
- *
- * PHP versions 4 and 5
- *
- * LICENSE: See the COPYING file included in this distribution.
- *
- * @package OpenID
- * @author JanRain, Inc. <openid@janrain.com>
- * @copyright 2005 Janrain, Inc.
- * @license http://www.gnu.org/copyleft/lesser.html LGPL
- */
-
-require_once 'PHPUnit.php';
-require_once 'Auth/OpenID/OIDUtil.php';
-
-class Tests_Auth_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 = base64_encode($s);
- checkEncoded($this, $b64, $allowed_d);
- $s_prime = base64_decode($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 = base64_encode($s);
- checkEncoded($this, $b64, $allowed_d);
- $s_prime = base64_decode($b64);
- $this->assertEquals($s_prime, $s);
- }
- }
-
- function test_normalizeUrl()
- {
- $this->assertEquals("http://foo.com/",
- Auth_OpenID_normalizeUrl("foo.com"));
-
- $this->assertEquals("http://foo.com/",
- Auth_OpenID_normalizeUrl("http://foo.com"));
-
- $this->assertEquals("https://foo.com/",
- Auth_OpenID_normalizeUrl("https://foo.com"));
-
- $this->assertEquals("http://foo.com/bar",
- Auth_OpenID_normalizeUrl("foo.com/bar"));
-
- $this->assertEquals("http://foo.com/bar",
- Auth_OpenID_normalizeUrl("http://foo.com/bar"));
-
- $this->assertEquals("http://foo.com/",
- Auth_OpenID_normalizeUrl("http://foo.com/"));
-
- $this->assertEquals("https://foo.com/",
- Auth_OpenID_normalizeUrl("https://foo.com/"));
-
- $this->assertEquals("https://foo.com/bar" ,
- Auth_OpenID_normalizeUrl("https://foo.com/bar"));
-
- if (0) {
- $this->assertEquals("http://foo.com/%E8%8D%89",
- Auth_OpenID_normalizeUrl("foo.com/\u8349"));
-
- $this->assertEquals("http://foo.com/%E8%8D%89",
- Auth_OpenID_normalizeUrl("http://foo.com/\u8349"));
- }
-
- $non_ascii_domain_cases = array(
- array("http://xn--vl1a.com/",
- "\u8349.com"),
-
- array("http://xn--vl1a.com/",
- "http://\u8349.com"),
-
- array("http://xn--vl1a.com/",
- "\u8349.com/"),
-
- array("http://xn--vl1a.com/",
- "http://\u8349.com/"),
-
- array("http://xn--vl1a.com/%E8%8D%89",
- "\u8349.com/\u8349"),
-
- array("http://xn--vl1a.com/%E8%8D%89",
- "http://\u8349.com/\u8349"),
- );
-
- // XXX
- /*
- codecs.getencoder('idna')
- except LookupError:
- # If there is no idna codec, these cases with
- # non-ascii-representable domain names should fail.
- should_raise = True
- else:
- should_raise = False
-
- for expected, case in non_ascii_domain_cases:
-try:
-actual = Auth_OpenID_normalizeUrl(case)
- except UnicodeError:
- assert should_raise
- else:
-assert not should_raise and actual == expected, case
- */
-
- $this->assertNull(Auth_OpenID_normalizeUrl(null));
- $this->assertNull(Auth_OpenID_normalizeUrl(''));
- $this->assertNull(Auth_OpenID_normalizeUrl('http://'));
- }
-
- function test_appendArgs()
- {
-
- $simple = 'http://www.example.com/';
-
- $cases = array(
- array('empty list',
- array($simple, array()),
- $simple),
-
- array('empty dict',
- array($simple, array()),
- $simple),
-
- array('one list',
- array($simple, array(array('a', 'b'))),
- $simple . '?a=b'),
-
- array('one dict',
- array($simple, array('a' => 'b')),
- $simple . '?a=b'),
-
- array('two list (same)',
- array($simple, array(array('a', 'b'),
- array('a', 'c'))),
- $simple . '?a=b&a=c'),
-
- array('two list',
- array($simple, array(array('a', 'b'),
- array('b', 'c'))),
- $simple . '?a=b&b=c'),
-
- array('two list (order)',
- array($simple, array(array('b', 'c'),
- array('a', 'b'))),
- $simple . '?b=c&a=b'),
-
- array('two dict (order)',
- array($simple, array('b' => 'c',
- 'a' => 'b')),
- $simple . '?a=b&b=c'),
-
- array('escape',
- array($simple, array(array('=', '='))),
- $simple . '?%3D=%3D'),
-
- array('escape (URL)',
- array($simple, array(array('this_url',
- $simple))),
- $simple .
- '?this_url=http%3A%2F%2Fwww.example.com%2F'),
-
- array('use dots',
- array($simple, array(array('openid.stuff',
- 'bother'))),
- $simple . '?openid.stuff=bother'),
-
- array('args exist (empty)',
- array($simple . '?stuff=bother', array()),
- $simple . '?stuff=bother'),
-
- array('args exist',
- array($simple . '?stuff=bother',
- array(array('ack', 'ack'))),
- $simple . '?stuff=bother&ack=ack'),
-
- array('args exist',
- array($simple . '?stuff=bother',
- array(array('ack', 'ack'))),
- $simple . '?stuff=bother&ack=ack'),
-
- array('args exist (dict)',
- array($simple . '?stuff=bother',
- array('ack' => 'ack')),
- $simple . '?stuff=bother&ack=ack'),
-
- array('args exist (dict 2)',
- array($simple . '?stuff=bother',
- array('ack' => 'ack', 'zebra' => 'lion')),
- $simple . '?stuff=bother&ack=ack&zebra=lion'),
-
- array('three args (dict)',
- array($simple, array('stuff' => 'bother',
- 'ack' => 'ack',
- 'zebra' => 'lion')),
- $simple . '?ack=ack&stuff=bother&zebra=lion'),
-
- array('three args (list)',
- array($simple, array(
- array('stuff', 'bother'),
- array('ack', 'ack'),
- array('zebra', 'lion'))),
- $simple . '?stuff=bother&ack=ack&zebra=lion'),
- );
-
- // Tests.
- foreach ($cases as $case) {
- list($desc, $data, $expected) = $case;
- list($url, $query) = $data;
- $this->assertEquals($expected,
- Auth_OpenID_appendArgs($url, $query));
- }
- }
-}
-
-?>
diff --git a/Tests/Auth/OpenID/Parse.php b/Tests/Auth/OpenID/Parse.php
index 62990c3..4d5dbd3 100644
--- a/Tests/Auth/OpenID/Parse.php
+++ b/Tests/Auth/OpenID/Parse.php
@@ -13,7 +13,7 @@
* @license http://www.gnu.org/copyleft/lesser.html LGPL
*/
-require_once 'Tests/Auth/OpenID/Util.php';
+require_once 'Tests/Auth/OpenID/TestUtil.php';
require_once 'Auth/OpenID/Consumer/Parse.php';
require_once 'PHPUnit.php';
diff --git a/Tests/Auth/OpenID/StoreTest.php b/Tests/Auth/OpenID/StoreTest.php
index 32c9d14..bf20828 100644
--- a/Tests/Auth/OpenID/StoreTest.php
+++ b/Tests/Auth/OpenID/StoreTest.php
@@ -18,7 +18,7 @@
*/
require_once 'Auth/OpenID/Association.php';
require_once 'Auth/OpenID/CryptUtil.php';
-require_once 'Auth/OpenID/OIDUtil.php';
+require_once 'Auth/OpenID/Util.php';
require_once 'PHPUnit.php';
/**
diff --git a/Tests/Auth/OpenID/TestUtil.php b/Tests/Auth/OpenID/TestUtil.php
new file mode 100644
index 0000000..8358160
--- /dev/null
+++ b/Tests/Auth/OpenID/TestUtil.php
@@ -0,0 +1,28 @@
+<?php
+
+/**
+ * Utilites for test functions
+ */
+
+function Tests_Auth_OpenID_datafile($name, $reader)
+{
+ $path = dirname(realpath(__FILE__));
+ $sep = DIRECTORY_SEPARATOR;
+ $filename = $path . $sep . 'data' . $sep . $name;
+ $data = $reader($filename);
+ if ($data === false) {
+ $msg = "Failed to open data file: $name";
+ trigger_error($msg, E_USER_ERROR);
+ }
+ return $data;
+}
+
+function Tests_Auth_OpenID_readdata($name)
+{
+ return Tests_Auth_OpenID_datafile($name, 'file_get_contents');
+}
+
+function Tests_Auth_OpenID_readlines($name)
+{
+ return Tests_Auth_OpenID_datafile($name, 'file');
+}
diff --git a/Tests/Auth/OpenID/TrustRoot.php b/Tests/Auth/OpenID/TrustRoot.php
index 54694d0..80fa93b 100644
--- a/Tests/Auth/OpenID/TrustRoot.php
+++ b/Tests/Auth/OpenID/TrustRoot.php
@@ -5,7 +5,7 @@
*/
require_once "Auth/OpenID/TrustRoot.php";
-require_once "Tests/Auth/OpenID/Util.php";
+require_once "Tests/Auth/OpenID/TestUtil.php";
require_once "PHPUnit.php";
class Tests_Auth_OpenID_TRParseCase extends PHPUnit_TestCase {
diff --git a/Tests/Auth/OpenID/Util.php b/Tests/Auth/OpenID/Util.php
index 8358160..c6fa07c 100644
--- a/Tests/Auth/OpenID/Util.php
+++ b/Tests/Auth/OpenID/Util.php
@@ -1,28 +1,260 @@
<?php
/**
- * Utilites for test functions
+ * Tests for utility functions used by the OpenID library.
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE: See the COPYING file included in this distribution.
+ *
+ * @package OpenID
+ * @author JanRain, Inc. <openid@janrain.com>
+ * @copyright 2005 Janrain, Inc.
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL
*/
-function Tests_Auth_OpenID_datafile($name, $reader)
-{
- $path = dirname(realpath(__FILE__));
- $sep = DIRECTORY_SEPARATOR;
- $filename = $path . $sep . 'data' . $sep . $name;
- $data = $reader($filename);
- if ($data === false) {
- $msg = "Failed to open data file: $name";
- trigger_error($msg, E_USER_ERROR);
+require_once 'PHPUnit.php';
+require_once 'Auth/OpenID/Util.php';
+
+class Tests_Auth_OpenID_Util 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 = base64_encode($s);
+ checkEncoded($this, $b64, $allowed_d);
+ $s_prime = base64_decode($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 = base64_encode($s);
+ checkEncoded($this, $b64, $allowed_d);
+ $s_prime = base64_decode($b64);
+ $this->assertEquals($s_prime, $s);
+ }
}
- return $data;
-}
-function Tests_Auth_OpenID_readdata($name)
-{
- return Tests_Auth_OpenID_datafile($name, 'file_get_contents');
-}
+ function test_normalizeUrl()
+ {
+ $this->assertEquals("http://foo.com/",
+ Auth_OpenID_normalizeUrl("foo.com"));
+
+ $this->assertEquals("http://foo.com/",
+ Auth_OpenID_normalizeUrl("http://foo.com"));
+
+ $this->assertEquals("https://foo.com/",
+ Auth_OpenID_normalizeUrl("https://foo.com"));
+
+ $this->assertEquals("http://foo.com/bar",
+ Auth_OpenID_normalizeUrl("foo.com/bar"));
+
+ $this->assertEquals("http://foo.com/bar",
+ Auth_OpenID_normalizeUrl("http://foo.com/bar"));
+
+ $this->assertEquals("http://foo.com/",
+ Auth_OpenID_normalizeUrl("http://foo.com/"));
+
+ $this->assertEquals("https://foo.com/",
+ Auth_OpenID_normalizeUrl("https://foo.com/"));
+
+ $this->assertEquals("https://foo.com/bar" ,
+ Auth_OpenID_normalizeUrl("https://foo.com/bar"));
+
+ if (0) {
+ $this->assertEquals("http://foo.com/%E8%8D%89",
+ Auth_OpenID_normalizeUrl("foo.com/\u8349"));
+
+ $this->assertEquals("http://foo.com/%E8%8D%89",
+ Auth_OpenID_normalizeUrl("http://foo.com/\u8349"));
+ }
+
+ $non_ascii_domain_cases = array(
+ array("http://xn--vl1a.com/",
+ "\u8349.com"),
+
+ array("http://xn--vl1a.com/",
+ "http://\u8349.com"),
+
+ array("http://xn--vl1a.com/",
+ "\u8349.com/"),
+
+ array("http://xn--vl1a.com/",
+ "http://\u8349.com/"),
+
+ array("http://xn--vl1a.com/%E8%8D%89",
+ "\u8349.com/\u8349"),
+
+ array("http://xn--vl1a.com/%E8%8D%89",
+ "http://\u8349.com/\u8349"),
+ );
+
+ // XXX
+ /*
+ codecs.getencoder('idna')
+ except LookupError:
+ # If there is no idna codec, these cases with
+ # non-ascii-representable domain names should fail.
+ should_raise = True
+ else:
+ should_raise = False
-function Tests_Auth_OpenID_readlines($name)
-{
- return Tests_Auth_OpenID_datafile($name, 'file');
+ for expected, case in non_ascii_domain_cases:
+try:
+actual = Auth_OpenID_normalizeUrl(case)
+ except UnicodeError:
+ assert should_raise
+ else:
+assert not should_raise and actual == expected, case
+ */
+
+ $this->assertNull(Auth_OpenID_normalizeUrl(null));
+ $this->assertNull(Auth_OpenID_normalizeUrl(''));
+ $this->assertNull(Auth_OpenID_normalizeUrl('http://'));
+ }
+
+ function test_appendArgs()
+ {
+
+ $simple = 'http://www.example.com/';
+
+ $cases = array(
+ array('empty list',
+ array($simple, array()),
+ $simple),
+
+ array('empty dict',
+ array($simple, array()),
+ $simple),
+
+ array('one list',
+ array($simple, array(array('a', 'b'))),
+ $simple . '?a=b'),
+
+ array('one dict',
+ array($simple, array('a' => 'b')),
+ $simple . '?a=b'),
+
+ array('two list (same)',
+ array($simple, array(array('a', 'b'),
+ array('a', 'c'))),
+ $simple . '?a=b&a=c'),
+
+ array('two list',
+ array($simple, array(array('a', 'b'),
+ array('b', 'c'))),
+ $simple . '?a=b&b=c'),
+
+ array('two list (order)',
+ array($simple, array(array('b', 'c'),
+ array('a', 'b'))),
+ $simple . '?b=c&a=b'),
+
+ array('two dict (order)',
+ array($simple, array('b' => 'c',
+ 'a' => 'b')),
+ $simple . '?a=b&b=c'),
+
+ array('escape',
+ array($simple, array(array('=', '='))),
+ $simple . '?%3D=%3D'),
+
+ array('escape (URL)',
+ array($simple, array(array('this_url',
+ $simple))),
+ $simple .
+ '?this_url=http%3A%2F%2Fwww.example.com%2F'),
+
+ array('use dots',
+ array($simple, array(array('openid.stuff',
+ 'bother'))),
+ $simple . '?openid.stuff=bother'),
+
+ array('args exist (empty)',
+ array($simple . '?stuff=bother', array()),
+ $simple . '?stuff=bother'),
+
+ array('args exist',
+ array($simple . '?stuff=bother',
+ array(array('ack', 'ack'))),
+ $simple . '?stuff=bother&ack=ack'),
+
+ array('args exist',
+ array($simple . '?stuff=bother',
+ array(array('ack', 'ack'))),
+ $simple . '?stuff=bother&ack=ack'),
+
+ array('args exist (dict)',
+ array($simple . '?stuff=bother',
+ array('ack' => 'ack')),
+ $simple . '?stuff=bother&ack=ack'),
+
+ array('args exist (dict 2)',
+ array($simple . '?stuff=bother',
+ array('ack' => 'ack', 'zebra' => 'lion')),
+ $simple . '?stuff=bother&ack=ack&zebra=lion'),
+
+ array('three args (dict)',
+ array($simple, array('stuff' => 'bother',
+ 'ack' => 'ack',
+ 'zebra' => 'lion')),
+ $simple . '?ack=ack&stuff=bother&zebra=lion'),
+
+ array('three args (list)',
+ array($simple, array(
+ array('stuff', 'bother'),
+ array('ack', 'ack'),
+ array('zebra', 'lion'))),
+ $simple . '?stuff=bother&ack=ack&zebra=lion'),
+ );
+
+ // Tests.
+ foreach ($cases as $case) {
+ list($desc, $data, $expected) = $case;
+ list($url, $query) = $data;
+ $this->assertEquals($expected,
+ Auth_OpenID_appendArgs($url, $query));
+ }
+ }
}
+
+?>