mirror of
				https://github.com/brmlab/brmsklad.git
				synced 2025-10-31 08:13:58 +01:00 
			
		
		
		
	Upgrade CakePHP from 2.2.5 to 2.9.5
This commit is contained in:
		
							parent
							
								
									5a580df460
								
							
						
					
					
						commit
						235a541597
					
				
					 793 changed files with 60746 additions and 23753 deletions
				
			
		|  | @ -2,19 +2,18 @@ | |||
| /** | ||||
|  * BasicAuthenticateTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP(tm) Project | ||||
|  * @package       Cake.Test.Case.Controller.Component.Auth | ||||
|  * @since         CakePHP(tm) v 2.0 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('AuthComponent', 'Controller/Component'); | ||||
|  | @ -23,7 +22,6 @@ App::uses('AppModel', 'Model'); | |||
| App::uses('CakeRequest', 'Network'); | ||||
| App::uses('CakeResponse', 'Network'); | ||||
| 
 | ||||
| 
 | ||||
| require_once CAKE . 'Test' . DS . 'Case' . DS . 'Model' . DS . 'models.php'; | ||||
| 
 | ||||
| /** | ||||
|  | @ -33,7 +31,12 @@ require_once CAKE . 'Test' . DS . 'Case' . DS . 'Model' . DS . 'models.php'; | |||
|  */ | ||||
| class BasicAuthenticateTest extends CakeTestCase { | ||||
| 
 | ||||
| 	public $fixtures = array('core.user', 'core.auth_user'); | ||||
| /** | ||||
|  * Fixtures | ||||
|  * | ||||
|  * @var array | ||||
|  */ | ||||
| 	public $fixtures = array('core.user', 'core.auth_user', 'core.article'); | ||||
| 
 | ||||
| /** | ||||
|  * setup | ||||
|  | @ -79,11 +82,10 @@ class BasicAuthenticateTest extends CakeTestCase { | |||
| 	public function testAuthenticateNoData() { | ||||
| 		$request = new CakeRequest('posts/index', false); | ||||
| 
 | ||||
| 		$this->response->expects($this->once()) | ||||
| 			->method('header') | ||||
| 			->with('WWW-Authenticate: Basic realm="localhost"'); | ||||
| 		$this->response->expects($this->never()) | ||||
| 			->method('header'); | ||||
| 
 | ||||
| 		$this->assertFalse($this->auth->authenticate($request, $this->response)); | ||||
| 		$this->assertFalse($this->auth->getUser($request)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -95,10 +97,6 @@ class BasicAuthenticateTest extends CakeTestCase { | |||
| 		$request = new CakeRequest('posts/index', false); | ||||
| 		$_SERVER['PHP_AUTH_PW'] = 'foobar'; | ||||
| 
 | ||||
| 		$this->response->expects($this->once()) | ||||
| 			->method('header') | ||||
| 			->with('WWW-Authenticate: Basic realm="localhost"'); | ||||
| 
 | ||||
| 		$this->assertFalse($this->auth->authenticate($request, $this->response)); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -112,10 +110,6 @@ class BasicAuthenticateTest extends CakeTestCase { | |||
| 		$_SERVER['PHP_AUTH_USER'] = 'mariano'; | ||||
| 		$_SERVER['PHP_AUTH_PW'] = null; | ||||
| 
 | ||||
| 		$this->response->expects($this->once()) | ||||
| 			->method('header') | ||||
| 			->with('WWW-Authenticate: Basic realm="localhost"'); | ||||
| 
 | ||||
| 		$this->assertFalse($this->auth->authenticate($request, $this->response)); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -131,9 +125,36 @@ class BasicAuthenticateTest extends CakeTestCase { | |||
| 		$_SERVER['PHP_AUTH_USER'] = '> 1'; | ||||
| 		$_SERVER['PHP_AUTH_PW'] = "' OR 1 = 1"; | ||||
| 
 | ||||
| 		$this->assertFalse($this->auth->getUser($request)); | ||||
| 		$this->assertFalse($this->auth->authenticate($request, $this->response)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test that username of 0 works. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testAuthenticateUsernameZero() { | ||||
| 		$User = ClassRegistry::init('User'); | ||||
| 		$User->updateAll(array('user' => $User->getDataSource()->value('0')), array('user' => 'mariano')); | ||||
| 
 | ||||
| 		$request = new CakeRequest('posts/index', false); | ||||
| 		$request->data = array('User' => array( | ||||
| 			'user' => '0', | ||||
| 			'password' => 'password' | ||||
| 		)); | ||||
| 		$_SERVER['PHP_AUTH_USER'] = '0'; | ||||
| 		$_SERVER['PHP_AUTH_PW'] = 'password'; | ||||
| 
 | ||||
| 		$expected = array( | ||||
| 			'id' => 1, | ||||
| 			'user' => '0', | ||||
| 			'created' => '2007-03-17 01:16:23', | ||||
| 			'updated' => '2007-03-17 01:18:31' | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $this->auth->authenticate($request, $this->response)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that challenge headers are sent when no credentials are found. | ||||
|  * | ||||
|  | @ -143,19 +164,19 @@ class BasicAuthenticateTest extends CakeTestCase { | |||
| 		$request = new CakeRequest('posts/index', false); | ||||
| 		$request->addParams(array('pass' => array(), 'named' => array())); | ||||
| 
 | ||||
| 		$this->response->expects($this->at(0)) | ||||
| 			->method('header') | ||||
| 			->with('WWW-Authenticate: Basic realm="localhost"'); | ||||
| 		try { | ||||
| 			$this->auth->unauthenticated($request, $this->response); | ||||
| 		} catch (UnauthorizedException $e) { | ||||
| 		} | ||||
| 
 | ||||
| 		$this->response->expects($this->at(1)) | ||||
| 			->method('send'); | ||||
| 		$this->assertNotEmpty($e); | ||||
| 
 | ||||
| 		$result = $this->auth->authenticate($request, $this->response); | ||||
| 		$this->assertFalse($result); | ||||
| 		$expected = array('WWW-Authenticate: Basic realm="localhost"'); | ||||
| 		$this->assertEquals($expected, $e->responseHeader()); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test authenticate sucesss | ||||
|  * test authenticate success | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
|  | @ -176,9 +197,89 @@ class BasicAuthenticateTest extends CakeTestCase { | |||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test contain success | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testAuthenticateContainSuccess() { | ||||
| 		$User = ClassRegistry::init('User'); | ||||
| 		$User->bindModel(array('hasMany' => array('Article'))); | ||||
| 		$User->Behaviors->load('Containable'); | ||||
| 		$this->auth->settings['contain'] = 'Article'; | ||||
| 		$request = new CakeRequest('posts/index', false); | ||||
| 		$request->addParams(array('pass' => array(), 'named' => array())); | ||||
| 
 | ||||
| 		$_SERVER['PHP_AUTH_USER'] = 'mariano'; | ||||
| 		$_SERVER['PHP_AUTH_PW'] = 'password'; | ||||
| 
 | ||||
| 		$result = $this->auth->authenticate($request, $this->response); | ||||
| 		$expected = array( | ||||
| 			'id' => 1, | ||||
| 			'user_id' => 1, | ||||
| 			'title' => 'First Article', | ||||
| 			'body' => 'First Article Body', | ||||
| 			'published' => 'Y', | ||||
| 			'created' => '2007-03-18 10:39:23', | ||||
| 			'updated' => '2007-03-18 10:41:31' | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $result['Article'][0]); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test userFields success | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testAuthenticateUserFieldsSuccess() { | ||||
| 		$this->auth->settings['userFields'] = array('id', 'user'); | ||||
| 		$request = new CakeRequest('posts/index', false); | ||||
| 		$request->addParams(array('pass' => array(), 'named' => array())); | ||||
| 
 | ||||
| 		$_SERVER['PHP_AUTH_USER'] = 'mariano'; | ||||
| 		$_SERVER['PHP_AUTH_PW'] = 'password'; | ||||
| 
 | ||||
| 		$result = $this->auth->authenticate($request, $this->response); | ||||
| 		$expected = array( | ||||
| 			'id' => 1, | ||||
| 			'user' => 'mariano', | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test userFields and related models success | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testAuthenticateUserFieldsRelatedModelsSuccess() { | ||||
| 		$User = ClassRegistry::init('User'); | ||||
| 		$User->bindModel(array('hasOne' => array( | ||||
| 			'Article' => array( | ||||
| 				'order' => 'Article.id ASC' | ||||
| 			) | ||||
| 		))); | ||||
| 		$this->auth->settings['recursive'] = 0; | ||||
| 		$this->auth->settings['userFields'] = array('Article.id', 'Article.title'); | ||||
| 		$request = new CakeRequest('posts/index', false); | ||||
| 		$request->addParams(array('pass' => array(), 'named' => array())); | ||||
| 
 | ||||
| 		$_SERVER['PHP_AUTH_USER'] = 'mariano'; | ||||
| 		$_SERVER['PHP_AUTH_PW'] = 'password'; | ||||
| 
 | ||||
| 		$result = $this->auth->authenticate($request, $this->response); | ||||
| 		$expected = array( | ||||
| 			'id' => 1, | ||||
| 			'title' => 'First Article', | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $result['Article']); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test scope failure. | ||||
|  * | ||||
|  * @expectedException UnauthorizedException | ||||
|  * @expectedExceptionCode 401 | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testAuthenticateFailReChallenge() { | ||||
|  | @ -189,18 +290,40 @@ class BasicAuthenticateTest extends CakeTestCase { | |||
| 		$_SERVER['PHP_AUTH_USER'] = 'mariano'; | ||||
| 		$_SERVER['PHP_AUTH_PW'] = 'password'; | ||||
| 
 | ||||
| 		$this->response->expects($this->at(0)) | ||||
| 			->method('header') | ||||
| 			->with('WWW-Authenticate: Basic realm="localhost"'); | ||||
| 		$this->auth->unauthenticated($request, $this->response); | ||||
| 	} | ||||
| 
 | ||||
| 		$this->response->expects($this->at(1)) | ||||
| 			->method('statusCode') | ||||
| 			->with(401); | ||||
| /** | ||||
|  * testAuthenticateWithBlowfish | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testAuthenticateWithBlowfish() { | ||||
| 		$hash = Security::hash('password', 'blowfish'); | ||||
| 		$this->skipIf(strpos($hash, '$2a$') === false, 'Skipping blowfish tests as hashing is not working'); | ||||
| 
 | ||||
| 		$this->response->expects($this->at(2)) | ||||
| 			->method('send'); | ||||
| 		$request = new CakeRequest('posts/index', false); | ||||
| 		$request->addParams(array('pass' => array(), 'named' => array())); | ||||
| 
 | ||||
| 		$this->assertFalse($this->auth->authenticate($request, $this->response)); | ||||
| 		$_SERVER['PHP_AUTH_USER'] = 'mariano'; | ||||
| 		$_SERVER['PHP_AUTH_PW'] = 'password'; | ||||
| 
 | ||||
| 		$User = ClassRegistry::init('User'); | ||||
| 		$User->updateAll( | ||||
| 			array('password' => $User->getDataSource()->value($hash)), | ||||
| 			array('User.user' => 'mariano') | ||||
| 		); | ||||
| 
 | ||||
| 		$this->auth->settings['passwordHasher'] = 'Blowfish'; | ||||
| 
 | ||||
| 		$result = $this->auth->authenticate($request, $this->response); | ||||
| 		$expected = array( | ||||
| 			'id' => 1, | ||||
| 			'user' => 'mariano', | ||||
| 			'created' => '2007-03-17 01:16:23', | ||||
| 			'updated' => '2007-03-17 01:18:31' | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Brm Ko
						Brm Ko