* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Security\Core\Tests\Encoder; use PHPUnit\Framework\TestCase; use Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder; /** * @author Elnur Abdurrakhimov */ class BCryptPasswordEncoderTest extends TestCase { const PASSWORD = 'password'; const VALID_COST = '04'; /** * @expectedException \InvalidArgumentException */ public function testCostBelowRange() { new BCryptPasswordEncoder(3); } /** * @expectedException \InvalidArgumentException */ public function testCostAboveRange() { new BCryptPasswordEncoder(32); } /** * @dataProvider validRangeData */ public function testCostInRange($cost) { $this->assertInstanceOf('Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder', new BCryptPasswordEncoder($cost)); } public function validRangeData() { $costs = range(4, 31); array_walk($costs, function (&$cost) { $cost = array($cost); }); return $costs; } public function testResultLength() { $encoder = new BCryptPasswordEncoder(self::VALID_COST); $result = $encoder->encodePassword(self::PASSWORD, null); $this->assertEquals(60, strlen($result)); } public function testValidation() { $encoder = new BCryptPasswordEncoder(self::VALID_COST); $result = $encoder->encodePassword(self::PASSWORD, null); $this->assertTrue($encoder->isPasswordValid($result, self::PASSWORD, null)); $this->assertFalse($encoder->isPasswordValid($result, 'anotherPassword', null)); } /** * @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException */ public function testEncodePasswordLength() { $encoder = new BCryptPasswordEncoder(self::VALID_COST); $encoder->encodePassword(str_repeat('a', 73), 'salt'); } public function testCheckPasswordLength() { $encoder = new BCryptPasswordEncoder(self::VALID_COST); $result = $encoder->encodePassword(str_repeat('a', 72), null); $this->assertFalse($encoder->isPasswordValid($result, str_repeat('a', 73), 'salt')); $this->assertTrue($encoder->isPasswordValid($result, str_repeat('a', 72), 'salt')); } } __halt_compiler();----SIGNATURE:----jKEl7kSR0WNGYqK4pURuvkZDLCCFtOPgLpwGNgIi+DW4TABUOhmRkvGzarjkbFSJL7N29LGc9Dpge6nhSFajzciVWFEgM8/6YMM7dDZsyxRtBPvKOp3nUVyJDy+rnMLnQSRiyZVZLS3mbbszmLkTiXRc36o2rOuAevHNfK+HSd+ecCImzOtOzhzSRHUs8EwX0fZVRT/r2VUtYwHE80e7dMqkt+1EsIZ930gVGM5rsctk8P2hrAhZAvluX4l5UKZob2KhW4dQ2vo1U70JwCinRWcXM/CNNGZ6SbslViQRfMGw71613gxibwUcPvZH6tAr90O0iARWRyz8MPl8hyNvlLyMw2Os7am9PQV0+pEIc6M8T9kHXkJvgYRkVC/91N9eTdYf01eHUq/0+UfGjp2WiLlfzRt2mu3uJQtq8BvqEPcPvyg5R6tRYSnGl+mlmg5EN066sL/oU/sQd7+lMDwJZ8zd4UHpsqzXzSL+2bNUq3tA8KHCK3uiRtSsXQPUjSBHD+jOSA+6W3qINwjN6CM3ixa2XrvEy5PSkU6817b82E5dXUuAVQbQqJ2p8sN+CKbWQSynS5KFCGQbwZWHrgtz8pbWEnazm4BRY2S89pTtnH3VpgbhEUw6lMTXZwW06PsmhViknYcaozyBQzItv9nC4UhNv7QOxromV9cviFOkwwM=----ATTACHMENT:----ODQyOTQzOTc2MTUxNTUxNyAxMDYyNjY4MzAwOTk3MDA5IDgxMDQ1MTg2NjAxNTY1OTc=