diff options
author | Bernhard Schussek <bschussek@gmail.com> | 2013-09-16 10:03:00 +0200 |
---|---|---|
committer | Fabien Potencier <fabien.potencier@gmail.com> | 2013-09-18 09:16:41 +0200 |
commit | 5a6aaab2c35213f5ca7e57f061fbb2675e2ece35 (patch) | |
tree | 461816fef8160401dc113d3fef190fb437d01cc7 /Core/Tests/Encoder/BCryptPasswordEncoderTest.php | |
parent | 513a354be10f0ed87933adcb788e48660f8e6ed4 (diff) | |
download | symfony-security-5a6aaab2c35213f5ca7e57f061fbb2675e2ece35.zip symfony-security-5a6aaab2c35213f5ca7e57f061fbb2675e2ece35.tar.gz symfony-security-5a6aaab2c35213f5ca7e57f061fbb2675e2ece35.tar.bz2 |
[Security] Split the component into 3 sub-components Core, ACL, HTTP
Diffstat (limited to 'Core/Tests/Encoder/BCryptPasswordEncoderTest.php')
-rw-r--r-- | Core/Tests/Encoder/BCryptPasswordEncoderTest.php | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/Core/Tests/Encoder/BCryptPasswordEncoderTest.php b/Core/Tests/Encoder/BCryptPasswordEncoderTest.php new file mode 100644 index 0000000..4780411 --- /dev/null +++ b/Core/Tests/Encoder/BCryptPasswordEncoderTest.php @@ -0,0 +1,73 @@ +<?php + +/* + * This file is part of the Symfony package. + * + * (c) Fabien Potencier <fabien@symfony.com> + * + * 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 Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder; + +/** + * @author Elnur Abdurrakhimov <elnur@elnur.pro> + */ +class BCryptPasswordEncoderTest extends \PHPUnit_Framework_TestCase +{ + const PASSWORD = 'password'; + const BYTES = '0123456789abcdef'; + const VALID_COST = '04'; + + /** + * @expectedException \InvalidArgumentException + */ + public function testCostBelowRange() + { + new BCryptPasswordEncoder(3); + } + + /** + * @expectedException \InvalidArgumentException + */ + public function testCostAboveRange() + { + new BCryptPasswordEncoder(32); + } + + public function testCostInRange() + { + for ($cost = 4; $cost <= 31; $cost++) { + new BCryptPasswordEncoder($cost); + } + } + + public function testResultLength() + { + $this->skipIfPhpVersionIsNotSupported(); + + $encoder = new BCryptPasswordEncoder(self::VALID_COST); + $result = $encoder->encodePassword(self::PASSWORD, null); + $this->assertEquals(60, strlen($result)); + } + + public function testValidation() + { + $this->skipIfPhpVersionIsNotSupported(); + + $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)); + } + + private function skipIfPhpVersionIsNotSupported() + { + if (version_compare(phpversion(), '5.3.7', '<')) { + $this->markTestSkipped('Requires PHP >= 5.3.7'); + } + } +} |