Merge branch 'styleci'

This commit is contained in:
El RIDO 2016-11-01 06:30:37 +01:00
commit d6c445092f
No known key found for this signature in database
GPG key ID: 0F5C940A6BD81F92
36 changed files with 462 additions and 458 deletions

View file

@ -38,6 +38,6 @@ indent_style = space
indent_size = 2 indent_size = 2
trim_trailing_whitespace = false trim_trailing_whitespace = false
[.travis.yml] [*.yml]
indent_style = space indent_style = space
indent_size = 4 indent_size = 2

View file

@ -15,9 +15,9 @@ return Symfony\CS\Config\Config::create()
->fixers(['concat_with_spaces', 'long_array_syntax', 'standardize_not_equal', ->fixers(['concat_with_spaces', 'long_array_syntax', 'standardize_not_equal',
'operators_spaces', 'duplicate_semicolon', 'operators_spaces', 'duplicate_semicolon',
'remove_leading_slash_use', 'align_equals', 'remove_leading_slash_use', 'align_equals',
'single_array_no_trailing_comma', 'phpdoc_indent', 'phpdoc_scalar', 'single_array_no_trailing_comma', 'phpdoc_indent', 'phpdoc_order',
'phpdoc_to_comment', 'phpdoc_trim', 'phpdoc_scalar', 'phpdoc_to_comment', 'phpdoc_trim',
'phpdoc_types', 'print_to_echo', 'self_accessor', 'single_quote', 'phpdoc_types', 'print_to_echo', 'self_accessor', 'single_quote',
'spaces_cast', 'ternary_spaces', 'phpdoc_order']) 'spaces_cast', 'ternary_spaces'])
->finder($finder) ->finder($finder)
; ;

26
.styleci.yml Normal file
View file

@ -0,0 +1,26 @@
preset: recommended
risky: false
enabled:
- no_empty_comment
- align_equals
- long_array_syntax
- concat_with_spaces
disabled:
- blank_line_after_opening_tag
- blank_line_before_return
- concat_without_spaces
- declare_equal_normalize
- heredoc_to_nowdoc
- method_argument_space
- new_with_braces
- phpdoc_align
- phpdoc_no_access
- phpdoc_separation
- phpdoc_single_line_var_spacing
- phpdoc_summary
- short_array_syntax
- single_line_after_imports
- unalign_equals

View file

@ -9,10 +9,8 @@
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
* @version 1.0 * @version 1.0
*/ */
namespace PrivateBin; namespace PrivateBin;
use PrivateBin\I18n;
use Exception; use Exception;
use PDO; use PDO;
@ -37,51 +35,51 @@ class Configuration
*/ */
private static $_defaults = array( private static $_defaults = array(
'main' => array( 'main' => array(
'discussion' => true, 'discussion' => true,
'opendiscussion' => false, 'opendiscussion' => false,
'password' => true, 'password' => true,
'fileupload' => false, 'fileupload' => false,
'burnafterreadingselected' => false, 'burnafterreadingselected' => false,
'defaultformatter' => 'plaintext', 'defaultformatter' => 'plaintext',
'syntaxhighlightingtheme' => null, 'syntaxhighlightingtheme' => null,
'sizelimit' => 2097152, 'sizelimit' => 2097152,
'template' => 'bootstrap', 'template' => 'bootstrap',
'notice' => '', 'notice' => '',
'languageselection' => false, 'languageselection' => false,
'languagedefault' => '', 'languagedefault' => '',
'urlshortener' => '', 'urlshortener' => '',
'icon' => 'identicon', 'icon' => 'identicon',
'cspheader' => 'default-src \'none\'; manifest-src \'self\'; connect-src *; script-src \'self\'; style-src \'self\'; font-src \'self\'; img-src \'self\' data:; referrer no-referrer;', 'cspheader' => 'default-src \'none\'; manifest-src \'self\'; connect-src *; script-src \'self\'; style-src \'self\'; font-src \'self\'; img-src \'self\' data:; referrer no-referrer;',
'zerobincompatibility' => false, 'zerobincompatibility' => false,
), ),
'expire' => array( 'expire' => array(
'default' => '1week', 'default' => '1week',
'clone' => true, 'clone' => true,
), ),
'expire_options' => array( 'expire_options' => array(
'5min' => 300, '5min' => 300,
'10min' => 600, '10min' => 600,
'1hour' => 3600, '1hour' => 3600,
'1day' => 86400, '1day' => 86400,
'1week' => 604800, '1week' => 604800,
'1month' => 2592000, '1month' => 2592000,
'1year' => 31536000, '1year' => 31536000,
'never' => 0, 'never' => 0,
), ),
'formatter_options' => array( 'formatter_options' => array(
'plaintext' => 'Plain Text', 'plaintext' => 'Plain Text',
'syntaxhighlighting' => 'Source Code', 'syntaxhighlighting' => 'Source Code',
'markdown' => 'Markdown', 'markdown' => 'Markdown',
), ),
'traffic' => array( 'traffic' => array(
'limit' => 10, 'limit' => 10,
'header' => null, 'header' => null,
'dir' => 'data', 'dir' => 'data',
), ),
'purge' => array( 'purge' => array(
'limit' => 300, 'limit' => 300,
'batchsize' => 10, 'batchsize' => 10,
'dir' => 'data', 'dir' => 'data',
), ),
'model' => array( 'model' => array(
'class' => 'Filesystem', 'class' => 'Filesystem',

View file

@ -9,7 +9,6 @@
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
* @version 1.0 * @version 1.0
*/ */
namespace PrivateBin\Data; namespace PrivateBin\Data;
use stdClass; use stdClass;

View file

@ -9,13 +9,12 @@
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
* @version 1.0 * @version 1.0
*/ */
namespace PrivateBin\Data; namespace PrivateBin\Data;
use PrivateBin\PrivateBin;
use Exception; use Exception;
use PDO; use PDO;
use PDOException; use PDOException;
use PrivateBin\PrivateBin;
use stdClass; use stdClass;
/** /**

View file

@ -9,11 +9,10 @@
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
* @version 1.0 * @version 1.0
*/ */
namespace PrivateBin\Data; namespace PrivateBin\Data;
use PrivateBin\Model\Paste;
use PrivateBin\Json; use PrivateBin\Json;
use PrivateBin\Model\Paste;
/** /**
* Filesystem * Filesystem

View file

@ -9,10 +9,8 @@
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
* @version 1.0 * @version 1.0
*/ */
namespace PrivateBin; namespace PrivateBin;
use PrivateBin\I18n;
use Exception; use Exception;
/** /**

View file

@ -9,7 +9,6 @@
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
* @version 1.0 * @version 1.0
*/ */
namespace PrivateBin; namespace PrivateBin;
/** /**
@ -296,12 +295,12 @@ class I18n
switch (self::$_language) { switch (self::$_language) {
case 'fr': case 'fr':
case 'zh': case 'zh':
return ($n > 1 ? 1 : 0); return $n > 1 ? 1 : 0;
case 'pl': case 'pl':
return ($n == 1 ? 0 : $n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2); return $n == 1 ? 0 : $n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2;
// en, de // en, de
default: default:
return ($n != 1 ? 1 : 0); return $n != 1 ? 1 : 0;
} }
} }

View file

@ -9,7 +9,6 @@
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
* @version 1.0 * @version 1.0
*/ */
namespace PrivateBin; namespace PrivateBin;
use Exception; use Exception;

View file

@ -9,10 +9,8 @@
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
* @version 1.0 * @version 1.0
*/ */
namespace PrivateBin; namespace PrivateBin;
use PrivateBin\Data;
use PrivateBin\Model\Paste; use PrivateBin\Model\Paste;
use PrivateBin\Persistence\PurgeLimiter; use PrivateBin\Persistence\PurgeLimiter;

View file

@ -9,13 +9,12 @@
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
* @version 1.0 * @version 1.0
*/ */
namespace PrivateBin\Model; namespace PrivateBin\Model;
use Exception;
use PrivateBin\Configuration; use PrivateBin\Configuration;
use PrivateBin\Data\AbstractData; use PrivateBin\Data\AbstractData;
use PrivateBin\Sjcl; use PrivateBin\Sjcl;
use Exception;
use stdClass; use stdClass;
/** /**

View file

@ -9,14 +9,13 @@
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
* @version 1.0 * @version 1.0
*/ */
namespace PrivateBin\Model; namespace PrivateBin\Model;
use PrivateBin\Sjcl;
use PrivateBin\Persistence\TrafficLimiter;
use PrivateBin\Vizhash16x16;
use Identicon\Identicon;
use Exception; use Exception;
use Identicon\Identicon;
use PrivateBin\Persistence\TrafficLimiter;
use PrivateBin\Sjcl;
use PrivateBin\Vizhash16x16;
/** /**
* Comment * Comment

View file

@ -9,13 +9,12 @@
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
* @version 1.0 * @version 1.0
*/ */
namespace PrivateBin\Model; namespace PrivateBin\Model;
use PrivateBin\PrivateBin;
use PrivateBin\Persistence\ServerSalt;
use PrivateBin\Sjcl;
use Exception; use Exception;
use PrivateBin\Persistence\ServerSalt;
use PrivateBin\PrivateBin;
use PrivateBin\Sjcl;
/** /**
* Paste * Paste
@ -307,7 +306,6 @@ class Paste extends AbstractModel
$this->_data->meta->burnafterreading === true; $this->_data->meta->burnafterreading === true;
} }
/** /**
* Check if paste has discussions enabled. * Check if paste has discussions enabled.
* *

View file

@ -9,7 +9,6 @@
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
* @version 1.0 * @version 1.0
*/ */
namespace PrivateBin\Persistence; namespace PrivateBin\Persistence;
use Exception; use Exception;

View file

@ -9,7 +9,6 @@
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
* @version 1.0 * @version 1.0
*/ */
namespace PrivateBin\Persistence; namespace PrivateBin\Persistence;
use PrivateBin\Configuration; use PrivateBin\Configuration;

View file

@ -9,7 +9,6 @@
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
* @version 1.0 * @version 1.0
*/ */
namespace PrivateBin\Persistence; namespace PrivateBin\Persistence;
use Exception; use Exception;

View file

@ -9,7 +9,6 @@
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
* @version 1.0 * @version 1.0
*/ */
namespace PrivateBin\Persistence; namespace PrivateBin\Persistence;
use PrivateBin\Configuration; use PrivateBin\Configuration;

View file

@ -9,12 +9,11 @@
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
* @version 1.0 * @version 1.0
*/ */
namespace PrivateBin; namespace PrivateBin;
use PrivateBin\Persistence\TrafficLimiter;
use PrivateBin\Persistence\ServerSalt;
use Exception; use Exception;
use PrivateBin\Persistence\ServerSalt;
use PrivateBin\Persistence\TrafficLimiter;
/** /**
* PrivateBin * PrivateBin

View file

@ -9,7 +9,6 @@
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
* @version 1.0 * @version 1.0
*/ */
namespace PrivateBin; namespace PrivateBin;
/** /**

View file

@ -9,7 +9,6 @@
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
* @version 1.0 * @version 1.0
*/ */
namespace PrivateBin; namespace PrivateBin;
/** /**
@ -31,7 +30,7 @@ class Sjcl
*/ */
public static function isValid($encoded) public static function isValid($encoded)
{ {
$accepted_keys = array('iv','v','iter','ks','ts','mode','adata','cipher','salt','ct'); $accepted_keys = array('iv', 'v', 'iter', 'ks', 'ts', 'mode', 'adata', 'cipher', 'salt', 'ct');
// Make sure content is valid json // Make sure content is valid json
$decoded = json_decode($encoded); $decoded = json_decode($encoded);

View file

@ -9,7 +9,6 @@
* @license http://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @license http://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
* @version 1.0 * @version 1.0
*/ */
namespace PrivateBin; namespace PrivateBin;
use Exception; use Exception;

View file

@ -10,7 +10,6 @@
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
* @version 0.0.5 beta PrivateBin 1.0 * @version 0.0.5 beta PrivateBin 1.0
*/ */
namespace PrivateBin; namespace PrivateBin;
/** /**
@ -23,7 +22,6 @@ namespace PrivateBin;
* echo $data; * echo $data;
* exit; * exit;
*/ */
class Vizhash16x16 class Vizhash16x16
{ {
/** /**
@ -105,7 +103,7 @@ class Vizhash16x16
$op = 'v'; $op = 'v';
if (($this->getInt() % 2) == 0) { if (($this->getInt() % 2) == 0) {
$op = 'h'; $op = 'h';
}; }
$image = $this->degrade($image, $op, array($r0, $g0, $b0), array(0, 0, 0)); $image = $this->degrade($image, $op, array($r0, $g0, $b0), array(0, 0, 0));
for ($i = 0; $i < 7; ++$i) { for ($i = 0; $i < 7; ++$i) {
@ -189,7 +187,7 @@ class Vizhash16x16
$diffs = array( $diffs = array(
(($color2[0] - $color1[0]) / $size), (($color2[0] - $color1[0]) / $size),
(($color2[1] - $color1[1]) / $size), (($color2[1] - $color1[1]) / $size),
(($color2[2] - $color1[2]) / $size) (($color2[2] - $color1[2]) / $size),
); );
for ($i = 0; $i < $size; ++$i) { for ($i = 0; $i < $size; ++$i) {
$r = $color1[0] + ($diffs[0] * $i); $r = $color1[0] + ($diffs[0] * $i);
@ -217,20 +215,20 @@ class Vizhash16x16
{ {
switch ($action % 7) { switch ($action % 7) {
case 0: case 0:
ImageFilledRectangle($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $color); imagefilledrectangle($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $color);
break; break;
case 1: case 1:
case 2: case 2:
ImageFilledEllipse($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $color); imagefilledellipse($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $color);
break; break;
case 3: case 3:
$points = array($this->getX(), $this->getY(), $this->getX(), $this->getY(), $this->getX(), $this->getY(), $this->getX(), $this->getY()); $points = array($this->getX(), $this->getY(), $this->getX(), $this->getY(), $this->getX(), $this->getY(), $this->getX(), $this->getY());
ImageFilledPolygon($image, $points, 4, $color); imagefilledpolygon($image, $points, 4, $color);
break; break;
default: default:
$start = $this->getInt() * 360 / 256; $start = $this->getInt() * 360 / 256;
$end = $start + $this->getInt() * 180 / 256; $end = $start + $this->getInt() * 180 / 256;
ImageFilledArc($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $start, $end, $color, IMG_ARC_PIE); imagefilledarc($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $start, $end, $color, IMG_ARC_PIE);
} }
} }
} }

View file

@ -36,12 +36,12 @@ class Helper
* @var array * @var array
*/ */
private static $paste = array( private static $paste = array(
'data' => '{"iv":"EN39/wd5Nk8HAiSG2K5AsQ","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","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"}',
'attachment' => '{"iv":"Pd4pOKWkmDTT9uPwVwd5Ag","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"6nOCU3peNDclDDpFtJEBKA"}', 'attachment' => '{"iv":"Pd4pOKWkmDTT9uPwVwd5Ag","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"6nOCU3peNDclDDpFtJEBKA"}',
'attachmentname' => '{"iv":"76MkAtOGC4oFogX/aSMxRA","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"b6Ae/U1xJdsX/+lATud4sQ"}', 'attachmentname' => '{"iv":"76MkAtOGC4oFogX/aSMxRA","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"b6Ae/U1xJdsX/+lATud4sQ"}',
'meta' => array( 'meta' => array(
'formatter' => 'plaintext', 'formatter' => 'plaintext',
'postdate' => 1344803344, 'postdate' => 1344803344,
'opendiscussion' => true, 'opendiscussion' => true,
), ),
); );
@ -62,7 +62,7 @@ class Helper
'data' => '{"iv":"Pd4pOKWkmDTT9uPwVwd5Ag","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","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","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","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,
), ),
); );
@ -103,9 +103,9 @@ class Helper
*/ */
public static function getPasteWithAttachment($meta = array()) public static function getPasteWithAttachment($meta = array())
{ {
$example = self::$paste; $example = self::$paste;
$example['meta']['salt'] = ServerSalt::generate(); $example['meta']['salt'] = ServerSalt::generate();
$example['meta'] = array_merge($example['meta'], $meta); $example['meta'] = array_merge($example['meta'], $meta);
return $example; return $example;
} }
@ -122,10 +122,10 @@ class Helper
if (count($meta)) { if (count($meta)) {
$example['meta'] = $meta; $example['meta'] = $meta;
} }
$example['comments'] = array(); $example['comments'] = array();
$example['comment_count'] = 0; $example['comment_count'] = 0;
$example['comment_offset'] = 0; $example['comment_offset'] = 0;
$example['@context'] = 'js/paste.jsonld'; $example['@context'] = 'js/paste.jsonld';
return json_encode($example); return json_encode($example);
} }
@ -146,7 +146,7 @@ class Helper
*/ */
public static function getComment($meta = array()) public static function getComment($meta = array())
{ {
$example = self::$comment; $example = self::$comment;
$example['meta'] = array_merge($example['meta'], $meta); $example['meta'] = array_merge($example['meta'], $meta);
return $example; return $example;
} }
@ -158,7 +158,7 @@ class Helper
*/ */
public static function getCommentPost($meta = array()) public static function getCommentPost($meta = array())
{ {
$example = self::getComment($meta); $example = self::getComment($meta);
$example['nickname'] = $example['meta']['nickname']; $example['nickname'] = $example['meta']['nickname'];
unset($example['meta']['nickname']); unset($example['meta']['nickname']);
return $example; return $example;

View file

@ -12,11 +12,11 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
{ {
/* Setup Routine */ /* Setup Routine */
Helper::confBackup(); Helper::confBackup();
$this->_options = configuration::getDefaults(); $this->_options = configuration::getDefaults();
$this->_options['model_options']['dir'] = PATH . $this->_options['model_options']['dir']; $this->_options['model_options']['dir'] = PATH . $this->_options['model_options']['dir'];
$this->_options['traffic']['dir'] = PATH . $this->_options['traffic']['dir']; $this->_options['traffic']['dir'] = PATH . $this->_options['traffic']['dir'];
$this->_options['purge']['dir'] = PATH . $this->_options['purge']['dir']; $this->_options['purge']['dir'] = PATH . $this->_options['purge']['dir'];
$this->_minimalConfig = '[main]' . PHP_EOL . '[model]' . PHP_EOL . '[model_options]'; $this->_minimalConfig = '[main]' . PHP_EOL . '[model]' . PHP_EOL . '[model_options]';
} }
public function tearDown() public function tearDown()
@ -94,19 +94,19 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
public function testHandleWrongTypes() public function testHandleWrongTypes()
{ {
$original_options = $this->_options; $original_options = $this->_options;
$original_options['main']['syntaxhighlightingtheme'] = 'foo'; $original_options['main']['syntaxhighlightingtheme'] = 'foo';
$options = $original_options; $options = $original_options;
$options['main']['discussion'] = 'true'; $options['main']['discussion'] = 'true';
$options['main']['opendiscussion'] = 0; $options['main']['opendiscussion'] = 0;
$options['main']['password'] = -1; // evaluates to TRUE $options['main']['password'] = -1; // evaluates to TRUE
$options['main']['fileupload'] = 'false'; $options['main']['fileupload'] = 'false';
$options['expire_options']['foo'] = 'bar'; $options['expire_options']['foo'] = 'bar';
$options['formatter_options'][] = 'foo'; $options['formatter_options'][] = 'foo';
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
$conf = new Configuration; $conf = new Configuration;
$original_options['expire_options']['foo'] = intval('bar'); $original_options['expire_options']['foo'] = intval('bar');
$original_options['formatter_options'][0] = 'foo'; $original_options['formatter_options'][0] = 'foo';
$this->assertEquals($original_options, $conf->get(), 'incorrect types are corrected'); $this->assertEquals($original_options, $conf->get(), 'incorrect types are corrected');
} }
@ -117,14 +117,14 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
unset($options['expire_options']['1year']); unset($options['expire_options']['1year']);
unset($options['expire_options']['never']); unset($options['expire_options']['never']);
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
$conf = new Configuration; $conf = new Configuration;
$options['expire']['default'] = '5min'; $options['expire']['default'] = '5min';
$this->assertEquals($options, $conf->get(), 'not overriding "missing" subkeys'); $this->assertEquals($options, $conf->get(), 'not overriding "missing" subkeys');
} }
public function testHandlePreRenameConfig() public function testHandlePreRenameConfig()
{ {
$options = $this->_options; $options = $this->_options;
$options['model']['class'] = 'zerobin_data'; $options['model']['class'] = 'zerobin_data';
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
$conf = new Configuration; $conf = new Configuration;

View file

@ -9,7 +9,6 @@
* DANGER: Too many options/settings and too high max iteration setting may trigger * DANGER: Too many options/settings and too high max iteration setting may trigger
* a fork bomb. Please save your work before executing this script. * a fork bomb. Please save your work before executing this script.
*/ */
include 'Bootstrap.php'; include 'Bootstrap.php';
$vrd = array('view', 'read', 'delete'); $vrd = array('view', 'read', 'delete');
@ -19,85 +18,85 @@ new ConfigurationTestGenerator(array(
'main/discussion' => array( 'main/discussion' => array(
array( array(
'setting' => true, 'setting' => true,
'tests' => array( 'tests' => array(
array( array(
'conditions' => array('steps' => $vrd), 'conditions' => array('steps' => $vrd),
'type' => 'RegExp', 'type' => 'RegExp',
'args' => array( 'args' => array(
'#<div[^>]*id="opendisc"[^>]*>#', '#<div[^>]*id="opendisc"[^>]*>#',
'$content', '$content',
'outputs enabled discussion correctly' 'outputs enabled discussion correctly',
), ),
), array( ), array(
'conditions' => array('steps' => array('create'), 'traffic/limit' => 10), 'conditions' => array('steps' => array('create'), 'traffic/limit' => 10),
'settings' => array('$_POST["opendiscussion"] = "neither 1 nor 0"'), 'settings' => array('$_POST["opendiscussion"] = "neither 1 nor 0"'),
'type' => 'Equals', 'type' => 'Equals',
'args' => array( 'args' => array(
1, 1,
'$response["status"]', '$response["status"]',
'when discussions are enabled, but invalid flag posted, fail to create paste' 'when discussions are enabled, but invalid flag posted, fail to create paste',
), ),
), array( ), array(
'conditions' => array('steps' => array('create'), 'traffic/limit' => 10), 'conditions' => array('steps' => array('create'), 'traffic/limit' => 10),
'settings' => array('$_POST["opendiscussion"] = "neither 1 nor 0"'), 'settings' => array('$_POST["opendiscussion"] = "neither 1 nor 0"'),
'type' => 'False', 'type' => 'False',
'args' => array( 'args' => array(
'$this->_model->exists(Helper::getPasteId())', '$this->_model->exists(Helper::getPasteId())',
'when discussions are enabled, but invalid flag posted, paste is not created' 'when discussions are enabled, but invalid flag posted, paste is not created',
), ),
), ),
), ),
'affects' => $vcud 'affects' => $vcud,
), array( ), array(
'setting' => false, 'setting' => false,
'tests' => array( 'tests' => array(
array( array(
'type' => 'NotRegExp', 'type' => 'NotRegExp',
'args' => array( 'args' => array(
'#<div[^>]*id="opendisc"[^>]*>#', '#<div[^>]*id="opendisc"[^>]*>#',
'$content', '$content',
'outputs disabled discussion correctly' 'outputs disabled discussion correctly',
), ),
), ),
), ),
'affects' => $vrd 'affects' => $vrd,
), ),
), ),
'main/opendiscussion' => array( 'main/opendiscussion' => array(
array( array(
'setting' => true, 'setting' => true,
'tests' => array( 'tests' => array(
array( array(
'conditions' => array('main/discussion' => true), 'conditions' => array('main/discussion' => true),
'type' => 'RegExp', 'type' => 'RegExp',
'args' => array( 'args' => array(
'#<input[^>]+id="opendiscussion"[^>]*checked="checked"[^>]*>#', '#<input[^>]+id="opendiscussion"[^>]*checked="checked"[^>]*>#',
'$content', '$content',
'outputs checked discussion correctly' 'outputs checked discussion correctly',
), ),
), ),
), ),
'affects' => $vrd 'affects' => $vrd,
), array( ), array(
'setting' => false, 'setting' => false,
'tests' => array( 'tests' => array(
array( array(
'conditions' => array('main/discussion' => true), 'conditions' => array('main/discussion' => true),
'type' => 'NotRegExp', 'type' => 'NotRegExp',
'args' => array( 'args' => array(
'#<input[^>]+id="opendiscussion"[^>]*checked="checked"[^>]*>#', '#<input[^>]+id="opendiscussion"[^>]*checked="checked"[^>]*>#',
'$content', '$content',
'outputs unchecked discussion correctly' 'outputs unchecked discussion correctly',
), ),
), ),
), ),
'affects' => $vrd 'affects' => $vrd,
), ),
), ),
'main/burnafterreadingselected' => array( 'main/burnafterreadingselected' => array(
array( array(
'setting' => true, 'setting' => true,
'tests' => array( 'tests' => array(
array( array(
'type' => 'RegExp', 'type' => 'RegExp',
'args' => array( 'args' => array(
@ -110,7 +109,7 @@ new ConfigurationTestGenerator(array(
'affects' => array('view'), 'affects' => array('view'),
), array( ), array(
'setting' => false, 'setting' => false,
'tests' => array( 'tests' => array(
array( array(
'type' => 'NotRegExp', 'type' => 'NotRegExp',
'args' => array( 'args' => array(
@ -126,37 +125,37 @@ new ConfigurationTestGenerator(array(
'main/password' => array( 'main/password' => array(
array( array(
'setting' => true, 'setting' => true,
'tests' => array( 'tests' => array(
array( array(
'type' => 'RegExp', 'type' => 'RegExp',
'args' => array( 'args' => array(
'#<div[^>]*id="password"[^>]*>#', '#<div[^>]*id="password"[^>]*>#',
'$content', '$content',
'outputs password input correctly' 'outputs password input correctly',
), ),
), ),
), ),
'affects' => $vrd 'affects' => $vrd,
), array( ), array(
'setting' => false, 'setting' => false,
'tests' => array( 'tests' => array(
array( array(
'conditions' => array('main/discussion' => true), 'conditions' => array('main/discussion' => true),
'type' => 'NotRegExp', 'type' => 'NotRegExp',
'args' => array( 'args' => array(
'#<div[^>]*id="password"[^>]*>#', '#<div[^>]*id="password"[^>]*>#',
'$content', '$content',
'removes password input correctly' 'removes password input correctly',
), ),
), ),
), ),
'affects' => $vrd 'affects' => $vrd,
), ),
), ),
'main/template' => array( 'main/template' => array(
array( array(
'setting' => 'page', 'setting' => 'page',
'tests' => array( 'tests' => array(
array( array(
'type' => 'RegExp', 'type' => 'RegExp',
'args' => array( 'args' => array(
@ -176,7 +175,7 @@ new ConfigurationTestGenerator(array(
'affects' => $vrd, 'affects' => $vrd,
), array( ), array(
'setting' => 'bootstrap', 'setting' => 'bootstrap',
'tests' => array( 'tests' => array(
array( array(
'type' => 'NotRegExp', 'type' => 'NotRegExp',
'args' => array( 'args' => array(
@ -199,102 +198,102 @@ new ConfigurationTestGenerator(array(
'main/sizelimit' => array( 'main/sizelimit' => array(
array( array(
'setting' => 10, 'setting' => 10,
'tests' => array( 'tests' => array(
array( array(
'conditions' => array('steps' => array('create'), 'traffic/limit' => 10), 'conditions' => array('steps' => array('create'), 'traffic/limit' => 10),
'type' => 'Equals', 'type' => 'Equals',
'args' => array( 'args' => array(
1, 1,
'$response["status"]', '$response["status"]',
'when sizelimit limit exceeded, fail to create paste' 'when sizelimit limit exceeded, fail to create paste',
), ),
), ),
), ),
'affects' => array('create') 'affects' => array('create'),
), array( ), array(
'setting' => 2097152, 'setting' => 2097152,
'tests' => array( 'tests' => array(
array( array(
'conditions' => array('steps' => array('create'), 'traffic/limit' => 0, 'main/burnafterreadingselected' => true), 'conditions' => array('steps' => array('create'), 'traffic/limit' => 0, 'main/burnafterreadingselected' => true),
'settings' => array('sleep(3)'), 'settings' => array('sleep(3)'),
'type' => 'Equals', 'type' => 'Equals',
'args' => array( 'args' => array(
0, 0,
'$response["status"]', '$response["status"]',
'when sizelimit limit is not reached, successfully create paste' 'when sizelimit limit is not reached, successfully create paste',
), ),
), array( ), array(
'conditions' => array('steps' => array('create'), 'traffic/limit' => 0, 'main/burnafterreadingselected' => true), 'conditions' => array('steps' => array('create'), 'traffic/limit' => 0, 'main/burnafterreadingselected' => true),
'settings' => array('sleep(3)'), 'settings' => array('sleep(3)'),
'type' => 'True', 'type' => 'True',
'args' => array( 'args' => array(
'$this->_model->exists($response["id"])', '$this->_model->exists($response["id"])',
'when sizelimit limit is not reached, paste exists after posting data' 'when sizelimit limit is not reached, paste exists after posting data',
), ),
), ),
), ),
'affects' => array('create') 'affects' => array('create'),
), ),
), ),
'traffic/limit' => array( 'traffic/limit' => array(
array( array(
'setting' => 0, 'setting' => 0,
'tests' => array( 'tests' => array(
array( array(
'conditions' => array('steps' => array('create'), 'main/sizelimit' => 2097152), 'conditions' => array('steps' => array('create'), 'main/sizelimit' => 2097152),
'type' => 'Equals', 'type' => 'Equals',
'args' => array( 'args' => array(
0, 0,
'$response["status"]', '$response["status"]',
'when traffic limit is disabled, successfully create paste' 'when traffic limit is disabled, successfully create paste',
), ),
), array( ), array(
'conditions' => array('steps' => array('create'), 'main/sizelimit' => 2097152), 'conditions' => array('steps' => array('create'), 'main/sizelimit' => 2097152),
'type' => 'True', 'type' => 'True',
'args' => array( 'args' => array(
'$this->_model->exists($response["id"])', '$this->_model->exists($response["id"])',
'when traffic limit is disabled, paste exists after posting data' 'when traffic limit is disabled, paste exists after posting data',
), ),
), ),
), ),
'affects' => array('create') 'affects' => array('create'),
), array( ), array(
'setting' => 10, 'setting' => 10,
'tests' => array( 'tests' => array(
array( array(
'conditions' => array('steps' => array('create')), 'conditions' => array('steps' => array('create')),
'type' => 'Equals', 'type' => 'Equals',
'args' => array( 'args' => array(
1, 1,
'$response["status"]', '$response["status"]',
'when traffic limit is on and we do not wait, fail to create paste' 'when traffic limit is on and we do not wait, fail to create paste',
), ),
), ),
), ),
'affects' => array('create') 'affects' => array('create'),
), array( ), array(
'setting' => 2, 'setting' => 2,
'tests' => array( 'tests' => array(
array( array(
'conditions' => array('steps' => array('create'), 'main/sizelimit' => 2097152), 'conditions' => array('steps' => array('create'), 'main/sizelimit' => 2097152),
'settings' => array('sleep(3)'), 'settings' => array('sleep(3)'),
'type' => 'Equals', 'type' => 'Equals',
'args' => array( 'args' => array(
0, 0,
'$response["status"]', '$response["status"]',
'when traffic limit is on and we wait, successfully create paste' 'when traffic limit is on and we wait, successfully create paste',
), ),
), array( ), array(
'conditions' => array('steps' => array('create'), 'main/sizelimit' => 2097152), 'conditions' => array('steps' => array('create'), 'main/sizelimit' => 2097152),
'settings' => array('sleep(3)'), 'settings' => array('sleep(3)'),
'type' => 'True', 'type' => 'True',
'args' => array( 'args' => array(
'$this->_model->exists($response["id"])', '$this->_model->exists($response["id"])',
'when traffic limit is on and we wait, paste exists after posting data' 'when traffic limit is on and we wait, paste exists after posting data',
), ),
), ),
), ),
'affects' => array('create') 'affects' => array('create'),
), ),
), ),
)); ));
@ -325,7 +324,7 @@ class ConfigurationTestGenerator
* @var array * @var array
*/ */
private $_configurations = array( private $_configurations = array(
array('options' => array(), 'tests' => array(), 'affects' => array()) array('options' => array(), 'tests' => array(), 'affects' => array()),
); );
/** /**
@ -346,10 +345,10 @@ class ConfigurationTestGenerator
private function _writeConfigurationTest() private function _writeConfigurationTest()
{ {
$defaultOptions = parse_ini_file(CONF, true); $defaultOptions = parse_ini_file(CONF, true);
$code = $this->_getHeader(); $code = $this->_getHeader();
foreach ($this->_configurations as $key => $conf) { foreach ($this->_configurations as $key => $conf) {
$fullOptions = array_replace_recursive($defaultOptions, $conf['options']); $fullOptions = array_replace_recursive($defaultOptions, $conf['options']);
$options = Helper::varExportMin($fullOptions, true); $options = Helper::varExportMin($fullOptions, true);
foreach ($conf['affects'] as $step) { foreach ($conf['affects'] as $step) {
$testCode = $preCode = array(); $testCode = $preCode = array();
foreach ($conf['tests'] as $tests) { foreach ($conf['tests'] as $tests) {
@ -470,7 +469,7 @@ EOT;
private function _getFunction($step, $key, &$options, $preCode, $testCode) private function _getFunction($step, $key, &$options, $preCode, $testCode)
{ {
if (count($testCode) == 0) { if (count($testCode) == 0) {
echo "skipping creation of test$step$key, no valid tests found for configuration: $options". PHP_EOL; echo "skipping creation of test$step$key, no valid tests found for configuration: $options" . PHP_EOL;
return ''; return '';
} }
@ -593,7 +592,7 @@ EOT;
// create clones for each of the other settings // create clones for each of the other settings
while ($setting = next($settings)) { while ($setting = next($settings)) {
$clone = $this->_configurations[$c]; $clone = $this->_configurations[$c];
$this->_configurations[] = $this->_addSetting($clone, $setting, $section, $option); $this->_configurations[] = $this->_addSetting($clone, $setting, $section, $option);
} }
reset($settings); reset($settings);
@ -626,7 +625,7 @@ EOT;
throw new Exception("Endless loop or error in options detected: option '$option' already exists with setting '$val' in one of the configurations!"); throw new Exception("Endless loop or error in options detected: option '$option' already exists with setting '$val' in one of the configurations!");
} }
$configuration['options'][$section][$option] = $setting['setting']; $configuration['options'][$section][$option] = $setting['setting'];
$configuration['tests'][$option] = array($setting['tests'], $setting['affects']); $configuration['tests'][$option] = array($setting['tests'], $setting['affects']);
foreach ($setting['affects'] as $affects) { foreach ($setting['affects'] as $affects) {
if (!in_array($affects, $configuration['affects'])) { if (!in_array($affects, $configuration['affects'])) {
$configuration['affects'][] = $affects; $configuration['affects'][] = $affects;

View file

@ -19,7 +19,7 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
public function setUp() public function setUp()
{ {
/* Setup Routine */ /* Setup Routine */
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data'; $this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
$this->_model = Database::getInstance($this->_options); $this->_model = Database::getInstance($this->_options);
} }
@ -47,8 +47,8 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
$this->assertFalse($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId()), 'comment does not yet exist'); $this->assertFalse($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId()), 'comment does not yet exist');
$this->assertTrue($this->_model->createComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId(), Helper::getComment()) !== false, 'store comment'); $this->assertTrue($this->_model->createComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId(), Helper::getComment()) !== false, 'store comment');
$this->assertTrue($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId()), 'comment exists after storing it'); $this->assertTrue($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId()), 'comment exists after storing it');
$comment = json_decode(json_encode(Helper::getComment())); $comment = json_decode(json_encode(Helper::getComment()));
$comment->id = Helper::getCommentId(); $comment->id = Helper::getCommentId();
$comment->parentid = Helper::getPasteId(); $comment->parentid = Helper::getPasteId();
$this->assertEquals( $this->assertEquals(
array($comment->meta->postdate => $comment), array($comment->meta->postdate => $comment),
@ -65,10 +65,10 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
public function testDatabaseBasedAttachmentStoreWorks() public function testDatabaseBasedAttachmentStoreWorks()
{ {
$this->_model->delete(Helper::getPasteId()); $this->_model->delete(Helper::getPasteId());
$original = $paste = Helper::getPasteWithAttachment(array('expire_date' => 1344803344)); $original = $paste = Helper::getPasteWithAttachment(array('expire_date' => 1344803344));
$paste['meta']['burnafterreading'] = $original['meta']['burnafterreading'] = true; $paste['meta']['burnafterreading'] = $original['meta']['burnafterreading'] = true;
$paste['meta']['attachment'] = $paste['attachment']; $paste['meta']['attachment'] = $paste['attachment'];
$paste['meta']['attachmentname'] = $paste['attachmentname']; $paste['meta']['attachmentname'] = $paste['attachmentname'];
unset($paste['attachment'], $paste['attachmentname']); unset($paste['attachment'], $paste['attachmentname']);
$this->assertFalse($this->_model->exists(Helper::getPasteId()), 'paste does not yet exist'); $this->assertFalse($this->_model->exists(Helper::getPasteId()), 'paste does not yet exist');
$this->assertTrue($this->_model->create(Helper::getPasteId(), $paste), 'store new paste'); $this->assertTrue($this->_model->create(Helper::getPasteId(), $paste), 'store new paste');
@ -81,9 +81,9 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
{ {
$this->_model->delete(Helper::getPasteId()); $this->_model->delete(Helper::getPasteId());
$expired = Helper::getPaste(array('expire_date' => 1344803344)); $expired = Helper::getPaste(array('expire_date' => 1344803344));
$paste = Helper::getPaste(array('expire_date' => time() + 3600)); $paste = Helper::getPaste(array('expire_date' => time() + 3600));
$keys = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'x', 'y', 'z'); $keys = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'x', 'y', 'z');
$ids = array(); $ids = array();
foreach ($keys as $key) { foreach ($keys as $key) {
$ids[$key] = substr(md5($key), 0, 16); $ids[$key] = substr(md5($key), 0, 16);
$this->_model->delete($ids[$key]); $this->_model->delete($ids[$key]);
@ -113,7 +113,7 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
{ {
Database::getInstance(array( Database::getInstance(array(
'dsn' => 'ibm:', 'usr' => null, 'pwd' => null, 'dsn' => 'ibm:', 'usr' => null, 'pwd' => null,
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION) 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION),
)); ));
} }
@ -124,7 +124,7 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
{ {
Database::getInstance(array( Database::getInstance(array(
'dsn' => 'informix:', 'usr' => null, 'pwd' => null, 'dsn' => 'informix:', 'usr' => null, 'pwd' => null,
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION) 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION),
)); ));
} }
@ -135,7 +135,7 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
{ {
Database::getInstance(array( Database::getInstance(array(
'dsn' => 'mssql:', 'usr' => null, 'pwd' => null, 'dsn' => 'mssql:', 'usr' => null, 'pwd' => null,
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION) 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION),
)); ));
} }
@ -146,7 +146,7 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
{ {
Database::getInstance(array( Database::getInstance(array(
'dsn' => 'mysql:', 'usr' => null, 'pwd' => null, 'dsn' => 'mysql:', 'usr' => null, 'pwd' => null,
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION) 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION),
)); ));
} }
@ -157,7 +157,7 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
{ {
Database::getInstance(array( Database::getInstance(array(
'dsn' => 'oci:', 'usr' => null, 'pwd' => null, 'dsn' => 'oci:', 'usr' => null, 'pwd' => null,
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION) 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION),
)); ));
} }
@ -168,7 +168,7 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
{ {
Database::getInstance(array( Database::getInstance(array(
'dsn' => 'pgsql:', 'usr' => null, 'pwd' => null, 'dsn' => 'pgsql:', 'usr' => null, 'pwd' => null,
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION) 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION),
)); ));
} }
@ -179,7 +179,7 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
public function testGetFooInstance() public function testGetFooInstance()
{ {
Database::getInstance(array( Database::getInstance(array(
'dsn' => 'foo:', 'usr' => null, 'pwd' => null, 'opt' => null 'dsn' => 'foo:', 'usr' => null, 'pwd' => null, 'opt' => null,
)); ));
} }
@ -231,13 +231,15 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
{ {
mkdir($this->_path); mkdir($this->_path);
$path = $this->_path . DIRECTORY_SEPARATOR . 'attachement-test.sq3'; $path = $this->_path . DIRECTORY_SEPARATOR . 'attachement-test.sq3';
if (is_file($path)) unlink($path); if (is_file($path)) {
unlink($path);
}
$this->_options['dsn'] = 'sqlite:' . $path; $this->_options['dsn'] = 'sqlite:' . $path;
$this->_options['tbl'] = 'bar_'; $this->_options['tbl'] = 'bar_';
$model = Database::getInstance($this->_options); $model = Database::getInstance($this->_options);
$original = $paste = Helper::getPasteWithAttachment(array('expire_date' => 1344803344)); $original = $paste = Helper::getPasteWithAttachment(array('expire_date' => 1344803344));
$paste['meta']['attachment'] = $paste['attachment']; $paste['meta']['attachment'] = $paste['attachment'];
$paste['meta']['attachmentname'] = $paste['attachmentname']; $paste['meta']['attachmentname'] = $paste['attachmentname'];
unset($paste['attachment'], $paste['attachmentname']); unset($paste['attachment'], $paste['attachmentname']);
$meta = $paste['meta']; $meta = $paste['meta'];
@ -274,10 +276,12 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
{ {
mkdir($this->_path); mkdir($this->_path);
$path = $this->_path . DIRECTORY_SEPARATOR . 'db-test.sq3'; $path = $this->_path . DIRECTORY_SEPARATOR . 'db-test.sq3';
if (is_file($path)) unlink($path); if (is_file($path)) {
unlink($path);
}
$this->_options['dsn'] = 'sqlite:' . $path; $this->_options['dsn'] = 'sqlite:' . $path;
$this->_options['tbl'] = 'foo_'; $this->_options['tbl'] = 'foo_';
$db = new PDO( $db = new PDO(
$this->_options['dsn'], $this->_options['dsn'],
$this->_options['usr'], $this->_options['usr'],
$this->_options['pwd'], $this->_options['pwd'],
@ -294,13 +298,13 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
); );
$db->exec( $db->exec(
'CREATE TABLE foo_comment ( ' . 'CREATE TABLE foo_comment ( ' .
"dataid CHAR(16) NOT NULL, " . 'dataid CHAR(16) NOT NULL, ' .
'pasteid CHAR(16), ' . 'pasteid CHAR(16), ' .
'parentid CHAR(16), ' . 'parentid CHAR(16), ' .
'data BLOB, ' . 'data BLOB, ' .
'nickname BLOB, ' . 'nickname BLOB, ' .
'vizhash BLOB, ' . 'vizhash BLOB, ' .
"postdate INT );" 'postdate INT );'
); );
$this->assertInstanceOf(Database::class, Database::getInstance($this->_options)); $this->assertInstanceOf(Database::class, Database::getInstance($this->_options));

View file

@ -11,7 +11,7 @@ class FilesystemTest extends PHPUnit_Framework_TestCase
public function setUp() public function setUp()
{ {
/* Setup Routine */ /* Setup Routine */
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data'; $this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
$this->_model = Filesystem::getInstance(array('dir' => $this->_path)); $this->_model = Filesystem::getInstance(array('dir' => $this->_path));
} }
@ -37,8 +37,8 @@ class FilesystemTest extends PHPUnit_Framework_TestCase
$this->assertFalse($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId()), 'comment does not yet exist'); $this->assertFalse($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId()), 'comment does not yet exist');
$this->assertTrue($this->_model->createComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId(), Helper::getComment()), 'store comment'); $this->assertTrue($this->_model->createComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId(), Helper::getComment()), 'store comment');
$this->assertTrue($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId()), 'comment exists after storing it'); $this->assertTrue($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId()), 'comment exists after storing it');
$comment = json_decode(json_encode(Helper::getComment())); $comment = json_decode(json_encode(Helper::getComment()));
$comment->id = Helper::getCommentId(); $comment->id = Helper::getCommentId();
$comment->parentid = Helper::getPasteId(); $comment->parentid = Helper::getPasteId();
$this->assertEquals( $this->assertEquals(
array($comment->meta->postdate => $comment), array($comment->meta->postdate => $comment),
@ -55,8 +55,8 @@ class FilesystemTest extends PHPUnit_Framework_TestCase
public function testFileBasedAttachmentStoreWorks() public function testFileBasedAttachmentStoreWorks()
{ {
$this->_model->delete(Helper::getPasteId()); $this->_model->delete(Helper::getPasteId());
$original = $paste = Helper::getPasteWithAttachment(array('expire_date' => 1344803344)); $original = $paste = Helper::getPasteWithAttachment(array('expire_date' => 1344803344));
$paste['meta']['attachment'] = $paste['attachment']; $paste['meta']['attachment'] = $paste['attachment'];
$paste['meta']['attachmentname'] = $paste['attachmentname']; $paste['meta']['attachmentname'] = $paste['attachmentname'];
unset($paste['attachment'], $paste['attachmentname']); unset($paste['attachment'], $paste['attachmentname']);
$this->assertFalse($this->_model->exists(Helper::getPasteId()), 'paste does not yet exist'); $this->assertFalse($this->_model->exists(Helper::getPasteId()), 'paste does not yet exist');
@ -70,9 +70,9 @@ class FilesystemTest extends PHPUnit_Framework_TestCase
{ {
mkdir($this->_path . DIRECTORY_SEPARATOR . '00', 0777, true); mkdir($this->_path . DIRECTORY_SEPARATOR . '00', 0777, true);
$expired = Helper::getPaste(array('expire_date' => 1344803344)); $expired = Helper::getPaste(array('expire_date' => 1344803344));
$paste = Helper::getPaste(array('expire_date' => time() + 3600)); $paste = Helper::getPaste(array('expire_date' => time() + 3600));
$keys = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'x', 'y', 'z'); $keys = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'x', 'y', 'z');
$ids = array(); $ids = array();
foreach ($keys as $key) { foreach ($keys as $key) {
$ids[$key] = substr(md5($key), 0, 16); $ids[$key] = substr(md5($key), 0, 16);
$this->assertFalse($this->_model->exists($ids[$key]), "paste $key does not yet exist"); $this->assertFalse($this->_model->exists($ids[$key]), "paste $key does not yet exist");

View file

@ -23,7 +23,7 @@ class I18nTest extends PHPUnit_Framework_TestCase
public function testTranslationFallback() public function testTranslationFallback()
{ {
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'foobar'; $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'foobar';
$messageId = 'It does not matter if the message ID exists'; $messageId = 'It does not matter if the message ID exists';
I18n::loadTranslations(); I18n::loadTranslations();
$this->assertEquals($messageId, I18n::_($messageId), 'fallback to en'); $this->assertEquals($messageId, I18n::_($messageId), 'fallback to en');
} }

View file

@ -1,9 +1,9 @@
<?php <?php
use PrivateBin\Data\Filesystem; use PrivateBin\Data\Filesystem;
use PrivateBin\Persistence\ServerSalt;
use PrivateBin\PrivateBin; use PrivateBin\PrivateBin;
use PrivateBin\Request; use PrivateBin\Request;
use PrivateBin\Persistence\ServerSalt;
class JsonApiTest extends PHPUnit_Framework_TestCase class JsonApiTest extends PHPUnit_Framework_TestCase
{ {
@ -15,7 +15,7 @@ class JsonApiTest extends PHPUnit_Framework_TestCase
{ {
/* Setup Routine */ /* Setup Routine */
Helper::confBackup(); Helper::confBackup();
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data'; $this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
$this->_model = Filesystem::getInstance(array('dir' => $this->_path)); $this->_model = Filesystem::getInstance(array('dir' => $this->_path));
ServerSalt::setPath($this->_path); ServerSalt::setPath($this->_path);
$this->reset(); $this->reset();
@ -30,16 +30,16 @@ class JsonApiTest extends PHPUnit_Framework_TestCase
public function reset() public function reset()
{ {
$_POST = array(); $_POST = array();
$_GET = array(); $_GET = array();
$_SERVER = array(); $_SERVER = array();
if ($this->_model->exists(Helper::getPasteId())) { if ($this->_model->exists(Helper::getPasteId())) {
$this->_model->delete(Helper::getPasteId()); $this->_model->delete(Helper::getPasteId());
} }
Helper::confRestore(); Helper::confRestore();
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['purge']['dir'] = $this->_path; $options['purge']['dir'] = $this->_path;
$options['traffic']['dir'] = $this->_path; $options['traffic']['dir'] = $this->_path;
$options['model_options']['dir'] = $this->_path; $options['model_options']['dir'] = $this->_path;
Helper::confBackup(); Helper::confBackup();
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
@ -51,14 +51,14 @@ class JsonApiTest extends PHPUnit_Framework_TestCase
public function testCreate() public function testCreate()
{ {
$this->reset(); $this->reset();
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['traffic']['limit'] = 0; $options['traffic']['limit'] = 0;
Helper::confBackup(); Helper::confBackup();
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
$_POST = Helper::getPaste(); $_POST = Helper::getPaste();
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['REMOTE_ADDR'] = '::1'; $_SERVER['REMOTE_ADDR'] = '::1';
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
$content = ob_get_contents(); $content = ob_get_contents();
@ -81,7 +81,7 @@ class JsonApiTest extends PHPUnit_Framework_TestCase
public function testPut() public function testPut()
{ {
$this->reset(); $this->reset();
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['traffic']['limit'] = 0; $options['traffic']['limit'] = 0;
Helper::confBackup(); Helper::confBackup();
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
@ -90,10 +90,10 @@ class JsonApiTest extends PHPUnit_Framework_TestCase
$file = tempnam(sys_get_temp_dir(), 'FOO'); $file = tempnam(sys_get_temp_dir(), 'FOO');
file_put_contents($file, http_build_query($paste)); file_put_contents($file, http_build_query($paste));
Request::setInputStream($file); Request::setInputStream($file);
$_SERVER['QUERY_STRING'] = Helper::getPasteId(); $_SERVER['QUERY_STRING'] = Helper::getPasteId();
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['REQUEST_METHOD'] = 'PUT'; $_SERVER['REQUEST_METHOD'] = 'PUT';
$_SERVER['REMOTE_ADDR'] = '::1'; $_SERVER['REMOTE_ADDR'] = '::1';
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
$content = ob_get_contents(); $content = ob_get_contents();
@ -120,14 +120,14 @@ class JsonApiTest extends PHPUnit_Framework_TestCase
$this->_model->create(Helper::getPasteId(), Helper::getPaste()); $this->_model->create(Helper::getPasteId(), Helper::getPaste());
$this->assertTrue($this->_model->exists(Helper::getPasteId()), 'paste exists before deleting data'); $this->assertTrue($this->_model->exists(Helper::getPasteId()), 'paste exists before deleting data');
$paste = $this->_model->read(Helper::getPasteId()); $paste = $this->_model->read(Helper::getPasteId());
$file = tempnam(sys_get_temp_dir(), 'FOO'); $file = tempnam(sys_get_temp_dir(), 'FOO');
file_put_contents($file, http_build_query(array( file_put_contents($file, http_build_query(array(
'deletetoken' => hash_hmac('sha256', Helper::getPasteId(), $paste->meta->salt), 'deletetoken' => hash_hmac('sha256', Helper::getPasteId(), $paste->meta->salt),
))); )));
Request::setInputStream($file); Request::setInputStream($file);
$_SERVER['QUERY_STRING'] = Helper::getPasteId(); $_SERVER['QUERY_STRING'] = Helper::getPasteId();
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['REQUEST_METHOD'] = 'DELETE'; $_SERVER['REQUEST_METHOD'] = 'DELETE';
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
$content = ob_get_contents(); $content = ob_get_contents();
@ -147,12 +147,12 @@ class JsonApiTest extends PHPUnit_Framework_TestCase
$this->assertTrue($this->_model->exists(Helper::getPasteId()), 'paste exists before deleting data'); $this->assertTrue($this->_model->exists(Helper::getPasteId()), 'paste exists before deleting data');
$paste = $this->_model->read(Helper::getPasteId()); $paste = $this->_model->read(Helper::getPasteId());
$_POST = array( $_POST = array(
'action' => 'delete', 'action' => 'delete',
'deletetoken' => hash_hmac('sha256', Helper::getPasteId(), $paste->meta->salt), 'deletetoken' => hash_hmac('sha256', Helper::getPasteId(), $paste->meta->salt),
); );
$_SERVER['QUERY_STRING'] = Helper::getPasteId(); $_SERVER['QUERY_STRING'] = Helper::getPasteId();
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REQUEST_METHOD'] = 'POST';
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
$content = ob_get_contents(); $content = ob_get_contents();
@ -168,13 +168,13 @@ class JsonApiTest extends PHPUnit_Framework_TestCase
public function testRead() public function testRead()
{ {
$this->reset(); $this->reset();
$paste = Helper::getPasteWithAttachment(); $paste = Helper::getPasteWithAttachment();
$paste['meta']['attachment'] = $paste['attachment']; $paste['meta']['attachment'] = $paste['attachment'];
$paste['meta']['attachmentname'] = $paste['attachmentname']; $paste['meta']['attachmentname'] = $paste['attachmentname'];
unset($paste['attachment']); unset($paste['attachment']);
unset($paste['attachmentname']); unset($paste['attachmentname']);
$this->_model->create(Helper::getPasteId(), $paste); $this->_model->create(Helper::getPasteId(), $paste);
$_SERVER['QUERY_STRING'] = Helper::getPasteId(); $_SERVER['QUERY_STRING'] = Helper::getPasteId();
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
ob_start(); ob_start();
new PrivateBin; new PrivateBin;

View file

@ -1,5 +1,6 @@
<?php <?php
use Identicon\Identicon;
use PrivateBin\Configuration; use PrivateBin\Configuration;
use PrivateBin\Data\Database; use PrivateBin\Data\Database;
use PrivateBin\Model; use PrivateBin\Model;
@ -7,7 +8,6 @@ use PrivateBin\Model\Paste;
use PrivateBin\Persistence\ServerSalt; use PrivateBin\Persistence\ServerSalt;
use PrivateBin\Persistence\TrafficLimiter; use PrivateBin\Persistence\TrafficLimiter;
use PrivateBin\Vizhash16x16; use PrivateBin\Vizhash16x16;
use Identicon\Identicon;
class ModelTest extends PHPUnit_Framework_TestCase class ModelTest extends PHPUnit_Framework_TestCase
{ {
@ -22,11 +22,13 @@ class ModelTest extends PHPUnit_Framework_TestCase
/* Setup Routine */ /* Setup Routine */
Helper::confRestore(); Helper::confRestore();
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data'; $this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
if (!is_dir($this->_path)) mkdir($this->_path); if (!is_dir($this->_path)) {
mkdir($this->_path);
}
ServerSalt::setPath($this->_path); ServerSalt::setPath($this->_path);
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['purge']['limit'] = 0; $options['purge']['limit'] = 0;
$options['model'] = array( $options['model'] = array(
'class' => 'Database', 'class' => 'Database',
); );
$options['model_options'] = array( $options['model_options'] = array(
@ -37,8 +39,8 @@ class ModelTest extends PHPUnit_Framework_TestCase
); );
Helper::confBackup(); Helper::confBackup();
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
$this->_conf = new Configuration; $this->_conf = new Configuration;
$this->_model = new Model($this->_conf); $this->_model = new Model($this->_conf);
$_SERVER['REMOTE_ADDR'] = '::1'; $_SERVER['REMOTE_ADDR'] = '::1';
} }
@ -73,8 +75,8 @@ class ModelTest extends PHPUnit_Framework_TestCase
// storing comments // storing comments
$commentData = Helper::getComment(); $commentData = Helper::getComment();
$paste = $this->_model->getPaste(Helper::getPasteId()); $paste = $this->_model->getPaste(Helper::getPasteId());
$comment = $paste->getComment(Helper::getPasteId(), Helper::getCommentId()); $comment = $paste->getComment(Helper::getPasteId(), Helper::getCommentId());
$this->assertFalse($comment->exists(), 'comment does not yet exist'); $this->assertFalse($comment->exists(), 'comment does not yet exist');
$comment = $paste->getComment(Helper::getPasteId()); $comment = $paste->getComment(Helper::getPasteId());
@ -123,7 +125,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
*/ */
public function testCommentDuplicate() public function testCommentDuplicate()
{ {
$pasteData = Helper::getPaste(); $pasteData = Helper::getPaste();
$commentData = Helper::getComment(); $commentData = Helper::getComment();
$this->_model->getPaste(Helper::getPasteId())->delete(); $this->_model->getPaste(Helper::getPasteId())->delete();
@ -146,7 +148,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
public function testImplicitDefaults() public function testImplicitDefaults()
{ {
$pasteData = Helper::getPaste(); $pasteData = Helper::getPaste();
$commentData = Helper::getComment(); $commentData = Helper::getComment();
$this->_model->getPaste(Helper::getPasteId())->delete(); $this->_model->getPaste(Helper::getPasteId())->delete();
@ -175,8 +177,8 @@ class ModelTest extends PHPUnit_Framework_TestCase
$comment->store(); $comment->store();
$identicon = new Identicon(); $identicon = new Identicon();
$pngdata = $identicon->getImageDataUri(TrafficLimiter::getHash(), 16); $pngdata = $identicon->getImageDataUri(TrafficLimiter::getHash(), 16);
$comment = $paste->getComment(Helper::getPasteId(), Helper::getCommentId())->get(); $comment = $paste->getComment(Helper::getPasteId(), Helper::getCommentId())->get();
$this->assertEquals($pngdata, $comment->meta->vizhash, 'nickname triggers vizhash to be set'); $this->assertEquals($pngdata, $comment->meta->vizhash, 'nickname triggers vizhash to be set');
} }
@ -230,13 +232,13 @@ class ModelTest extends PHPUnit_Framework_TestCase
public function testPurge() public function testPurge()
{ {
$conf = new Configuration; $conf = new Configuration;
$store = Database::getInstance($conf->getSection('model_options')); $store = Database::getInstance($conf->getSection('model_options'));
$store->delete(Helper::getPasteId()); $store->delete(Helper::getPasteId());
$expired = Helper::getPaste(array('expire_date' => 1344803344)); $expired = Helper::getPaste(array('expire_date' => 1344803344));
$paste = Helper::getPaste(array('expire_date' => time() + 3600)); $paste = Helper::getPaste(array('expire_date' => time() + 3600));
$keys = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'x', 'y', 'z'); $keys = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'x', 'y', 'z');
$ids = array(); $ids = array();
foreach ($keys as $key) { foreach ($keys as $key) {
$ids[$key] = substr(md5($key), 0, 16); $ids[$key] = substr(md5($key), 0, 16);
$store->delete($ids[$key]); $store->delete($ids[$key]);
@ -261,9 +263,9 @@ class ModelTest extends PHPUnit_Framework_TestCase
public function testCommentWithDisabledVizhash() public function testCommentWithDisabledVizhash()
{ {
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['main']['icon'] = 'none'; $options['main']['icon'] = 'none';
$options['model'] = array( $options['model'] = array(
'class' => 'Database', 'class' => 'Database',
); );
$options['model_options'] = array( $options['model_options'] = array(
@ -297,8 +299,8 @@ class ModelTest extends PHPUnit_Framework_TestCase
// storing comments // storing comments
$commentData = Helper::getComment(); $commentData = Helper::getComment();
$paste = $model->getPaste(Helper::getPasteId()); $paste = $model->getPaste(Helper::getPasteId());
$comment = $paste->getComment(Helper::getPasteId(), Helper::getCommentId()); $comment = $paste->getComment(Helper::getPasteId(), Helper::getCommentId());
$this->assertFalse($comment->exists(), 'comment does not yet exist'); $this->assertFalse($comment->exists(), 'comment does not yet exist');
$comment = $paste->getComment(Helper::getPasteId()); $comment = $paste->getComment(Helper::getPasteId());
@ -316,9 +318,9 @@ class ModelTest extends PHPUnit_Framework_TestCase
public function testCommentIdenticon() public function testCommentIdenticon()
{ {
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['main']['icon'] = 'identicon'; $options['main']['icon'] = 'identicon';
$options['model'] = array( $options['model'] = array(
'class' => 'Database', 'class' => 'Database',
); );
$options['model_options'] = array( $options['model_options'] = array(
@ -331,7 +333,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
$model = new Model(new Configuration); $model = new Model(new Configuration);
$pasteData = Helper::getPaste(); $pasteData = Helper::getPaste();
$commentData = Helper::getComment(); $commentData = Helper::getComment();
$model->getPaste(Helper::getPasteId())->delete(); $model->getPaste(Helper::getPasteId())->delete();
@ -347,16 +349,16 @@ class ModelTest extends PHPUnit_Framework_TestCase
$comment->store(); $comment->store();
$identicon = new Identicon(); $identicon = new Identicon();
$pngdata = $identicon->getImageDataUri(TrafficLimiter::getHash(), 16); $pngdata = $identicon->getImageDataUri(TrafficLimiter::getHash(), 16);
$comment = $paste->getComment(Helper::getPasteId(), Helper::getCommentId())->get(); $comment = $paste->getComment(Helper::getPasteId(), Helper::getCommentId())->get();
$this->assertEquals($pngdata, $comment->meta->vizhash, 'nickname triggers vizhash to be set'); $this->assertEquals($pngdata, $comment->meta->vizhash, 'nickname triggers vizhash to be set');
} }
public function testCommentVizhash() public function testCommentVizhash()
{ {
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['main']['icon'] = 'vizhash'; $options['main']['icon'] = 'vizhash';
$options['model'] = array( $options['model'] = array(
'class' => 'Database', 'class' => 'Database',
); );
$options['model_options'] = array( $options['model_options'] = array(
@ -369,7 +371,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
$model = new Model(new Configuration); $model = new Model(new Configuration);
$pasteData = Helper::getPaste(); $pasteData = Helper::getPaste();
$commentData = Helper::getComment(); $commentData = Helper::getComment();
$model->getPaste(Helper::getPasteId())->delete(); $model->getPaste(Helper::getPasteId())->delete();
@ -384,7 +386,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
$comment->setNickname($commentData['meta']['nickname']); $comment->setNickname($commentData['meta']['nickname']);
$comment->store(); $comment->store();
$vz = new Vizhash16x16(); $vz = new Vizhash16x16();
$pngdata = 'data:image/png;base64,' . base64_encode($vz->generate(TrafficLimiter::getHash())); $pngdata = 'data:image/png;base64,' . base64_encode($vz->generate(TrafficLimiter::getHash()));
$comment = $paste->getComment(Helper::getPasteId(), Helper::getCommentId())->get(); $comment = $paste->getComment(Helper::getPasteId(), Helper::getCommentId())->get();
$this->assertEquals($pngdata, $comment->meta->vizhash, 'nickname triggers vizhash to be set'); $this->assertEquals($pngdata, $comment->meta->vizhash, 'nickname triggers vizhash to be set');

View file

@ -1,9 +1,9 @@
<?php <?php
use PrivateBin\Data\Filesystem; use PrivateBin\Data\Filesystem;
use PrivateBin\PrivateBin;
use PrivateBin\Persistence\ServerSalt; use PrivateBin\Persistence\ServerSalt;
use PrivateBin\Persistence\TrafficLimiter; use PrivateBin\Persistence\TrafficLimiter;
use PrivateBin\PrivateBin;
class PrivateBinTest extends PHPUnit_Framework_TestCase class PrivateBinTest extends PHPUnit_Framework_TestCase
{ {
@ -14,7 +14,7 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
public function setUp() public function setUp()
{ {
/* Setup Routine */ /* Setup Routine */
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data'; $this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
$this->_model = Filesystem::getInstance(array('dir' => $this->_path)); $this->_model = Filesystem::getInstance(array('dir' => $this->_path));
ServerSalt::setPath($this->_path); ServerSalt::setPath($this->_path);
$this->reset(); $this->reset();
@ -29,16 +29,16 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
public function reset() public function reset()
{ {
$_POST = array(); $_POST = array();
$_GET = array(); $_GET = array();
$_SERVER = array(); $_SERVER = array();
if ($this->_model->exists(Helper::getPasteId())) { if ($this->_model->exists(Helper::getPasteId())) {
$this->_model->delete(Helper::getPasteId()); $this->_model->delete(Helper::getPasteId());
} }
Helper::confRestore(); Helper::confRestore();
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['purge']['dir'] = $this->_path; $options['purge']['dir'] = $this->_path;
$options['traffic']['dir'] = $this->_path; $options['traffic']['dir'] = $this->_path;
$options['model_options']['dir'] = $this->_path; $options['model_options']['dir'] = $this->_path;
Helper::confBackup(); Helper::confBackup();
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
@ -72,7 +72,7 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
public function testViewLanguageSelection() public function testViewLanguageSelection()
{ {
$this->reset(); $this->reset();
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['main']['languageselection'] = true; $options['main']['languageselection'] = true;
Helper::confBackup(); Helper::confBackup();
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
@ -94,9 +94,9 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
public function testViewForceLanguageDefault() public function testViewForceLanguageDefault()
{ {
$this->reset(); $this->reset();
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['main']['languageselection'] = false; $options['main']['languageselection'] = false;
$options['main']['languagedefault'] = 'fr'; $options['main']['languagedefault'] = 'fr';
Helper::confBackup(); Helper::confBackup();
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
$_COOKIE['lang'] = 'de'; $_COOKIE['lang'] = 'de';
@ -118,7 +118,7 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
{ {
$shortener = 'https://shortener.example.com/api?link='; $shortener = 'https://shortener.example.com/api?link=';
$this->reset(); $this->reset();
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['main']['urlshortener'] = $shortener; $options['main']['urlshortener'] = $shortener;
Helper::confBackup(); Helper::confBackup();
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
@ -175,14 +175,14 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
public function testCreate() public function testCreate()
{ {
$this->reset(); $this->reset();
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['traffic']['limit'] = 0; $options['traffic']['limit'] = 0;
Helper::confBackup(); Helper::confBackup();
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
$_POST = Helper::getPaste(); $_POST = Helper::getPaste();
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['REMOTE_ADDR'] = '::1'; $_SERVER['REMOTE_ADDR'] = '::1';
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
$content = ob_get_contents(); $content = ob_get_contents();
@ -204,14 +204,14 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
public function testCreateInvalidTimelimit() public function testCreateInvalidTimelimit()
{ {
$this->reset(); $this->reset();
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['traffic']['limit'] = 0; $options['traffic']['limit'] = 0;
Helper::confBackup(); Helper::confBackup();
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
$_POST = Helper::getPaste(array('expire' => 25)); $_POST = Helper::getPaste(array('expire' => 25));
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['REMOTE_ADDR'] = '::1'; $_SERVER['REMOTE_ADDR'] = '::1';
TrafficLimiter::canPass(); TrafficLimiter::canPass();
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
@ -234,15 +234,15 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
public function testCreateInvalidSize() public function testCreateInvalidSize()
{ {
$this->reset(); $this->reset();
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['main']['sizelimit'] = 10; $options['main']['sizelimit'] = 10;
$options['traffic']['limit'] = 0; $options['traffic']['limit'] = 0;
Helper::confBackup(); Helper::confBackup();
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
$_POST = Helper::getPaste(); $_POST = Helper::getPaste();
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['REMOTE_ADDR'] = '::1'; $_SERVER['REMOTE_ADDR'] = '::1';
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
$content = ob_get_contents(); $content = ob_get_contents();
@ -258,15 +258,15 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
public function testCreateProxyHeader() public function testCreateProxyHeader()
{ {
$this->reset(); $this->reset();
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['traffic']['header'] = 'X_FORWARDED_FOR'; $options['traffic']['header'] = 'X_FORWARDED_FOR';
Helper::confBackup(); Helper::confBackup();
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
$_POST = Helper::getPaste(); $_POST = Helper::getPaste();
$_SERVER['HTTP_X_FORWARDED_FOR'] = '::2'; $_SERVER['HTTP_X_FORWARDED_FOR'] = '::2';
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['REMOTE_ADDR'] = '::1'; $_SERVER['REMOTE_ADDR'] = '::1';
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
$content = ob_get_contents(); $content = ob_get_contents();
@ -288,15 +288,15 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
public function testCreateDuplicateId() public function testCreateDuplicateId()
{ {
$this->reset(); $this->reset();
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['traffic']['limit'] = 0; $options['traffic']['limit'] = 0;
Helper::confBackup(); Helper::confBackup();
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
$this->_model->create(Helper::getPasteId(), Helper::getPaste()); $this->_model->create(Helper::getPasteId(), Helper::getPaste());
$_POST = Helper::getPaste(); $_POST = Helper::getPaste();
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['REMOTE_ADDR'] = '::1'; $_SERVER['REMOTE_ADDR'] = '::1';
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
$content = ob_get_contents(); $content = ob_get_contents();
@ -312,17 +312,17 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
public function testCreateValidExpire() public function testCreateValidExpire()
{ {
$this->reset(); $this->reset();
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['traffic']['limit'] = 0; $options['traffic']['limit'] = 0;
Helper::confBackup(); Helper::confBackup();
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
$_POST = Helper::getPaste(); $_POST = Helper::getPaste();
$_POST['expire'] = '5min'; $_POST['expire'] = '5min';
$_POST['formatter'] = 'foo'; $_POST['formatter'] = 'foo';
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['REMOTE_ADDR'] = '::1'; $_SERVER['REMOTE_ADDR'] = '::1';
$time = time(); $time = time();
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
$content = ob_get_contents(); $content = ob_get_contents();
@ -345,17 +345,17 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
public function testCreateValidExpireWithDiscussion() public function testCreateValidExpireWithDiscussion()
{ {
$this->reset(); $this->reset();
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['traffic']['limit'] = 0; $options['traffic']['limit'] = 0;
Helper::confBackup(); Helper::confBackup();
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
$_POST = Helper::getPaste(); $_POST = Helper::getPaste();
$_POST['expire'] = '5min'; $_POST['expire'] = '5min';
$_POST['opendiscussion'] = '1'; $_POST['opendiscussion'] = '1';
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['REMOTE_ADDR'] = '::1'; $_SERVER['REMOTE_ADDR'] = '::1';
$time = time(); $time = time();
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
$content = ob_get_contents(); $content = ob_get_contents();
@ -379,15 +379,15 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
public function testCreateInvalidExpire() public function testCreateInvalidExpire()
{ {
$this->reset(); $this->reset();
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['traffic']['limit'] = 0; $options['traffic']['limit'] = 0;
Helper::confBackup(); Helper::confBackup();
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
$_POST = Helper::getPaste(); $_POST = Helper::getPaste();
$_POST['expire'] = 'foo'; $_POST['expire'] = 'foo';
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['REMOTE_ADDR'] = '::1'; $_SERVER['REMOTE_ADDR'] = '::1';
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
$content = ob_get_contents(); $content = ob_get_contents();
@ -409,15 +409,15 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
public function testCreateInvalidBurn() public function testCreateInvalidBurn()
{ {
$this->reset(); $this->reset();
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['traffic']['limit'] = 0; $options['traffic']['limit'] = 0;
Helper::confBackup(); Helper::confBackup();
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
$_POST = Helper::getPaste(); $_POST = Helper::getPaste();
$_POST['burnafterreading'] = 'neither 1 nor 0'; $_POST['burnafterreading'] = 'neither 1 nor 0';
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['REMOTE_ADDR'] = '::1'; $_SERVER['REMOTE_ADDR'] = '::1';
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
$content = ob_get_contents(); $content = ob_get_contents();
@ -433,15 +433,15 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
public function testCreateInvalidOpenDiscussion() public function testCreateInvalidOpenDiscussion()
{ {
$this->reset(); $this->reset();
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['traffic']['limit'] = 0; $options['traffic']['limit'] = 0;
Helper::confBackup(); Helper::confBackup();
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
$_POST = Helper::getPaste(); $_POST = Helper::getPaste();
$_POST['opendiscussion'] = 'neither 1 nor 0'; $_POST['opendiscussion'] = 'neither 1 nor 0';
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['REMOTE_ADDR'] = '::1'; $_SERVER['REMOTE_ADDR'] = '::1';
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
$content = ob_get_contents(); $content = ob_get_contents();
@ -457,15 +457,15 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
public function testCreateAttachment() public function testCreateAttachment()
{ {
$this->reset(); $this->reset();
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['traffic']['limit'] = 0; $options['traffic']['limit'] = 0;
$options['main']['fileupload'] = true; $options['main']['fileupload'] = true;
Helper::confBackup(); Helper::confBackup();
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
$_POST = Helper::getPasteWithAttachment(); $_POST = Helper::getPasteWithAttachment();
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['REMOTE_ADDR'] = '::1'; $_SERVER['REMOTE_ADDR'] = '::1';
$this->assertFalse($this->_model->exists(Helper::getPasteId()), 'paste does not exists before posting data'); $this->assertFalse($this->_model->exists(Helper::getPasteId()), 'paste does not exists before posting data');
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
@ -475,7 +475,7 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
$this->assertEquals(0, $response['status'], 'outputs status'); $this->assertEquals(0, $response['status'], 'outputs status');
$this->assertTrue($this->_model->exists($response['id']), 'paste exists after posting data'); $this->assertTrue($this->_model->exists($response['id']), 'paste exists after posting data');
$original = json_decode(json_encode($_POST)); $original = json_decode(json_encode($_POST));
$stored = $this->_model->read($response['id']); $stored = $this->_model->read($response['id']);
foreach (array('data', 'attachment', 'attachmentname') as $key) { foreach (array('data', 'attachment', 'attachmentname') as $key) {
$this->assertEquals($original->$key, $stored->$key); $this->assertEquals($original->$key, $stored->$key);
} }
@ -495,16 +495,16 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
public function testCreateBrokenAttachmentUpload() public function testCreateBrokenAttachmentUpload()
{ {
$this->reset(); $this->reset();
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['traffic']['limit'] = 0; $options['traffic']['limit'] = 0;
$options['main']['fileupload'] = true; $options['main']['fileupload'] = true;
Helper::confBackup(); Helper::confBackup();
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
$_POST = Helper::getPasteWithAttachment(); $_POST = Helper::getPasteWithAttachment();
unset($_POST['attachment']); unset($_POST['attachment']);
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['REMOTE_ADDR'] = '::1'; $_SERVER['REMOTE_ADDR'] = '::1';
$this->assertFalse($this->_model->exists(Helper::getPasteId()), 'paste does not exists before posting data'); $this->assertFalse($this->_model->exists(Helper::getPasteId()), 'paste does not exists before posting data');
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
@ -521,10 +521,10 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
public function testCreateTooSoon() public function testCreateTooSoon()
{ {
$this->reset(); $this->reset();
$_POST = Helper::getPaste(); $_POST = Helper::getPaste();
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['REMOTE_ADDR'] = '::1'; $_SERVER['REMOTE_ADDR'] = '::1';
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
ob_end_clean(); ob_end_clean();
@ -544,15 +544,15 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
public function testCreateValidNick() public function testCreateValidNick()
{ {
$this->reset(); $this->reset();
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['traffic']['limit'] = 0; $options['traffic']['limit'] = 0;
Helper::confBackup(); Helper::confBackup();
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
$_POST = Helper::getPaste(); $_POST = Helper::getPaste();
$_POST['nickname'] = Helper::getComment()['meta']['nickname']; $_POST['nickname'] = Helper::getComment()['meta']['nickname'];
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['REMOTE_ADDR'] = '::1'; $_SERVER['REMOTE_ADDR'] = '::1';
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
$content = ob_get_contents(); $content = ob_get_contents();
@ -574,17 +574,17 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
public function testCreateInvalidNick() public function testCreateInvalidNick()
{ {
$this->reset(); $this->reset();
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['traffic']['limit'] = 0; $options['traffic']['limit'] = 0;
Helper::confBackup(); Helper::confBackup();
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
$_POST = Helper::getCommentPost(); $_POST = Helper::getCommentPost();
$_POST['pasteid'] = Helper::getPasteId(); $_POST['pasteid'] = Helper::getPasteId();
$_POST['parentid'] = Helper::getPasteId(); $_POST['parentid'] = Helper::getPasteId();
$_POST['nickname'] = 'foo'; $_POST['nickname'] = 'foo';
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['REMOTE_ADDR'] = '::1'; $_SERVER['REMOTE_ADDR'] = '::1';
$this->_model->create(Helper::getPasteId(), Helper::getPaste()); $this->_model->create(Helper::getPasteId(), Helper::getPaste());
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
@ -601,16 +601,16 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
public function testCreateComment() public function testCreateComment()
{ {
$this->reset(); $this->reset();
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['traffic']['limit'] = 0; $options['traffic']['limit'] = 0;
Helper::confBackup(); Helper::confBackup();
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
$_POST = Helper::getCommentPost(); $_POST = Helper::getCommentPost();
$_POST['pasteid'] = Helper::getPasteId(); $_POST['pasteid'] = Helper::getPasteId();
$_POST['parentid'] = Helper::getPasteId(); $_POST['parentid'] = Helper::getPasteId();
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['REMOTE_ADDR'] = '::1'; $_SERVER['REMOTE_ADDR'] = '::1';
$this->_model->create(Helper::getPasteId(), Helper::getPaste()); $this->_model->create(Helper::getPasteId(), Helper::getPaste());
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
@ -627,16 +627,16 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
public function testCreateInvalidComment() public function testCreateInvalidComment()
{ {
$this->reset(); $this->reset();
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['traffic']['limit'] = 0; $options['traffic']['limit'] = 0;
Helper::confBackup(); Helper::confBackup();
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
$_POST = Helper::getCommentPost(); $_POST = Helper::getCommentPost();
$_POST['pasteid'] = Helper::getPasteId(); $_POST['pasteid'] = Helper::getPasteId();
$_POST['parentid'] = 'foo'; $_POST['parentid'] = 'foo';
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['REMOTE_ADDR'] = '::1'; $_SERVER['REMOTE_ADDR'] = '::1';
$this->_model->create(Helper::getPasteId(), Helper::getPaste()); $this->_model->create(Helper::getPasteId(), Helper::getPaste());
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
@ -653,17 +653,17 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
public function testCreateCommentDiscussionDisabled() public function testCreateCommentDiscussionDisabled()
{ {
$this->reset(); $this->reset();
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['traffic']['limit'] = 0; $options['traffic']['limit'] = 0;
Helper::confBackup(); Helper::confBackup();
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
$_POST = Helper::getCommentPost(); $_POST = Helper::getCommentPost();
$_POST['pasteid'] = Helper::getPasteId(); $_POST['pasteid'] = Helper::getPasteId();
$_POST['parentid'] = Helper::getPasteId(); $_POST['parentid'] = Helper::getPasteId();
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['REMOTE_ADDR'] = '::1'; $_SERVER['REMOTE_ADDR'] = '::1';
$paste = Helper::getPaste(array('opendiscussion' => false)); $paste = Helper::getPaste(array('opendiscussion' => false));
$this->_model->create(Helper::getPasteId(), $paste); $this->_model->create(Helper::getPasteId(), $paste);
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
@ -680,16 +680,16 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
public function testCreateCommentInvalidPaste() public function testCreateCommentInvalidPaste()
{ {
$this->reset(); $this->reset();
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['traffic']['limit'] = 0; $options['traffic']['limit'] = 0;
Helper::confBackup(); Helper::confBackup();
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
$_POST = Helper::getCommentPost(); $_POST = Helper::getCommentPost();
$_POST['pasteid'] = Helper::getPasteId(); $_POST['pasteid'] = Helper::getPasteId();
$_POST['parentid'] = Helper::getPasteId(); $_POST['parentid'] = Helper::getPasteId();
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['REMOTE_ADDR'] = '::1'; $_SERVER['REMOTE_ADDR'] = '::1';
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
$content = ob_get_contents(); $content = ob_get_contents();
@ -705,19 +705,19 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
public function testCreateDuplicateComment() public function testCreateDuplicateComment()
{ {
$this->reset(); $this->reset();
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['traffic']['limit'] = 0; $options['traffic']['limit'] = 0;
Helper::confBackup(); Helper::confBackup();
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
$this->_model->create(Helper::getPasteId(), Helper::getPaste()); $this->_model->create(Helper::getPasteId(), Helper::getPaste());
$this->_model->createComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId(), Helper::getComment()); $this->_model->createComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId(), Helper::getComment());
$this->assertTrue($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId()), 'comment exists before posting data'); $this->assertTrue($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId()), 'comment exists before posting data');
$_POST = Helper::getCommentPost(); $_POST = Helper::getCommentPost();
$_POST['pasteid'] = Helper::getPasteId(); $_POST['pasteid'] = Helper::getPasteId();
$_POST['parentid'] = Helper::getPasteId(); $_POST['parentid'] = Helper::getPasteId();
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['REMOTE_ADDR'] = '::1'; $_SERVER['REMOTE_ADDR'] = '::1';
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
$content = ob_get_contents(); $content = ob_get_contents();
@ -835,7 +835,7 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
$this->reset(); $this->reset();
$paste = Helper::getPaste(); $paste = Helper::getPaste();
$this->_model->create(Helper::getPasteId(), $paste); $this->_model->create(Helper::getPasteId(), $paste);
$_SERVER['QUERY_STRING'] = Helper::getPasteId(); $_SERVER['QUERY_STRING'] = Helper::getPasteId();
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
@ -859,7 +859,7 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
public function testReadInvalidJson() public function testReadInvalidJson()
{ {
$this->reset(); $this->reset();
$_SERVER['QUERY_STRING'] = Helper::getPasteId(); $_SERVER['QUERY_STRING'] = Helper::getPasteId();
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
@ -876,9 +876,9 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
{ {
$this->reset(); $this->reset();
$oldPaste = Helper::getPaste(); $oldPaste = Helper::getPaste();
$meta = array( $meta = array(
'syntaxcoloring' => true, 'syntaxcoloring' => true,
'postdate' => $oldPaste['meta']['postdate'], 'postdate' => $oldPaste['meta']['postdate'],
'opendiscussion' => $oldPaste['meta']['opendiscussion'], 'opendiscussion' => $oldPaste['meta']['opendiscussion'],
); );
$oldPaste['meta'] = $meta; $oldPaste['meta'] = $meta;
@ -931,8 +931,8 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
$this->reset(); $this->reset();
$this->_model->create(Helper::getPasteId(), Helper::getPaste()); $this->_model->create(Helper::getPasteId(), Helper::getPaste());
$this->assertTrue($this->_model->exists(Helper::getPasteId()), 'paste exists before deleting data'); $this->assertTrue($this->_model->exists(Helper::getPasteId()), 'paste exists before deleting data');
$paste = $this->_model->read(Helper::getPasteId()); $paste = $this->_model->read(Helper::getPasteId());
$_GET['pasteid'] = Helper::getPasteId(); $_GET['pasteid'] = Helper::getPasteId();
$_GET['deletetoken'] = hash_hmac('sha256', Helper::getPasteId(), $paste->meta->salt); $_GET['deletetoken'] = hash_hmac('sha256', Helper::getPasteId(), $paste->meta->salt);
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
@ -953,7 +953,7 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
{ {
$this->reset(); $this->reset();
$this->_model->create(Helper::getPasteId(), Helper::getPaste()); $this->_model->create(Helper::getPasteId(), Helper::getPaste());
$_GET['pasteid'] = 'foo'; $_GET['pasteid'] = 'foo';
$_GET['deletetoken'] = 'bar'; $_GET['deletetoken'] = 'bar';
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
@ -973,7 +973,7 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
public function testDeleteInexistantId() public function testDeleteInexistantId()
{ {
$this->reset(); $this->reset();
$_GET['pasteid'] = Helper::getPasteId(); $_GET['pasteid'] = Helper::getPasteId();
$_GET['deletetoken'] = 'bar'; $_GET['deletetoken'] = 'bar';
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
@ -993,7 +993,7 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
{ {
$this->reset(); $this->reset();
$this->_model->create(Helper::getPasteId(), Helper::getPaste()); $this->_model->create(Helper::getPasteId(), Helper::getPaste());
$_GET['pasteid'] = Helper::getPasteId(); $_GET['pasteid'] = Helper::getPasteId();
$_GET['deletetoken'] = 'bar'; $_GET['deletetoken'] = 'bar';
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
@ -1016,10 +1016,10 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
$burnPaste = Helper::getPaste(array('burnafterreading' => true)); $burnPaste = Helper::getPaste(array('burnafterreading' => true));
$this->_model->create(Helper::getPasteId(), $burnPaste); $this->_model->create(Helper::getPasteId(), $burnPaste);
$this->assertTrue($this->_model->exists(Helper::getPasteId()), 'paste exists before deleting data'); $this->assertTrue($this->_model->exists(Helper::getPasteId()), 'paste exists before deleting data');
$_POST['deletetoken'] = 'burnafterreading'; $_POST['deletetoken'] = 'burnafterreading';
$_SERVER['QUERY_STRING'] = Helper::getPasteId(); $_SERVER['QUERY_STRING'] = Helper::getPasteId();
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REQUEST_METHOD'] = 'POST';
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
$content = ob_get_contents(); $content = ob_get_contents();
@ -1037,10 +1037,10 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
$this->reset(); $this->reset();
$this->_model->create(Helper::getPasteId(), Helper::getPaste()); $this->_model->create(Helper::getPasteId(), Helper::getPaste());
$this->assertTrue($this->_model->exists(Helper::getPasteId()), 'paste exists before deleting data'); $this->assertTrue($this->_model->exists(Helper::getPasteId()), 'paste exists before deleting data');
$_POST['deletetoken'] = 'burnafterreading'; $_POST['deletetoken'] = 'burnafterreading';
$_SERVER['QUERY_STRING'] = Helper::getPasteId(); $_SERVER['QUERY_STRING'] = Helper::getPasteId();
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REQUEST_METHOD'] = 'POST';
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
$content = ob_get_contents(); $content = ob_get_contents();
@ -1060,7 +1060,7 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
$this->assertFalse($this->_model->exists(Helper::getPasteId()), 'paste does not exist before being created'); $this->assertFalse($this->_model->exists(Helper::getPasteId()), 'paste does not exist before being created');
$this->_model->create(Helper::getPasteId(), $expiredPaste); $this->_model->create(Helper::getPasteId(), $expiredPaste);
$this->assertTrue($this->_model->exists(Helper::getPasteId()), 'paste exists before deleting data'); $this->assertTrue($this->_model->exists(Helper::getPasteId()), 'paste exists before deleting data');
$_GET['pasteid'] = Helper::getPasteId(); $_GET['pasteid'] = Helper::getPasteId();
$_GET['deletetoken'] = 'does not matter in this context, but has to be set'; $_GET['deletetoken'] = 'does not matter in this context, but has to be set';
ob_start(); ob_start();
new PrivateBin; new PrivateBin;
@ -1084,7 +1084,7 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
unset($paste['meta']['salt']); unset($paste['meta']['salt']);
$this->_model->create(Helper::getPasteId(), $paste); $this->_model->create(Helper::getPasteId(), $paste);
$this->assertTrue($this->_model->exists(Helper::getPasteId()), 'paste exists before deleting data'); $this->assertTrue($this->_model->exists(Helper::getPasteId()), 'paste exists before deleting data');
$_GET['pasteid'] = Helper::getPasteId(); $_GET['pasteid'] = Helper::getPasteId();
$_GET['deletetoken'] = hash_hmac('sha256', Helper::getPasteId(), ServerSalt::get()); $_GET['deletetoken'] = hash_hmac('sha256', Helper::getPasteId(), ServerSalt::get());
ob_start(); ob_start();
new PrivateBin; new PrivateBin;

View file

@ -1,9 +1,7 @@
<?php <?php
use PrivateBin\Data\Database; use PrivateBin\Data\Database;
use PrivateBin\PrivateBin;
use PrivateBin\Persistence\ServerSalt; use PrivateBin\Persistence\ServerSalt;
use PrivateBin\Persistence\TrafficLimiter;
require_once 'PrivateBinTest.php'; require_once 'PrivateBinTest.php';
@ -13,8 +11,8 @@ class PrivateBinWithDbTest extends PrivateBinTest
'usr' => null, 'usr' => null,
'pwd' => null, 'pwd' => null,
'opt' => array( 'opt' => array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_PERSISTENT => true PDO::ATTR_PERSISTENT => true,
), ),
); );
@ -27,7 +25,7 @@ class PrivateBinWithDbTest extends PrivateBinTest
} }
ServerSalt::setPath($this->_path); ServerSalt::setPath($this->_path);
$this->_options['dsn'] = 'sqlite:' . $this->_path . DIRECTORY_SEPARATOR . 'tst.sq3'; $this->_options['dsn'] = 'sqlite:' . $this->_path . DIRECTORY_SEPARATOR . 'tst.sq3';
$this->_model = Database::getInstance($this->_options); $this->_model = Database::getInstance($this->_options);
$this->reset(); $this->reset();
} }
@ -35,13 +33,13 @@ class PrivateBinWithDbTest extends PrivateBinTest
{ {
parent::reset(); parent::reset();
// but then inject a db config // but then inject a db config
$options = parse_ini_file(CONF, true); $options = parse_ini_file(CONF, true);
$options['model'] = array( $options['model'] = array(
'class' => 'Database', 'class' => 'Database',
); );
$options['purge']['dir'] = $this->_path; $options['purge']['dir'] = $this->_path;
$options['traffic']['dir'] = $this->_path; $options['traffic']['dir'] = $this->_path;
$options['model_options'] = $this->_options; $options['model_options'] = $this->_options;
Helper::confBackup(); Helper::confBackup();
Helper::createIniFile(CONF, $options); Helper::createIniFile(CONF, $options);
} }

View file

@ -17,15 +17,15 @@ class RequestTest extends PHPUnit_Framework_TestCase
public function reset() public function reset()
{ {
$_SERVER = array(); $_SERVER = array();
$_GET = array(); $_GET = array();
$_POST = array(); $_POST = array();
} }
public function testView() public function testView()
{ {
$this->reset(); $this->reset();
$_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['REQUEST_METHOD'] = 'GET';
$request = new Request; $request = new Request;
$this->assertFalse($request->isJsonApiCall(), 'is HTML call'); $this->assertFalse($request->isJsonApiCall(), 'is HTML call');
$this->assertEquals('view', $request->getOperation()); $this->assertEquals('view', $request->getOperation());
} }
@ -34,8 +34,8 @@ class RequestTest extends PHPUnit_Framework_TestCase
{ {
$this->reset(); $this->reset();
$_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['QUERY_STRING'] = 'foo'; $_SERVER['QUERY_STRING'] = 'foo';
$request = new Request; $request = new Request;
$this->assertFalse($request->isJsonApiCall(), 'is HTML call'); $this->assertFalse($request->isJsonApiCall(), 'is HTML call');
$this->assertEquals('foo', $request->getParam('pasteid')); $this->assertEquals('foo', $request->getParam('pasteid'));
$this->assertEquals('read', $request->getOperation()); $this->assertEquals('read', $request->getOperation());
@ -45,9 +45,9 @@ class RequestTest extends PHPUnit_Framework_TestCase
{ {
$this->reset(); $this->reset();
$_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['REQUEST_METHOD'] = 'GET';
$_GET['pasteid'] = 'foo'; $_GET['pasteid'] = 'foo';
$_GET['deletetoken'] = 'bar'; $_GET['deletetoken'] = 'bar';
$request = new Request; $request = new Request;
$this->assertFalse($request->isJsonApiCall(), 'is HTML call'); $this->assertFalse($request->isJsonApiCall(), 'is HTML call');
$this->assertEquals('delete', $request->getOperation()); $this->assertEquals('delete', $request->getOperation());
$this->assertEquals('foo', $request->getParam('pasteid')); $this->assertEquals('foo', $request->getParam('pasteid'));
@ -57,9 +57,9 @@ class RequestTest extends PHPUnit_Framework_TestCase
public function testApiCreate() public function testApiCreate()
{ {
$this->reset(); $this->reset();
$_SERVER['REQUEST_METHOD'] = 'PUT'; $_SERVER['REQUEST_METHOD'] = 'PUT';
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$file = tempnam(sys_get_temp_dir(), 'FOO'); $file = tempnam(sys_get_temp_dir(), 'FOO');
file_put_contents($file, 'data=foo'); file_put_contents($file, 'data=foo');
Request::setInputStream($file); Request::setInputStream($file);
$request = new Request; $request = new Request;
@ -72,9 +72,9 @@ class RequestTest extends PHPUnit_Framework_TestCase
{ {
$this->reset(); $this->reset();
$_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['HTTP_ACCEPT'] = 'application/json, text/javascript, */*; q=0.01'; $_SERVER['HTTP_ACCEPT'] = 'application/json, text/javascript, */*; q=0.01';
$_POST['attachment'] = 'foo'; $_POST['attachment'] = 'foo';
$request = new Request; $request = new Request;
$this->assertTrue($request->isJsonApiCall(), 'is JSON Api call'); $this->assertTrue($request->isJsonApiCall(), 'is JSON Api call');
$this->assertEquals('create', $request->getOperation()); $this->assertEquals('create', $request->getOperation());
$this->assertEquals('foo', $request->getParam('attachment')); $this->assertEquals('foo', $request->getParam('attachment'));
@ -84,9 +84,9 @@ class RequestTest extends PHPUnit_Framework_TestCase
{ {
$this->reset(); $this->reset();
$_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['HTTP_ACCEPT'] = 'application/json, text/javascript, */*; q=0.01'; $_SERVER['HTTP_ACCEPT'] = 'application/json, text/javascript, */*; q=0.01';
$_SERVER['QUERY_STRING'] = 'foo'; $_SERVER['QUERY_STRING'] = 'foo';
$request = new Request; $request = new Request;
$this->assertTrue($request->isJsonApiCall(), 'is JSON Api call'); $this->assertTrue($request->isJsonApiCall(), 'is JSON Api call');
$this->assertEquals('foo', $request->getParam('pasteid')); $this->assertEquals('foo', $request->getParam('pasteid'));
$this->assertEquals('read', $request->getOperation()); $this->assertEquals('read', $request->getOperation());
@ -95,11 +95,11 @@ class RequestTest extends PHPUnit_Framework_TestCase
public function testApiDelete() public function testApiDelete()
{ {
$this->reset(); $this->reset();
$_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['QUERY_STRING'] = 'foo'; $_SERVER['QUERY_STRING'] = 'foo';
$_POST['deletetoken'] = 'bar'; $_POST['deletetoken'] = 'bar';
$request = new Request; $request = new Request;
$this->assertTrue($request->isJsonApiCall(), 'is JSON Api call'); $this->assertTrue($request->isJsonApiCall(), 'is JSON Api call');
$this->assertEquals('delete', $request->getOperation()); $this->assertEquals('delete', $request->getOperation());
$this->assertEquals('foo', $request->getParam('pasteid')); $this->assertEquals('foo', $request->getParam('pasteid'));
@ -110,9 +110,9 @@ class RequestTest extends PHPUnit_Framework_TestCase
{ {
$this->reset(); $this->reset();
$_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['HTTP_ACCEPT'] = 'text/html,text/html; charset=UTF-8,application/xhtml+xml, application/xml;q=0.9,*/*;q=0.8, text/csv,application/json'; $_SERVER['HTTP_ACCEPT'] = 'text/html,text/html; charset=UTF-8,application/xhtml+xml, application/xml;q=0.9,*/*;q=0.8, text/csv,application/json';
$_SERVER['QUERY_STRING'] = 'foo'; $_SERVER['QUERY_STRING'] = 'foo';
$request = new Request; $request = new Request;
$this->assertFalse($request->isJsonApiCall(), 'is HTML call'); $this->assertFalse($request->isJsonApiCall(), 'is HTML call');
$this->assertEquals('foo', $request->getParam('pasteid')); $this->assertEquals('foo', $request->getParam('pasteid'));
$this->assertEquals('read', $request->getOperation()); $this->assertEquals('read', $request->getOperation());
@ -122,9 +122,9 @@ class RequestTest extends PHPUnit_Framework_TestCase
{ {
$this->reset(); $this->reset();
$_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['HTTP_ACCEPT'] = 'application/xhtml+xml,text/html,text/html; charset=UTF-8, application/xml;q=0.9,*/*;q=0.8, text/csv,application/json'; $_SERVER['HTTP_ACCEPT'] = 'application/xhtml+xml,text/html,text/html; charset=UTF-8, application/xml;q=0.9,*/*;q=0.8, text/csv,application/json';
$_SERVER['QUERY_STRING'] = 'foo'; $_SERVER['QUERY_STRING'] = 'foo';
$request = new Request; $request = new Request;
$this->assertFalse($request->isJsonApiCall(), 'is HTML call'); $this->assertFalse($request->isJsonApiCall(), 'is HTML call');
$this->assertEquals('foo', $request->getParam('pasteid')); $this->assertEquals('foo', $request->getParam('pasteid'));
$this->assertEquals('read', $request->getOperation()); $this->assertEquals('read', $request->getOperation());
@ -134,9 +134,9 @@ class RequestTest extends PHPUnit_Framework_TestCase
{ {
$this->reset(); $this->reset();
$_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['HTTP_ACCEPT'] = 'text/plain,text/csv, application/xml;q=0.9, application/json, text/html,text/html; charset=UTF-8,application/xhtml+xml, */*;q=0.8'; $_SERVER['HTTP_ACCEPT'] = 'text/plain,text/csv, application/xml;q=0.9, application/json, text/html,text/html; charset=UTF-8,application/xhtml+xml, */*;q=0.8';
$_SERVER['QUERY_STRING'] = 'foo'; $_SERVER['QUERY_STRING'] = 'foo';
$request = new Request; $request = new Request;
$this->assertTrue($request->isJsonApiCall(), 'is JSON Api call'); $this->assertTrue($request->isJsonApiCall(), 'is JSON Api call');
$this->assertEquals('foo', $request->getParam('pasteid')); $this->assertEquals('foo', $request->getParam('pasteid'));
$this->assertEquals('read', $request->getOperation()); $this->assertEquals('read', $request->getOperation());
@ -146,9 +146,9 @@ class RequestTest extends PHPUnit_Framework_TestCase
{ {
$this->reset(); $this->reset();
$_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['HTTP_ACCEPT'] = 'text/plain,text/csv, application/xml;q=0.9, */*;q=0.8'; $_SERVER['HTTP_ACCEPT'] = 'text/plain,text/csv, application/xml;q=0.9, */*;q=0.8';
$_SERVER['QUERY_STRING'] = 'foo'; $_SERVER['QUERY_STRING'] = 'foo';
$request = new Request; $request = new Request;
$this->assertFalse($request->isJsonApiCall(), 'is HTML call'); $this->assertFalse($request->isJsonApiCall(), 'is HTML call');
$this->assertEquals('foo', $request->getParam('pasteid')); $this->assertEquals('foo', $request->getParam('pasteid'));
$this->assertEquals('read', $request->getOperation()); $this->assertEquals('read', $request->getOperation());

View file

@ -10,15 +10,15 @@ class ViewTest extends PHPUnit_Framework_TestCase
private static $status = '!*#@?$+'; private static $status = '!*#@?$+';
private static $formatters = array( private static $formatters = array(
'plaintext' => 'Plain Text', 'plaintext' => 'Plain Text',
'syntaxhighlighting' => 'Source Code', 'syntaxhighlighting' => 'Source Code',
'markdown' => 'Markdown', 'markdown' => 'Markdown',
); );
private static $formatter_default = 'plaintext'; private static $formatter_default = 'plaintext';
private static $expire = array( private static $expire = array(
'5min' => '5 minutes', '5min' => '5 minutes',
'1hour' => '1 hour', '1hour' => '1 hour',
'never' => 'Never', 'never' => 'Never',
); );

View file

@ -29,7 +29,7 @@ class Vizhash16x16Test extends PHPUnit_Framework_TestCase
public function testVizhashGeneratesUniquePngsPerIp() public function testVizhashGeneratesUniquePngsPerIp()
{ {
$vz = new Vizhash16x16(); $vz = new Vizhash16x16();
$pngdata = $vz->generate(hash('sha512', '127.0.0.1')); $pngdata = $vz->generate(hash('sha512', '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);