Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Composer file updated & some minor fixes #8

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
vendor
test.php
composer.lock
*.iml
.log.git
composer.lock
nbproject/*
.idea
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "padraic/security-multitool",
"name": "siu/security-multitool",
"description": "A multitool library offering access to recommended security related libraries, standardised implementations of security defences, and secure implementations of commonly performed tasks.",
"keywords": ["library", "security", "escaping", "sanitisation", "sanitization", "csrf", "xss", "ssl", "tls", "PRNG", "RNG", "random", "htmlpurifier"],
"homepage": "http://github.com/padraic/SecurityMultiTool",
Expand All @@ -14,14 +14,14 @@
],
"require": {
"ezyang/htmlpurifier": ">=4.5.0",
"ircmaxell/random-lib": "dev-master@dev",
"ircmaxell/security-lib": "dev-master@dev",
"dflydev/markdown": ">=1.0.2",
"paragonie/random-lib": "~2.0",
"ircmaxell/security-lib": "1.1.*@dev",
"michelf/php-markdown": ">=1.0.2",
"mjohnson/decoda": ">=5.1.2",
"zendframework/zend-uri": "2.2.*"
"laminas/laminas-uri": "2.7.*"
},
"require-dev": {
"mockery/mockery": "dev-master@dev"
"mockery/mockery": "~1.3"
},
"autoload": {
"psr-0": { "SecurityMultiTool": "library/" }
Expand Down
2 changes: 1 addition & 1 deletion library/SecurityMultiTool/Csrf/FormDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function decorate($form)
}
} else {
throw new Exception\RuntimeException(
'Unable to decorate as the given argument does not appear to '
'Unable to decorate as the given argument does not appear to '.
'contain valid HTML form markup'
);
}
Expand Down
4 changes: 2 additions & 2 deletions library/SecurityMultiTool/Csrf/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Provider extends Common\AbstractOptions implements Common\OptionsInterface
'token_name_prefix' => 'CSRFToken',
'name' => '',
'timeout' => 3600
)
);

public function __construct(array $options = null)
{
Expand Down Expand Up @@ -88,7 +88,7 @@ protected function storeTokenToSession()
}
$_SESSION[$this->getTokenName()] = array(
'token' => $this->getToken(),
'expire' => $expire;
'expire' => $expire
);
}

Expand Down
2 changes: 1 addition & 1 deletion library/SecurityMultiTool/Http/Redirector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use SecurityMultiTool\Http\HostDetector;
use SecurityMultiTool\Http\Header;
use SecurityMultiTool\Exception;
use Zend\Uri\Uri;
use Laminas\Uri\Uri;

class Redirector
{
Expand Down
6 changes: 3 additions & 3 deletions library/SecurityMultiTool/Markdown/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace SecurityMultiTool\Markdown;

use dflydev\markdown\MarkdownParser;
use Michelf\Markdown;
use SecurityMultiTool\Html\Sanitizer;
use SecurityMultiTool\Exception;
use SecurityMultiTool\Common;
Expand All @@ -20,12 +20,12 @@ public function __construct($cachePath, array $options = null)
{
$this->sanitizer = new Sanitizer($cachePath, $options);
//$this->sanitizer->setOption('HTML.Allowed', $this->filter);
$this->parser = new MarkdownParser;
$this->parser = new Markdown;
}

public function parse($markdown, $filter = null)
{
$unsanitized = $this->parser->transformMarkdown($markdown);
$unsanitized = $this->parser->transform($markdown);
$sanitized = $this->sanitizer->sanitize($unsanitized, $filter);
return $sanitized;
}
Expand Down
5 changes: 5 additions & 0 deletions library/SecurityMultiTool/Random/Source/HashTiming.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public static function getStrength()
return new Strength(Strength::VERYLOW);
}

public static function isSupported()
{
return (function_exists('mt_rand') && function_exists('microtime') && function_exists('sha1'));
}

public function generate($size)
{
$result = '';
Expand Down
6 changes: 4 additions & 2 deletions tests/SecurityMultiTool/BBCode/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use SecurityMultiTool\BBCode\Parser;
use Mockery as M;

class BBCodeParserTest extends \PHPUnit_Framework_TestCase
class BBCodeParserTest extends PHPUnit\Framework\TestCase
{

public $cache = '';
Expand All @@ -36,7 +36,7 @@ public function setup()

public function testParserCreationThrowsExceptionIfCacheDirectoryNotExists()
{
$this->setExpectedException('\SecurityMultiTool\Exception\RuntimeException');
$this->expectException('\SecurityMultiTool\Exception\RuntimeException');
$parser = new Parser('/does/not/exist');
}

Expand Down Expand Up @@ -75,6 +75,7 @@ public function testParsingCallsHtmlPurifier()
$sanitizer->shouldReceive('sanitize')->once()->with("foo", null);
$this->parser->setSanitizer($sanitizer);
$this->parser->parse('foo');
M::close();
}

public function testCanRestSanitizer()
Expand All @@ -83,6 +84,7 @@ public function testCanRestSanitizer()
$sanitizer->shouldReceive('reset')->once();
$this->parser->setSanitizer($sanitizer);
$this->parser->resetSanitizer();
M::close();
}

}
2 changes: 1 addition & 1 deletion tests/SecurityMultiTool/Html/EscaperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

use SecurityMultiTool\Html\Escaper;

class EscaperTest extends \PHPUnit_Framework_TestCase
class EscaperTest extends PHPUnit\Framework\TestCase
{

/**
Expand Down
6 changes: 4 additions & 2 deletions tests/SecurityMultiTool/Html/SanitizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use SecurityMultiTool\Html\Sanitizer;
use Mockery as M;

class SanitizerTest extends \PHPUnit_Framework_TestCase
class SanitizerTest extends PHPUnit\Framework\TestCase
{

protected $cache = '';
Expand All @@ -37,7 +37,7 @@ public function setup()

public function testSanitizerCreationThrowsExceptionIfCacheDirectoryNotExists()
{
$this->setExpectedException('\SecurityMultiTool\Exception\RuntimeException');
$this->expectException('\SecurityMultiTool\Exception\RuntimeException');
$sanitizer = new Sanitizer('/does/not/exist');
}

Expand Down Expand Up @@ -97,6 +97,7 @@ public function testSanitizeMethodCallsHtmlPurifier()
$purifier->shouldReceive('purify')->once()->with('html', null);
$this->sanitizer->setHtmlPurifier($purifier);
$this->sanitizer->sanitize('html');
M::close();
}

public function testOptionsMapToHtmlPurifierConfigObject()
Expand All @@ -117,6 +118,7 @@ public function testOptionsMapToHtmlPurifierConfigObject()
$this->assertEquals('baz', $this->sanitizer->getOption('foo'));
$this->assertEquals('baz1', $this->sanitizer->getOption('foo1'));
$this->assertEquals('baz2', $this->sanitizer->getOption('foo2'));
M::close();
}

}
5 changes: 2 additions & 3 deletions tests/SecurityMultiTool/Http/Header/CsrfTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
*/

use SecurityMultiTool\Http\Header\CsrfToken;
use Mockery as M;

class CsrfTokenTest extends \PHPUnit_Framework_TestCase
class CsrfTokenTest extends PHPUnit\Framework\TestCase
{

public function testImplementsOptionsInterfaceAndAbstractClass()
Expand All @@ -48,7 +47,7 @@ public function testHeaderConstruction()

public function testThrowsExceptionOnInvalidOptionName()
{
$this->setExpectedException('SecurityMultiTool\Exception\InvalidArgumentException');
$this->expectException('SecurityMultiTool\Exception\InvalidArgumentException');
$header = new CsrfToken(array('foo'=>'bar'));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

use SecurityMultiTool\Http\Header\StrictTransportSecurity;

class StrictTransportSecurityTest extends \PHPUnit_Framework_TestCase
class StrictTransportSecurityTest extends PHPUnit\Framework\TestCase
{

public function testImplementsOptionsInterfaceAndAbstractClass()
Expand Down Expand Up @@ -56,7 +56,7 @@ public function testHeaderConstructionWithIncludeSubdomains()

public function testThrowsExceptionOnInvalidOptionName()
{
$this->setExpectedException('SecurityMultiTool\Exception\InvalidArgumentException');
$this->expectException('SecurityMultiTool\Exception\InvalidArgumentException');
$header = new StrictTransportSecurity(array('foo'=>'bar'));
}

Expand Down
8 changes: 6 additions & 2 deletions tests/SecurityMultiTool/Http/HeadersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use SecurityMultiTool\Http\Header;
use Mockery as M;

class HeadersTest extends \PHPUnit_Framework_TestCase
class HeadersTest extends PHPUnit\Framework\TestCase
{

public function testOptionSetting()
Expand Down Expand Up @@ -54,8 +54,12 @@ public function testHeadersAreSent()
$h1->shouldReceive('send')->once()->with(false);
$h2->shouldReceive('send')->once()->with(false);
$headers = new Headers;
$headers->addHeader($h1)->addHeader($h2);
//$headers->addHeader($h1)->addHeader($h2); Daisychaining won't work because the name is the same on both headers.
$headers->addHeader($h1);
$headers->send();
$headers->addHeader($h2);
$headers->send();
M::close();
}

}
2 changes: 1 addition & 1 deletion tests/SecurityMultiTool/Http/HttpsDetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

use SecurityMultiTool\Http\HttpsDetector;

class HttpsDetectorTest extends \PHPUnit_Framework_TestCase
class HttpsDetectorTest extends PHPUnit\Framework\TestCase
{

public function setup()
Expand Down
2 changes: 1 addition & 1 deletion tests/SecurityMultiTool/Http/RedirectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

use SecurityMultiTool\Http\Redirector;

class RedirectorTest extends \PHPUnit_Framework_TestCase
class RedirectorTest extends PHPUnit\Framework\TestCase
{

protected $httpHost = null;
Expand Down
2 changes: 1 addition & 1 deletion tests/SecurityMultiTool/LoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @license http://github.com/padraic/SecurityMultiTool/blob/master/LICENSE New BSD License
*/

class SecurityMultiTool_LoaderTest extends PHPUnit_Framework_TestCase
class SecurityMultiTool_LoaderTest extends PHPUnit\Framework\TestCase
{

public function setUp()
Expand Down
6 changes: 4 additions & 2 deletions tests/SecurityMultiTool/Markdown/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use SecurityMultiTool\Markdown\Parser;
use Mockery as M;

class ParserTest extends \PHPUnit_Framework_TestCase
class ParserTest extends PHPUnit\Framework\TestCase
{

public $cache = '';
Expand All @@ -36,7 +36,7 @@ public function setup()

public function testParserCreationThrowsExceptionIfCacheDirectoryNotExists()
{
$this->setExpectedException('\SecurityMultiTool\Exception\RuntimeException');
$this->expectException('\SecurityMultiTool\Exception\RuntimeException');
$parser = new Parser('/does/not/exist');
}

Expand Down Expand Up @@ -75,6 +75,7 @@ public function testParsingCallsHtmlPurifier()
$sanitizer->shouldReceive('sanitize')->once()->with("<p>foo</p>\n", null);
$this->parser->setSanitizer($sanitizer);
$this->parser->parse('foo');
M::close();
}

public function testCanRestSanitizer()
Expand All @@ -83,6 +84,7 @@ public function testCanRestSanitizer()
$sanitizer->shouldReceive('reset')->once();
$this->parser->setSanitizer($sanitizer);
$this->parser->resetSanitizer();
M::close();
}

}
5 changes: 2 additions & 3 deletions tests/SecurityMultiTool/Random/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@

use SecurityMultiTool\Random\Generator;
use SecurityMultiTool\Random\Source;
use Mockery as M;

class GeneratorTest extends \PHPUnit_Framework_TestCase
class GeneratorTest extends PHPUnit\Framework\TestCase
{

public function setup()
Expand Down Expand Up @@ -105,7 +104,7 @@ public function testRandInteger($num, $valid, $cycles, $tot, $min, $max, $strong

public function testIntegerRangeFail()
{
$this->setExpectedException(
$this->expectException(
'\DomainException'
);
$rand = $this->rand->getInteger(100, 0);
Expand Down
6 changes: 3 additions & 3 deletions tests/SecurityMultiTool/String/FixedTimeComparisonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use SecurityMultiTool\String\FixedTimeComparison;
use SecurityMultiTool\Random\Generator;

class FixedTimeComparisonTest extends \PHPUnit_Framework_TestCase
class FixedTimeComparisonTest extends PHPUnit\Framework\TestCase
{

public function testCompareShouldReturnTrueOnMatchingStrings()
Expand Down Expand Up @@ -76,8 +76,8 @@ public function testCompareStringsWithFixedTime()
* factor of 100 (could use 512 but a 100 is enough to prove the fixed
* time comparison is working given we're using completely random bytes)
*/
$this->assertTrue(($t3-$t2) > ($t2-$t1));
$this->assertTrue(($t3-$t2) > (($t2-$t1)*100));
$this->assertTrue(round($t3-$t2) > round($t2-$t1));
$this->assertTrue(round($t3-$t2) > round(($t2-$t1)*100));
}

}