found and fixed a bug when using expiration together with discussion

This commit is contained in:
El RIDO 2015-10-03 17:54:18 +02:00
parent add980d36f
commit e5b096ed8c
2 changed files with 36 additions and 1 deletions

View file

@ -243,6 +243,8 @@ class zerobin
{ {
$paste = $this->_model->getPaste(); $paste = $this->_model->getPaste();
try { try {
$paste->setData($data);
if (!empty($attachment)) if (!empty($attachment))
{ {
$paste->setAttachment($attachment); $paste->setAttachment($attachment);
@ -262,7 +264,6 @@ class zerobin
$formatter = $this->_request->getParam('formatter'); $formatter = $this->_request->getParam('formatter');
if (!empty($formatter)) $paste->setFormatter($formatter); if (!empty($formatter)) $paste->setFormatter($formatter);
$paste->setData($data);
$paste->store(); $paste->store();
} catch (Exception $e) { } catch (Exception $e) {
return $this->_return_message(1, $e->getMessage()); return $this->_return_message(1, $e->getMessage());

View file

@ -248,6 +248,40 @@ class zerobinTest extends PHPUnit_Framework_TestCase
'outputs valid delete token' 'outputs valid delete token'
); );
$this->assertTrue($this->_model->exists($response['id']), 'paste exists after posting data'); $this->assertTrue($this->_model->exists($response['id']), 'paste exists after posting data');
$paste = $this->_model->read($response['id']);
$this->assertEquals(time() + 300, $paste->meta->expire_date, 'time is set correctly');
}
/**
* @runInSeparateProcess
*/
public function testCreateValidExpireWithDiscussion()
{
$this->reset();
$options = parse_ini_file(CONF, true);
$options['traffic']['limit'] = 0;
helper::confBackup();
helper::createIniFile(CONF, $options);
$_POST = helper::getPaste();
$_POST['expire'] = '5min';
$_POST['opendiscussion'] = '1';
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['REMOTE_ADDR'] = '::1';
ob_start();
new zerobin;
$content = ob_get_contents();
$response = json_decode($content, true);
$this->assertEquals(0, $response['status'], 'outputs status');
$this->assertEquals(
hash_hmac('sha1', $response['id'], serversalt::get()),
$response['deletetoken'],
'outputs valid delete token'
);
$this->assertTrue($this->_model->exists($response['id']), 'paste exists after posting data');
$paste = $this->_model->read($response['id']);
$this->assertEquals(time() + 300, $paste->meta->expire_date, 'time is set correctly');
$this->assertEquals(1, $paste->meta->opendiscussion, 'time is set correctly');
} }
/** /**