Вход Регистрация
Файл: symfony-2.7/src/Symfony/Component/Security/Core/Tests/Encoder/BCryptPasswordEncoderTest.php
Строк: 101
<?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 SymfonyComponentSecurityCoreTestsEncoder;

use 
SymfonyComponentSecurityCoreEncoderBCryptPasswordEncoder;

/**
 * @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()
    {
        
$encoder = new BCryptPasswordEncoder(self::VALID_COST);
        
$result $encoder->encodePassword(self::PASSWORDnull);
        
$this->assertEquals(60strlen($result));
    }

    public function 
testValidation()
    {
        
$encoder = new BCryptPasswordEncoder(self::VALID_COST);
        
$result $encoder->encodePassword(self::PASSWORDnull);
        
$this->assertTrue($encoder->isPasswordValid($resultself::PASSWORDnull));
        
$this->assertFalse($encoder->isPasswordValid($result'anotherPassword'null));
    }

    
/**
     * @expectedException SymfonyComponentSecurityCoreExceptionBadCredentialsException
     */
    
public function testEncodePasswordLength()
    {
        
$encoder = new BCryptPasswordEncoder(self::VALID_COST);

        
$encoder->encodePassword(str_repeat('a'5000), 'salt');
    }

    public function 
testCheckPasswordLength()
    {
        
$encoder = new BCryptPasswordEncoder(self::VALID_COST);

        
$this->assertFalse($encoder->isPasswordValid('encoded'str_repeat('a'5000), 'salt'));
    }
}
Онлайн: 1
Реклама