diff options
author | tailor <cygnus@janrain.com> | 2006-08-10 21:41:07 +0000 |
---|---|---|
committer | tailor <cygnus@janrain.com> | 2006-08-10 21:41:07 +0000 |
commit | e21e8446061c17caa9fbacc6f1b815c13f15681b (patch) | |
tree | bb6373fbe0be6dd1ea00d65aa25d453622619b6f /Tests/Auth | |
parent | d8e179f4a6e50a95c52ece680cb63809dbf075a7 (diff) | |
download | php-openid-e21e8446061c17caa9fbacc6f1b815c13f15681b.zip php-openid-e21e8446061c17caa9fbacc6f1b815c13f15681b.tar.gz php-openid-e21e8446061c17caa9fbacc6f1b815c13f15681b.tar.bz2 |
[project @ Added impl and tests for URI normalization]
Diffstat (limited to 'Tests/Auth')
-rw-r--r-- | Tests/Auth/OpenID/URINorm.php | 68 | ||||
-rw-r--r-- | Tests/Auth/OpenID/data/urinorm.txt | 79 |
2 files changed, 147 insertions, 0 deletions
diff --git a/Tests/Auth/OpenID/URINorm.php b/Tests/Auth/OpenID/URINorm.php new file mode 100644 index 0000000..02263af --- /dev/null +++ b/Tests/Auth/OpenID/URINorm.php @@ -0,0 +1,68 @@ +<?php + +/** + * Tests for the URI normalization routines 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/URINorm.php'; +require_once 'Tests/Auth/OpenID/TestUtil.php'; + +class Tests_Auth_OpenID_URINorm_TestCase extends PHPUnit_TestCase { + function Tests_Auth_OpenID_URINorm_TestCase( + $name, $uri, $expected) + { + + $this->setName($name); + $this->uri = $uri; + $this->expected = $expected; + } + + function runTest() + { + $actual = Auth_OpenID_urinorm($this->uri); + $this->assertEquals($this->expected, $actual); + } +} + +class Tests_Auth_OpenID_URINorm extends PHPUnit_TestSuite { + function _readTestCases() + { + $lines = Tests_Auth_OpenID_readlines('urinorm.txt'); + $cases = array(); + $case = array(); + for ($i = 0; $i < count($lines) && ($i + 3 <= count($lines)); $i += 4) { + $name = trim($lines[$i]); + $uri = trim($lines[$i + 1]); + $expected = trim($lines[$i + 2]); + if ($expected == 'fail') { + $expected = null; + } + $cases[] = array($name, $uri, $expected); + } + + return $cases; + } + + function Tests_Auth_OpenID_URINorm($name) + { + $this->setName($name); + $cases = $this->_readTestCases(); + foreach ($cases as $case) { + list($name, $uri, $expected) = $case; + $this->addTest(new Tests_Auth_OpenID_URINorm_TestCase($name, $uri, $expected)); + } + } +} + +?>
\ No newline at end of file diff --git a/Tests/Auth/OpenID/data/urinorm.txt b/Tests/Auth/OpenID/data/urinorm.txt new file mode 100644 index 0000000..95262fe --- /dev/null +++ b/Tests/Auth/OpenID/data/urinorm.txt @@ -0,0 +1,79 @@ +Already normal form +http://example.com/ +http://example.com/ + +Add a trailing slash +http://example.com +http://example.com/ + +Remove an empty port segment +http://example.com:/ +http://example.com/ + +Remove a default port segment +http://example.com:80/ +http://example.com/ + +Capitalization in host names +http://wWw.exaMPLE.COm/ +http://www.example.com/ + +Capitalization in scheme names +htTP://example.com/ +http://example.com/ + +Capitalization in percent-escaped reserved characters +http://example.com/foo%2cbar +http://example.com/foo%2Cbar + +Unescape percent-encoded unreserved characters +http://example.com/foo%2Dbar%2dbaz +http://example.com/foo-bar-baz + +remove_dot_segments example 1 +http://example.com/a/b/c/./../../g +http://example.com/a/g + +remove_dot_segments example 2 +http://example.com/mid/content=5/../6 +http://example.com/mid/6 + +remove_dot_segments: single-dot +http://example.com/a/./b +http://example.com/a/b + +remove_dot_segments: double-dot +http://example.com/a/../b +http://example.com/b + +remove_dot_segments: leading double-dot +http://example.com/../b +http://example.com/b + +remove_dot_segments: trailing single-dot +http://example.com/a/. +http://example.com/a/ + +remove_dot_segments: trailing double-dot +http://example.com/a/.. +http://example.com/ + +remove_dot_segments: trailing single-dot-slash +http://example.com/a/./ +http://example.com/a/ + +remove_dot_segments: trailing double-dot-slash +http://example.com/a/../ +http://example.com/ + +Test of all kinds of syntax-based normalization +hTTPS://a/./b/../b/%63/%7bfoo%7d +https://a/b/c/%7Bfoo%7D + +Unsupported scheme +ftp://example.com/ +fail + +Non-absolute URI +http:/foo +fail
\ No newline at end of file |