Merge branch 'master' into JSnotWorkingError

This commit is contained in:
El RIDO 2016-11-13 12:30:11 +01:00
commit 70482a4fc0
No known key found for this signature in database
GPG Key ID: 0F5C940A6BD81F92
40 changed files with 496 additions and 468 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

@ -1,5 +1,9 @@
# PrivateBin version history # PrivateBin version history
* **next (not yet released)**
* ADDED: Translations for Italian
* CHANGED: Suppressed referrer HTTP header sending when following links in a paste or comment (#96) and added additional HTTP headers for XSS mitigation (#91)
* CHANGED: Updated random_compat and jQuery libraries
* **1.0 (2016-08-25)** * **1.0 (2016-08-25)**
* ADDED: Translations for Slowene and Chinese * ADDED: Translations for Slowene and Chinese
* ADDED: re-introduced (optional) URL shortener support, which was removed back in version 0.16 for privacy concerns * ADDED: re-introduced (optional) URL shortener support, which was removed back in version 0.16 for privacy concerns

View File

@ -19,6 +19,7 @@ Sébastien Sauvage - original idea and main developer
* Adam Fisher - old Favicons * Adam Fisher - old Favicons
* rugk - new logo/icons * rugk - new logo/icons
* Sobak - PSR-4 and PSR-2 refactoring * Sobak - PSR-4 and PSR-2 refactoring
* Nathaniel Olsen - jQuery upgrade
## Translations ## Translations
* Hexalyse - French * Hexalyse - French
@ -27,3 +28,4 @@ Sébastien Sauvage - original idea and main developer
* Draky50110 - French * Draky50110 - French
* Filip Muki Dobranić - Slovene * Filip Muki Dobranić - Slovene
* Jiawei Zhou - Chinese * Jiawei Zhou - Chinese
* Stefano Marty - Italian

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;

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;
/** /**

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

@ -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');
@ -26,7 +25,7 @@ new ConfigurationTestGenerator(array(
'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),
@ -35,7 +34,7 @@ new ConfigurationTestGenerator(array(
'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),
@ -43,11 +42,11 @@ new ConfigurationTestGenerator(array(
'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(
@ -56,11 +55,11 @@ new ConfigurationTestGenerator(array(
'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(
@ -73,11 +72,11 @@ new ConfigurationTestGenerator(array(
'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(
@ -87,11 +86,11 @@ new ConfigurationTestGenerator(array(
'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(
@ -132,11 +131,11 @@ new ConfigurationTestGenerator(array(
'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(
@ -146,11 +145,11 @@ new ConfigurationTestGenerator(array(
'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(
@ -206,11 +205,11 @@ new ConfigurationTestGenerator(array(
'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(
@ -221,7 +220,7 @@ new ConfigurationTestGenerator(array(
'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),
@ -229,11 +228,11 @@ new ConfigurationTestGenerator(array(
'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(
@ -246,18 +245,18 @@ new ConfigurationTestGenerator(array(
'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(
@ -267,11 +266,11 @@ new ConfigurationTestGenerator(array(
'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(
@ -282,7 +281,7 @@ new ConfigurationTestGenerator(array(
'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),
@ -290,11 +289,11 @@ new ConfigurationTestGenerator(array(
'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()),
); );
/** /**

View File

@ -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,7 +231,9 @@ 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);
@ -274,7 +276,9 @@ 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(
@ -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

@ -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
{ {

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,7 +22,9 @@ 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;

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
{ {

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';
@ -14,7 +12,7 @@ class PrivateBinWithDbTest extends PrivateBinTest
'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,
), ),
); );

View File

@ -4,13 +4,13 @@ Running unit tests
In order to run these tests, you will need to install the following packages In order to run these tests, you will need to install the following packages
and its dependencies: and its dependencies:
* phpunit * phpunit
* php5-gd * php-gd
* php5-sqlite * php-sqlite
* php5-xdebug * php-xdebug
Example for Debian and Ubuntu: Example for Debian and Ubuntu:
```sh ```sh
$ sudo aptitude install phpunit php5-gd php5-sqlite php5-xdebug $ sudo aptitude install phpunit php-gd php-sqlite php-xdebug
``` ```
To run the tests, just change into this directory and run phpunit: To run the tests, just change into this directory and run phpunit:

View File

@ -3,8 +3,8 @@
* Random_* Compatibility Library * Random_* Compatibility Library
* for using the new PHP 7 random_* API in PHP 5 projects * for using the new PHP 7 random_* API in PHP 5 projects
* *
* @version 2.0.2 * @version 2.0.4
* @released 2016-04-03 * @released 2016-11-07
* *
* The MIT License (MIT) * The MIT License (MIT)
* *
@ -41,8 +41,10 @@ if (!defined('PHP_VERSION_ID')) {
$RandomCompatversion = null; $RandomCompatversion = null;
} }
/**
* PHP 7.0.0 and newer have these functions natively.
*/
if (PHP_VERSION_ID < 70000) { if (PHP_VERSION_ID < 70000) {
if (!defined('RANDOM_COMPAT_READ_BUFFER')) { if (!defined('RANDOM_COMPAT_READ_BUFFER')) {
define('RANDOM_COMPAT_READ_BUFFER', 8); define('RANDOM_COMPAT_READ_BUFFER', 8);
} }
@ -67,7 +69,7 @@ if (PHP_VERSION_ID < 70000) {
* 4. COM('CAPICOM.Utilities.1')->GetRandom() * 4. COM('CAPICOM.Utilities.1')->GetRandom()
* 5. openssl_random_pseudo_bytes() (absolute last resort) * 5. openssl_random_pseudo_bytes() (absolute last resort)
* *
* See ERRATA.md for our reasoning behind this particular order * See RATIONALE.md for our reasoning behind this particular order
*/ */
if (extension_loaded('libsodium')) { if (extension_loaded('libsodium')) {
// See random_bytes_libsodium.php // See random_bytes_libsodium.php
@ -123,6 +125,20 @@ if (PHP_VERSION_ID < 70000) {
/** /**
* mcrypt_create_iv() * mcrypt_create_iv()
*
* We only want to use mcypt_create_iv() if:
*
* - random_bytes() hasn't already been defined
* - PHP >= 5.3.7
* - the mcrypt extensions is loaded
* - One of these two conditions is true:
* - We're on Windows (DIRECTORY_SEPARATOR !== '/')
* - We're not on Windows and /dev/urandom is readabale
* (i.e. we're not in a chroot jail)
* - Special case:
* - If we're not on Windows, but the PHP version is between
* 5.6.10 and 5.6.12, we don't want to use mcrypt. It will
* hang indefinitely. This is bad.
*/ */
if ( if (
!is_callable('random_bytes') !is_callable('random_bytes')
@ -130,8 +146,6 @@ if (PHP_VERSION_ID < 70000) {
PHP_VERSION_ID >= 50307 PHP_VERSION_ID >= 50307
&& &&
extension_loaded('mcrypt') extension_loaded('mcrypt')
&&
(DIRECTORY_SEPARATOR !== '/' || $RandomCompatUrandom)
) { ) {
// Prevent this code from hanging indefinitely on non-Windows; // Prevent this code from hanging indefinitely on non-Windows;
// see https://bugs.php.net/bug.php?id=69833 // see https://bugs.php.net/bug.php?id=69833
@ -145,6 +159,10 @@ if (PHP_VERSION_ID < 70000) {
} }
$RandomCompatUrandom = null; $RandomCompatUrandom = null;
/**
* This is a Windows-specific fallback, for when the mcrypt extension
* isn't loaded.
*/
if ( if (
!is_callable('random_bytes') !is_callable('random_bytes')
&& &&