This commit is contained in:
2025-11-20 16:34:30 +01:00
parent 15d1a30e88
commit 4e4351e833
631 changed files with 130125 additions and 36318 deletions

View File

@@ -1,26 +1,26 @@
{
"name": "ircmaxell\/security-lib",
"name": "ircmaxell/security-lib",
"type": "library",
"description": "A Base Security Library",
"keywords": [],
"homepage": "https:\/\/github.com\/ircmaxell\/SecurityLib",
"homepage": "https://github.com/ircmaxell/SecurityLib",
"license": "MIT",
"authors": [
{
"name": "Anthony Ferrara",
"email": "ircmaxell@ircmaxell.com",
"homepage": "http:\/\/blog.ircmaxell.com"
"homepage": "http://blog.ircmaxell.com"
}
],
"require-dev": {
"mikey179\/vfsStream": "1.1.*"
"mikey179/vfsstream": "1.1.*"
},
"require": {
"php": ">=5.3.2"
},
"autoload": {
"psr-4": {
"SecurityLib\\": "lib\/SecurityLib\/"
"psr-0": {
"SecurityLib": "lib"
}
},
"extra": {
@@ -28,4 +28,4 @@
"dev-master": "1.0.x-dev"
}
}
}
}

View File

@@ -0,0 +1,31 @@
{
"name": "ircmaxell/security-lib",
"type": "library",
"description": "A Base Security Library",
"keywords": [],
"homepage": "https://github.com/ircmaxell/SecurityLib",
"license": "MIT",
"authors": [
{
"name": "Anthony Ferrara",
"email": "ircmaxell@ircmaxell.com",
"homepage": "http://blog.ircmaxell.com"
}
],
"require-dev": {
"mikey179/vfsstream": "1.1.*"
},
"require": {
"php": ">=5.3.2"
},
"autoload": {
"psr-0": {
"SecurityLib": "lib"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
}
}

View File

@@ -1,5 +1,4 @@
<?php
/**
* The interface that all hash implementations must implement
*
@@ -12,6 +11,7 @@
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @license http://www.gnu.org/licenses/lgpl-2.1.html LGPL v 2.1
*/
namespace PasswordLibTest\Mocks;
/**
@@ -21,21 +21,21 @@ namespace PasswordLibTest\Mocks;
* @package Hash
* @author Anthony Ferrara <ircmaxell@ircmaxell.com>
*/
class AbstractMock
{
class AbstractMock {
protected $callbacks = array();
public static function init()
{
}
public function __construct(array $callbacks = array())
{
public static function init() {}
public function __construct(array $callbacks = array()) {
$this->callbacks = $callbacks;
}
public function __call($name, array $args = array())
{
public function __call($name, array $args = array()) {
if (isset($this->callbacks[$name])) {
return call_user_func_array($this->callbacks[$name], $args);
}
return null;
}
}

View File

@@ -1,5 +1,4 @@
<?php
/**
* The interface that all hash implementations must implement
*
@@ -12,6 +11,7 @@
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @license http://www.gnu.org/licenses/lgpl-2.1.html LGPL v 2.1
*/
namespace SecurityLibTest\Mocks;
/**
@@ -21,10 +21,11 @@ namespace SecurityLibTest\Mocks;
* @package Hash
* @author Anthony Ferrara <ircmaxell@ircmaxell.com>
*/
class Enum extends \SecurityLib\Enum
{
class Enum extends \SecurityLib\Enum {
const Value1 = 1;
const Value2 = 2;
const Value3 = 3;
const Value4 = 4;
}

View File

@@ -1,5 +1,4 @@
<?php
/**
* The interface that all hash implementations must implement
*
@@ -12,6 +11,7 @@
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @license http://www.gnu.org/licenses/lgpl-2.1.html LGPL v 2.1
*/
namespace SecurityLibTest\Mocks;
/**
@@ -21,29 +21,29 @@ namespace SecurityLibTest\Mocks;
* @package Hash
* @author Anthony Ferrara <ircmaxell@ircmaxell.com>
*/
class Factory extends \SecurityLib\AbstractFactory
{
class Factory extends \SecurityLib\AbstractFactory {
protected $callbacks = array();
public static function init()
{
}
public function __construct(array $callbacks = array())
{
public static function init() {}
public function __construct(array $callbacks = array()) {
$this->callbacks = $callbacks;
}
public function __call($name, array $args = array())
{
public function __call($name, array $args = array()) {
if (isset($this->callbacks[$name])) {
return call_user_func_array($this->callbacks[$name], $args);
}
return null;
}
public function registerType($a1, $a2, $a3, $a4, $a5 = \false)
{
public function registerType($a1, $a2, $a3, $a4, $a5 = false) {
return parent::registerType($a1, $a2, $a3, $a4, $a5);
}
public function loadFiles($dir, $name, $method)
{
public function loadFiles($dir, $name, $method) {
return parent::loadFiles($dir, $name, $method);
}
}

View File

@@ -1,5 +1,4 @@
<?php
/**
* The interface that all hash implementations must implement
*
@@ -12,6 +11,7 @@
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @license http://www.gnu.org/licenses/lgpl-2.1.html LGPL v 2.1
*/
namespace SecurityLibTest\Mocks;
/**
@@ -21,8 +21,9 @@ namespace SecurityLibTest\Mocks;
* @package Hash
* @author Anthony Ferrara <ircmaxell@ircmaxell.com>
*/
class Strength extends \SecurityLib\Strength
{
class Strength extends \SecurityLib\Strength {
const MEDIUMLOW = 4;
const SUPERHIGH = 999;
}

View File

@@ -1,58 +1,67 @@
<?php
use SecurityLibTest\Mocks\Factory;
use SecurityLibTest\Mocks\Factory;
use org\bovigo\vfs\vfsStream;
class Unit_Core_AbstractFactoryTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
$root = vfsStream::setup('SecurityLibTest');
//Setup Folders
$core = vfsStream::newDirectory('Core')->at($root);
$af = vfsStream::newDirectory('AbstractFactory')->at($core);
// Create Files
vfsStream::newFile('test.php')->at($af);
vfsStream::newFile('Some234Foo234Bar98Name.php')->at($af);
vfsStream::newFile('Invalid.csv')->at($af);
vfsStream::newFile('badlocation.php')->at($core);
}
/**
* @covers SecurityLib\AbstractFactory::registerType
*/
public function testRegisterType()
{
$factory = new Factory();
$factory->registerType('test', 'iteratoraggregate', 'foo', 'ArrayObject', \false);
}
/**
* @covers SecurityLib\AbstractFactory::registerType
* @expectedException InvalidArgumentException
*/
public function testRegisterTypeFail()
{
$factory = new Factory();
$factory->registerType('test', 'iterator', 'foo', 'ArrayObject', \false);
}
/**
* @covers SecurityLib\AbstractFactory::registerType
*/
public function testRegisterTypeInstantiate()
{
$factory = new Factory();
$factory->registerType('test', 'iteratoraggregate', 'foo', 'ArrayObject', \true);
}
public function testLoadFiles()
{
$dir = vfsStream::url('SecurityLibTest/Core/AbstractFactory');
$result = array();
$callback = function ($name, $class) use (&$result) {
$result[$name] = $class;
};
$factory = new Factory();
$factory->loadFiles($dir, 'foo\\', $callback);
$expect = array('test' => 'foo\test', 'Some234Foo234Bar98Name' => 'foo\Some234Foo234Bar98Name');
$this->assertEquals($expect, $result);
}
use org\bovigo\vfs\vfsStream;
class Unit_Core_AbstractFactoryTest extends PHPUnit_Framework_TestCase {
protected function setUp() {
$root = vfsStream::setup('SecurityLibTest');
//Setup Folders
$core = vfsStream::newDirectory('Core')->at($root);
$af = vfsStream::newDirectory('AbstractFactory')->at($core);
// Create Files
vfsStream::newFile('test.php')->at($af);
vfsStream::newFile('Some234Foo234Bar98Name.php')->at($af);
vfsStream::newFile('Invalid.csv')->at($af);
vfsStream::newFile('badlocation.php')->at($core);
}
/**
* @covers SecurityLib\AbstractFactory::registerType
*/
public function testRegisterType() {
$factory = new Factory;
$factory->registerType('test', 'iteratoraggregate', 'foo', 'ArrayObject', false);
}
/**
* @covers SecurityLib\AbstractFactory::registerType
* @expectedException InvalidArgumentException
*/
public function testRegisterTypeFail() {
$factory = new Factory;
$factory->registerType('test', 'iterator', 'foo', 'ArrayObject', false);
}
/**
* @covers SecurityLib\AbstractFactory::registerType
*/
public function testRegisterTypeInstantiate() {
$factory = new Factory;
$factory->registerType('test', 'iteratoraggregate', 'foo', 'ArrayObject', true);
}
public function testLoadFiles() {
$dir = vfsStream::url('SecurityLibTest/Core/AbstractFactory');
$result = array();
$callback = function($name, $class) use (&$result) {
$result[$name] = $class;
};
$factory = new Factory();
$factory->loadFiles($dir, 'foo\\', $callback);
$expect = array(
'test' => 'foo\\test',
'Some234Foo234Bar98Name' => 'foo\\Some234Foo234Bar98Name'
);
$this->assertEquals($expect, $result);
}
}

View File

@@ -1,66 +1,69 @@
<?php
use SecurityLib\BaseConverter;
use SecurityLib\BaseConverter;
class Unit_Core_BaseConverterTest extends \PHPUnit_Framework_TestCase
{
public static function provideConvertFromBinary()
{
$return = array(array('', '', ''), array(\chr(0), '012', '0'), array(\chr(9), '01', '1001'), array(\chr(1) . \chr(2) . \chr(3), '0123456789', '66051'));
return $return;
}
public static function provideConvertToFromBinary()
{
$return = array();
$str = \chr(1) . \chr(0);
for ($i = 2; $i < 256; $i++) {
$str .= \chr($i);
$return[] = array($str, \strrev($str));
}
return $return;
}
/**
* @covers SecurityLib\BaseConverter::convertFromBinary
* @covers SecurityLib\BaseConverter::baseConvert
* @dataProvider provideConvertFromBinary
*/
public function testConvertFromBinary($from, $to, $expect)
{
$result = BaseConverter::convertFromBinary($from, $to);
$this->assertEquals($expect, $result);
}
/**
* @covers SecurityLib\BaseConverter::convertToBinary
* @covers SecurityLib\BaseConverter::baseConvert
* @dataProvider provideConvertFromBinary
*/
public function testConvertToBinary($expect, $from, $str)
{
$result = BaseConverter::convertToBinary($str, $from);
$result = \ltrim($result, \chr(0));
$expect = \ltrim($expect, \chr(0));
$this->assertEquals($expect, $result);
}
/**
* @covers SecurityLib\BaseConverter::convertToBinary
* @covers SecurityLib\BaseConverter::convertFromBinary
* @covers SecurityLib\BaseConverter::baseConvert
* @dataProvider provideConvertToFromBinary
*/
public function testConvertToAndFromBinary($str, $from)
{
return \false;
$result1 = BaseConverter::convertFromBinary($str, $from);
$result = BaseConverter::convertToBinary($result1, $from);
$this->assertEquals($str, $result);
}
/**
* @covers SecurityLib\BaseConverter::baseConvert
* @expectedException InvalidArgumentException
*/
public function testBaseConvertFailure()
{
BaseConverter::baseConvert(array(1), 1, 1);
}
class Unit_Core_BaseConverterTest extends PHPUnit_Framework_TestCase {
public static function provideConvertFromBinary() {
$return = array(
array('', '', ''),
array(chr(0), '012', '0'),
array(chr(9), '01', '1001'),
array(chr(1) . chr(2) . chr(3), '0123456789', '66051'),
);
return $return;
}
public static function provideConvertToFromBinary() {
$return = array();
$str = chr(1) . chr(0);
for ($i = 2; $i < 256; $i++) {
$str .= chr($i);
$return[] = array($str, strrev($str));
}
return $return;
}
/**
* @covers SecurityLib\BaseConverter::convertFromBinary
* @covers SecurityLib\BaseConverter::baseConvert
* @dataProvider provideConvertFromBinary
*/
public function testConvertFromBinary($from, $to, $expect) {
$result = BaseConverter::convertFromBinary($from, $to);
$this->assertEquals($expect, $result);
}
/**
* @covers SecurityLib\BaseConverter::convertToBinary
* @covers SecurityLib\BaseConverter::baseConvert
* @dataProvider provideConvertFromBinary
*/
public function testConvertToBinary($expect, $from, $str) {
$result = BaseConverter::convertToBinary($str, $from);
$result = ltrim($result, chr(0));
$expect = ltrim($expect, chr(0));
$this->assertEquals($expect, $result);
}
/**
* @covers SecurityLib\BaseConverter::convertToBinary
* @covers SecurityLib\BaseConverter::convertFromBinary
* @covers SecurityLib\BaseConverter::baseConvert
* @dataProvider provideConvertToFromBinary
*/
public function testConvertToAndFromBinary($str, $from) {
return false;
$result1 = BaseConverter::convertFromBinary($str, $from);
$result = BaseConverter::convertToBinary($result1, $from);
$this->assertEquals($str, $result);
}
/**
* @covers SecurityLib\BaseConverter::baseConvert
* @expectedException InvalidArgumentException
*/
public function testBaseConvertFailure() {
BaseConverter::baseConvert(array(1), 1, 1);
}
}

View File

@@ -1,31 +1,30 @@
<?php
require_once __DIR__ . '/../BigMathTest.php';
require_once __DIR__ . '/../BigMathTest.php';
class Unit_Core_BigMath_BCMathTest extends \Unit_Core_BigMathTest
{
protected static $mathImplementations = array();
protected function setUp()
{
if (!\extension_loaded('bcmath')) {
$this->markTestSkipped('BCMath is not loaded');
}
}
/**
* @dataProvider provideAddTest
*/
public function testAdd($left, $right, $expected)
{
$obj = new \SecurityLib\BigMath\BCMath();
$this->assertEquals($expected, $obj->add($left, $right));
}
/**
* @dataProvider provideSubtractTest
*/
public function testSubtract($left, $right, $expected)
{
$obj = new \SecurityLib\BigMath\BCMath();
$this->assertEquals($expected, $obj->subtract($left, $right));
class Unit_Core_BigMath_BCMathTest extends Unit_Core_BigMathTest {
protected static $mathImplementations = array();
protected function setUp() {
if (!extension_loaded('bcmath')) {
$this->markTestSkipped('BCMath is not loaded');
}
}
/**
* @dataProvider provideAddTest
*/
public function testAdd($left, $right, $expected) {
$obj = new \SecurityLib\BigMath\BCMath;
$this->assertEquals($expected, $obj->add($left, $right));
}
/**
* @dataProvider provideSubtractTest
*/
public function testSubtract($left, $right, $expected) {
$obj = new \SecurityLib\BigMath\BCMath;
$this->assertEquals($expected, $obj->subtract($left, $right));
}
}

View File

@@ -1,31 +1,30 @@
<?php
require_once __DIR__ . '/../BigMathTest.php';
require_once __DIR__ . '/../BigMathTest.php';
class Unit_Core_BigMath_GMPTest extends \Unit_Core_BigMathTest
{
protected static $mathImplementations = array();
protected function setUp()
{
if (!\extension_loaded('gmp')) {
$this->markTestSkipped('BCMath is not loaded');
}
}
/**
* @dataProvider provideAddTest
*/
public function testAdd($left, $right, $expected)
{
$obj = new \SecurityLib\BigMath\GMP();
$this->assertEquals($expected, $obj->add($left, $right));
}
/**
* @dataProvider provideSubtractTest
*/
public function testSubtract($left, $right, $expected)
{
$obj = new \SecurityLib\BigMath\GMP();
$this->assertEquals($expected, $obj->subtract($left, $right));
class Unit_Core_BigMath_GMPTest extends Unit_Core_BigMathTest {
protected static $mathImplementations = array();
protected function setUp() {
if (!extension_loaded('gmp')) {
$this->markTestSkipped('BCMath is not loaded');
}
}
/**
* @dataProvider provideAddTest
*/
public function testAdd($left, $right, $expected) {
$obj = new \SecurityLib\BigMath\GMP;
$this->assertEquals($expected, $obj->add($left, $right));
}
/**
* @dataProvider provideSubtractTest
*/
public function testSubtract($left, $right, $expected) {
$obj = new \SecurityLib\BigMath\GMP;
$this->assertEquals($expected, $obj->subtract($left, $right));
}
}

View File

@@ -1,25 +1,24 @@
<?php
require_once __DIR__ . '/../BigMathTest.php';
require_once __DIR__ . '/../BigMathTest.php';
class Unit_Core_BigMath_PHPMathTest extends \Unit_Core_BigMathTest
{
protected static $mathImplementations = array();
/**
* @dataProvider provideAddTest
*/
public function testAdd($left, $right, $expected)
{
$obj = new \SecurityLib\BigMath\PHPMath();
$this->assertEquals($expected, $obj->add($left, $right));
}
/**
* @dataProvider provideSubtractTest
*/
public function testSubtract($left, $right, $expected)
{
$obj = new \SecurityLib\BigMath\PHPMath();
$this->assertEquals($expected, $obj->subtract($left, $right));
}
class Unit_Core_BigMath_PHPMathTest extends Unit_Core_BigMathTest {
protected static $mathImplementations = array();
/**
* @dataProvider provideAddTest
*/
public function testAdd($left, $right, $expected) {
$obj = new \SecurityLib\BigMath\PHPMath;
$this->assertEquals($expected, $obj->add($left, $right));
}
/**
* @dataProvider provideSubtractTest
*/
public function testSubtract($left, $right, $expected) {
$obj = new \SecurityLib\BigMath\PHPMath;
$this->assertEquals($expected, $obj->subtract($left, $right));
}
}

View File

@@ -1,28 +1,46 @@
<?php
class Unit_Core_BigMathTest extends PHPUnit_Framework_TestCase {
class Unit_Core_BigMathTest extends \PHPUnit_Framework_TestCase
{
protected static $mathImplementations = array();
public static function provideAddTest()
{
$ret = array(array('1', '1', '2'), array('11', '11', '22'), array('1111111111', '1111111111', '2222222222'), array('555', '555', '1110'), array('-10', '10', '0'), array('10', '-10', '0'), array('-10', '-10', '-20'), array('0', '0', '0'), array('5', '0', '5'));
return $ret;
}
public static function provideSubtractTest()
{
return array(array('1', '1', '0'), array('6', '3', '3'), array('200', '250', '-50'), array('10', '300', '-290'), array('-1', '-1', '0'), array('-5', '5', '-10'), array('5', '-5', '10'), array('0', '0', '0'), array('5', '0', '5'));
}
public function testCreateFromServerConfiguration()
{
$instance = \SecurityLib\BigMath::createFromServerConfiguration();
if (\extension_loaded('bcmath')) {
$this->assertEquals('SecurityLib\BigMath\BCMath', \get_class($instance));
} elseif (\extension_loaded('gmp')) {
$this->assertEquals('SecurityLib\BigMath\GMP', \get_class($instance));
} else {
$this->assertEquals('SecurityLib\BigMath\PHPMath', \get_class($instance));
}
protected static $mathImplementations = array();
public static function provideAddTest() {
$ret = array(
array('1', '1', '2'),
array('11', '11', '22'),
array('1111111111', '1111111111', '2222222222'),
array('555', '555', '1110'),
array('-10', '10', '0'),
array('10', '-10', '0'),
array('-10', '-10', '-20'),
array('0', '0', '0'),
array('5', '0', '5'),
);
return $ret;
}
public static function provideSubtractTest() {
return array(
array('1', '1', '0'),
array('6', '3', '3'),
array('200', '250', '-50'),
array('10', '300', '-290'),
array('-1', '-1', '0'),
array('-5', '5', '-10'),
array('5', '-5', '10'),
array('0', '0', '0'),
array('5', '0', '5'),
);
}
public function testCreateFromServerConfiguration() {
$instance = \SecurityLib\BigMath::createFromServerConfiguration();
if (extension_loaded('bcmath')) {
$this->assertEquals('SecurityLib\\BigMath\\BCMath', get_class($instance));
} elseif (extension_loaded('gmp')) {
$this->assertEquals('SecurityLib\\BigMath\\GMP', get_class($instance));
} else {
$this->assertEquals('SecurityLib\\BigMath\\PHPMath', get_class($instance));
}
}
}

View File

@@ -1,49 +1,61 @@
<?php
use SecurityLibTest\Mocks\Enum;
use SecurityLibTest\Mocks\Enum;
class Unit_Core_EnumTest extends \PHPUnit_Framework_TestCase
{
public static function provideTestCompare()
{
return array(array(new Enum(Enum::Value1), new Enum(Enum::Value1), 0), array(new Enum(Enum::Value2), new Enum(Enum::Value1), -1), array(new Enum(Enum::Value1), new Enum(Enum::Value2), 1));
}
/**
* @expectedException UnexpectedValueException
*/
public function testConstructFail()
{
$obj = new Enum();
}
public function testConstruct()
{
$obj = new Enum(Enum::Value3);
$this->assertTrue($obj instanceof \SecurityLib\Enum);
}
public function testToString()
{
$obj = new Enum(Enum::Value3);
$this->assertEquals('3', (string) $obj);
}
/**
* @covers SecurityLib\Core\Enum::compare
* @dataProvider provideTestCompare
*/
public function testCompare(Enum $from, Enum $to, $expected)
{
$this->assertEquals($expected, $from->compare($to));
}
public function testGetConstList()
{
$obj = new Enum(Enum::Value3);
$const = $obj->getConstList();
$this->assertEquals(array('Value1' => 1, 'Value2' => 2, 'Value3' => 3, 'Value4' => 4), $const);
}
public function testGetConstListWithDefault()
{
$obj = new Enum(Enum::Value3);
$const = $obj->getConstList(\true);
$this->assertEquals(array('__DEFAULT' => null, 'Value1' => 1, 'Value2' => 2, 'Value3' => 3, 'Value4' => 4), $const);
}
class Unit_Core_EnumTest extends PHPUnit_Framework_TestCase {
public static function provideTestCompare() {
return array(
array(new Enum(Enum::Value1), new Enum(Enum::Value1), 0),
array(new Enum(Enum::Value2), new Enum(Enum::Value1), -1),
array(new Enum(Enum::Value1), new Enum(Enum::Value2), 1),
);
}
/**
* @expectedException UnexpectedValueException
*/
public function testConstructFail() {
$obj = new Enum();
}
public function testConstruct() {
$obj = new Enum(Enum::Value3);
$this->assertTrue($obj instanceof \SecurityLib\Enum);
}
public function testToString() {
$obj = new Enum(Enum::Value3);
$this->assertEquals('3', (string) $obj);
}
/**
* @covers SecurityLib\Core\Enum::compare
* @dataProvider provideTestCompare
*/
public function testCompare(Enum $from, Enum $to, $expected) {
$this->assertEquals($expected, $from->compare($to));
}
public function testGetConstList() {
$obj = new Enum(Enum::Value3);
$const = $obj->getConstList();
$this->assertEquals(array(
'Value1' => 1,
'Value2' => 2,
'Value3' => 3,
'Value4' => 4,
), $const);
}
public function testGetConstListWithDefault() {
$obj = new Enum(Enum::Value3);
$const = $obj->getConstList(true);
$this->assertEquals(array(
'__DEFAULT' => null,
'Value1' => 1,
'Value2' => 2,
'Value3' => 3,
'Value4' => 4,
), $const);
}
}

View File

@@ -1,26 +1,35 @@
<?php
use SecurityLib\Strength;
use SecurityLib\Strength;
class Unit_Core_StrengthTest extends \PHPUnit_Framework_TestCase
{
public function testConstruct()
{
$obj = new Strength(Strength::LOW);
$this->assertTrue($obj instanceof \SecurityLib\Strength);
$this->assertTrue($obj instanceof \SecurityLib\Enum);
}
public function testGetConstList()
{
$obj = new Strength();
$const = $obj->getConstList();
$this->assertEquals(array('VERYLOW' => 1, 'LOW' => 3, 'MEDIUM' => 5, 'HIGH' => 7), $const);
}
public function testGetConstListWithDefault()
{
$obj = new Strength();
$const = $obj->getConstList(\true);
$this->assertEquals(array('__DEFAULT' => 1, 'VERYLOW' => 1, 'LOW' => 3, 'MEDIUM' => 5, 'HIGH' => 7), $const);
}
class Unit_Core_StrengthTest extends PHPUnit_Framework_TestCase {
public function testConstruct() {
$obj = new Strength(Strength::LOW);
$this->assertTrue($obj instanceof \SecurityLib\Strength);
$this->assertTrue($obj instanceof \SecurityLib\Enum);
}
public function testGetConstList() {
$obj = new Strength();
$const = $obj->getConstList();
$this->assertEquals(array(
'VERYLOW' => 1,
'LOW' => 3,
'MEDIUM' => 5,
'HIGH' => 7,
), $const);
}
public function testGetConstListWithDefault() {
$obj = new Strength();
$const = $obj->getConstList(true);
$this->assertEquals(array(
'__DEFAULT' => 1,
'VERYLOW' => 1,
'LOW' => 3,
'MEDIUM' => 5,
'HIGH' => 7,
), $const);
}
}

View File

@@ -1,5 +1,4 @@
<?php
namespace SecurityLib;
/**
@@ -7,16 +6,15 @@ namespace SecurityLib;
* mbstring.func_overload = 7
* in your php.ini file to verify its correctness.
*/
class UtilTest extends \PHPUnit_Framework_TestCase
{
public function testSafeStrlen()
{
$this->assertEquals(\SecurityLib\Util::safeStrlen("\x03?"), 2);
class UtilTest extends \PHPUnit_Framework_TestCase {
public function testSafeStrlen() {
$this->assertEquals(Util::safeStrlen("\x03\x3f"), 2);
}
public function testSafeSubstr()
{
$a = "abcdefg\x03?hijk";
$b = "\x03?";
$this->assertEquals(\SecurityLib\Util::safeSubstr($a, 7, 2), $b);
public function testSafeSubstr() {
$a = "abcdefg\x03\x3fhijk";
$b = "\x03\x3f";
$this->assertEquals(Util::safeSubstr($a, 7, 2), $b);
}
}

View File

@@ -1,5 +1,4 @@
<?php
/**
* Bootstrap the library. This registers a simple autoloader for autoloading
* classes
@@ -16,9 +15,11 @@
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @license http://www.gnu.org/licenses/lgpl-2.1.html LGPL v 2.1
*/
namespace SecurityLibTest;
ini_set('memory_limit', '1G');
/**
* The simple autoloader for the PasswordLibTest libraries.
*
@@ -41,5 +42,8 @@ spl_autoload_register(function ($class) {
require $path;
}
});
define('PATH_ROOT', dirname(__DIR__));
require_once dirname(__DIR__) . '/vendor/autoload.php';