From 65eb18849a4231c6c0fd06daefb5b7c1adb1f4ff Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 19 Dec 2015 14:25:32 +0100 Subject: [PATCH 1/2] skip bcrypt tests on incompatible platforms Not all PHP versions before 5.3.7 have backported fixes that make it possible to use `password_hash()` function. Therefore, we have to skip tests on not supported platforms. --- .../Core/Encoder/BCryptPasswordEncoderTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Symfony/Component/Security/Tests/Core/Encoder/BCryptPasswordEncoderTest.php b/src/Symfony/Component/Security/Tests/Core/Encoder/BCryptPasswordEncoderTest.php index 355850a703..b3ddff6e9b 100644 --- a/src/Symfony/Component/Security/Tests/Core/Encoder/BCryptPasswordEncoderTest.php +++ b/src/Symfony/Component/Security/Tests/Core/Encoder/BCryptPasswordEncoderTest.php @@ -47,6 +47,8 @@ class BCryptPasswordEncoderTest extends \PHPUnit_Framework_TestCase public function testResultLength() { + $this->skipIfPhpVersionIsNotSupported(); + $encoder = new BCryptPasswordEncoder(self::VALID_COST); $result = $encoder->encodePassword(self::PASSWORD, null); $this->assertEquals(60, strlen($result)); @@ -54,6 +56,8 @@ class BCryptPasswordEncoderTest extends \PHPUnit_Framework_TestCase 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)); @@ -72,10 +76,19 @@ class BCryptPasswordEncoderTest extends \PHPUnit_Framework_TestCase public function testCheckPasswordLength() { + $this->skipIfPhpVersionIsNotSupported(); + $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')); } + + private function skipIfPhpVersionIsNotSupported() + { + if (PHP_VERSION_ID < 50307 && !\PasswordCompat\binary\check()) { + $this->markTestSkipped('Skipping test as this PHP version is not compatible with the ircmaxell/password-compat library.'); + } + } } From 2a6fa7bbaba0b19be52b3462afc678d156d14a6f Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 22 Dec 2015 09:19:23 +0100 Subject: [PATCH 2/2] use requires annotation --- .../Encoder/BCryptPasswordEncoderTest.php | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/Symfony/Component/Security/Tests/Core/Encoder/BCryptPasswordEncoderTest.php b/src/Symfony/Component/Security/Tests/Core/Encoder/BCryptPasswordEncoderTest.php index b3ddff6e9b..9894c6f216 100644 --- a/src/Symfony/Component/Security/Tests/Core/Encoder/BCryptPasswordEncoderTest.php +++ b/src/Symfony/Component/Security/Tests/Core/Encoder/BCryptPasswordEncoderTest.php @@ -45,19 +45,21 @@ class BCryptPasswordEncoderTest extends \PHPUnit_Framework_TestCase } } + /** + * @requires PHP 5.3.7 + */ public function testResultLength() { - $this->skipIfPhpVersionIsNotSupported(); - $encoder = new BCryptPasswordEncoder(self::VALID_COST); $result = $encoder->encodePassword(self::PASSWORD, null); $this->assertEquals(60, strlen($result)); } + /** + * @requires PHP 5.3.7 + */ 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)); @@ -74,21 +76,15 @@ class BCryptPasswordEncoderTest extends \PHPUnit_Framework_TestCase $encoder->encodePassword(str_repeat('a', 73), 'salt'); } + /** + * @requires PHP 5.3.7 + */ public function testCheckPasswordLength() { - $this->skipIfPhpVersionIsNotSupported(); - $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')); } - - private function skipIfPhpVersionIsNotSupported() - { - if (PHP_VERSION_ID < 50307 && !\PasswordCompat\binary\check()) { - $this->markTestSkipped('Skipping test as this PHP version is not compatible with the ircmaxell/password-compat library.'); - } - } }