diff options
Diffstat (limited to 'Tests/Core/Encoder')
-rw-r--r-- | Tests/Core/Encoder/BCryptPasswordEncoderTest.php | 60 |
1 files changed, 5 insertions, 55 deletions
diff --git a/Tests/Core/Encoder/BCryptPasswordEncoderTest.php b/Tests/Core/Encoder/BCryptPasswordEncoderTest.php index 45c8f74..6378433 100644 --- a/Tests/Core/Encoder/BCryptPasswordEncoderTest.php +++ b/Tests/Core/Encoder/BCryptPasswordEncoderTest.php @@ -22,30 +22,12 @@ class BCryptPasswordEncoderTest extends \PHPUnit_Framework_TestCase const BYTES = '0123456789abcdef'; const VALID_COST = '04'; - const SECURE_RANDOM_INTERFACE = 'Symfony\Component\Security\Core\Util\SecureRandomInterface'; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - private $secureRandom; - - protected function setUp() - { - $this->secureRandom = $this->getMock(self::SECURE_RANDOM_INTERFACE); - - $this->secureRandom - ->expects($this->any()) - ->method('nextBytes') - ->will($this->returnValue(self::BYTES)) - ; - } - /** * @expectedException \InvalidArgumentException */ public function testCostBelowRange() { - new BCryptPasswordEncoder($this->secureRandom, 3); + new BCryptPasswordEncoder(3); } /** @@ -53,60 +35,28 @@ class BCryptPasswordEncoderTest extends \PHPUnit_Framework_TestCase */ public function testCostAboveRange() { - new BCryptPasswordEncoder($this->secureRandom, 32); + new BCryptPasswordEncoder(32); } public function testCostInRange() { for ($cost = 4; $cost <= 31; $cost++) { - new BCryptPasswordEncoder($this->secureRandom, $cost); + new BCryptPasswordEncoder($cost); } } public function testResultLength() { - $encoder = new BCryptPasswordEncoder($this->secureRandom, self::VALID_COST); + $encoder = new BCryptPasswordEncoder(self::VALID_COST); $result = $encoder->encodePassword(self::PASSWORD, null); $this->assertEquals(60, strlen($result)); } public function testValidation() { - $encoder = new BCryptPasswordEncoder($this->secureRandom, self::VALID_COST); + $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)); } - - public function testValidationKnownPassword() - { - $encoder = new BCryptPasswordEncoder($this->secureRandom, self::VALID_COST); - $prefix = '$'.(version_compare(phpversion(), '5.3.7', '>=') - ? '2y' : '2a').'$'; - - $encrypted = $prefix.'04$ABCDEFGHIJKLMNOPQRSTU.uTmwd4KMSHxbUsG7bng8x7YdA0PM1iq'; - $this->assertTrue($encoder->isPasswordValid($encrypted, self::PASSWORD, null)); - } - - public function testSecureRandomIsUsed() - { - if (function_exists('mcrypt_create_iv')) { - return; - } - - $this->secureRandom - ->expects($this->atLeastOnce()) - ->method('nextBytes') - ; - - $encoder = new BCryptPasswordEncoder($this->secureRandom, self::VALID_COST); - $result = $encoder->encodePassword(self::PASSWORD, null); - - $prefix = '$'.(version_compare(phpversion(), '5.3.7', '>=') - ? '2y' : '2a').'$'; - $salt = 'MDEyMzQ1Njc4OWFiY2RlZe'; - $expected = crypt(self::PASSWORD, $prefix.self::VALID_COST.'$'.$salt); - - $this->assertEquals($expected, $result); - } } |