PSR-2/4 fixes

This commit is contained in:
El RIDO 2016-08-22 16:20:14 +02:00
parent 62dd25b91a
commit 3d7b35aed4
5 changed files with 54 additions and 103 deletions

2
tst/.gitignore vendored
View File

@ -1 +1 @@
/configurationCombinations.php /ConfigurationCombinationsTest.php

View File

@ -104,7 +104,7 @@ 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;
} }

View File

@ -34,7 +34,7 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
public function testHandleFreshConfigFile() public function testHandleFreshConfigFile()
{ {
helper::createIniFile(CONF, $this->_options); Helper::createIniFile(CONF, $this->_options);
$conf = new Configuration; $conf = new Configuration;
$this->assertEquals($this->_options, $conf->get(), 'newly generated configuration is correct'); $this->assertEquals($this->_options, $conf->get(), 'newly generated configuration is correct');
} }
@ -116,7 +116,7 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
unset($options['expire_options']['1week']); unset($options['expire_options']['1week']);
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');

View File

@ -22,11 +22,9 @@ new ConfigurationTestGenerator(array(
'tests' => array( 'tests' => array(
array( array(
'conditions' => array('steps' => $vrd), 'conditions' => array('steps' => $vrd),
'type' => 'Tag', 'type' => 'RegExp',
'args' => array( 'args' => array(
array( '#<div[^>]*id="opendisc"[^>]*>#',
'id' => 'opendisc',
),
'$content', '$content',
'outputs enabled discussion correctly' 'outputs enabled discussion correctly'
), ),
@ -44,7 +42,7 @@ new ConfigurationTestGenerator(array(
'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'
), ),
), ),
@ -54,11 +52,9 @@ new ConfigurationTestGenerator(array(
'setting' => false, 'setting' => false,
'tests' => array( 'tests' => array(
array( array(
'type' => 'NotTag', 'type' => 'NotRegExp',
'args' => array( 'args' => array(
array( '#<div[^>]*id="opendisc"[^>]*>#',
'id' => 'opendisc',
),
'$content', '$content',
'outputs disabled discussion correctly' 'outputs disabled discussion correctly'
), ),
@ -73,14 +69,9 @@ new ConfigurationTestGenerator(array(
'tests' => array( 'tests' => array(
array( array(
'conditions' => array('main/discussion' => true), 'conditions' => array('main/discussion' => true),
'type' => 'Tag', 'type' => 'RegExp',
'args' => array( 'args' => array(
array( '#<input[^>]+id="opendiscussion"[^>]*checked="checked"[^>]*>#',
'id' => 'opendiscussion',
'attributes' => array(
'checked' => 'checked',
),
),
'$content', '$content',
'outputs checked discussion correctly' 'outputs checked discussion correctly'
), ),
@ -92,14 +83,9 @@ new ConfigurationTestGenerator(array(
'tests' => array( 'tests' => array(
array( array(
'conditions' => array('main/discussion' => true), 'conditions' => array('main/discussion' => true),
'type' => 'NotTag', 'type' => 'NotRegExp',
'args' => array( 'args' => array(
array( '#<input[^>]+id="opendiscussion"[^>]*checked="checked"[^>]*>#',
'id' => 'opendiscussion',
'attributes' => array(
'checked' => 'checked',
),
),
'$content', '$content',
'outputs unchecked discussion correctly' 'outputs unchecked discussion correctly'
), ),
@ -113,14 +99,9 @@ new ConfigurationTestGenerator(array(
'setting' => true, 'setting' => true,
'tests' => array( 'tests' => array(
array( array(
'type' => 'Tag', 'type' => 'RegExp',
'args' => array( 'args' => array(
array( '#<input[^>]+id="burnafterreading"[^>]*checked="checked"[^>]*>#',
'id' => 'burnafterreading',
'attributes' => array(
'checked' => 'checked',
),
),
'$content', '$content',
'preselects burn after reading option', 'preselects burn after reading option',
), ),
@ -131,14 +112,9 @@ new ConfigurationTestGenerator(array(
'setting' => false, 'setting' => false,
'tests' => array( 'tests' => array(
array( array(
'type' => 'NotTag', 'type' => 'NotRegExp',
'args' => array( 'args' => array(
array( '#<input[^>]+id="burnafterreading"[^>]*checked="checked"[^>]*>#',
'id' => 'burnafterreading',
'attributes' => array(
'checked' => 'checked',
),
),
'$content', '$content',
'burn after reading option is unchecked', 'burn after reading option is unchecked',
), ),
@ -152,11 +128,9 @@ new ConfigurationTestGenerator(array(
'setting' => true, 'setting' => true,
'tests' => array( 'tests' => array(
array( array(
'type' => 'Tag', 'type' => 'RegExp',
'args' => array( 'args' => array(
array( '#<div[^>]*id="password"[^>]*>#',
'id' => 'password',
),
'$content', '$content',
'outputs password input correctly' 'outputs password input correctly'
), ),
@ -168,11 +142,9 @@ new ConfigurationTestGenerator(array(
'tests' => array( 'tests' => array(
array( array(
'conditions' => array('main/discussion' => true), 'conditions' => array('main/discussion' => true),
'type' => 'NotTag', 'type' => 'NotRegExp',
'args' => array( 'args' => array(
array( '#<div[^>]*id="password"[^>]*>#',
'id' => 'password',
),
'$content', '$content',
'removes password input correctly' 'removes password input correctly'
), ),
@ -186,30 +158,16 @@ new ConfigurationTestGenerator(array(
'setting' => 'page', 'setting' => 'page',
'tests' => array( 'tests' => array(
array( array(
'type' => 'Tag', 'type' => 'RegExp',
'args' => array( 'args' => array(
array( '#<link[^>]+type="text/css"[^>]+rel="stylesheet"[^>]+href="css/privatebin\.css\\?\d+\.\d+"[^>]*/>#',
'tag' => 'link',
'attributes' => array(
'type' => 'text/css',
'rel' => 'stylesheet',
'href' => 'regexp:#css/privatebin\.css#',
),
),
'$content', '$content',
'outputs "page" stylesheet correctly', 'outputs "page" stylesheet correctly',
), ),
), array( ), array(
'type' => 'NotTag', 'type' => 'NotRegExp',
'args' => array( 'args' => array(
array( '#<link[^>]+type="text/css"[^>]+rel="stylesheet"[^>]+href="css/bootstrap/bootstrap-\d[\d\.]+\d\.css"[^>]*/>#',
'tag' => 'link',
'attributes' => array(
'type' => 'text/css',
'rel' => 'stylesheet',
'href' => 'regexp:#css/bootstrap/bootstrap-\d[\d\.]+\d\.css#',
),
),
'$content', '$content',
'removes "bootstrap" stylesheet correctly', 'removes "bootstrap" stylesheet correctly',
), ),
@ -220,30 +178,16 @@ new ConfigurationTestGenerator(array(
'setting' => 'bootstrap', 'setting' => 'bootstrap',
'tests' => array( 'tests' => array(
array( array(
'type' => 'NotTag', 'type' => 'NotRegExp',
'args' => array( 'args' => array(
array( '#<link[^>]+type="text/css"[^>]+rel="stylesheet"[^>]+href="css/privatebin\.css\\?\d+\.\d+"[^>]*/>#',
'tag' => 'link',
'attributes' => array(
'type' => 'text/css',
'rel' => 'stylesheet',
'href' => 'regexp:#css/privatebin.css#',
),
),
'$content', '$content',
'removes "page" stylesheet correctly', 'removes "page" stylesheet correctly',
), ),
), array( ), array(
'type' => 'Tag', 'type' => 'RegExp',
'args' => array( 'args' => array(
array( '#<link[^>]+type="text/css"[^>]+rel="stylesheet"[^>]+href="css/bootstrap/bootstrap-\d[\d\.]+\d\.css"[^>]*/>#',
'tag' => 'link',
'attributes' => array(
'type' => 'text/css',
'rel' => 'stylesheet',
'href' => 'regexp:#css/bootstrap/bootstrap-\d[\d\.]+\d\.css#',
),
),
'$content', '$content',
'outputs "bootstrap" stylesheet correctly', 'outputs "bootstrap" stylesheet correctly',
), ),
@ -465,7 +409,10 @@ class ConfigurationTestGenerator
* DO NOT EDIT: This file is generated automatically using configGenerator.php * DO NOT EDIT: This file is generated automatically using configGenerator.php
*/ */
use PrivateBin\PrivateBin;
use PrivateBin\Data\Filesystem; use PrivateBin\Data\Filesystem;
use PrivateBin\Persistence\ServerSalt;
use PrivateBin\Persistence\TrafficLimiter;
class ConfigurationCombinationsTest extends PHPUnit_Framework_TestCase class ConfigurationCombinationsTest extends PHPUnit_Framework_TestCase
{ {
@ -481,7 +428,8 @@ class ConfigurationCombinationsTest extends PHPUnit_Framework_TestCase
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);
TrafficLimiter::setPath($this->_path);
$this->reset(); $this->reset();
} }
@ -497,8 +445,11 @@ class ConfigurationCombinationsTest extends PHPUnit_Framework_TestCase
$_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());
$configuration['model_options']['dir'] = $this->_path;
$configuration['traffic']['dir'] = $this->_path;
$configuration['purge']['dir'] = $this->_path;
Helper::createIniFile(CONF, $configuration); Helper::createIniFile(CONF, $configuration);
} }
@ -545,24 +496,25 @@ EOT;
switch ($step) { switch ($step) {
case 'Create': case 'Create':
$code .= PHP_EOL . <<<'EOT' $code .= PHP_EOL . <<<'EOT'
$_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';
TrafficLimiter::canPass();
EOT; EOT;
break; break;
case 'Read': case 'Read':
$code .= PHP_EOL . <<<'EOT' $code .= PHP_EOL . <<<'EOT'
$this->_model->create(helper::getPasteId(), helper::getPaste()); $this->_model->create(Helper::getPasteId(), Helper::getPaste());
$_SERVER['QUERY_STRING'] = helper::getPasteId(); $_SERVER['QUERY_STRING'] = Helper::getPasteId();
EOT; EOT;
break; break;
case 'Delete': case 'Delete':
$code .= PHP_EOL . <<<'EOT' $code .= PHP_EOL . <<<'EOT'
$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');
$_GET['pasteid'] = helper::getPasteId(); $_GET['pasteid'] = Helper::getPasteId();
$_GET['deletetoken'] = hash_hmac('sha1', helper::getPasteId(), serversalt::get()); $_GET['deletetoken'] = hash_hmac('sha256', Helper::getPasteId(), $this->_model->read(Helper::getPasteId())->meta->salt);
EOT; EOT;
break; break;
} }
@ -571,8 +523,9 @@ EOT;
$code .= PHP_EOL . $preString; $code .= PHP_EOL . $preString;
$code .= <<<'EOT' $code .= <<<'EOT'
ob_start(); ob_start();
new privatebin; new PrivateBin;
$content = ob_get_contents(); $content = ob_get_contents();
ob_end_clean();
EOT; EOT;
// step specific tests // step specific tests
@ -587,9 +540,7 @@ EOT;
$code .= <<<'EOT' $code .= <<<'EOT'
$this->assertContains( $this->assertContains(
'<div id="cipherdata" class="hidden">' . htmlspecialchars(json_encode(Helper::getPaste()['data']), ENT_NOQUOTES),
htmlspecialchars(helper::getPasteAsJson(), ENT_NOQUOTES) .
'</div>',
$content, $content,
'outputs data correctly' 'outputs data correctly'
); );
@ -599,11 +550,11 @@ EOT;
$code .= <<<'EOT' $code .= <<<'EOT'
$this->assertRegExp( $this->assertRegExp(
'#<div[^>]*id="status"[^>]*>.*Paste was properly deleted</div>#', '#<div[^>]*id="status"[^>]*>.*Paste was properly deleted[^<]*</div>#s',
$content, $content,
'outputs deleted status correctly' 'outputs deleted status correctly'
); );
$this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste successfully deleted'); $this->assertFalse($this->_model->exists(Helper::getPasteId()), 'paste successfully deleted');
EOT; EOT;
break; break;
} }

View File

@ -33,7 +33,7 @@ class ViewTest extends PHPUnit_Framework_TestCase
{ {
/* Setup Routine */ /* Setup Routine */
$page = new View; $page = new View;
$page->assign('CIPHERDATA', helper::getPaste()['data']); $page->assign('CIPHERDATA', Helper::getPaste()['data']);
$page->assign('ERROR', self::$error); $page->assign('ERROR', self::$error);
$page->assign('STATUS', self::$status); $page->assign('STATUS', self::$status);
$page->assign('VERSION', self::$version); $page->assign('VERSION', self::$version);
@ -70,7 +70,7 @@ class ViewTest extends PHPUnit_Framework_TestCase
{ {
$this->assertContains( $this->assertContains(
'<div id="cipherdata" class="hidden">' . '<div id="cipherdata" class="hidden">' .
htmlspecialchars(helper::getPaste()['data'], ENT_NOQUOTES) . htmlspecialchars(Helper::getPaste()['data'], ENT_NOQUOTES) .
'</div>', '</div>',
$this->_content, $this->_content,
'outputs data correctly' 'outputs data correctly'