From e5b096ed8c653650d2965bed970ea33544f559bd Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sat, 3 Oct 2015 17:54:18 +0200 Subject: [PATCH] found and fixed a bug when using expiration together with discussion --- lib/zerobin.php | 3 ++- tst/zerobin.php | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/zerobin.php b/lib/zerobin.php index 2f51d2f..0de26bb 100644 --- a/lib/zerobin.php +++ b/lib/zerobin.php @@ -243,6 +243,8 @@ class zerobin { $paste = $this->_model->getPaste(); try { + $paste->setData($data); + if (!empty($attachment)) { $paste->setAttachment($attachment); @@ -262,7 +264,6 @@ class zerobin $formatter = $this->_request->getParam('formatter'); if (!empty($formatter)) $paste->setFormatter($formatter); - $paste->setData($data); $paste->store(); } catch (Exception $e) { return $this->_return_message(1, $e->getMessage()); diff --git a/tst/zerobin.php b/tst/zerobin.php index ac1fb1b..e92378d 100644 --- a/tst/zerobin.php +++ b/tst/zerobin.php @@ -248,6 +248,40 @@ class zerobinTest extends PHPUnit_Framework_TestCase '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'); + } + + /** + * @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'); } /**