diff --git a/app/webroot/.htaccess b/app/webroot/.htaccess index f9d8b938bdb..8e7f16397b2 100644 --- a/app/webroot/.htaccess +++ b/app/webroot/.htaccess @@ -2,5 +2,5 @@ RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f - RewriteRule ^(.*)$ index.php?url=$1 [QSA,L] + RewriteRule ^(.*)$ index.php/$1 [QSA,L] \ No newline at end of file diff --git a/app/webroot/index.php b/app/webroot/index.php index 5955688f62a..f1ff8d1974d 100644 --- a/app/webroot/index.php +++ b/app/webroot/index.php @@ -70,10 +70,11 @@ if (!include(CORE_PATH . 'cake' . DS . 'bootstrap.php')) { trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR); } - if (isset($_GET['url']) && $_GET['url'] === 'favicon.ico') { + + if (isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] == '/favicon.ico') { return; - } else { - require LIBS . 'dispatcher.php'; - $Dispatcher = new Dispatcher(); - $Dispatcher->dispatch(new CakeRequest(isset($_GET['url']) ? $_GET['url'] : null)); } + + require LIBS . 'dispatcher.php'; + $Dispatcher = new Dispatcher(); + $Dispatcher->dispatch(new CakeRequest()); diff --git a/cake/console/templates/skel/webroot/.htaccess b/cake/console/templates/skel/webroot/.htaccess index f9d8b938bdb..8e7f16397b2 100644 --- a/cake/console/templates/skel/webroot/.htaccess +++ b/cake/console/templates/skel/webroot/.htaccess @@ -2,5 +2,5 @@ RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f - RewriteRule ^(.*)$ index.php?url=$1 [QSA,L] + RewriteRule ^(.*)$ index.php/$1 [QSA,L] \ No newline at end of file diff --git a/cake/console/templates/skel/webroot/index.php b/cake/console/templates/skel/webroot/index.php index 5955688f62a..f1ff8d1974d 100644 --- a/cake/console/templates/skel/webroot/index.php +++ b/cake/console/templates/skel/webroot/index.php @@ -70,10 +70,11 @@ if (!include(CORE_PATH . 'cake' . DS . 'bootstrap.php')) { trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR); } - if (isset($_GET['url']) && $_GET['url'] === 'favicon.ico') { + + if (isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] == '/favicon.ico') { return; - } else { - require LIBS . 'dispatcher.php'; - $Dispatcher = new Dispatcher(); - $Dispatcher->dispatch(new CakeRequest(isset($_GET['url']) ? $_GET['url'] : null)); } + + require LIBS . 'dispatcher.php'; + $Dispatcher = new Dispatcher(); + $Dispatcher->dispatch(new CakeRequest()); diff --git a/cake/libs/cake_request.php b/cake/libs/cake_request.php index 1f2cfd03780..7a80b43a5ba 100644 --- a/cake/libs/cake_request.php +++ b/cake/libs/cake_request.php @@ -112,7 +112,7 @@ class CakeRequest implements ArrayAccess { * @return void */ public function __construct($url = null, $parseEnvironment = true) { - $this->base = $this->_base(); + $this->_base(); if (empty($url)) { $url = $this->_url(); } @@ -167,98 +167,50 @@ protected function _processGet() { } else { $query = $_GET; } + if (strpos($this->url, '?') !== false) { list(, $querystr) = explode('?', $this->url); parse_str($querystr, $queryArgs); - $query += $queryArgs; + $query += $queryArgs; } if (isset($this->params['url'])) { $query = array_merge($this->params['url'], $query); } - $query['url'] = $this->url; $this->query = $query; } /** - * Returns the REQUEST_URI from the server environment, or, failing that, - * constructs a new one, using the PHP_SELF constant and other variables. + * Get the request uri. Looks in PATH_INFO first, as this is the exact value we need prepared + * by PHP. Following that, REQUEST_URI, PHP_SELF, HTTP_X_REWRITE_URL and argv are checked in that order. + * Each of these server variables have the base path, and query strings stripped off * - * @return string URI + * @return string URI The CakePHP request path that is being accessed. */ - protected function _uri() { - foreach (array('HTTP_X_REWRITE_URL', 'REQUEST_URI', 'argv') as $var) { + protected function _url() { + $pathInfo = env('PATH_INFO'); + if (!empty($pathInfo)) { + return $pathInfo; + } + foreach (array('PHP_SELF', 'REQUEST_URI', 'HTTP_X_REWRITE_URL', 'argv') as $var) { if ($uri = env($var)) { if ($var == 'argv') { - $uri = $uri[0]; + $uri = $url[0]; } break; } } + $base = $this->base; - $base = trim(Configure::read('App.baseUrl'), '/'); - - if ($base) { - $uri = preg_replace('/^(?:\/)?(?:' . preg_quote($base, '/') . ')?(?:url=)?/', '', $uri); - } - if (PHP_SAPI == 'isapi') { - $uri = preg_replace('/^(?:\/)?(?:\/)?(?:\?)?(?:url=)?/', '', $uri); - } - if (!empty($uri)) { - if (key($_GET) && strpos(key($_GET), '?') !== false) { - unset($_GET[key($_GET)]); - } - $uri = explode('?', $uri, 2); - - if (isset($uri[1])) { - parse_str($uri[1], $_GET); - } - $uri = $uri[0]; - } else { - $uri = env('QUERY_STRING'); + if (strpos($uri, $base) === 0) { + $uri = substr($uri, strlen($base)); } - if (is_string($uri) && strpos($uri, 'index.php') !== false) { - list(, $uri) = explode('index.php', $uri, 2); + if (strpos($uri, '?') !== false) { + $uri = parse_url($uri, PHP_URL_PATH); } if (empty($uri) || $uri == '/' || $uri == '//') { - return ''; + return '/'; } - return str_replace('//', '/', '/' . $uri); - } - -/** - * Returns and sets the $_GET[url] derived from the REQUEST_URI - * - * @return string URL - */ - protected function _url() { - if (empty($_GET['url'])) { - $uri = $this->_uri(); - $base = $this->base; - - $url = null; - $tmpUri = preg_replace('/^(?:\?)?(?:\/)?/', '', $uri); - $baseDir = trim(dirname($base) . '/', '/'); - - if ($tmpUri === '/' || $tmpUri == $baseDir || $tmpUri == $base) { - $url = '/'; - } else { - $elements = array(); - if ($base && strpos($uri, $base) !== false) { - $elements = explode($base, $uri); - } elseif (preg_match('/^[\/\?\/|\/\?|\?\/]/', $uri)) { - $elements = array(1 => preg_replace('/^[\/\?\/|\/\?|\?\/]/', '', $uri)); - } - - if (!empty($elements[1])) { - $url = $elements[1]; - } else { - $url = '/'; - } - } - } else { - $url = $_GET['url']; - } - return $url; + return $uri; } /** @@ -279,8 +231,7 @@ protected function _base() { return $this->base = $base; } if (!$baseUrl) { - $replace = array('<', '>', '*', '\'', '"'); - $base = str_replace($replace, '', dirname(env('PHP_SELF'))); + $base = dirname(env('SCRIPT_NAME')); if ($webroot === 'webroot' && $webroot === basename($base)) { $base = dirname($base); @@ -294,7 +245,7 @@ protected function _base() { } $this->webroot = $base .'/'; - return $base; + return $this->base = $base; } $file = '/' . basename($baseUrl); @@ -306,7 +257,6 @@ protected function _base() { $this->webroot = $base . '/'; $docRoot = env('DOCUMENT_ROOT'); - $script = realpath(env('SCRIPT_FILENAME')); $docRootContainsWebroot = strpos($docRoot, $dir . '/' . $webroot); if (!empty($base) || !$docRootContainsWebroot) { @@ -317,7 +267,7 @@ protected function _base() { $this->webroot .= $webroot . '/'; } } - return $base . $file; + return $this->base = $base . $file; } /** diff --git a/cake/libs/controller/components/auth.php b/cake/libs/controller/components/auth.php index a9384cb49ae..b37ebe69ef5 100644 --- a/cake/libs/controller/components/auth.php +++ b/cake/libs/controller/components/auth.php @@ -289,8 +289,8 @@ public function startup($controller) { $url = ''; - if (isset($request->query['url'])) { - $url = $request->query['url']; + if (isset($request->url)) { + $url = $request->url; } $url = Router::normalize($url); $loginAction = Router::normalize($this->loginAction); diff --git a/cake/tests/cases/console/shells/api.test.php b/cake/tests/cases/console/shells/api.test.php index 79deea55117..99e5abf33b4 100644 --- a/cake/tests/cases/console/shells/api.test.php +++ b/cake/tests/cases/console/shells/api.test.php @@ -66,20 +66,19 @@ public function testMethodNameDetection () { '8. getResponse()', '9. header($status)', '10. httpCodes($code = NULL)', - '11. isAuthorized()', - '12. loadModel($modelClass = NULL, $id = NULL)', - '13. paginate($object = NULL, $scope = array (), $whitelist = array ())', - '14. postConditions($data = array (), $op = NULL, $bool = \'AND\', $exclusive = false)', - '15. redirect($url, $status = NULL, $exit = true)', - '16. referer($default = NULL, $local = false)', - '17. render($action = NULL, $layout = NULL, $file = NULL)', - '18. set($one, $two = NULL)', - '19. setAction($action)', - '20. setRequest($request)', - '21. shutdownProcess()', - '22. startupProcess()', - '23. validate()', - '24. validateErrors()' + '11. loadModel($modelClass = NULL, $id = NULL)', + '12. paginate($object = NULL, $scope = array (), $whitelist = array ())', + '13. postConditions($data = array (), $op = NULL, $bool = \'AND\', $exclusive = false)', + '14. redirect($url, $status = NULL, $exit = true)', + '15. referer($default = NULL, $local = false)', + '16. render($view = NULL, $layout = NULL)', + '17. set($one, $two = NULL)', + '18. setAction($action)', + '19. setRequest($request)', + '20. shutdownProcess()', + '21. startupProcess()', + '22. validate()', + '23. validateErrors()' ); $this->Shell->expects($this->at(2))->method('out')->with($expected); diff --git a/cake/tests/cases/libs/cake_request.test.php b/cake/tests/cases/libs/cake_request.test.php index df018ad0bef..0a1381e9dec 100644 --- a/cake/tests/cases/libs/cake_request.test.php +++ b/cake/tests/cases/libs/cake_request.test.php @@ -31,6 +31,9 @@ function setUp() { $this->_get = $_GET; $this->_post = $_POST; $this->_files = $_FILES; + $this->_app = Configure::read('App'); + + Configure::write('App.baseUrl', false); } /** @@ -44,6 +47,7 @@ function tearDown() { $_GET = $this->_get; $_POST = $this->_post; $_FILES = $this->_files; + Configure::write('App', $this->_app); } /** @@ -70,12 +74,11 @@ function testConstructionGetParsing() { 'two' => 'banana' ); $request = new CakeRequest('some/path'); - $this->assertEqual($request->query, $_GET + array('url' => 'some/path')); + $this->assertEqual($request->query, $_GET); $_GET = array( 'one' => 'param', 'two' => 'banana', - 'url' => 'some/path' ); $request = new CakeRequest('some/path'); $this->assertEqual($request->query, $_GET); @@ -90,8 +93,10 @@ function testConstructionGetParsing() { function testQueryStringParsingFromInputUrl() { $_GET = array(); $request = new CakeRequest('some/path?one=something&two=else'); - $expected = array('one' => 'something', 'two' => 'else', 'url' => 'some/path?one=something&two=else'); + $expected = array('one' => 'something', 'two' => 'else'); $this->assertEqual($request->query, $expected); + $this->assertEquals('some/path?one=something&two=else', $request->url); + } /** @@ -790,9 +795,8 @@ public function testBaseUrlAndWebrootWithModRewrite() { Configure::write('App.baseUrl', false); $_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches'; - $_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/app/webroot/index.php'; - $_SERVER['PHP_SELF'] = '/1.2.x.x/app/webroot/index.php'; - $_GET['url'] = 'posts/view/1'; + $_SERVER['SCRIPT_NAME'] = '/1.2.x.x/app/webroot/index.php'; + $_SERVER['PATH_INFO'] = '/posts/view/1'; $request = new CakeRequest(); $this->assertEqual($request->base, '/1.2.x.x'); @@ -801,9 +805,8 @@ public function testBaseUrlAndWebrootWithModRewrite() { $_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches/1.2.x.x/app/webroot'; - $_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/app/webroot/index.php'; - $_SERVER['PHP_SELF'] = '/index.php'; - $_GET['url'] = 'posts/add'; + $_SERVER['SCRIPT_NAME'] = '/index.php'; + $_SERVER['PATH_INFO'] = '/posts/add'; $request = new CakeRequest(); $this->assertEqual($request->base, ''); @@ -811,8 +814,7 @@ public function testBaseUrlAndWebrootWithModRewrite() { $this->assertEqual($request->url, 'posts/add'); $_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches/1.2.x.x/test/'; - $_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/test/webroot/index.php'; - $_SERVER['PHP_SELF'] = '/webroot/index.php'; + $_SERVER['SCRIPT_NAME'] = '/webroot/index.php'; $request = new CakeRequest(); $this->assertEqual('', $request->base); @@ -820,18 +822,16 @@ public function testBaseUrlAndWebrootWithModRewrite() { $_SERVER['DOCUMENT_ROOT'] = '/some/apps/where'; - $_SERVER['SCRIPT_FILENAME'] = '/some/apps/where/app/webroot/index.php'; - $_SERVER['PHP_SELF'] = '/some/apps/where/app/webroot/index.php'; + $_SERVER['SCRIPT_NAME'] = '/app/webroot/index.php'; $request = new CakeRequest(); - $this->assertEqual($request->base, '/some/apps/where'); - $this->assertEqual($request->webroot, '/some/apps/where/'); + $this->assertEqual($request->base, ''); + $this->assertEqual($request->webroot, '/'); Configure::write('App.dir', 'auth'); $_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches'; - $_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/demos/auth/webroot/index.php'; - $_SERVER['PHP_SELF'] = '/demos/auth/webroot/index.php'; + $_SERVER['SCRIPT_NAME'] = '/demos/auth/webroot/index.php'; $request = new CakeRequest(); @@ -841,8 +841,7 @@ public function testBaseUrlAndWebrootWithModRewrite() { Configure::write('App.dir', 'code'); $_SERVER['DOCUMENT_ROOT'] = '/Library/WebServer/Documents'; - $_SERVER['SCRIPT_FILENAME'] = '/Library/WebServer/Documents/clients/PewterReport/code/webroot/index.php'; - $_SERVER['PHP_SELF'] = '/clients/PewterReport/code/webroot/index.php'; + $_SERVER['SCRIPT_NAME'] = '/clients/PewterReport/code/webroot/index.php'; $request = new CakeRequest(); $this->assertEqual($request->base, '/clients/PewterReport/code'); @@ -856,8 +855,7 @@ public function testBaseUrlAndWebrootWithModRewrite() { */ public function testBaseUrlwithModRewriteAlias() { $_SERVER['DOCUMENT_ROOT'] = '/home/aplusnur/public_html'; - $_SERVER['SCRIPT_FILENAME'] = '/home/aplusnur/cake2/app/webroot/index.php'; - $_SERVER['PHP_SELF'] = '/control/index.php'; + $_SERVER['SCRIPT_NAME'] = '/control/index.php'; Configure::write('App.base', '/control'); @@ -871,8 +869,7 @@ public function testBaseUrlwithModRewriteAlias() { Configure::write('App.webroot', 'newaffiliate'); $_SERVER['DOCUMENT_ROOT'] = '/var/www/abtravaff/html'; - $_SERVER['SCRIPT_FILENAME'] = '/var/www/abtravaff/html/newaffiliate/index.php'; - $_SERVER['PHP_SELF'] = '/newaffiliate/index.php'; + $_SERVER['SCRIPT_NAME'] = '/newaffiliate/index.php'; $request = new CakeRequest(); $this->assertEqual($request->base, '/newaffiliate'); @@ -983,34 +980,25 @@ function testBaseUrlNoRewriteWebrootIndex() { } /** - * testEnvironmentDetection method + * generator for environment configurations * * @return void */ - public function testEnvironmentDetection() { - $environments = array( - 'IIS' => array( - 'No rewrite base path' => array( + public static function environmentGenerator() { + return array( + array( + 'IIS - No rewrite base path', + array( 'App' => array( 'base' => false, - 'baseUrl' => '/index.php?', - 'server' => 'IIS', + 'baseUrl' => '/index.php', 'dir' => 'app', 'webroot' => 'webroot' ), 'SERVER' => array( - 'HTTPS' => 'off', 'SCRIPT_NAME' => '/index.php', 'PATH_TRANSLATED' => 'C:\\Inetpub\\wwwroot', 'QUERY_STRING' => '', - 'REMOTE_ADDR' => '127.0.0.1', - 'REMOTE_HOST' => '127.0.0.1', - 'REQUEST_METHOD' => 'GET', - 'SERVER_NAME' => 'localhost', - 'SERVER_PORT' => '80', - 'SERVER_PROTOCOL' => 'HTTP/1.1', - 'SERVER_SOFTWARE' => 'Microsoft-IIS/5.1', - 'APPL_PHYSICAL_PATH' => 'C:\\Inetpub\\wwwroot\\', 'REQUEST_URI' => '/index.php', 'URL' => '/index.php', 'SCRIPT_FILENAME' => 'C:\\Inetpub\\wwwroot\\index.php', @@ -1019,73 +1007,47 @@ public function testEnvironmentDetection() { 'ORIG_PATH_TRANSLATED' => 'C:\\Inetpub\\wwwroot\\index.php', 'DOCUMENT_ROOT' => 'C:\\Inetpub\\wwwroot', 'PHP_SELF' => '/index.php', - 'HTTP_HOST' => 'localhost', - 'argv' => array(), - 'argc' => 0 ), - 'reload' => true, - 'base' => '/index.php?', + ), + array( + 'base' => '/index.php', 'webroot' => '/app/webroot/', 'url' => '' ), - 'No rewrite with path' => array( + ), + array( + 'IIS - No rewrite with path, no PHP_SELF', + array( + 'App' => array( + 'base' => false, + 'baseUrl' => '/index.php?', + 'dir' => 'app', + 'webroot' => 'webroot' + ), 'SERVER' => array( 'QUERY_STRING' => '/posts/add', 'REQUEST_URI' => '/index.php?/posts/add', + 'PHP_SELF' => '', 'URL' => '/index.php?/posts/add', 'argv' => array('/posts/add'), 'argc' => 1 ), - 'reload' => false, - 'url' => 'posts/add', - 'base' => '/index.php?', - 'webroot' => '/app/webroot/' - ), - 'No rewrite sub dir 1' => array( - 'GET' => array(), - 'SERVER' => array( - 'QUERY_STRING' => '', - 'REQUEST_URI' => '/index.php', - 'URL' => '/index.php', - 'SCRIPT_FILENAME' => 'C:\\Inetpub\\wwwroot\\index.php', - 'ORIG_PATH_INFO' => '/index.php', - 'PATH_INFO' => '', - 'ORIG_PATH_TRANSLATED' => 'C:\\Inetpub\\wwwroot\\index.php', - 'DOCUMENT_ROOT' => 'C:\\Inetpub\\wwwroot', - 'PHP_SELF' => '/index.php', - 'argv' => array(), - 'argc' => 0 - ), - 'reload' => false, - 'url' => '', - 'base' => '/index.php?', - 'webroot' => '/app/webroot/' ), - 'No rewrite sub dir 1 with path' => array( - 'GET' => array('/posts/add' => ''), - 'SERVER' => array( - 'QUERY_STRING' => '/posts/add', - 'REQUEST_URI' => '/index.php?/posts/add', - 'URL' => '/index.php?/posts/add', - 'SCRIPT_FILENAME' => 'C:\\Inetpub\\wwwroot\\index.php', - 'argv' => array('/posts/add'), - 'argc' => 1 - ), - 'reload' => false, + array( 'url' => 'posts/add', 'base' => '/index.php?', 'webroot' => '/app/webroot/' - ), - 'No rewrite sub dir 2' => array( + ) + ), + array( + 'IIS - No rewrite sub dir 2', + array( 'App' => array( 'base' => false, - 'baseUrl' => '/site/index.php?', + 'baseUrl' => '/site/index.php', 'dir' => 'app', 'webroot' => 'webroot', - 'server' => 'IIS' ), - 'GET' => array(), - 'POST' => array(), 'SERVER' => array( 'SCRIPT_NAME' => '/site/index.php', 'PATH_TRANSLATED' => 'C:\\Inetpub\\wwwroot', @@ -1098,33 +1060,45 @@ public function testEnvironmentDetection() { 'argv' => array(), 'argc' => 0 ), - 'reload' => false, + ), + array( 'url' => '', - 'base' => '/site/index.php?', + 'base' => '/site/index.php', 'webroot' => '/site/app/webroot/' ), - 'No rewrite sub dir 2 with path' => array( + ), + array( + 'IIS - No rewrite sub dir 2 with path', + array( + 'App' => array( + 'base' => false, + 'baseUrl' => '/site/index.php', + 'dir' => 'app', + 'webroot' => 'webroot' + ), 'GET' => array('/posts/add' => ''), 'SERVER' => array( 'SCRIPT_NAME' => '/site/index.php', 'PATH_TRANSLATED' => 'C:\\Inetpub\\wwwroot', 'QUERY_STRING' => '/posts/add', - 'REQUEST_URI' => '/site/index.php?/posts/add', - 'URL' => '/site/index.php?/posts/add', + 'REQUEST_URI' => '/site/index.php/posts/add', + 'URL' => '/site/index.php/posts/add', 'ORIG_PATH_TRANSLATED' => 'C:\\Inetpub\\wwwroot\\site\\index.php', 'DOCUMENT_ROOT' => 'C:\\Inetpub\\wwwroot', - 'PHP_SELF' => '/site/index.php', + 'PHP_SELF' => '/site/index.php/posts/add', 'argv' => array('/posts/add'), 'argc' => 1 ), - 'reload' => false, + ), + array( 'url' => 'posts/add', - 'base' => '/site/index.php?', + 'base' => '/site/index.php', 'webroot' => '/site/app/webroot/' ) ), - 'Apache' => array( - 'No rewrite base path' => array( + array( + 'Apache - No rewrite, document root set to webroot, requesting path', + array( 'App' => array( 'base' => false, 'baseUrl' => '/index.php', @@ -1132,153 +1106,143 @@ public function testEnvironmentDetection() { 'webroot' => 'webroot' ), 'SERVER' => array( - 'SERVER_NAME' => 'localhost', - 'SERVER_ADDR' => '::1', - 'SERVER_PORT' => '80', - 'REMOTE_ADDR' => '::1', 'DOCUMENT_ROOT' => '/Library/WebServer/Documents/site/app/webroot', 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/app/webroot/index.php', - 'REQUEST_METHOD' => 'GET', 'QUERY_STRING' => '', - 'REQUEST_URI' => '/', - 'SCRIPT_NAME' => '/index.php', - 'PHP_SELF' => '/index.php', - 'argv' => array(), - 'argc' => 0 + 'REQUEST_URI' => '/index.php/posts/index', + 'SCRIPT_NAME' => '/index.php', + 'PATH_INFO' => '/posts/index', + 'PHP_SELF' => '/index.php/posts/index', ), - 'reload' => true, - 'url' => '', + ), + array( + 'url' => 'posts/index', 'base' => '/index.php', 'webroot' => '/' ), - 'No rewrite with path' => array( + ), + array( + 'Apache - No rewrite, document root set to webroot, requesting root', + array( + 'App' => array( + 'base' => false, + 'baseUrl' => '/index.php', + 'dir' => 'app', + 'webroot' => 'webroot' + ), 'SERVER' => array( - 'HTTP_HOST' => 'localhost', 'DOCUMENT_ROOT' => '/Library/WebServer/Documents/site/app/webroot', 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/app/webroot/index.php', 'QUERY_STRING' => '', - 'REQUEST_URI' => '/index.php/posts/add', + 'REQUEST_URI' => '/index.php', 'SCRIPT_NAME' => '/index.php', - 'PATH_INFO' => '/posts/add', - 'PHP_SELF' => '/index.php/posts/add', - 'argv' => array(), - 'argc' => 0 + 'PATH_INFO' => '', + 'PHP_SELF' => '/index.php', ), - 'reload' => false, - 'url' => 'posts/add', + ), + array( + 'url' => '', 'base' => '/index.php', 'webroot' => '/' ), - 'GET Request at base domain' => array( + ), + array( + 'Apache - No rewrite, document root set above top level cake dir, requesting path', + array( + 'App' => array( + 'base' => false, + 'baseUrl' => '/site/index.php', + 'dir' => 'app', + 'webroot' => 'webroot' + ), + 'SERVER' => array( + 'SERVER_NAME' => 'localhost', + 'DOCUMENT_ROOT' => '/Library/WebServer/Documents', + 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/index.php', + 'REQUEST_URI' => '/site/index.php/posts/index', + 'SCRIPT_NAME' => '/site/index.php', + 'PATH_INFO' => '/posts/index', + 'PHP_SELF' => '/site/index.php/posts/index', + ), + ), + array( + 'url' => 'posts/index', + 'base' => '/site/index.php', + 'webroot' => '/site/app/webroot/', + ), + ), + array( + 'Apache - No rewrite, document root set above top level cake dir, requesting root', + array( 'App' => array( 'base' => false, - 'baseUrl' => null, + 'baseUrl' => '/site/index.php', 'dir' => 'app', 'webroot' => 'webroot' ), 'SERVER' => array( - 'HTTP_HOST' => 'cake.1.2', - 'SERVER_NAME' => 'cake.1.2', - 'SERVER_ADDR' => '127.0.0.1', - 'SERVER_PORT' => '80', - 'REMOTE_ADDR' => '127.0.0.1', - 'DOCUMENT_ROOT' => '/Volumes/Home/htdocs/cake/repo/branches/1.2.x.x/app/webroot', - 'SERVER_ADMIN' => 'you@example.com', - 'SCRIPT_FILENAME' => '/Volumes/Home/htdocs/cake/repo/branches/1.2.x.x/app/webroot/index.php', - 'REMOTE_PORT' => '53550', - 'GATEWAY_INTERFACE' => 'CGI/1.1', - 'SERVER_PROTOCOL' => 'HTTP/1.1', - 'REQUEST_METHOD' => 'GET', - 'QUERY_STRING' => 'a=b', - 'REQUEST_URI' => '/?a=b', - 'SCRIPT_NAME' => '/index.php', - 'PHP_SELF' => '/index.php' + 'SERVER_NAME' => 'localhost', + 'DOCUMENT_ROOT' => '/Library/WebServer/Documents', + 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/index.php', + 'REQUEST_URI' => '/site/index.php/', + 'SCRIPT_NAME' => '/site/index.php', + 'PATH_INFO' => '', + 'PHP_SELF' => '/site/index.php/', ), - 'GET' => array('a' => 'b'), - 'POST' => array(), - 'reload' => true, + ), + array( 'url' => '', - 'base' => '', - 'webroot' => '/', - 'urlParams' => array('a' => 'b'), - 'environment' => array('CGI_MODE' => false) + 'base' => '/site/index.php', + 'webroot' => '/site/app/webroot/', ), - 'New CGI no mod_rewrite' => array( + ), + array( + 'Apache - No rewrite, document root set above top level cake dir, request path, with GET', + array( 'App' => array( 'base' => false, - 'baseUrl' => '/limesurvey20/index.php', + 'baseUrl' => '/site/index.php', 'dir' => 'app', 'webroot' => 'webroot' ), + 'GET' => array('a' => 'b', 'c' => 'd'), 'SERVER' => array( - 'DOCUMENT_ROOT' => '/home/.sites/110/site313/web', - 'PATH_INFO' => '/installations', - 'PATH_TRANSLATED' => '/home/.sites/110/site313/web/limesurvey20/index.php', - 'PHPRC' => '/home/.sites/110/site313', - 'QUERY_STRING' => '', - 'REQUEST_METHOD' => 'GET', - 'REQUEST_URI' => '/limesurvey20/index.php/installations', - 'SCRIPT_FILENAME' => '/home/.sites/110/site313/web/limesurvey20/index.php', - 'SCRIPT_NAME' => '/limesurvey20/index.php', - 'SCRIPT_URI' => 'http://www.gisdat-umfragen.at/limesurvey20/index.php/installations', - 'PHP_SELF' => '/limesurvey20/index.php/installations', - 'CGI_MODE' => true + 'SERVER_NAME' => 'localhost', + 'DOCUMENT_ROOT' => '/Library/WebServer/Documents', + 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/index.php', + 'REQUEST_URI' => '/site/index.php/posts/index?a=b&c=d', + 'SCRIPT_NAME' => '/site/index.php', + 'PATH_INFO' => '/posts/index', + 'PHP_SELF' => '/site/index.php/posts/index', + 'QUERY_STRING' => 'a=b&c=d' ), - 'GET' => array(), - 'POST' => array(), - 'reload' => true, - 'webroot' => '/limesurvey20/app/webroot/', - 'base' => '/limesurvey20/index.php', - 'url' => 'installations', - 'urlParams' => array(), - 'environment' => array('CGI_MODE' => true) - ) + ), + array( + 'urlParams' => array('a' => 'b', 'c' => 'd'), + 'url' => 'posts/index', + 'base' => '/site/index.php', + 'webroot' => '/site/app/webroot/', + ), ) ); - $backup = $this->__backupEnvironment(); - - foreach ($environments as $name => $env) { - foreach ($env as $descrip => $settings) { - if ($settings['reload']) { - $this->__reloadEnvironment(); - } - $this->__loadEnvironment($settings); - - $request = new CakeRequest(); - $this->assertEqual($request->url, $settings['url'], "%s url on env: {$name} on setting {$descrip}"); - $this->assertEqual($request->base, $settings['base'], "%s base on env: {$name} on setting {$descrip}"); - $this->assertEqual($request->webroot, $settings['webroot'], "%s webroot on env: {$name} on setting {$descrip}"); - - - if (isset($settings['urlParams'])) { - $this->assertEqual($_GET, $settings['urlParams'], "%s on environment: {$name}, on setting: {$descrip}"); - } - - - if (isset($settings['environment'])) { - foreach ($settings['environment'] as $key => $val) { - $this->assertEqual(env($key), $val, "%s on key {$key} on environment: {$name}, on setting: {$descrip}"); - } - } - } - } - $this->__loadEnvironment(array_merge(array('reload' => true), $backup)); } /** - * test that XSS can't be performed against the base path. + * testEnvironmentDetection method * + * @dataProvider environmentGenerator * @return void */ - function testBasePathInjection() { - $self = $_SERVER['PHP_SELF']; - $_SERVER['PHP_SELF'] = urldecode( - "/index.php/%22%3E%3Ch1%20onclick=%22alert('xss');%22%3Eheya%3C/h1%3E" - ); + public function testEnvironmentDetection($name, $env, $expected) { + $this->__loadEnvironment($env); $request = new CakeRequest(); - $expected = '/index.php/h1 onclick=alert(xss);heya'; - $this->assertEqual($request->base, $expected); + $this->assertEquals($expected['url'], $request->url, "url error"); + $this->assertEquals($expected['base'], $request->base, "base error"); + $this->assertEquals($expected['webroot'],$request->webroot, "webroot error"); + if (isset($expected['urlParams'])) { + $this->assertEqual($_GET, $expected['urlParams'], "GET param mismatch"); + } } /** @@ -1364,40 +1328,6 @@ function testAcceptLanguage() { $this->assertFalse($result); } -/** - * backupEnvironment method - * - * @return void - * @access private - */ - function __backupEnvironment() { - return array( - 'App' => Configure::read('App'), - 'GET' => $_GET, - 'POST' => $_POST, - 'SERVER' => $_SERVER - ); - } - -/** - * reloadEnvironment method - * - * @return void - * @access private - */ - function __reloadEnvironment() { - foreach ($_GET as $key => $val) { - unset($_GET[$key]); - } - foreach ($_POST as $key => $val) { - unset($_POST[$key]); - } - foreach ($_SERVER as $key => $val) { - unset($_SERVER[$key]); - } - Configure::write('App', array()); - } - /** * loadEnvironment method * @@ -1406,10 +1336,6 @@ function __reloadEnvironment() { * @access private */ function __loadEnvironment($env) { - if ($env['reload']) { - $this->__reloadEnvironment(); - } - if (isset($env['App'])) { Configure::write('App', $env['App']); } diff --git a/cake/tests/cases/libs/cake_socket.test.php b/cake/tests/cases/libs/cake_socket.test.php index ac12b455392..0fc6f826aaf 100644 --- a/cake/tests/cases/libs/cake_socket.test.php +++ b/cake/tests/cases/libs/cake_socket.test.php @@ -108,7 +108,7 @@ function testSocketConnection() { */ public static function invalidConnections() { return array( - array(array('host' => 'invalid.host', 'timeout' => 1)), + array(array('host' => 'invalid.host', 'port' => 9999, 'timeout' => 1)), array(array('host' => '127.0.0.1', 'port' => '70000', 'timeout' => 1)) ); } diff --git a/cake/tests/cases/libs/controller/components/auth.test.php b/cake/tests/cases/libs/controller/components/auth.test.php index 8400651814d..2c6701e9320 100644 --- a/cake/tests/cases/libs/controller/components/auth.test.php +++ b/cake/tests/cases/libs/controller/components/auth.test.php @@ -443,7 +443,7 @@ function testLoginActionNotSettingAuthRedirect() { $this->Controller->data = array(); $this->Controller->request->addParams(Router::parse('auth_test/login')); - $this->Controller->request->query['url'] = 'auth_test/login'; + $this->Controller->request->url = 'auth_test/login'; $this->Auth->Session->delete('Auth'); $this->Auth->loginRedirect = '/users/dashboard'; @@ -730,7 +730,7 @@ function testLoginRedirect() { )); $this->Auth->request->addParams(Router::parse('users/login')); - $this->Auth->request->query['url'] = 'users/login'; + $this->Auth->request->url = 'users/login'; $this->Auth->initialize($this->Controller); $this->Auth->loginRedirect = array( @@ -771,7 +771,7 @@ function testLoginRedirect() { 'AuthUser' => array('id'=>'1', 'username' => 'nate') )); $this->Auth->request->params['action'] = 'login'; - $this->Auth->request->query['url'] = 'auth_test/login'; + $this->Auth->request->url = 'auth_test/login'; $this->Auth->initialize($this->Controller); $this->Auth->loginAction = 'auth_test/login'; $this->Auth->loginRedirect = false; @@ -784,7 +784,7 @@ function testLoginRedirect() { $this->Auth->Session->delete('Auth'); $url = '/posts/index/year:2008/month:feb'; $this->Auth->request->addParams(Router::parse($url)); - $this->Auth->request->query['url'] = Router::normalize($url); + $this->Auth->request->url = Router::normalize($url); $this->Auth->initialize($this->Controller); $this->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login'); $this->Auth->startup($this->Controller); @@ -795,7 +795,7 @@ function testLoginRedirect() { $this->Auth->Session->delete('Auth'); $url = '/posts/view/1'; $this->Auth->request->addParams(Router::parse($url)); - $this->Auth->request->query['url'] = Router::normalize($url); + $this->Auth->request->url = Router::normalize($url); $this->Auth->initialize($this->Controller); $this->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login'); $this->Auth->startup($this->Controller); @@ -843,7 +843,7 @@ function testLoginRedirect() { $url = '/posts/edit/1'; $this->Auth->request = $this->Controller->request = new CakeRequest($url); $this->Auth->request->addParams(Router::parse($url)); - $this->Auth->request->query = array('url' => Router::normalize($url)); + $this->Auth->request->url = Router::normalize($url); $this->Auth->initialize($this->Controller); $this->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login'); $this->Auth->startup($this->Controller); @@ -856,7 +856,7 @@ function testLoginRedirect() { $url = '/AuthTest/login'; $this->Auth->request = $this->Controller->request = new CakeRequest($url); $this->Auth->request->addParams(Router::parse($url)); - $this->Auth->request->query['url'] = Router::normalize($url); + $this->Auth->request->url = Router::normalize($url); $this->Auth->initialize($this->Controller); $this->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login'); $this->Auth->startup($this->Controller); @@ -965,11 +965,11 @@ function testLoginActionRedirect() { $url = '/admin/auth_test/login'; $this->Auth->request->addParams(Router::parse($url)); - $this->Auth->request->query['url'] = ltrim($url, '/'); + $this->Auth->request->url = ltrim($url, '/'); Router::setRequestInfo(array( array( 'pass' => array(), 'action' => 'admin_login', 'plugin' => null, 'controller' => 'auth_test', - 'admin' => true, 'url' => array('url' => $this->Auth->request->query['url']), + 'admin' => true, ), array( 'base' => null, 'here' => $url, diff --git a/cake/tests/cases/libs/controller/components/auth/crud_authorize.test.php b/cake/tests/cases/libs/controller/components/auth/crud_authorize.test.php index d9c28b8735c..a78fb71ec83 100644 --- a/cake/tests/cases/libs/controller/components/auth/crud_authorize.test.php +++ b/cake/tests/cases/libs/controller/components/auth/crud_authorize.test.php @@ -27,6 +27,8 @@ class CrudAuthorizeTest extends CakeTestCase { * @return void */ function setUp() { + Configure::write('Routing.prefixes', array()); + parent::setUp(); $this->Acl = $this->getMock('AclComponent', array(), array(), '', false); diff --git a/cake/tests/cases/libs/controller/controller.test.php b/cake/tests/cases/libs/controller/controller.test.php index 5ff4b833e6d..dd637e62287 100644 --- a/cake/tests/cases/libs/controller/controller.test.php +++ b/cake/tests/cases/libs/controller/controller.test.php @@ -1020,20 +1020,6 @@ function testSetAction() { $this->assertidentical($TestController->data, $expected); } -/** - * testUnimplementedIsAuthorized method - * - * @expectedException PHPUnit_Framework_Error - * @access public - * @return void - */ - function testUnimplementedIsAuthorized() { - $request = new CakeRequest('controller_posts/index'); - - $TestController = new TestController($request); - $TestController->isAuthorized(); - } - /** * testValidateErrors method * diff --git a/cake/tests/cases/libs/controller/scaffold.test.php b/cake/tests/cases/libs/controller/scaffold.test.php index 031d8a0c570..54a67beff4a 100644 --- a/cake/tests/cases/libs/controller/scaffold.test.php +++ b/cake/tests/cases/libs/controller/scaffold.test.php @@ -771,11 +771,11 @@ function testScaffoldVariableSetting() { function testScaffoldChangingViewProperty() { $this->Controller->action = 'edit'; $this->Controller->theme = 'test_theme'; - $this->Controller->view = 'Theme'; + $this->Controller->viewClass = 'Theme'; $this->Controller->constructClasses(); $Scaffold = new TestScaffoldMock($this->Controller, $this->Controller->request); - $this->assertEqual($this->Controller->view, 'Scaffold'); + $this->assertEqual($this->Controller->viewClass, 'Scaffold'); } /** diff --git a/cake/tests/cases/libs/controller_test_case.test.php b/cake/tests/cases/libs/controller_test_case.test.php index 1ffb518c6fc..9e4feb4b76e 100644 --- a/cake/tests/cases/libs/controller_test_case.test.php +++ b/cake/tests/cases/libs/controller_test_case.test.php @@ -388,7 +388,6 @@ function testTestActionGetData() { 'return' => 'vars', 'method' => 'get', )); - $this->assertTrue(isset($result['params']['url']['url'])); $this->assertEqual(array_keys($result['params']['named']), array('var1', 'var2')); $result = $this->Case->testAction('/tests_apps_posts/url_var/gogo/val2', array( @@ -407,7 +406,6 @@ function testTestActionGetData() { )); $this->assertTrue(isset($result['params']['url']['red'])); $this->assertTrue(isset($result['params']['url']['blue'])); - $this->assertTrue(isset($result['params']['url']['url'])); } /** diff --git a/cake/tests/cases/libs/debugger.test.php b/cake/tests/cases/libs/debugger.test.php index a7694556652..e728fb5ea47 100644 --- a/cake/tests/cases/libs/debugger.test.php +++ b/cake/tests/cases/libs/debugger.test.php @@ -227,6 +227,7 @@ function testExportVar() { View::$helpers = array View::$viewPath = "" View::$viewVars = array + View::$view = NULL View::$layout = "default" View::$layoutPath = NULL View::$autoLayout = true diff --git a/cake/tests/cases/libs/dispatcher.test.php b/cake/tests/cases/libs/dispatcher.test.php index 20fab006b84..0f9a6bbbbb4 100644 --- a/cake/tests/cases/libs/dispatcher.test.php +++ b/cake/tests/cases/libs/dispatcher.test.php @@ -862,7 +862,6 @@ public function testAdminDispatch() { */ public function testPluginDispatch() { $_POST = array(); - $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php'; Router::reload(); $Dispatcher = new TestDispatcher(); @@ -879,7 +878,6 @@ public function testPluginDispatch() { 'pass' => array('home'), 'named' => array('param'=> 'value', 'param2'=> 'value2'), 'plugin'=> 'my_plugin', 'controller'=> 'some_pages', 'action'=> 'display', 'form'=> array(), - 'url'=> array('url'=> 'my_plugin/some_pages/home/param:value/param2:value2'), ); foreach ($expected as $key => $value) { $this->assertEqual($result[$key], $value, 'Value mismatch ' . $key . ' %'); @@ -889,12 +887,6 @@ public function testPluginDispatch() { $this->assertIdentical($controller->name, 'SomePages'); $this->assertIdentical($controller->params['controller'], 'some_pages'); $this->assertIdentical($controller->passedArgs, array('0' => 'home', 'param'=>'value', 'param2'=>'value2')); - - $expected = '/cake/repo/branches/1.2.x.x/my_plugin/some_pages/home/param:value/param2:value2'; - $this->assertIdentical($expected, $controller->here); - - $expected = '/cake/repo/branches/1.2.x.x'; - $this->assertIdentical($expected, $controller->base); } /** @@ -904,7 +896,7 @@ public function testPluginDispatch() { */ public function testAutomaticPluginDispatch() { $_POST = array(); - $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php'; + $_SERVER['SCRIPT_NAME'] = '/cake/repo/branches/1.2.x.x/index.php'; Router::reload(); $Dispatcher = new TestDispatcher(); @@ -1018,11 +1010,10 @@ public function testAutomaticPluginControllerDispatch() { 'prefix' => 'admin', 'admin' => true, 'form' => array(), - 'url' => array('url' => 'admin/articles_test'), 'return' => 1 ); foreach ($expected as $key => $value) { - $this->assertEqual($controller->params[$key], $expected[$key], 'Value mismatch ' . $key . ' %s'); + $this->assertEqual($controller->request[$key], $expected[$key], 'Value mismatch ' . $key . ' %s'); } }