Skip to content

Commit

Permalink
added instantburnafterreading option to address #174
Browse files Browse the repository at this point in the history
  • Loading branch information
elrido committed Apr 11, 2017
1 parent ab2e789 commit f540369
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cfg/conf.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions lib/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Configuration
'password' => true,
'fileupload' => false,
'burnafterreadingselected' => false,
'instantburnafterreading' => false,
'defaultformatter' => 'plaintext',
'syntaxhighlightingtheme' => null,
'sizelimit' => 2097152,
Expand Down
5 changes: 5 additions & 0 deletions lib/Model/Paste.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public function get()
$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
Expand Down
31 changes: 31 additions & 0 deletions tst/PrivateBinTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,37 @@ public function testReadBurn()
$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(
'#<div id="cipherdata"[^>]*>' .
preg_quote(htmlspecialchars(Helper::getPasteAsJson($burnPaste['meta']), ENT_NOQUOTES)) .
'</div>#',
$content,
'outputs data correctly'
);
// in this case the changed configuration deletes it instantly
$this->assertFalse($this->_model->exists(Helper::getPasteId()), 'paste exists after reading');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tst/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit f540369

Please sign in to comment.