Merge branch 'loops'
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());
|
||||
}
|
||||
}
|
||||
48
core/lib/Thelia/Tests/Type/AlphaNumStringListTypeTest.php
Executable file
48
core/lib/Thelia/Tests/Type/AlphaNumStringListTypeTest.php
Executable file
@@ -0,0 +1,48 @@
|
||||
<?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\Type;
|
||||
|
||||
use Thelia\Type\AlphaNumStringListType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AlphaNumStringListTypeTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testAlphaNumStringListType()
|
||||
{
|
||||
$type = new AlphaNumStringListType();
|
||||
$this->assertTrue($type->isValid('FOO1,FOO_2,FOO-3'));
|
||||
$this->assertFalse($type->isValid('FOO.1,FOO$_2,FOO-3'));
|
||||
}
|
||||
|
||||
public function testFormatAlphaNumStringListType()
|
||||
{
|
||||
$type = new AlphaNumStringListType();
|
||||
$this->assertTrue(is_array($type->getFormatedValue('FOO1,FOO_2,FOO-3')));
|
||||
$this->assertNull($type->getFormatedValue('5€'));
|
||||
}
|
||||
}
|
||||
43
core/lib/Thelia/Tests/Type/AlphaNumStringTypeTest.php
Executable file
43
core/lib/Thelia/Tests/Type/AlphaNumStringTypeTest.php
Executable file
@@ -0,0 +1,43 @@
|
||||
<?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\Type;
|
||||
|
||||
use Thelia\Type\AlphaNumStringType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AlphaNumStringTypeTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testAlphaNumStringType()
|
||||
{
|
||||
$type = new AlphaNumStringType();
|
||||
$this->assertTrue($type->isValid('azs_qs-0-9ds'));
|
||||
$this->assertFalse($type->isValid('3.3'));
|
||||
$this->assertFalse($type->isValid('3 3'));
|
||||
$this->assertFalse($type->isValid('3€3'));
|
||||
}
|
||||
}
|
||||
55
core/lib/Thelia/Tests/Type/BooleanTypeTest.php
Executable file
55
core/lib/Thelia/Tests/Type/BooleanTypeTest.php
Executable file
@@ -0,0 +1,55 @@
|
||||
<?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\Type;
|
||||
|
||||
use Thelia\Type\BooleanType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class BooleanTypeTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testBooleanType()
|
||||
{
|
||||
$booleanType = new BooleanType();
|
||||
$this->assertTrue($booleanType->isValid('y'));
|
||||
$this->assertTrue($booleanType->isValid('yes'));
|
||||
$this->assertTrue($booleanType->isValid('true'));
|
||||
$this->assertTrue($booleanType->isValid('no'));
|
||||
$this->assertTrue($booleanType->isValid('n'));
|
||||
$this->assertTrue($booleanType->isValid('false'));
|
||||
$this->assertFalse($booleanType->isValid('foo'));
|
||||
$this->assertFalse($booleanType->isValid(5));
|
||||
}
|
||||
|
||||
public function testFormatBooleanType()
|
||||
{
|
||||
$booleanType = new BooleanType();
|
||||
$this->assertTrue($booleanType->getFormatedValue('yes'));
|
||||
$this->assertFalse($booleanType->getFormatedValue('no'));
|
||||
$this->assertNull($booleanType->getFormatedValue('foo'));
|
||||
}
|
||||
}
|
||||
@@ -39,4 +39,11 @@ class IntListTypeTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertTrue($intListType->isValid('1,2,3'));
|
||||
$this->assertFalse($intListType->isValid('1,2,3.3'));
|
||||
}
|
||||
|
||||
public function testFormatIntListType()
|
||||
{
|
||||
$intListType = new IntListType();
|
||||
$this->assertTrue(is_array($intListType->getFormatedValue('1,2,3')));
|
||||
$this->assertNull($intListType->getFormatedValue('foo'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,4 +38,11 @@ class JsonTypeTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertTrue($jsonType->isValid('{"k0":"v0","k1":"v1","k2":"v2"}'));
|
||||
$this->assertFalse($jsonType->isValid('1,2,3'));
|
||||
}
|
||||
|
||||
public function testFormatJsonType()
|
||||
{
|
||||
$jsonType = new JsonType();
|
||||
$this->assertTrue(is_array($jsonType->getFormatedValue('{"k0":"v0","k1":"v1","k2":"v2"}')));
|
||||
$this->assertNull($jsonType->getFormatedValue('foo'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user