cleaned up CSS, changed template to output clean XHTML 5, added unit tests for 60% of the code, found a few bugs by doing that and fixed thempull/17/head
parent
f37303d858
commit
907538875b
@ -1,6 +1,7 @@
|
|||||||
# Ignore data/ and tmp/
|
# Ignore data/ and tmp/
|
||||||
data/
|
data/
|
||||||
tmp/
|
tmp/
|
||||||
|
tst/log/
|
||||||
.settings/
|
.settings/
|
||||||
.buildpath
|
.buildpath
|
||||||
.project
|
.project
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
[submodule "uglifyjs"]
|
|
||||||
path = uglifyjs
|
|
||||||
url = https://github.com/mishoo/UglifyJS.git
|
|
@ -0,0 +1,8 @@
|
|||||||
|
Credits
|
||||||
|
=======
|
||||||
|
Sébastien Sauvage - original idea and main developer
|
||||||
|
|
||||||
|
Alexey Gladkov - syntax highlighting
|
||||||
|
Greg Knaddison - robots.txt
|
||||||
|
MrKooky - XHTML5 markup, CSS cleanup
|
||||||
|
Simon Rupf - MVC refactoring, configuration support and unit tests
|
Before Width: | Height: | Size: 391 B After Width: | Height: | Size: 381 B |
@ -1,39 +0,0 @@
|
|||||||
#!/bin/sh -eu
|
|
||||||
|
|
||||||
myname="$(readlink -ev "$0")"
|
|
||||||
compiler='uglifyjs/bin/uglifyjs'
|
|
||||||
|
|
||||||
SOURCES='cfg css img lib tpl index.php'
|
|
||||||
JSDIR='js'
|
|
||||||
|
|
||||||
if [ "$#" -eq 0 ]; then
|
|
||||||
printf 'Usage: %s <destdir>\n' "${0##*/}"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
destdir="$1"
|
|
||||||
shift
|
|
||||||
|
|
||||||
if [ ! -d "$destdir" ]; then
|
|
||||||
printf 'Error: %s: Not directory\n' "$destdir"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
destdir="$(readlink -ev "$destdir")"
|
|
||||||
|
|
||||||
cd "${myname%/*}"
|
|
||||||
cp -aurt "$destdir" -- $SOURCES
|
|
||||||
|
|
||||||
mkdir -p -- "$destdir/js"
|
|
||||||
for src in "$JSDIR"/*.js; do
|
|
||||||
[ -f "$src" ] ||
|
|
||||||
continue
|
|
||||||
printf 'Processing %s ... ' "$src"
|
|
||||||
|
|
||||||
rc='done'
|
|
||||||
$compiler -nc -c -o "$destdir/js/${src##*/}" "$src" || rc='fail'
|
|
||||||
|
|
||||||
printf '%s\n' "$rc"
|
|
||||||
|
|
||||||
[ "$rc" = 'done' ] ||
|
|
||||||
exit 1
|
|
||||||
done
|
|
@ -1,88 +1,96 @@
|
|||||||
<html>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<head>
|
<!DOCTYPE html>
|
||||||
<title>ZeroBin</title>
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||||
<link type="text/css" rel="stylesheet" href="css/zerobin.css?{$VERSION|rawurlencode}#" />
|
<head>
|
||||||
<link type="text/css" rel="stylesheet" href="css/prettify.css?{$VERSION|rawurlencode}#" />
|
<meta charset="utf-8" />
|
||||||
<script src="js/jquery.js#"></script>
|
<title>ZeroBin</title>
|
||||||
<script src="js/sjcl.js#"></script>
|
<link type="text/css" rel="stylesheet" href="css/zerobin.css?{$VERSION|rawurlencode}#" />
|
||||||
<script src="js/base64.js#"></script>
|
<link type="text/css" rel="stylesheet" href="css/prettify.css?{$VERSION|rawurlencode}#" />
|
||||||
<script src="js/rawdeflate.js#"></script>
|
<script src="js/jquery.js#"></script>
|
||||||
<script src="js/rawinflate.js#"></script>
|
<script src="js/sjcl.js#"></script>
|
||||||
<script src="js/prettify.js#"></script>
|
<script src="js/base64.js#"></script>
|
||||||
<script src="js/zerobin.js?{$VERSION|rawurlencode}#"></script>
|
<script src="js/rawdeflate.js#"></script>
|
||||||
|
<script src="js/rawinflate.js#"></script>
|
||||||
<!--[if lt IE 10]>
|
<script src="js/prettify.js#"></script>
|
||||||
<style> body {padding-left:60px;padding-right:60px;} div#ienotice {display:block;} </style>
|
<script src="js/zerobin.js?{$VERSION|rawurlencode}#"></script>
|
||||||
<![endif]-->
|
<!--[if lt IE 10]>
|
||||||
|
<style> body {padding-left:60px;padding-right:60px;} div#ienotice {display:block;} </style>
|
||||||
<!--[if lt IE 10]>
|
<![endif]-->
|
||||||
<style> div#ienotice {display:block; } div#oldienotice {display:block; } </style>
|
<!--[if lt IE 10]>
|
||||||
<![endif]-->
|
<style> div#ienotice {display:block; } div#oldienotice {display:block; } </style>
|
||||||
|
<![endif]-->
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="aboutbox">
|
<header>
|
||||||
ZeroBin is a minimalist, opensource online pastebin where the server has zero knowledge of pasted data.
|
<div id="aboutbox">
|
||||||
Data is encrypted/decrypted <i>in the browser</i> using 256 bits AES.
|
ZeroBin is a minimalist, opensource online pastebin where the server has zero knowledge of pasted data.
|
||||||
More information on the <a href="http://sebsauvage.net/wiki/doku.php?id=php:zerobin">project page</a>.<br />
|
Data is encrypted/decrypted <i>in the browser</i> using 256 bits AES.
|
||||||
<span style="text-decoration:blink;font-size:10pt;color:#a4b3c4;">▶</span> Note: This is a test service:
|
More information on the <a href="http://sebsauvage.net/wiki/doku.php?id=php:zerobin">project page</a>.<br />
|
||||||
Data may be deleted anytime. Kittens will die if you abuse this service.
|
<span class="blink">▶</span> Note: This is a test service:
|
||||||
</div>
|
Data may be deleted anytime. Kittens will die if you abuse this service.
|
||||||
<h1 title="ZeroBin" onclick="window.location.href=scriptLocation();return false;">ZeroBin</h1><br>
|
</div>
|
||||||
<h2>Because ignorance is bliss</h2><br>
|
<h1 title="ZeroBin" onclick="window.location.href=scriptLocation();return false;">ZeroBin</h1><br />
|
||||||
<h3>{$VERSION}</h3>
|
<h2>Because ignorance is bliss</h2><br />
|
||||||
<noscript><div class="nonworking">Javascript is required for ZeroBin to work.<br>Sorry for the inconvenience.</div></noscript>
|
<h3>{$VERSION}</h3>
|
||||||
<div id="oldienotice" class="nonworking">ZeroBin requires a modern browser to work.</div>
|
<div id="noscript" class="nonworking">Javascript is required for ZeroBin to work.<br />Sorry for the inconvenience.</div>
|
||||||
<div id="ienotice">Still using Internet Explorer ? Do yourself a favor, switch to a modern browser:
|
<div id="oldienotice" class="nonworking">ZeroBin requires a modern browser to work.</div>
|
||||||
<a href="http://www.mozilla.org/firefox/">Firefox</a>,
|
<div id="ienotice">Still using Internet Explorer ? Do yourself a favor, switch to a modern browser:
|
||||||
<a href="http://www.opera.com/">Opera</a>,
|
<a href="http://www.mozilla.org/firefox/">Firefox</a>,
|
||||||
<a href="http://www.google.com/chrome">Chrome</a>,
|
<a href="http://www.opera.com/">Opera</a>,
|
||||||
<a href="http://www.apple.com/safari">Safari</a>...
|
<a href="http://www.google.com/chrome">Chrome</a>,
|
||||||
</div>
|
<a href="http://www.apple.com/safari">Safari</a>...
|
||||||
<div id="status"> </div>
|
</div>
|
||||||
<div id="errormessage" style="display:none">{$ERRORMESSAGE|htmlspecialchars}</div>
|
</header>
|
||||||
<div id="toolbar">
|
<section>
|
||||||
<button id="newbutton" onclick="window.location.href=scriptLocation();return false;" style="display:none;"><img src="img/icon_new.png#" width="11" height="15" />New</button>
|
<article>
|
||||||
<button id="sendbutton" onclick="send_data();return false;" style="display:none;"><img src="img/icon_send.png#" width="18" height="15" />Send</button>
|
<div id="status"> </div>
|
||||||
<button id="clonebutton" onclick="clonePaste();return false;" style="display:none;"><img src="img/icon_clone.png#" width="15" height="17" />Clone</button>
|
<div id="errormessage" class="hidden">{$ERRORMESSAGE|htmlspecialchars}</div>
|
||||||
<div id="expiration" style="display:none;">Expire:
|
<div id="toolbar">
|
||||||
<select id="pasteExpiration" name="pasteExpiration">
|
<button id="newbutton" onclick="window.location.href=scriptLocation();return false;" class="hidden"><img src="img/icon_new.png#" width="11" height="15" />New</button>
|
||||||
<option value="burn">Burn after reading</option>
|
<button id="sendbutton" onclick="send_data();return false;" class="hidden"><img src="img/icon_send.png#" width="18" height="15" />Send</button>
|
||||||
<option value="5min">5 minutes</option>
|
<button id="clonebutton" onclick="clonePaste();return false;" class="hidden"><img src="img/icon_clone.png#" width="15" height="17" />Clone</button>
|
||||||
<option value="10min">10 minutes</option>
|
<div id="expiration" class="hidden">Expire:
|
||||||
<option value="1hour">1 hour</option>
|
<select id="pasteExpiration" name="pasteExpiration">
|
||||||
<option value="1day">1 day</option>
|
<option value="burn">Burn after reading</option>
|
||||||
<option value="1week">1 week</option>
|
<option value="5min">5 minutes</option>
|
||||||
<option value="1month" selected="selected">1 month</option>
|
<option value="10min">10 minutes</option>
|
||||||
<option value="1year">1 year</option>
|
<option value="1hour">1 hour</option>
|
||||||
<option value="never">Never</option>
|
<option value="1day">1 day</option>
|
||||||
</select>
|
<option value="1week">1 week</option>
|
||||||
</div>
|
<option value="1month" selected="selected">1 month</option>
|
||||||
<div id="remainingtime" style="display:none;"></div>
|
<option value="1year">1 year</option>
|
||||||
<div id="language" style="display:none;">
|
<option value="never">Never</option>
|
||||||
<select name="language">
|
</select>
|
||||||
<option value="language" selected="selected">Language</option>
|
</div>
|
||||||
<option value="C/C++">C/C++</option>
|
<div id="remainingtime" class="hidden"></div>
|
||||||
<option value="php">php</option>
|
<div id="language" class="hidden">
|
||||||
<option value="python">Python</option>
|
<select name="language">
|
||||||
</select>
|
<option value="language" selected="selected">Language</option>
|
||||||
</div>
|
<option value="C/C++">C/C++</option>
|
||||||
<input id="password" value="Optional password..." style="display:none;" />
|
<option value="php">php</option>
|
||||||
<div id="opendisc" class="button" style="display:none;">
|
<option value="python">Python</option>
|
||||||
<input type="checkbox" id="opendiscussion" name="opendiscussion" {if="!$OPENDISCUSSION"} disabled="disabled"{/if} />
|
</select>
|
||||||
<label for="opendiscussion">Open discussion</label>
|
</div>
|
||||||
</div>
|
<input id="password" value="Optional password..." class="hidden" />
|
||||||
</div>
|
<div id="opendisc" class="button" class="hidden">
|
||||||
<div id="pastelink" style="display:none;"></div>
|
<input type="checkbox" id="opendiscussion" name="opendiscussion" {if="!$OPENDISCUSSION"} disabled="disabled"{/if} />
|
||||||
<div id="prettymessage" style="display:none;">
|
<label for="opendiscussion">Open discussion</label>
|
||||||
<pre id="prettyprint" class="prettyprint linenums:1"></pre>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="cleartext" style="display:none;"></div>
|
<div id="pastelink" class="hidden"></div>
|
||||||
<textarea id="message" name="message" cols="80" rows="25" style="display:none;"></textarea>
|
<div id="prettymessage" class="hidden">
|
||||||
<div id="discussion" style="display:none;">
|
<div id="prettyprint" class="prettyprint linenums:1"></div>
|
||||||
<h4>Discussion</h4>
|
</div>
|
||||||
<div id="comments"></div>
|
<div id="cleartext" class="hidden"></div>
|
||||||
</div>
|
<textarea id="message" name="message" cols="80" rows="25" class="hidden"></textarea>
|
||||||
<div id="cipherdata" style="display:none;">{$CIPHERDATA}</div>
|
</article>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<div id="discussion" class="hidden">
|
||||||
|
<h4>Discussion</h4>
|
||||||
|
<div id="comments"></div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<div id="cipherdata" class="hidden">{$CIPHERDATA}</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
Running unit tests
|
||||||
|
==================
|
||||||
|
|
||||||
|
In order to run these tests, you will need to install the following packages
|
||||||
|
and its dependencies:
|
||||||
|
* phpunit
|
||||||
|
* php5-gd
|
||||||
|
* php5-sqlite
|
||||||
|
* php5-xdebug
|
||||||
|
|
||||||
|
Example for Debian and Ubuntu:
|
||||||
|
$ sudo aptitude install phpunit php5-mysql php5-xdebug
|
||||||
|
|
||||||
|
To run the tests, just change into this directory and run phpunit:
|
||||||
|
$ cd ZeroBin/tst
|
||||||
|
$ phpunit
|
@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
class RainTPLTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
private static $data = '{"iv":"EN39/wd5Nk8HAiSG2K5AsQ","salt":"QKN1DBXe5PI","ct":"8hA83xDdXjD7K2qfmw5NdA"}';
|
||||||
|
|
||||||
|
private static $error = 'foo bar';
|
||||||
|
|
||||||
|
private static $version = 'Version 1.2.3';
|
||||||
|
|
||||||
|
private $_content;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
/* Setup Routine */
|
||||||
|
$page = new RainTPL;
|
||||||
|
$page::configure(array('cache_dir' => 'tmp/'));
|
||||||
|
// We escape it here because ENT_NOQUOTES can't be used in RainTPL templates.
|
||||||
|
$page->assign('CIPHERDATA', htmlspecialchars(self::$data, ENT_NOQUOTES));
|
||||||
|
$page->assign('ERRORMESSAGE', self::$error);
|
||||||
|
$page->assign('OPENDISCUSSION', false);
|
||||||
|
$page->assign('VERSION', self::$version);
|
||||||
|
ob_start();
|
||||||
|
$page->draw('page');
|
||||||
|
$this->_content = ob_get_contents();
|
||||||
|
// run a second time from cache
|
||||||
|
$page->cache('page');
|
||||||
|
$page->draw('page');
|
||||||
|
ob_end_clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tearDown()
|
||||||
|
{
|
||||||
|
/* Tear Down Routine */
|
||||||
|
helper::rmdir(PATH . 'tmp');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testTemplateRendersCorrectly()
|
||||||
|
{
|
||||||
|
$this->assertTag(
|
||||||
|
array(
|
||||||
|
'id' => 'cipherdata',
|
||||||
|
'content' => htmlspecialchars(self::$data, ENT_NOQUOTES)
|
||||||
|
),
|
||||||
|
$this->_content,
|
||||||
|
'outputs data correctly'
|
||||||
|
);
|
||||||
|
$this->assertTag(
|
||||||
|
array(
|
||||||
|
'id' => 'errormessage',
|
||||||
|
'content' => self::$error
|
||||||
|
),
|
||||||
|
$this->_content,
|
||||||
|
'outputs error correctly'
|
||||||
|
);
|
||||||
|
$this->assertTag(
|
||||||
|
array(
|
||||||
|
'id' => 'opendiscussion',
|
||||||
|
'attributes' => array(
|
||||||
|
'disabled' => 'disabled'
|
||||||
|
),
|
||||||
|
),
|
||||||
|
$this->_content,
|
||||||
|
'disables discussions if configured'
|
||||||
|
);
|
||||||
|
// testing version number in JS address, since other instances may not be present in different templates
|
||||||
|
$this->assertTag(
|
||||||
|
array(
|
||||||
|
'tag' => 'script',
|
||||||
|
'attributes' => array(
|
||||||
|
'src' => 'js/zerobin.js?' . rawurlencode(self::$version)
|
||||||
|
),
|
||||||
|
),
|
||||||
|
$this->_content,
|
||||||
|
'outputs version correctly'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
class autoTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function testAutoloaderReturnsFalseWhenCallingNonExistingClass()
|
||||||
|
{
|
||||||
|
$this->assertFalse(auto::loader('foo2501bar42'), 'calling non existent class');
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
error_reporting( E_ALL | E_STRICT );
|
||||||
|
|
||||||
|
// change this, if your php files and data is outside of your webservers document root
|
||||||
|
define('PATH', '..' . DIRECTORY_SEPARATOR);
|
||||||
|
|
||||||
|
require PATH . 'lib/auto.php';
|
||||||
|
|
||||||
|
class helper
|
||||||
|
{
|
||||||
|
public static function rmdir($path)
|
||||||
|
{
|
||||||
|
$path .= DIRECTORY_SEPARATOR;
|
||||||
|
$dir = dir($path);
|
||||||
|
while(false !== ($file = $dir->read())) {
|
||||||
|
if($file != '.' && $file != '..') {
|
||||||
|
if(is_dir($path . $file)) {
|
||||||
|
self::rmdir($path . $file);
|
||||||
|
} elseif(is_file($path . $file)) {
|
||||||
|
if(!@unlink($path . $file)) {
|
||||||
|
throw new Exception('Error deleting file "' . $path . $file . '".');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$dir->close();
|
||||||
|
if(!@rmdir($path)) {
|
||||||
|
throw new Exception('Error deleting directory "' . $path . '".');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
class filterTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function testFilterStripsSlashesDeeply()
|
||||||
|
{
|
||||||
|
$this->assertEquals(
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
$this->assertEquals('1 B', filter::size_humanreadable(1));
|
||||||
|
$this->assertEquals('1 000 B', filter::size_humanreadable(1000));
|
||||||
|
$this->assertEquals('1.00 kiB', filter::size_humanreadable(1024));
|
||||||
|
$this->assertEquals('1.21 kiB', filter::size_humanreadable(1234));
|
||||||
|
$exponent = 1024;
|
||||||
|
$this->assertEquals('1 000.00 kiB', filter::size_humanreadable(1000 * $exponent));
|
||||||
|
$this->assertEquals('1.00 MiB', filter::size_humanreadable(1024 * $exponent));
|
||||||
|
$this->assertEquals('1.21 MiB', filter::size_humanreadable(1234 * $exponent));
|
||||||
|
$exponent *= 1024;
|
||||||
|
$this->assertEquals('1 000.00 MiB', filter::size_humanreadable(1000 * $exponent));
|
||||||
|
$this->assertEquals('1.00 GiB', filter::size_humanreadable(1024 * $exponent));
|
||||||
|
$this->assertEquals('1.21 GiB', filter::size_humanreadable(1234 * $exponent));
|
||||||
|
$exponent *= 1024;
|
||||||
|
$this->assertEquals('1 000.00 GiB', filter::size_humanreadable(1000 * $exponent));
|
||||||
|
$this->assertEquals('1.00 TiB', filter::size_humanreadable(1024 * $exponent));
|
||||||
|
$this->assertEquals('1.21 TiB', filter::size_humanreadable(1234 * $exponent));
|
||||||
|
$exponent *= 1024;
|
||||||
|
$this->assertEquals('1 000.00 TiB', filter::size_humanreadable(1000 * $exponent));
|
||||||
|
$this->assertEquals('1.00 PiB', filter::size_humanreadable(1024 * $exponent));
|
||||||
|
$this->assertEquals('1.21 PiB', filter::size_humanreadable(1234 * $exponent));
|
||||||
|
$exponent *= 1024;
|
||||||
|
$this->assertEquals('1 000.00 PiB', filter::size_humanreadable(1000 * $exponent));
|
||||||
|
$this->assertEquals('1.00 EiB', filter::size_humanreadable(1024 * $exponent));
|
||||||
|
$this->assertEquals('1.21 EiB', filter::size_humanreadable(1234 * $exponent));
|
||||||
|
$exponent *= 1024;
|
||||||
|
$this->assertEquals('1 000.00 EiB', filter::size_humanreadable(1000 * $exponent));
|
||||||
|
$this->assertEquals('1.00 ZiB', filter::size_humanreadable(1024 * $exponent));
|
||||||
|
$this->assertEquals('1.21 ZiB', filter::size_humanreadable(1234 * $exponent));
|
||||||
|
$exponent *= 1024;
|
||||||
|
$this->assertEquals('1 000.00 ZiB', filter::size_humanreadable(1000 * $exponent));
|
||||||
|
$this->assertEquals('1.00 YiB', filter::size_humanreadable(1024 * $exponent));
|
||||||
|
$this->assertEquals('1.21 YiB', filter::size_humanreadable(1234 * $exponent));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
<phpunit bootstrap="bootstrap.php" colors="true">
|
||||||
|
<testsuite name="ZeroBin Test Suite">
|
||||||
|
<directory suffix=".php">./</directory>
|
||||||
|
</testsuite>
|
||||||
|
<filter>
|
||||||
|
<whitelist>
|
||||||
|
<directory suffix=".php">../lib</directory>
|
||||||
|
<exclude>
|
||||||
|
<file>../lib/zerobin/abstract.php</file>
|
||||||
|
</exclude>
|
||||||
|
</whitelist>
|
||||||
|
</filter>
|
||||||
|
<logging>
|
||||||
|
<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" />
|
||||||
|
</logging>
|
||||||
|
</phpunit>
|
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
class sjclTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function testSjclValidatorValidatesCorrectly()
|
||||||
|
{
|
||||||
|
$this->assertTrue(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","salt":"Gx1vA2/gQ3U","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'valid sjcl');
|
||||||
|
$this->assertFalse(sjcl::isValid('{"iv":"$","salt":"Gx1vA2/gQ3U","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'invalid base64 encoding of iv');
|
||||||
|
$this->assertFalse(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","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":"MTIzNDU2Nzg5MDEyMzQ1Njc4OTA=","salt":"Gx1vA2/gQ3U","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'iv to long');
|
||||||
|
$this->assertFalse(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","salt":"MTIzNDU2Nzg5MDEyMzQ1Njc4OTA=","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'salt to long');
|
||||||
|
$this->assertFalse(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","salt":"Gx1vA2/gQ3U","ct":"j7ImByuE5xCqD2YXm6aSyA","foo":"MTIzNDU2Nzg5MDEyMzQ1Njc4OTA="}'), 'invalid additional key');
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
class trafficlimiterTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
private $_path;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
/* Setup Routine */
|
||||||
|
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'trafficlimit' . DIRECTORY_SEPARATOR;
|
||||||
|
trafficlimiter::setPath($this->_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tearDown()
|
||||||
|
{
|
||||||
|
/* Tear Down Routine */
|
||||||
|
helper::rmdir($this->_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testTrafficGetsLimited()
|
||||||
|
{
|
||||||
|
trafficlimiter::setLimit(4);
|
||||||
|
$this->assertTrue(trafficlimiter::canPass('127.0.0.1'), 'first request may pass');
|
||||||
|
sleep(2);
|
||||||
|
$this->assertFalse(trafficlimiter::canPass('127.0.0.1'), 'second 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');
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
class vizhash16x16Test extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
private $_dataDirCreated;
|
||||||
|
|
||||||
|
private $_file;
|
||||||
|
|
||||||
|
private $_path;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
/* Setup Routine */
|
||||||
|
$this->_path = PATH . 'data' . DIRECTORY_SEPARATOR;
|
||||||
|
$this->_dataDirCreated = !is_dir($this->_path);
|
||||||
|
if($this->_dataDirCreated) mkdir($this->_path);
|
||||||
|
$this->_file = $this->_path . 'vizhash.png';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tearDown()
|
||||||
|
{
|
||||||
|
/* Tear Down Routine */
|
||||||
|
if($this->_dataDirCreated) {
|
||||||
|
helper::rmdir($this->_path);
|
||||||
|
} else {
|
||||||
|
if(!@unlink($this->_file)) {
|
||||||
|
throw new Exception('Error deleting file "' . $this->_file . '".');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testVizhashGeneratesUniquePngsPerIp()
|
||||||
|
{
|
||||||
|
$vz = new vizhash16x16();
|
||||||
|
$pngdata = $vz->generate('127.0.0.1');
|
||||||
|
file_put_contents($this->_file, $pngdata);
|
||||||
|
$finfo = new finfo(FILEINFO_MIME_TYPE);
|
||||||
|
$this->assertEquals('image/png', $finfo->file($this->_file));
|
||||||
|
$this->assertNotEquals($pngdata, $vz->generate('2001:1620:2057:dead:beef::cafe:babe'));
|
||||||
|
$this->assertEquals($pngdata, $vz->generate('127.0.0.1'));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
class zerobin_dataTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
private static $pasteid = '501f02e9eeb8bcec';
|
||||||
|
|
||||||
|
private static $paste = array(
|
||||||
|
'data' => '{"iv":"EN39/wd5Nk8HAiSG2K5AsQ","salt":"QKN1DBXe5PI","ct":"8hA83xDdXjD7K2qfmw5NdA"}',
|
||||||
|
'meta' => array(
|
||||||
|
'postdate' => 1344803344,
|
||||||
|
'expire_date' => 1344803644,
|
||||||
|
'opendiscussion' => true,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
private static $commentid = 'c47efb4741195f42';
|
||||||
|
|
||||||
|
private static $comment = array(
|
||||||
|
'data' => '{"iv":"Pd4pOKWkmDTT9uPwVwd5Ag","salt":"ZIUhFTliVz4","ct":"6nOCU3peNDclDDpFtJEBKA"}',
|
||||||
|
'meta' => array(
|
||||||
|
'nickname' => '{"iv":"76MkAtOGC4oFogX/aSMxRA","salt":"ZIUhFTliVz4","ct":"b6Ae/U1xJdsX/+lATud4sQ"}',
|
||||||
|
'vizhash' => 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGUlEQVQokWOsl5/94983CNKQMjnxaOePf98MeKwPfNjkLZ3AgARab6b9+PeNEVnDj3/ff/z7ZiHnzsDA8Pv7H2TVPJw8EAYLAwb48OaVgIgYKycLsrYv378wMDB8//qdCVMDRA9EKSsnCwRBxNsepaLboMFlyMDAICAi9uHNK24GITQ/MDAwoNhgIGMLtwGrzegaLjw5jMz9+vUdnN17uwDCQDhJgk0O07yvX9+teDX1x79v6DYIsIjgcgMaYGFgYOBg4kJx2JejkAiBxAw+PzAwMNz4dp6wDXDw4MdNNOl0rWYsNkD89OLXI/xmo9sgzatJjAYmBgYGDiauD3/ePP18nVgb4MF89+M5ZX6js293wUMpnr8KTQMAxsCJnJ30apMAAAAASUVORK5CYII=',
|
||||||
|
'postdate' => 1344803528,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
private $_model;
|
||||||
|
|
||||||
|
private $_path;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
/* Setup Routine */
|
||||||
|
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'zerobin_data';
|
||||||
|
$this->_model = zerobin_data::getInstance(array('dir' => $this->_path));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tearDown()
|
||||||
|
{
|
||||||
|
/* Tear Down Routine */
|
||||||
|
helper::rmdir($this->_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFileBasedDataStoreWorks()
|
||||||
|
{
|
||||||
|
// storing pastes
|
||||||
|
$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->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->assertEquals(json_decode(json_encode(self::$paste)), $this->_model->read(self::$pasteid));
|
||||||
|
|
||||||
|
// storing comments
|
||||||
|
$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->existsComment(self::$pasteid, self::$pasteid, self::$commentid), 'comment exists after storing it');
|
||||||
|
$comment = json_decode(json_encode(self::$comment));
|
||||||
|
$comment->meta->commentid = self::$commentid;
|
||||||
|
$comment->meta->parentid = self::$pasteid;
|
||||||
|
$this->assertEquals(
|
||||||
|
array($comment->meta->postdate => $comment),
|
||||||
|
$this->_model->readComments(self::$pasteid)
|
||||||
|
);
|
||||||
|
|
||||||
|
// deleting pastes
|
||||||
|
$this->_model->delete(self::$pasteid);
|
||||||
|
$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->read(self::$pasteid), 'paste can no longer be found');
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
class zerobin_dbTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
private static $pasteid = '501f02e9eeb8bcec';
|
||||||
|
|
||||||
|
private static $paste = array(
|
||||||
|
'data' => '{"iv":"EN39/wd5Nk8HAiSG2K5AsQ","salt":"QKN1DBXe5PI","ct":"8hA83xDdXjD7K2qfmw5NdA"}',
|
||||||
|
'meta' => array(
|
||||||
|
'postdate' => 1344803344,
|
||||||
|
'expire_date' => 1344803644,
|
||||||
|
'opendiscussion' => true,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
private static $commentid = 'c47efb4741195f42';
|
||||||
|
|
||||||
|
private static $comment = array(
|
||||||
|
'data' => '{"iv":"Pd4pOKWkmDTT9uPwVwd5Ag","salt":"ZIUhFTliVz4","ct":"6nOCU3peNDclDDpFtJEBKA"}',
|
||||||
|
'meta' => array(
|
||||||
|
'nickname' => '{"iv":"76MkAtOGC4oFogX/aSMxRA","salt":"ZIUhFTliVz4","ct":"b6Ae/U1xJdsX/+lATud4sQ"}',
|
||||||
|
'vizhash' => 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGUlEQVQokWOsl5/94983CNKQMjnxaOePf98MeKwPfNjkLZ3AgARab6b9+PeNEVnDj3/ff/z7ZiHnzsDA8Pv7H2TVPJw8EAYLAwb48OaVgIgYKycLsrYv378wMDB8//qdCVMDRA9EKSsnCwRBxNsepaLboMFlyMDAICAi9uHNK24GITQ/MDAwoNhgIGMLtwGrzegaLjw5jMz9+vUdnN17uwDCQDhJgk0O07yvX9+teDX1x79v6DYIsIjgcgMaYGFgYOBg4kJx2JejkAiBxAw+PzAwMNz4dp6wDXDw4MdNNOl0rWYsNkD89OLXI/xmo9sgzatJjAYmBgYGDiauD3/ePP18nVgb4MF89+M5ZX6js293wUMpnr8KTQMAxsCJnJ30apMAAAAASUVORK5CYII=',
|
||||||
|
'postdate' => 1344803528,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
private $_model;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
/* Setup Routine */
|
||||||
|
$this->_model = zerobin_db::getInstance(
|
||||||
|
array(
|
||||||
|
'dsn' => 'sqlite::memory:',
|
||||||
|
'usr' => null,
|
||||||
|
'pwd' => null,
|
||||||
|
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDatabaseBasedDataStoreWorks()
|
||||||
|
{
|
||||||
|
// storing pastes
|
||||||
|
$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->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->assertEquals(json_decode(json_encode(self::$paste)), $this->_model->read(self::$pasteid));
|
||||||
|
|
||||||
|
// storing comments
|
||||||
|
$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->existsComment(self::$pasteid, self::$pasteid, self::$commentid), 'comment exists after storing it');
|
||||||
|
$comment = json_decode(json_encode(self::$comment));
|
||||||
|
$comment->meta->commentid = self::$commentid;
|
||||||
|
$comment->meta->parentid = self::$pasteid;
|
||||||
|
$this->assertEquals(
|
||||||
|
array($comment->meta->postdate => $comment),
|
||||||
|
$this->_model->readComments(self::$pasteid)
|
||||||
|
);
|
||||||
|
|
||||||
|
// deleting pastes
|
||||||
|
$this->_model->delete(self::$pasteid);
|
||||||
|
$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->read(self::$pasteid), 'paste can no longer be found');
|
||||||
|
}
|
||||||
|
}
|
@ -1 +0,0 @@
|
|||||||
Subproject commit ef4d776aedee6cbc8959a8e76403b82523615d3a
|
|
Loading…
Reference in new issue