mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2024-10-01 01:26:10 -04:00
reviewed unit tests, fixing line endings, added more tests
This commit is contained in:
parent
7db76d8d71
commit
ad70051323
@ -48,7 +48,7 @@ abstract class persistence
|
|||||||
public static function getPath($filename = null)
|
public static function getPath($filename = null)
|
||||||
{
|
{
|
||||||
if(strlen($filename)) {
|
if(strlen($filename)) {
|
||||||
return self::$_path . '/' . $filename;
|
return self::$_path . DIRECTORY_SEPARATOR . $filename;
|
||||||
} else {
|
} else {
|
||||||
return self::$_path;
|
return self::$_path;
|
||||||
}
|
}
|
||||||
|
206
tst/RainTPL.php
206
tst/RainTPL.php
@ -1,103 +1,103 @@
|
|||||||
<?php
|
<?php
|
||||||
class RainTPLTest extends PHPUnit_Framework_TestCase
|
class RainTPLTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
private static $data = '{"iv":"EN39/wd5Nk8HAiSG2K5AsQ","salt":"QKN1DBXe5PI","ct":"8hA83xDdXjD7K2qfmw5NdA"}';
|
private static $data = '{"iv":"EN39/wd5Nk8HAiSG2K5AsQ","salt":"QKN1DBXe5PI","ct":"8hA83xDdXjD7K2qfmw5NdA"}';
|
||||||
|
|
||||||
private static $error = 'foo bar';
|
private static $error = 'foo bar';
|
||||||
|
|
||||||
private static $status = '!*#@?$+';
|
private static $status = '!*#@?$+';
|
||||||
|
|
||||||
private static $expire = array(
|
private static $expire = array(
|
||||||
'5min' => '5 minutes',
|
'5min' => '5 minutes',
|
||||||
'1hour' => '1 hour',
|
'1hour' => '1 hour',
|
||||||
'never' => 'Never',
|
'never' => 'Never',
|
||||||
);
|
);
|
||||||
|
|
||||||
private static $expire_default = '1hour';
|
private static $expire_default = '1hour';
|
||||||
|
|
||||||
private static $version = 'Version 1.2.3';
|
private static $version = 'Version 1.2.3';
|
||||||
|
|
||||||
private $_content;
|
private $_content;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
/* Setup Routine */
|
/* Setup Routine */
|
||||||
$page = new RainTPL;
|
$page = new RainTPL;
|
||||||
$page::configure(array('cache_dir' => 'tmp/'));
|
$page::configure(array('cache_dir' => 'tmp/'));
|
||||||
|
|
||||||
$page = new RainTPL;
|
$page = new RainTPL;
|
||||||
// We escape it here because ENT_NOQUOTES can't be used in RainTPL templates.
|
// We escape it here because ENT_NOQUOTES can't be used in RainTPL templates.
|
||||||
$page->assign('CIPHERDATA', htmlspecialchars(self::$data, ENT_NOQUOTES));
|
$page->assign('CIPHERDATA', htmlspecialchars(self::$data, ENT_NOQUOTES));
|
||||||
$page->assign('ERROR', self::$error);
|
$page->assign('ERROR', self::$error);
|
||||||
$page->assign('STATUS', self::$status);
|
$page->assign('STATUS', self::$status);
|
||||||
$page->assign('VERSION', self::$version);
|
$page->assign('VERSION', self::$version);
|
||||||
$page->assign('BURNAFTERREADINGSELECTED', false);
|
$page->assign('BURNAFTERREADINGSELECTED', false);
|
||||||
$page->assign('OPENDISCUSSION', false);
|
$page->assign('OPENDISCUSSION', false);
|
||||||
$page->assign('SYNTAXHIGHLIGHTING', true);
|
$page->assign('SYNTAXHIGHLIGHTING', true);
|
||||||
$page->assign('EXPIRE', self::$expire);
|
$page->assign('EXPIRE', self::$expire);
|
||||||
$page->assign('EXPIREDEFAULT', self::$expire_default);
|
$page->assign('EXPIREDEFAULT', self::$expire_default);
|
||||||
ob_start();
|
ob_start();
|
||||||
$page->draw('page');
|
$page->draw('page');
|
||||||
$this->_content = ob_get_contents();
|
$this->_content = ob_get_contents();
|
||||||
// run a second time from cache
|
// run a second time from cache
|
||||||
$page->cache('page');
|
$page->cache('page');
|
||||||
$page->draw('page');
|
$page->draw('page');
|
||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
public function tearDown()
|
||||||
{
|
{
|
||||||
/* Tear Down Routine */
|
/* Tear Down Routine */
|
||||||
helper::rmdir(PATH . 'tmp');
|
helper::rmdir(PATH . 'tmp');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTemplateRendersCorrectly()
|
public function testTemplateRendersCorrectly()
|
||||||
{
|
{
|
||||||
$this->assertTag(
|
$this->assertTag(
|
||||||
array(
|
array(
|
||||||
'id' => 'cipherdata',
|
'id' => 'cipherdata',
|
||||||
'content' => htmlspecialchars(self::$data, ENT_NOQUOTES)
|
'content' => htmlspecialchars(self::$data, ENT_NOQUOTES)
|
||||||
),
|
),
|
||||||
$this->_content,
|
$this->_content,
|
||||||
'outputs data correctly'
|
'outputs data correctly'
|
||||||
);
|
);
|
||||||
$this->assertTag(
|
$this->assertTag(
|
||||||
array(
|
array(
|
||||||
'id' => 'errormessage',
|
'id' => 'errormessage',
|
||||||
'content' => self::$error
|
'content' => self::$error
|
||||||
),
|
),
|
||||||
$this->_content,
|
$this->_content,
|
||||||
'outputs error correctly'
|
'outputs error correctly'
|
||||||
);
|
);
|
||||||
$this->assertTag(
|
$this->assertTag(
|
||||||
array(
|
array(
|
||||||
'id' => 'opendiscussion',
|
'id' => 'opendiscussion',
|
||||||
'attributes' => array(
|
'attributes' => array(
|
||||||
'disabled' => 'disabled'
|
'disabled' => 'disabled'
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
$this->_content,
|
$this->_content,
|
||||||
'disables discussions if configured'
|
'disables discussions if configured'
|
||||||
);
|
);
|
||||||
// testing version number in JS address, since other instances may not be present in different templates
|
// testing version number in JS address, since other instances may not be present in different templates
|
||||||
$this->assertTag(
|
$this->assertTag(
|
||||||
array(
|
array(
|
||||||
'tag' => 'script',
|
'tag' => 'script',
|
||||||
'attributes' => array(
|
'attributes' => array(
|
||||||
'src' => 'js/zerobin.js?' . rawurlencode(self::$version)
|
'src' => 'js/zerobin.js?' . rawurlencode(self::$version)
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
$this->_content,
|
$this->_content,
|
||||||
'outputs version correctly'
|
'outputs version correctly'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException RainTpl_Exception
|
* @expectedException RainTpl_Exception
|
||||||
*/
|
*/
|
||||||
public function testMissingTemplate()
|
public function testMissingTemplate()
|
||||||
{
|
{
|
||||||
$test = new RainTPL;
|
$test = new RainTPL;
|
||||||
$test->draw('123456789 does not exist!');
|
$test->draw('123456789 does not exist!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
16
tst/auto.php
16
tst/auto.php
@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
class autoTest extends PHPUnit_Framework_TestCase
|
class autoTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testAutoloaderReturnsFalseWhenCallingNonExistingClass()
|
public function testAutoloaderReturnsFalseWhenCallingNonExistingClass()
|
||||||
{
|
{
|
||||||
$this->assertFalse(auto::loader('foo2501bar42'), 'calling non existent class');
|
$this->assertFalse(auto::loader('foo2501bar42'), 'calling non existent class');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,47 +1,47 @@
|
|||||||
<?php
|
<?php
|
||||||
class filterTest extends PHPUnit_Framework_TestCase
|
class filterTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testFilterStripsSlashesDeeply()
|
public function testFilterStripsSlashesDeeply()
|
||||||
{
|
{
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array("f'oo", "b'ar", array("fo'o", "b'ar")),
|
array("f'oo", "b'ar", array("fo'o", "b'ar")),
|
||||||
filter::stripslashes_deep(array("f\\'oo", "b\\'ar", array("fo\\'o", "b\\'ar")))
|
filter::stripslashes_deep(array("f\\'oo", "b\\'ar", array("fo\\'o", "b\\'ar")))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFilterMakesSizesHumanlyReadable()
|
public function testFilterMakesSizesHumanlyReadable()
|
||||||
{
|
{
|
||||||
$this->assertEquals('1 B', filter::size_humanreadable(1));
|
$this->assertEquals('1 B', filter::size_humanreadable(1));
|
||||||
$this->assertEquals('1 000 B', filter::size_humanreadable(1000));
|
$this->assertEquals('1 000 B', filter::size_humanreadable(1000));
|
||||||
$this->assertEquals('1.00 kiB', filter::size_humanreadable(1024));
|
$this->assertEquals('1.00 kiB', filter::size_humanreadable(1024));
|
||||||
$this->assertEquals('1.21 kiB', filter::size_humanreadable(1234));
|
$this->assertEquals('1.21 kiB', filter::size_humanreadable(1234));
|
||||||
$exponent = 1024;
|
$exponent = 1024;
|
||||||
$this->assertEquals('1 000.00 kiB', filter::size_humanreadable(1000 * $exponent));
|
$this->assertEquals('1 000.00 kiB', filter::size_humanreadable(1000 * $exponent));
|
||||||
$this->assertEquals('1.00 MiB', filter::size_humanreadable(1024 * $exponent));
|
$this->assertEquals('1.00 MiB', filter::size_humanreadable(1024 * $exponent));
|
||||||
$this->assertEquals('1.21 MiB', filter::size_humanreadable(1234 * $exponent));
|
$this->assertEquals('1.21 MiB', filter::size_humanreadable(1234 * $exponent));
|
||||||
$exponent *= 1024;
|
$exponent *= 1024;
|
||||||
$this->assertEquals('1 000.00 MiB', filter::size_humanreadable(1000 * $exponent));
|
$this->assertEquals('1 000.00 MiB', filter::size_humanreadable(1000 * $exponent));
|
||||||
$this->assertEquals('1.00 GiB', filter::size_humanreadable(1024 * $exponent));
|
$this->assertEquals('1.00 GiB', filter::size_humanreadable(1024 * $exponent));
|
||||||
$this->assertEquals('1.21 GiB', filter::size_humanreadable(1234 * $exponent));
|
$this->assertEquals('1.21 GiB', filter::size_humanreadable(1234 * $exponent));
|
||||||
$exponent *= 1024;
|
$exponent *= 1024;
|
||||||
$this->assertEquals('1 000.00 GiB', filter::size_humanreadable(1000 * $exponent));
|
$this->assertEquals('1 000.00 GiB', filter::size_humanreadable(1000 * $exponent));
|
||||||
$this->assertEquals('1.00 TiB', filter::size_humanreadable(1024 * $exponent));
|
$this->assertEquals('1.00 TiB', filter::size_humanreadable(1024 * $exponent));
|
||||||
$this->assertEquals('1.21 TiB', filter::size_humanreadable(1234 * $exponent));
|
$this->assertEquals('1.21 TiB', filter::size_humanreadable(1234 * $exponent));
|
||||||
$exponent *= 1024;
|
$exponent *= 1024;
|
||||||
$this->assertEquals('1 000.00 TiB', filter::size_humanreadable(1000 * $exponent));
|
$this->assertEquals('1 000.00 TiB', filter::size_humanreadable(1000 * $exponent));
|
||||||
$this->assertEquals('1.00 PiB', filter::size_humanreadable(1024 * $exponent));
|
$this->assertEquals('1.00 PiB', filter::size_humanreadable(1024 * $exponent));
|
||||||
$this->assertEquals('1.21 PiB', filter::size_humanreadable(1234 * $exponent));
|
$this->assertEquals('1.21 PiB', filter::size_humanreadable(1234 * $exponent));
|
||||||
$exponent *= 1024;
|
$exponent *= 1024;
|
||||||
$this->assertEquals('1 000.00 PiB', filter::size_humanreadable(1000 * $exponent));
|
$this->assertEquals('1 000.00 PiB', filter::size_humanreadable(1000 * $exponent));
|
||||||
$this->assertEquals('1.00 EiB', filter::size_humanreadable(1024 * $exponent));
|
$this->assertEquals('1.00 EiB', filter::size_humanreadable(1024 * $exponent));
|
||||||
$this->assertEquals('1.21 EiB', filter::size_humanreadable(1234 * $exponent));
|
$this->assertEquals('1.21 EiB', filter::size_humanreadable(1234 * $exponent));
|
||||||
$exponent *= 1024;
|
$exponent *= 1024;
|
||||||
$this->assertEquals('1 000.00 EiB', filter::size_humanreadable(1000 * $exponent));
|
$this->assertEquals('1 000.00 EiB', filter::size_humanreadable(1000 * $exponent));
|
||||||
$this->assertEquals('1.00 ZiB', filter::size_humanreadable(1024 * $exponent));
|
$this->assertEquals('1.00 ZiB', filter::size_humanreadable(1024 * $exponent));
|
||||||
$this->assertEquals('1.21 ZiB', filter::size_humanreadable(1234 * $exponent));
|
$this->assertEquals('1.21 ZiB', filter::size_humanreadable(1234 * $exponent));
|
||||||
$exponent *= 1024;
|
$exponent *= 1024;
|
||||||
$this->assertEquals('1 000.00 ZiB', filter::size_humanreadable(1000 * $exponent));
|
$this->assertEquals('1 000.00 ZiB', filter::size_humanreadable(1000 * $exponent));
|
||||||
$this->assertEquals('1.00 YiB', filter::size_humanreadable(1024 * $exponent));
|
$this->assertEquals('1.00 YiB', filter::size_humanreadable(1024 * $exponent));
|
||||||
$this->assertEquals('1.21 YiB', filter::size_humanreadable(1234 * $exponent));
|
$this->assertEquals('1.21 YiB', filter::size_humanreadable(1234 * $exponent));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,4 +14,4 @@
|
|||||||
<log type="coverage-html" target="log/coverage-report" charset="UTF-8" yui="true" highlight="true" lowUpperBound="50" highLowerBound="80" />
|
<log type="coverage-html" target="log/coverage-report" charset="UTF-8" yui="true" highlight="true" lowUpperBound="50" highLowerBound="80" />
|
||||||
<log type="testdox-html" target="log/testdox.html" />
|
<log type="testdox-html" target="log/testdox.html" />
|
||||||
</logging>
|
</logging>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
42
tst/sjcl.php
42
tst/sjcl.php
@ -1,21 +1,21 @@
|
|||||||
<?php
|
<?php
|
||||||
class sjclTest extends PHPUnit_Framework_TestCase
|
class sjclTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testSjclValidatorValidatesCorrectly()
|
public function testSjclValidatorValidatesCorrectly()
|
||||||
{
|
{
|
||||||
$this->assertTrue(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"Gx1vA2/gQ3U","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'valid sjcl');
|
$this->assertTrue(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"Gx1vA2/gQ3U","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'valid sjcl');
|
||||||
$this->assertFalse(sjcl::isValid('{"iv":"$","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"Gx1vA2/gQ3U","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'invalid base64 encoding of iv');
|
$this->assertFalse(sjcl::isValid('{"iv":"$","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"Gx1vA2/gQ3U","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'invalid base64 encoding of iv');
|
||||||
$this->assertFalse(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"$","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'invalid base64 encoding of salt');
|
$this->assertFalse(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"$","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'invalid base64 encoding of salt');
|
||||||
$this->assertFalse(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","salt":"Gx1vA2/gQ3U","ct":"$"}'), 'invalid base64 encoding of ct');
|
$this->assertFalse(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","salt":"Gx1vA2/gQ3U","ct":"$"}'), 'invalid base64 encoding of ct');
|
||||||
$this->assertFalse(sjcl::isValid('{"iv":"MTIzNDU2Nzg5MDEyMzQ1Njc4OTA=","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"Gx1vA2/gQ3U","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'iv to long');
|
$this->assertFalse(sjcl::isValid('{"iv":"MTIzNDU2Nzg5MDEyMzQ1Njc4OTA=","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"Gx1vA2/gQ3U","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'iv to long');
|
||||||
$this->assertFalse(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"MTIzNDU2Nzg5MDEyMzQ1Njc4OTA=","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'salt to long');
|
$this->assertFalse(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"MTIzNDU2Nzg5MDEyMzQ1Njc4OTA=","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'salt to long');
|
||||||
$this->assertFalse(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"Gx1vA2/gQ3U","ct":"j7ImByuE5xCqD2YXm6aSyA","foo":"MTIzNDU2Nzg5MDEyMzQ1Njc4OTA="}'), 'invalid additional key');
|
$this->assertFalse(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"Gx1vA2/gQ3U","ct":"j7ImByuE5xCqD2YXm6aSyA","foo":"MTIzNDU2Nzg5MDEyMzQ1Njc4OTA="}'), 'invalid additional key');
|
||||||
$this->assertFalse(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","v":0.9,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"Gx1vA2/gQ3U","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'unsupported version');
|
$this->assertFalse(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","v":0.9,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"Gx1vA2/gQ3U","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'unsupported version');
|
||||||
$this->assertFalse(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","v":1,"iter":100,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"Gx1vA2/gQ3U","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'not enough iterations');
|
$this->assertFalse(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","v":1,"iter":100,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"Gx1vA2/gQ3U","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'not enough iterations');
|
||||||
$this->assertFalse(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","v":1,"iter":1000,"ks":127,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"Gx1vA2/gQ3U","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'invalid key size');
|
$this->assertFalse(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","v":1,"iter":1000,"ks":127,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"Gx1vA2/gQ3U","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'invalid key size');
|
||||||
$this->assertFalse(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","v":1,"iter":1000,"ks":128,"ts":63,"mode":"ccm","adata":"","cipher":"aes","salt":"Gx1vA2/gQ3U","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'invalid tag length');
|
$this->assertFalse(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","v":1,"iter":1000,"ks":128,"ts":63,"mode":"ccm","adata":"","cipher":"aes","salt":"Gx1vA2/gQ3U","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'invalid tag length');
|
||||||
$this->assertFalse(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","v":1,"iter":1000,"ks":128,"ts":64,"mode":"!#@","adata":"","cipher":"aes","salt":"Gx1vA2/gQ3U","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'invalid mode');
|
$this->assertFalse(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","v":1,"iter":1000,"ks":128,"ts":64,"mode":"!#@","adata":"","cipher":"aes","salt":"Gx1vA2/gQ3U","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'invalid mode');
|
||||||
$this->assertFalse(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"!#@","salt":"Gx1vA2/gQ3U","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'invalid cipher');
|
$this->assertFalse(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"!#@","salt":"Gx1vA2/gQ3U","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'invalid cipher');
|
||||||
// @note adata is not validated, except as part of the total message length
|
// @note adata is not validated, except as part of the total message length
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,30 +1,33 @@
|
|||||||
<?php
|
<?php
|
||||||
class trafficlimiterTest extends PHPUnit_Framework_TestCase
|
class trafficlimiterTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
private $_path;
|
private $_path;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
/* Setup Routine */
|
/* Setup Routine */
|
||||||
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'trafficlimit';
|
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'trafficlimit';
|
||||||
trafficlimiter::setPath($this->_path);
|
trafficlimiter::setPath($this->_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
public function tearDown()
|
||||||
{
|
{
|
||||||
/* Tear Down Routine */
|
/* Tear Down Routine */
|
||||||
helper::rmdir($this->_path . DIRECTORY_SEPARATOR);
|
helper::rmdir($this->_path . DIRECTORY_SEPARATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTrafficGetsLimited()
|
public function testTrafficGetsLimited()
|
||||||
{
|
{
|
||||||
trafficlimiter::setLimit(4);
|
$this->assertEquals($this->_path, trafficlimiter::getPath());
|
||||||
$this->assertTrue(trafficlimiter::canPass('127.0.0.1'), 'first request may pass');
|
$file = 'baz';
|
||||||
sleep(2);
|
$this->assertEquals($this->_path . DIRECTORY_SEPARATOR . $file, trafficlimiter::getPath($file));
|
||||||
$this->assertFalse(trafficlimiter::canPass('127.0.0.1'), 'second request is to fast, may not pass');
|
trafficlimiter::setLimit(4);
|
||||||
sleep(3);
|
$this->assertTrue(trafficlimiter::canPass('127.0.0.1'), 'first request may pass');
|
||||||
$this->assertTrue(trafficlimiter::canPass('127.0.0.1'), 'third request waited long enough and may pass');
|
sleep(2);
|
||||||
$this->assertTrue(trafficlimiter::canPass('2001:1620:2057:dead:beef::cafe:babe'), 'fourth request has different ip and may pass');
|
$this->assertFalse(trafficlimiter::canPass('127.0.0.1'), 'second request is to fast, may not pass');
|
||||||
$this->assertFalse(trafficlimiter::canPass('127.0.0.1'), 'fifth request is to fast, may not pass');
|
sleep(3);
|
||||||
}
|
$this->assertTrue(trafficlimiter::canPass('127.0.0.1'), 'third request waited long enough and may pass');
|
||||||
}
|
$this->assertTrue(trafficlimiter::canPass('2001:1620:2057:dead:beef::cafe:babe'), 'fourth request has different ip and may pass');
|
||||||
|
$this->assertFalse(trafficlimiter::canPass('127.0.0.1'), 'fifth request is to fast, may not pass');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,41 +1,41 @@
|
|||||||
<?php
|
<?php
|
||||||
class vizhash16x16Test extends PHPUnit_Framework_TestCase
|
class vizhash16x16Test extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
private $_dataDirCreated;
|
private $_dataDirCreated;
|
||||||
|
|
||||||
private $_file;
|
private $_file;
|
||||||
|
|
||||||
private $_path;
|
private $_path;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
/* Setup Routine */
|
/* Setup Routine */
|
||||||
$this->_path = PATH . 'data' . DIRECTORY_SEPARATOR;
|
$this->_path = PATH . 'data' . DIRECTORY_SEPARATOR;
|
||||||
$this->_dataDirCreated = !is_dir($this->_path);
|
$this->_dataDirCreated = !is_dir($this->_path);
|
||||||
if($this->_dataDirCreated) mkdir($this->_path);
|
if($this->_dataDirCreated) mkdir($this->_path);
|
||||||
$this->_file = $this->_path . 'vizhash.png';
|
$this->_file = $this->_path . 'vizhash.png';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
public function tearDown()
|
||||||
{
|
{
|
||||||
/* Tear Down Routine */
|
/* Tear Down Routine */
|
||||||
if($this->_dataDirCreated) {
|
if($this->_dataDirCreated) {
|
||||||
helper::rmdir($this->_path);
|
helper::rmdir($this->_path);
|
||||||
} else {
|
} else {
|
||||||
if(!@unlink($this->_file)) {
|
if(!@unlink($this->_file)) {
|
||||||
throw new Exception('Error deleting file "' . $this->_file . '".');
|
throw new Exception('Error deleting file "' . $this->_file . '".');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testVizhashGeneratesUniquePngsPerIp()
|
public function testVizhashGeneratesUniquePngsPerIp()
|
||||||
{
|
{
|
||||||
$vz = new vizhash16x16();
|
$vz = new vizhash16x16();
|
||||||
$pngdata = $vz->generate('127.0.0.1');
|
$pngdata = $vz->generate('127.0.0.1');
|
||||||
file_put_contents($this->_file, $pngdata);
|
file_put_contents($this->_file, $pngdata);
|
||||||
$finfo = new finfo(FILEINFO_MIME_TYPE);
|
$finfo = new finfo(FILEINFO_MIME_TYPE);
|
||||||
$this->assertEquals('image/png', $finfo->file($this->_file));
|
$this->assertEquals('image/png', $finfo->file($this->_file));
|
||||||
$this->assertNotEquals($pngdata, $vz->generate('2001:1620:2057:dead:beef::cafe:babe'));
|
$this->assertNotEquals($pngdata, $vz->generate('2001:1620:2057:dead:beef::cafe:babe'));
|
||||||
$this->assertEquals($pngdata, $vz->generate('127.0.0.1'));
|
$this->assertEquals($pngdata, $vz->generate('127.0.0.1'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,70 +1,70 @@
|
|||||||
<?php
|
<?php
|
||||||
class zerobin_dataTest extends PHPUnit_Framework_TestCase
|
class zerobin_dataTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
private static $pasteid = '501f02e9eeb8bcec';
|
private static $pasteid = '501f02e9eeb8bcec';
|
||||||
|
|
||||||
private static $paste = array(
|
private static $paste = array(
|
||||||
'data' => '{"iv":"EN39/wd5Nk8HAiSG2K5AsQ","salt":"QKN1DBXe5PI","ct":"8hA83xDdXjD7K2qfmw5NdA"}',
|
'data' => '{"iv":"EN39/wd5Nk8HAiSG2K5AsQ","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"QKN1DBXe5PI","ct":"8hA83xDdXjD7K2qfmw5NdA"}',
|
||||||
'meta' => array(
|
'meta' => array(
|
||||||
'postdate' => 1344803344,
|
'postdate' => 1344803344,
|
||||||
'expire_date' => 1344803644,
|
'expire_date' => 1344803644,
|
||||||
'opendiscussion' => true,
|
'opendiscussion' => true,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
private static $commentid = 'c47efb4741195f42';
|
private static $commentid = 'c47efb4741195f42';
|
||||||
|
|
||||||
private static $comment = array(
|
private static $comment = array(
|
||||||
'data' => '{"iv":"Pd4pOKWkmDTT9uPwVwd5Ag","salt":"ZIUhFTliVz4","ct":"6nOCU3peNDclDDpFtJEBKA"}',
|
'data' => '{"iv":"Pd4pOKWkmDTT9uPwVwd5Ag","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"6nOCU3peNDclDDpFtJEBKA"}',
|
||||||
'meta' => array(
|
'meta' => array(
|
||||||
'nickname' => '{"iv":"76MkAtOGC4oFogX/aSMxRA","salt":"ZIUhFTliVz4","ct":"b6Ae/U1xJdsX/+lATud4sQ"}',
|
'nickname' => '{"iv":"76MkAtOGC4oFogX/aSMxRA","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"b6Ae/U1xJdsX/+lATud4sQ"}',
|
||||||
'vizhash' => 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGUlEQVQokWOsl5/94983CNKQMjnxaOePf98MeKwPfNjkLZ3AgARab6b9+PeNEVnDj3/ff/z7ZiHnzsDA8Pv7H2TVPJw8EAYLAwb48OaVgIgYKycLsrYv378wMDB8//qdCVMDRA9EKSsnCwRBxNsepaLboMFlyMDAICAi9uHNK24GITQ/MDAwoNhgIGMLtwGrzegaLjw5jMz9+vUdnN17uwDCQDhJgk0O07yvX9+teDX1x79v6DYIsIjgcgMaYGFgYOBg4kJx2JejkAiBxAw+PzAwMNz4dp6wDXDw4MdNNOl0rWYsNkD89OLXI/xmo9sgzatJjAYmBgYGDiauD3/ePP18nVgb4MF89+M5ZX6js293wUMpnr8KTQMAxsCJnJ30apMAAAAASUVORK5CYII=',
|
'vizhash' => 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGUlEQVQokWOsl5/94983CNKQMjnxaOePf98MeKwPfNjkLZ3AgARab6b9+PeNEVnDj3/ff/z7ZiHnzsDA8Pv7H2TVPJw8EAYLAwb48OaVgIgYKycLsrYv378wMDB8//qdCVMDRA9EKSsnCwRBxNsepaLboMFlyMDAICAi9uHNK24GITQ/MDAwoNhgIGMLtwGrzegaLjw5jMz9+vUdnN17uwDCQDhJgk0O07yvX9+teDX1x79v6DYIsIjgcgMaYGFgYOBg4kJx2JejkAiBxAw+PzAwMNz4dp6wDXDw4MdNNOl0rWYsNkD89OLXI/xmo9sgzatJjAYmBgYGDiauD3/ePP18nVgb4MF89+M5ZX6js293wUMpnr8KTQMAxsCJnJ30apMAAAAASUVORK5CYII=',
|
||||||
'postdate' => 1344803528,
|
'postdate' => 1344803528,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
private $_model;
|
private $_model;
|
||||||
|
|
||||||
private $_path;
|
private $_path;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
/* Setup Routine */
|
/* Setup Routine */
|
||||||
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'zerobin_data';
|
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'zerobin_data';
|
||||||
$this->_model = zerobin_data::getInstance(array('dir' => $this->_path));
|
$this->_model = zerobin_data::getInstance(array('dir' => $this->_path));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
public function tearDown()
|
||||||
{
|
{
|
||||||
/* Tear Down Routine */
|
/* Tear Down Routine */
|
||||||
helper::rmdir($this->_path);
|
helper::rmdir($this->_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFileBasedDataStoreWorks()
|
public function testFileBasedDataStoreWorks()
|
||||||
{
|
{
|
||||||
// storing pastes
|
// storing pastes
|
||||||
$this->assertFalse($this->_model->exists(self::$pasteid), 'paste does not yet exist');
|
$this->assertFalse($this->_model->exists(self::$pasteid), 'paste does not yet exist');
|
||||||
$this->assertTrue($this->_model->create(self::$pasteid, self::$paste), 'store new paste');
|
$this->assertTrue($this->_model->create(self::$pasteid, self::$paste), 'store new paste');
|
||||||
$this->assertTrue($this->_model->exists(self::$pasteid), 'paste exists after storing it');
|
$this->assertTrue($this->_model->exists(self::$pasteid), 'paste exists after storing it');
|
||||||
$this->assertFalse($this->_model->create(self::$pasteid, self::$paste), 'unable to store the same paste twice');
|
$this->assertFalse($this->_model->create(self::$pasteid, self::$paste), 'unable to store the same paste twice');
|
||||||
$this->assertEquals(json_decode(json_encode(self::$paste)), $this->_model->read(self::$pasteid));
|
$this->assertEquals(json_decode(json_encode(self::$paste)), $this->_model->read(self::$pasteid));
|
||||||
|
|
||||||
// storing comments
|
// storing comments
|
||||||
$this->assertFalse($this->_model->existsComment(self::$pasteid, self::$pasteid, self::$commentid), 'comment does not yet exist');
|
$this->assertFalse($this->_model->existsComment(self::$pasteid, self::$pasteid, self::$commentid), 'comment does not yet exist');
|
||||||
$this->assertTrue($this->_model->createComment(self::$pasteid, self::$pasteid, self::$commentid, self::$comment) !== false, 'store comment');
|
$this->assertTrue($this->_model->createComment(self::$pasteid, self::$pasteid, self::$commentid, self::$comment) !== false, 'store comment');
|
||||||
$this->assertTrue($this->_model->existsComment(self::$pasteid, self::$pasteid, self::$commentid), 'comment exists after storing it');
|
$this->assertTrue($this->_model->existsComment(self::$pasteid, self::$pasteid, self::$commentid), 'comment exists after storing it');
|
||||||
$comment = json_decode(json_encode(self::$comment));
|
$comment = json_decode(json_encode(self::$comment));
|
||||||
$comment->meta->commentid = self::$commentid;
|
$comment->meta->commentid = self::$commentid;
|
||||||
$comment->meta->parentid = self::$pasteid;
|
$comment->meta->parentid = self::$pasteid;
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array($comment->meta->postdate => $comment),
|
array($comment->meta->postdate => $comment),
|
||||||
$this->_model->readComments(self::$pasteid)
|
$this->_model->readComments(self::$pasteid)
|
||||||
);
|
);
|
||||||
|
|
||||||
// deleting pastes
|
// deleting pastes
|
||||||
$this->_model->delete(self::$pasteid);
|
$this->_model->delete(self::$pasteid);
|
||||||
$this->assertFalse($this->_model->exists(self::$pasteid), 'paste successfully deleted');
|
$this->assertFalse($this->_model->exists(self::$pasteid), 'paste successfully deleted');
|
||||||
$this->assertFalse($this->_model->existsComment(self::$pasteid, self::$pasteid, self::$commentid), 'comment was deleted with paste');
|
$this->assertFalse($this->_model->existsComment(self::$pasteid, self::$pasteid, self::$commentid), 'comment was deleted with paste');
|
||||||
$this->assertFalse($this->_model->read(self::$pasteid), 'paste can no longer be found');
|
$this->assertFalse($this->_model->read(self::$pasteid), 'paste can no longer be found');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ class zerobin_dbTest extends PHPUnit_Framework_TestCase
|
|||||||
private static $pasteid = '501f02e9eeb8bcec';
|
private static $pasteid = '501f02e9eeb8bcec';
|
||||||
|
|
||||||
private static $paste = array(
|
private static $paste = array(
|
||||||
'data' => '{"iv":"EN39/wd5Nk8HAiSG2K5AsQ","salt":"QKN1DBXe5PI","ct":"8hA83xDdXjD7K2qfmw5NdA"}',
|
'data' => '{"iv":"EN39/wd5Nk8HAiSG2K5AsQ","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"QKN1DBXe5PI","ct":"8hA83xDdXjD7K2qfmw5NdA"}',
|
||||||
'meta' => array(
|
'meta' => array(
|
||||||
'postdate' => 1344803344,
|
'postdate' => 1344803344,
|
||||||
'expire_date' => 1344803644,
|
'expire_date' => 1344803644,
|
||||||
@ -15,9 +15,9 @@ class zerobin_dbTest extends PHPUnit_Framework_TestCase
|
|||||||
private static $commentid = 'c47efb4741195f42';
|
private static $commentid = 'c47efb4741195f42';
|
||||||
|
|
||||||
private static $comment = array(
|
private static $comment = array(
|
||||||
'data' => '{"iv":"Pd4pOKWkmDTT9uPwVwd5Ag","salt":"ZIUhFTliVz4","ct":"6nOCU3peNDclDDpFtJEBKA"}',
|
'data' => '{"iv":"Pd4pOKWkmDTT9uPwVwd5Ag","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"6nOCU3peNDclDDpFtJEBKA"}',
|
||||||
'meta' => array(
|
'meta' => array(
|
||||||
'nickname' => '{"iv":"76MkAtOGC4oFogX/aSMxRA","salt":"ZIUhFTliVz4","ct":"b6Ae/U1xJdsX/+lATud4sQ"}',
|
'nickname' => '{"iv":"76MkAtOGC4oFogX/aSMxRA","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"b6Ae/U1xJdsX/+lATud4sQ"}',
|
||||||
'vizhash' => 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGUlEQVQokWOsl5/94983CNKQMjnxaOePf98MeKwPfNjkLZ3AgARab6b9+PeNEVnDj3/ff/z7ZiHnzsDA8Pv7H2TVPJw8EAYLAwb48OaVgIgYKycLsrYv378wMDB8//qdCVMDRA9EKSsnCwRBxNsepaLboMFlyMDAICAi9uHNK24GITQ/MDAwoNhgIGMLtwGrzegaLjw5jMz9+vUdnN17uwDCQDhJgk0O07yvX9+teDX1x79v6DYIsIjgcgMaYGFgYOBg4kJx2JejkAiBxAw+PzAwMNz4dp6wDXDw4MdNNOl0rWYsNkD89OLXI/xmo9sgzatJjAYmBgYGDiauD3/ePP18nVgb4MF89+M5ZX6js293wUMpnr8KTQMAxsCJnJ30apMAAAAASUVORK5CYII=',
|
'vizhash' => 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGUlEQVQokWOsl5/94983CNKQMjnxaOePf98MeKwPfNjkLZ3AgARab6b9+PeNEVnDj3/ff/z7ZiHnzsDA8Pv7H2TVPJw8EAYLAwb48OaVgIgYKycLsrYv378wMDB8//qdCVMDRA9EKSsnCwRBxNsepaLboMFlyMDAICAi9uHNK24GITQ/MDAwoNhgIGMLtwGrzegaLjw5jMz9+vUdnN17uwDCQDhJgk0O07yvX9+teDX1x79v6DYIsIjgcgMaYGFgYOBg4kJx2JejkAiBxAw+PzAwMNz4dp6wDXDw4MdNNOl0rWYsNkD89OLXI/xmo9sgzatJjAYmBgYGDiauD3/ePP18nVgb4MF89+M5ZX6js293wUMpnr8KTQMAxsCJnJ30apMAAAAASUVORK5CYII=',
|
||||||
'postdate' => 1344803528,
|
'postdate' => 1344803528,
|
||||||
),
|
),
|
||||||
|
Loading…
Reference in New Issue
Block a user