From 3d7b35aed43cb094e498db9bbf50491118422b91 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Mon, 22 Aug 2016 16:20:14 +0200 Subject: [PATCH] PSR-2/4 fixes --- tst/.gitignore | 2 +- tst/Bootstrap.php | 2 +- tst/ConfigurationTest.php | 4 +- tst/ConfigurationTestGenerator.php | 145 ++++++++++------------------- tst/ViewTest.php | 4 +- 5 files changed, 54 insertions(+), 103 deletions(-) diff --git a/tst/.gitignore b/tst/.gitignore index 0da7951..39ef6b9 100644 --- a/tst/.gitignore +++ b/tst/.gitignore @@ -1 +1 @@ -/configurationCombinations.php +/ConfigurationCombinationsTest.php diff --git a/tst/Bootstrap.php b/tst/Bootstrap.php index 590b1ab..65e1039 100644 --- a/tst/Bootstrap.php +++ b/tst/Bootstrap.php @@ -104,7 +104,7 @@ class Helper public static function getPasteWithAttachment($meta = array()) { $example = self::$paste; - $example['meta']['salt'] = serversalt::generate(); + $example['meta']['salt'] = ServerSalt::generate(); $example['meta'] = array_merge($example['meta'], $meta); return $example; } diff --git a/tst/ConfigurationTest.php b/tst/ConfigurationTest.php index 791f05a..7064a51 100644 --- a/tst/ConfigurationTest.php +++ b/tst/ConfigurationTest.php @@ -34,7 +34,7 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase public function testHandleFreshConfigFile() { - helper::createIniFile(CONF, $this->_options); + Helper::createIniFile(CONF, $this->_options); $conf = new Configuration; $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']['1year']); unset($options['expire_options']['never']); - helper::createIniFile(CONF, $options); + Helper::createIniFile(CONF, $options); $conf = new Configuration; $options['expire']['default'] = '5min'; $this->assertEquals($options, $conf->get(), 'not overriding "missing" subkeys'); diff --git a/tst/ConfigurationTestGenerator.php b/tst/ConfigurationTestGenerator.php index 4c4a657..db174bf 100755 --- a/tst/ConfigurationTestGenerator.php +++ b/tst/ConfigurationTestGenerator.php @@ -22,11 +22,9 @@ new ConfigurationTestGenerator(array( 'tests' => array( array( 'conditions' => array('steps' => $vrd), - 'type' => 'Tag', + 'type' => 'RegExp', 'args' => array( - array( - 'id' => 'opendisc', - ), + '#]*id="opendisc"[^>]*>#', '$content', 'outputs enabled discussion correctly' ), @@ -44,7 +42,7 @@ new ConfigurationTestGenerator(array( 'settings' => array('$_POST["opendiscussion"] = "neither 1 nor 0"'), 'type' => 'False', 'args' => array( - '$this->_model->exists(helper::getPasteId())', + '$this->_model->exists(Helper::getPasteId())', 'when discussions are enabled, but invalid flag posted, paste is not created' ), ), @@ -54,11 +52,9 @@ new ConfigurationTestGenerator(array( 'setting' => false, 'tests' => array( array( - 'type' => 'NotTag', + 'type' => 'NotRegExp', 'args' => array( - array( - 'id' => 'opendisc', - ), + '#]*id="opendisc"[^>]*>#', '$content', 'outputs disabled discussion correctly' ), @@ -73,14 +69,9 @@ new ConfigurationTestGenerator(array( 'tests' => array( array( 'conditions' => array('main/discussion' => true), - 'type' => 'Tag', + 'type' => 'RegExp', 'args' => array( - array( - 'id' => 'opendiscussion', - 'attributes' => array( - 'checked' => 'checked', - ), - ), + '#]+id="opendiscussion"[^>]*checked="checked"[^>]*>#', '$content', 'outputs checked discussion correctly' ), @@ -92,14 +83,9 @@ new ConfigurationTestGenerator(array( 'tests' => array( array( 'conditions' => array('main/discussion' => true), - 'type' => 'NotTag', + 'type' => 'NotRegExp', 'args' => array( - array( - 'id' => 'opendiscussion', - 'attributes' => array( - 'checked' => 'checked', - ), - ), + '#]+id="opendiscussion"[^>]*checked="checked"[^>]*>#', '$content', 'outputs unchecked discussion correctly' ), @@ -113,14 +99,9 @@ new ConfigurationTestGenerator(array( 'setting' => true, 'tests' => array( array( - 'type' => 'Tag', + 'type' => 'RegExp', 'args' => array( - array( - 'id' => 'burnafterreading', - 'attributes' => array( - 'checked' => 'checked', - ), - ), + '#]+id="burnafterreading"[^>]*checked="checked"[^>]*>#', '$content', 'preselects burn after reading option', ), @@ -131,14 +112,9 @@ new ConfigurationTestGenerator(array( 'setting' => false, 'tests' => array( array( - 'type' => 'NotTag', + 'type' => 'NotRegExp', 'args' => array( - array( - 'id' => 'burnafterreading', - 'attributes' => array( - 'checked' => 'checked', - ), - ), + '#]+id="burnafterreading"[^>]*checked="checked"[^>]*>#', '$content', 'burn after reading option is unchecked', ), @@ -152,11 +128,9 @@ new ConfigurationTestGenerator(array( 'setting' => true, 'tests' => array( array( - 'type' => 'Tag', + 'type' => 'RegExp', 'args' => array( - array( - 'id' => 'password', - ), + '#]*id="password"[^>]*>#', '$content', 'outputs password input correctly' ), @@ -168,11 +142,9 @@ new ConfigurationTestGenerator(array( 'tests' => array( array( 'conditions' => array('main/discussion' => true), - 'type' => 'NotTag', + 'type' => 'NotRegExp', 'args' => array( - array( - 'id' => 'password', - ), + '#]*id="password"[^>]*>#', '$content', 'removes password input correctly' ), @@ -186,30 +158,16 @@ new ConfigurationTestGenerator(array( 'setting' => 'page', 'tests' => array( array( - 'type' => 'Tag', + 'type' => 'RegExp', 'args' => array( - array( - 'tag' => 'link', - 'attributes' => array( - 'type' => 'text/css', - 'rel' => 'stylesheet', - 'href' => 'regexp:#css/privatebin\.css#', - ), - ), + '#]+type="text/css"[^>]+rel="stylesheet"[^>]+href="css/privatebin\.css\\?\d+\.\d+"[^>]*/>#', '$content', 'outputs "page" stylesheet correctly', ), ), array( - 'type' => 'NotTag', + 'type' => 'NotRegExp', 'args' => array( - array( - 'tag' => 'link', - 'attributes' => array( - 'type' => 'text/css', - 'rel' => 'stylesheet', - 'href' => 'regexp:#css/bootstrap/bootstrap-\d[\d\.]+\d\.css#', - ), - ), + '#]+type="text/css"[^>]+rel="stylesheet"[^>]+href="css/bootstrap/bootstrap-\d[\d\.]+\d\.css"[^>]*/>#', '$content', 'removes "bootstrap" stylesheet correctly', ), @@ -220,30 +178,16 @@ new ConfigurationTestGenerator(array( 'setting' => 'bootstrap', 'tests' => array( array( - 'type' => 'NotTag', + 'type' => 'NotRegExp', 'args' => array( - array( - 'tag' => 'link', - 'attributes' => array( - 'type' => 'text/css', - 'rel' => 'stylesheet', - 'href' => 'regexp:#css/privatebin.css#', - ), - ), + '#]+type="text/css"[^>]+rel="stylesheet"[^>]+href="css/privatebin\.css\\?\d+\.\d+"[^>]*/>#', '$content', 'removes "page" stylesheet correctly', ), ), array( - 'type' => 'Tag', + 'type' => 'RegExp', 'args' => array( - array( - 'tag' => 'link', - 'attributes' => array( - 'type' => 'text/css', - 'rel' => 'stylesheet', - 'href' => 'regexp:#css/bootstrap/bootstrap-\d[\d\.]+\d\.css#', - ), - ), + '#]+type="text/css"[^>]+rel="stylesheet"[^>]+href="css/bootstrap/bootstrap-\d[\d\.]+\d\.css"[^>]*/>#', '$content', 'outputs "bootstrap" stylesheet correctly', ), @@ -465,7 +409,10 @@ class ConfigurationTestGenerator * DO NOT EDIT: This file is generated automatically using configGenerator.php */ +use PrivateBin\PrivateBin; use PrivateBin\Data\Filesystem; +use PrivateBin\Persistence\ServerSalt; +use PrivateBin\Persistence\TrafficLimiter; class ConfigurationCombinationsTest extends PHPUnit_Framework_TestCase { @@ -481,7 +428,8 @@ class ConfigurationCombinationsTest extends PHPUnit_Framework_TestCase Helper::confBackup(); $this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data'; $this->_model = Filesystem::getInstance(array('dir' => $this->_path)); - serversalt::setPath($this->_path); + ServerSalt::setPath($this->_path); + TrafficLimiter::setPath($this->_path); $this->reset(); } @@ -497,8 +445,11 @@ class ConfigurationCombinationsTest extends PHPUnit_Framework_TestCase $_POST = array(); $_GET = array(); $_SERVER = array(); - if ($this->_model->exists(helper::getPasteId())) - $this->_model->delete(helper::getPasteId()); + if ($this->_model->exists(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); } @@ -545,24 +496,25 @@ EOT; switch ($step) { case 'Create': $code .= PHP_EOL . <<<'EOT' - $_POST = helper::getPaste(); + $_POST = Helper::getPaste(); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REMOTE_ADDR'] = '::1'; + TrafficLimiter::canPass(); EOT; break; case 'Read': $code .= PHP_EOL . <<<'EOT' - $this->_model->create(helper::getPasteId(), helper::getPaste()); - $_SERVER['QUERY_STRING'] = helper::getPasteId(); + $this->_model->create(Helper::getPasteId(), Helper::getPaste()); + $_SERVER['QUERY_STRING'] = Helper::getPasteId(); EOT; break; case 'Delete': $code .= PHP_EOL . <<<'EOT' - $this->_model->create(helper::getPasteId(), helper::getPaste()); - $this->assertTrue($this->_model->exists(helper::getPasteId()), 'paste exists before deleting data'); - $_GET['pasteid'] = helper::getPasteId(); - $_GET['deletetoken'] = hash_hmac('sha1', helper::getPasteId(), serversalt::get()); + $this->_model->create(Helper::getPasteId(), Helper::getPaste()); + $this->assertTrue($this->_model->exists(Helper::getPasteId()), 'paste exists before deleting data'); + $_GET['pasteid'] = Helper::getPasteId(); + $_GET['deletetoken'] = hash_hmac('sha256', Helper::getPasteId(), $this->_model->read(Helper::getPasteId())->meta->salt); EOT; break; } @@ -571,8 +523,9 @@ EOT; $code .= PHP_EOL . $preString; $code .= <<<'EOT' ob_start(); - new privatebin; + new PrivateBin; $content = ob_get_contents(); + ob_end_clean(); EOT; // step specific tests @@ -587,9 +540,7 @@ EOT; $code .= <<<'EOT' $this->assertContains( - '', + htmlspecialchars(json_encode(Helper::getPaste()['data']), ENT_NOQUOTES), $content, 'outputs data correctly' ); @@ -599,11 +550,11 @@ EOT; $code .= <<<'EOT' $this->assertRegExp( - '#]*id="status"[^>]*>.*Paste was properly deleted#', + '#]*id="status"[^>]*>.*Paste was properly deleted[^<]*#s', $content, '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; break; } diff --git a/tst/ViewTest.php b/tst/ViewTest.php index a352fdd..4b8f0cb 100644 --- a/tst/ViewTest.php +++ b/tst/ViewTest.php @@ -33,7 +33,7 @@ class ViewTest extends PHPUnit_Framework_TestCase { /* Setup Routine */ $page = new View; - $page->assign('CIPHERDATA', helper::getPaste()['data']); + $page->assign('CIPHERDATA', Helper::getPaste()['data']); $page->assign('ERROR', self::$error); $page->assign('STATUS', self::$status); $page->assign('VERSION', self::$version); @@ -70,7 +70,7 @@ class ViewTest extends PHPUnit_Framework_TestCase { $this->assertContains( '', $this->_content, 'outputs data correctly'