From f54036976a486d3f7c83e52fd37ea357fd4e7a62 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Tue, 11 Apr 2017 17:23:26 +0200 Subject: [PATCH] added instantburnafterreading option to address #174 --- cfg/conf.ini.sample | 4 ++++ lib/Configuration.php | 1 + lib/Model/Paste.php | 5 +++++ tst/PrivateBinTest.php | 31 +++++++++++++++++++++++++++++++ tst/README.md | 2 +- 5 files changed, 42 insertions(+), 1 deletion(-) diff --git a/cfg/conf.ini.sample b/cfg/conf.ini.sample index 0d251c1..d457b89 100644 --- a/cfg/conf.ini.sample +++ b/cfg/conf.ini.sample @@ -21,6 +21,10 @@ fileupload = false ; preselect the burn-after-reading feature, defaults to false burnafterreadingselected = false +; delete a burn after reading paste immediatly after it is first accessed from +; the server and do not wait for a successful decryption +instantburnafterreading = false + ; which display mode to preselect by default, defaults to "plaintext" ; make sure the value exists in [formatter_options] defaultformatter = "plaintext" diff --git a/lib/Configuration.php b/lib/Configuration.php index 4130a22..b6b9f6f 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -42,6 +42,7 @@ class Configuration 'password' => true, 'fileupload' => false, 'burnafterreadingselected' => false, + 'instantburnafterreading' => false, 'defaultformatter' => 'plaintext', 'syntaxhighlightingtheme' => null, 'sizelimit' => 2097152, diff --git a/lib/Model/Paste.php b/lib/Model/Paste.php index 8f171fe..fae808e 100644 --- a/lib/Model/Paste.php +++ b/lib/Model/Paste.php @@ -48,6 +48,11 @@ class Paste extends AbstractModel $data->meta->remaining_time = $data->meta->expire_date - time(); } + // check if non-expired burn after reading paste needs to be deleted + if (property_exists($data->meta, 'burnafterreading') && $data->meta->burnafterreading && $this->_conf->getKey('instantburnafterreading')) { + $this->delete(); + } + // set formatter for for the view. if (!property_exists($data->meta, 'formatter')) { // support < 0.21 syntax highlighting diff --git a/tst/PrivateBinTest.php b/tst/PrivateBinTest.php index a8aad11..44df563 100644 --- a/tst/PrivateBinTest.php +++ b/tst/PrivateBinTest.php @@ -822,6 +822,37 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase $content, 'outputs data correctly' ); + // by default it will be deleted after encryption by the JS + $this->assertTrue($this->_model->exists(Helper::getPasteId()), 'paste exists after reading'); + } + + /** + * @runInSeparateProcess + */ + public function testReadInstantBurn() + { + $this->reset(); + $options = parse_ini_file(CONF, true); + $options['main']['instantburnafterreading'] = 1; + Helper::confBackup(); + Helper::createIniFile(CONF, $options); + $burnPaste = Helper::getPaste(array('burnafterreading' => true)); + $this->_model->create(Helper::getPasteId(), $burnPaste); + $_SERVER['QUERY_STRING'] = Helper::getPasteId(); + ob_start(); + new PrivateBin; + $content = ob_get_contents(); + ob_end_clean(); + unset($burnPaste['meta']['salt']); + $this->assertRegExp( + '#
]*>' . + preg_quote(htmlspecialchars(Helper::getPasteAsJson($burnPaste['meta']), ENT_NOQUOTES)) . + '
#', + $content, + 'outputs data correctly' + ); + // in this case the changed configuration deletes it instantly + $this->assertFalse($this->_model->exists(Helper::getPasteId()), 'paste exists after reading'); } /** diff --git a/tst/README.md b/tst/README.md index e11bc49..77b0352 100644 --- a/tst/README.md +++ b/tst/README.md @@ -10,7 +10,7 @@ and their dependencies: Example for Debian and Ubuntu: ```console -$ sudo apt install phpunit php-gd php-sqlite php-xdebug +$ sudo apt install phpunit php-gd php-sqlite3 php-xdebug ``` To run the tests, change into the `tst` directory and run phpunit: