Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix loading of PasswordHasher class from plugin.
Fixes #4919
- Loading branch information
Showing
3 changed files
with
84 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
/** | ||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.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 (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* @link http://cakephp.org CakePHP(tm) Project | ||
* @since 3.0.0 | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace Cake\Test\TestCase\Auth; | ||
|
||
use Cake\Core\Plugin; | ||
use Cake\Auth\PasswordHasherFactory; | ||
use Cake\TestSuite\TestCase; | ||
|
||
/** | ||
* Test case for PasswordHasherFactory | ||
* | ||
*/ | ||
class PasswordHasherFactoryTest extends TestCase { | ||
|
||
/** | ||
* test passwordhasher instance building | ||
* | ||
* @return void | ||
*/ | ||
public function testBuild() { | ||
$hasher = PasswordHasherFactory::build('Default'); | ||
$this->assertInstanceof('Cake\Auth\DefaultPasswordHasher', $hasher); | ||
|
||
$hasher = PasswordHasherFactory::build([ | ||
'className' => 'Default', | ||
'hashOptions' => ['foo' =>' bar'] | ||
]); | ||
$this->assertInstanceof('Cake\Auth\DefaultPasswordHasher', $hasher); | ||
$this->assertEquals(['foo' =>' bar'], $hasher->config('hashOptions')); | ||
|
||
Plugin::load('TestPlugin'); | ||
$hasher = PasswordHasherFactory::build('TestPlugin.Legacy'); | ||
$this->assertInstanceof('TestPlugin\Auth\LegacyPasswordHasher', $hasher); | ||
} | ||
|
||
/** | ||
* test build() throws exception for non existent hasher | ||
* | ||
* @expectedException \RuntimeException | ||
* @expectedExceptionMessage Password hasher class "FooBar" was not found. | ||
* @return void | ||
*/ | ||
public function testBuildException() { | ||
$hasher = PasswordHasherFactory::build('FooBar'); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
tests/test_app/Plugin/TestPlugin/src/Auth/LegacyPasswordHasher.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
/** | ||
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html> | ||
* 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 (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests | ||
* @since 3.0.0 | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
|
||
namespace TestPlugin\Auth; | ||
|
||
use Cake\Auth\DefaultPasswordHasher; | ||
|
||
class LegacyPasswordHasher extends DefaultPasswordHasher { | ||
} |