summaryrefslogtreecommitdiffstats
path: root/Tests/Core/Encoder/BCryptPasswordEncoderTest.php
diff options
context:
space:
mode:
authorElnur Abdurrakhimov <elnur@elnur.pro>2013-03-03 15:51:00 +0400
committerFabien Potencier <fabien.potencier@gmail.com>2013-04-25 17:38:27 +0200
commitf7a0e499cf233a7a66c7f2fbfbd98504171f9603 (patch)
tree38df2668b64a91dfebde987a24bf4c2119c46b01 /Tests/Core/Encoder/BCryptPasswordEncoderTest.php
parentd156097a1b4653108637dedaaf2c64b876eb2f35 (diff)
downloadsymfony-security-f7a0e499cf233a7a66c7f2fbfbd98504171f9603.zip
symfony-security-f7a0e499cf233a7a66c7f2fbfbd98504171f9603.tar.gz
symfony-security-f7a0e499cf233a7a66c7f2fbfbd98504171f9603.tar.bz2
Outsource all the BCrypt heavy lifting to a library
Diffstat (limited to 'Tests/Core/Encoder/BCryptPasswordEncoderTest.php')
-rw-r--r--Tests/Core/Encoder/BCryptPasswordEncoderTest.php60
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);
- }
}