Classes List

Symfony\Component\Security\Core\Tests\Encoder\Argon2iPasswordEncoderTest

 1 
 2 
 3 
 4 
 5 
 6 
 7 
 8 
 9 
 10 
 11 
 12 
 13 
 14 
 15 
 16 
 17 
 18 
 19 
 20 
 21 
 22 
 23 
 24 
 25 
 26 
 27 
 28 
 29 
 30 
 31 
 32 
 33 
 34 
 35 
 36 
 37 
 38 
 39 
 40 
 41 
 42 
 43 
 44 
 45 
 46 
 47 
 48 
 49 
 50 
 51 
 52 
 53 
 54 
 55 
 56 
 57 
 58 
 59 
 60 
 61 
 62 
 63 
<?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 PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Core\Encoder\Argon2iPasswordEncoder;

/** * @author Zan Baldwin <hello@zanbaldwin.com> */
class Argon2iPasswordEncoderTest extends TestCase
{
    const PASSWORD = 'password';

    protected function setUp()
    {
        if (!Argon2iPasswordEncoder::isSupported()) {
            $this->markTestSkipped('Argon2i algorithm is not supported.');
        }
    }

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

    /** * @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException */
    public function testEncodePasswordLength()
    {
        $encoder = new Argon2iPasswordEncoder();
        $encoder->encodePassword(str_repeat('a'4097), 'salt');
    }

    public function testCheckPasswordLength()
    {
        $encoder = new Argon2iPasswordEncoder();
        $result = $encoder->encodePassword(str_repeat('a'4096), null);
        $this->assertFalse($encoder->isPasswordValid($resultstr_repeat('a'4097), null));
        $this->assertTrue($encoder->isPasswordValid($resultstr_repeat('a'4096), null));
    }

    public function testUserProvidedSaltIsNotUsed()
    {
        $encoder = new Argon2iPasswordEncoder();
        $result = $encoder->encodePassword(self::PASSWORD'salt');
        $this->assertTrue($encoder->isPasswordValid($resultself::PASSWORD'anotherSalt'));
    }
}