Introduction of loop scopes.
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
use Thelia\Core\Security\Encoder\PasswordHashEncoder;
|
||||
|
||||
class PasswordHashEncoderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testEncode()
|
||||
{
|
||||
$encoder = new PasswordHashEncoder();
|
||||
|
||||
$pass = $encoder->encode('password', 'sha512', 'a simple salt');
|
||||
|
||||
// echo "PASS=\{$pass\}";
|
||||
|
||||
$this->assertEquals("L3f/gGy4nBVhi8WSsC1a7E9JM8U+rtk6ZT+NiqX8M1UDJv6mahQEZ1z2cN/y9pixH+hgWbkBitONMiXWscomoQ==", $pass, "Expected password not found.");
|
||||
}
|
||||
|
||||
public function testIsEqual()
|
||||
{
|
||||
$encoder = new PasswordHashEncoder();
|
||||
|
||||
$exp = "L3f/gGy4nBVhi8WSsC1a7E9JM8U+rtk6ZT+NiqX8M1UDJv6mahQEZ1z2cN/y9pixH+hgWbkBitONMiXWscomoQ==";
|
||||
|
||||
$this->assertTrue($encoder->isEqual($exp, 'password', 'sha512', 'a simple salt'));
|
||||
}
|
||||
|
||||
public function testWrongPass()
|
||||
{
|
||||
$encoder = new PasswordHashEncoder();
|
||||
|
||||
$exp = "L3f/gGy4nBVhi8WSsC1a7E9JM8U+rtk6ZT+NiqX8M1UDJv6mahQEZ1z2cN/y9pixH+hgWbkBitONMiXWscomoQ==";
|
||||
|
||||
$this->assertFalse($encoder->isEqual($exp, 'grongron', 'sha512', 'a simple salt'));
|
||||
}
|
||||
|
||||
public function testWrongSalt()
|
||||
{
|
||||
$encoder = new PasswordHashEncoder();
|
||||
|
||||
$exp = "L3f/gGy4nBVhi8WSsC1a7E9JM8U+rtk6ZT+NiqX8M1UDJv6mahQEZ1z2cN/y9pixH+hgWbkBitONMiXWscomoQ==";
|
||||
|
||||
$this->assertFalse($encoder->isEqual($exp, 'password', 'sha512', 'another salt'));
|
||||
}
|
||||
|
||||
public function testWrongAlgo()
|
||||
{
|
||||
$encoder = new PasswordHashEncoder();
|
||||
|
||||
$exp = "L3f/gGy4nBVhi8WSsC1a7E9JM8U+rtk6ZT+NiqX8M1UDJv6mahQEZ1z2cN/y9pixH+hgWbkBitONMiXWscomoQ==";
|
||||
|
||||
$this->assertFalse($encoder->isEqual($exp, 'password', 'md5', 'another salt'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException LogicException
|
||||
*/
|
||||
public function testUnsupportedAlgo()
|
||||
{
|
||||
$encoder = new PasswordHashEncoder();
|
||||
|
||||
$exp = "L3f/gGy4nBVhi8WSsC1a7E9JM8U+rtk6ZT+NiqX8M1UDJv6mahQEZ1z2cN/y9pixH+hgWbkBitONMiXWscomoQ==";
|
||||
|
||||
$encoder->isEqual($exp, 'password', 'sbonk', 'another salt');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException LogicException
|
||||
*/
|
||||
public function testEncodeWrongAlgorithm()
|
||||
{
|
||||
$encoder = new PasswordHashEncoder();
|
||||
|
||||
$encoder->encode('password', 'pouët', 'a simple salt');
|
||||
}
|
||||
}
|
||||
49
core/lib/Thelia/Tests/Core/Security/SecurityManagerTest.php
Normal file
49
core/lib/Thelia/Tests/Core/Security/SecurityManagerTest.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Security;
|
||||
|
||||
use Thelia\Core\Security\SecurityManager;
|
||||
/**
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*
|
||||
*/
|
||||
class SecurityManagerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGetSetToken()
|
||||
{
|
||||
/*
|
||||
$context = new SecurityManager($authProvider)(
|
||||
$this->getMock('AuthenticationProviderInterface'),
|
||||
$this->getMock('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface')
|
||||
);
|
||||
$this->assertNull($context->getToken());
|
||||
|
||||
$context->setToken($token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'));
|
||||
$this->assertSame($token, $context->getToken());
|
||||
*/
|
||||
// $this->assertFalse(1==1, "faux !");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
use Thelia\Core\Security\Token\UsernamePasswordToken;
|
||||
|
||||
class UsernamePasswordTokenTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
{
|
||||
$token = new UsernamePasswordToken('username', 'password');
|
||||
|
||||
$this->assertFalse($token->isAuthenticated());
|
||||
|
||||
$token = new UsernamePasswordToken('username', 'password', true);
|
||||
$this->assertTrue($token->isAuthenticated());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException LogicException
|
||||
*/
|
||||
public function testSetAuthenticatedToTrue()
|
||||
{
|
||||
$token = new UsernamePasswordToken('foo', 'bar', true);
|
||||
$token->setAuthenticated(true);
|
||||
}
|
||||
|
||||
public function testSetAuthenticatedToFalse()
|
||||
{
|
||||
$token = new UsernamePasswordToken('foo', 'bar', true);
|
||||
$token->setAuthenticated(false);
|
||||
$this->assertFalse($token->isAuthenticated());
|
||||
}
|
||||
|
||||
public function testEraseCredentials()
|
||||
{
|
||||
$token = new UsernamePasswordToken('foo', 'bar', true);
|
||||
$token->eraseCredentials();
|
||||
$this->assertEquals('', $token->getCredentials());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user