2015-08-27 21:30:35 +00:00
|
|
|
<?php
|
2016-07-21 15:09:48 +00:00
|
|
|
|
2020-10-10 10:08:58 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2018-07-29 14:15:52 +00:00
|
|
|
use PrivateBin\Controller;
|
2016-08-09 09:54:42 +00:00
|
|
|
use PrivateBin\Data\Filesystem;
|
|
|
|
use PrivateBin\Persistence\ServerSalt;
|
|
|
|
use PrivateBin\Persistence\TrafficLimiter;
|
2019-05-13 20:31:52 +00:00
|
|
|
use PrivateBin\Request;
|
2016-07-21 15:09:48 +00:00
|
|
|
|
2020-10-10 10:08:58 +00:00
|
|
|
class ControllerTest extends TestCase
|
2015-08-27 21:30:35 +00:00
|
|
|
{
|
2019-05-15 05:44:03 +00:00
|
|
|
protected $_data;
|
2015-08-27 21:30:35 +00:00
|
|
|
|
2016-08-09 09:54:42 +00:00
|
|
|
protected $_path;
|
|
|
|
|
2020-10-10 10:22:20 +00:00
|
|
|
public function setUp(): void
|
2015-08-27 21:30:35 +00:00
|
|
|
{
|
|
|
|
/* Setup Routine */
|
2016-10-29 08:24:08 +00:00
|
|
|
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
|
2022-10-27 23:01:02 +00:00
|
|
|
$this->_data = new Filesystem(array('dir' => $this->_path));
|
2021-06-09 05:47:40 +00:00
|
|
|
ServerSalt::setStore($this->_data);
|
2021-06-08 05:49:22 +00:00
|
|
|
TrafficLimiter::setStore($this->_data);
|
2015-08-27 21:30:35 +00:00
|
|
|
$this->reset();
|
|
|
|
}
|
|
|
|
|
2020-10-10 10:22:20 +00:00
|
|
|
public function tearDown(): void
|
2015-08-27 21:30:35 +00:00
|
|
|
{
|
|
|
|
/* Tear Down Routine */
|
2017-10-08 09:03:17 +00:00
|
|
|
unlink(CONF);
|
2016-08-09 09:54:42 +00:00
|
|
|
Helper::confRestore();
|
|
|
|
Helper::rmDir($this->_path);
|
2015-08-27 21:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function reset()
|
|
|
|
{
|
2016-10-29 08:24:08 +00:00
|
|
|
$_POST = array();
|
|
|
|
$_GET = array();
|
2015-08-27 21:30:35 +00:00
|
|
|
$_SERVER = array();
|
2019-05-15 05:44:03 +00:00
|
|
|
if ($this->_data->exists(Helper::getPasteId())) {
|
|
|
|
$this->_data->delete(Helper::getPasteId());
|
2016-07-26 06:19:35 +00:00
|
|
|
}
|
2017-10-08 09:03:17 +00:00
|
|
|
$options = parse_ini_file(CONF_SAMPLE, true);
|
2016-08-09 09:54:42 +00:00
|
|
|
$options['model_options']['dir'] = $this->_path;
|
|
|
|
Helper::createIniFile(CONF, $options);
|
2015-08-27 21:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testView()
|
|
|
|
{
|
2022-10-23 11:09:54 +00:00
|
|
|
$_SERVER['HTTP_HOST'] = 'example.com';
|
2021-06-13 08:44:26 +00:00
|
|
|
$_SERVER['QUERY_STRING'] = Helper::getPasteId();
|
|
|
|
$_GET[Helper::getPasteId()] = '';
|
2015-08-27 21:30:35 +00:00
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-08-27 21:30:35 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2020-10-11 08:31:24 +00:00
|
|
|
$this->assertStringContainsString(
|
2016-07-11 09:58:15 +00:00
|
|
|
'<title>PrivateBin</title>',
|
2015-08-27 21:30:35 +00:00
|
|
|
$content,
|
|
|
|
'outputs title correctly'
|
|
|
|
);
|
2020-10-11 08:31:24 +00:00
|
|
|
$this->assertStringNotContainsString(
|
2016-05-22 16:35:07 +00:00
|
|
|
'id="shortenbutton"',
|
2016-01-31 08:56:06 +00:00
|
|
|
$content,
|
|
|
|
'doesn\'t output shortener button'
|
|
|
|
);
|
2022-10-25 04:53:07 +00:00
|
|
|
$this->assertMatchesRegularExpression(
|
2022-10-23 11:09:54 +00:00
|
|
|
'# href="https://' . preg_quote($_SERVER['HTTP_HOST']) . '/">switching to HTTPS#',
|
|
|
|
$content,
|
|
|
|
'outputs configured https URL correctly'
|
|
|
|
);
|
2015-08-27 21:30:35 +00:00
|
|
|
}
|
|
|
|
|
2015-09-19 15:23:10 +00:00
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testViewLanguageSelection()
|
|
|
|
{
|
2016-10-29 08:24:08 +00:00
|
|
|
$options = parse_ini_file(CONF, true);
|
2015-09-19 15:23:10 +00:00
|
|
|
$options['main']['languageselection'] = true;
|
2016-08-09 09:54:42 +00:00
|
|
|
Helper::createIniFile(CONF, $options);
|
2015-09-19 15:23:10 +00:00
|
|
|
$_COOKIE['lang'] = 'de';
|
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-09-19 15:23:10 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2020-10-11 08:31:24 +00:00
|
|
|
$this->assertStringContainsString(
|
2016-07-11 09:58:15 +00:00
|
|
|
'<title>PrivateBin</title>',
|
2015-09-19 15:23:10 +00:00
|
|
|
$content,
|
|
|
|
'outputs title correctly'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-01-31 08:56:06 +00:00
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testViewForceLanguageDefault()
|
|
|
|
{
|
2016-10-29 08:24:08 +00:00
|
|
|
$options = parse_ini_file(CONF, true);
|
2016-01-31 08:56:06 +00:00
|
|
|
$options['main']['languageselection'] = false;
|
2016-10-29 08:24:08 +00:00
|
|
|
$options['main']['languagedefault'] = 'fr';
|
2016-08-09 09:54:42 +00:00
|
|
|
Helper::createIniFile(CONF, $options);
|
2016-01-31 08:56:06 +00:00
|
|
|
$_COOKIE['lang'] = 'de';
|
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2016-01-31 08:56:06 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2020-10-11 08:31:24 +00:00
|
|
|
$this->assertStringContainsString(
|
2016-07-11 09:58:15 +00:00
|
|
|
'<title>PrivateBin</title>',
|
2016-01-31 08:56:06 +00:00
|
|
|
$content,
|
|
|
|
'outputs title correctly'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testViewUrlShortener()
|
|
|
|
{
|
2017-10-08 09:31:41 +00:00
|
|
|
$shortener = 'https://shortener.example.com/api?link=';
|
2016-10-29 08:24:08 +00:00
|
|
|
$options = parse_ini_file(CONF, true);
|
2016-01-31 08:56:06 +00:00
|
|
|
$options['main']['urlshortener'] = $shortener;
|
2016-08-09 09:54:42 +00:00
|
|
|
Helper::createIniFile(CONF, $options);
|
2016-01-31 08:56:06 +00:00
|
|
|
$_COOKIE['lang'] = 'de';
|
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2016-01-31 08:56:06 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2020-10-11 08:31:24 +00:00
|
|
|
$this->assertMatchesRegularExpression(
|
2016-05-22 16:35:07 +00:00
|
|
|
'#id="shortenbutton"[^>]*data-shortener="' . preg_quote($shortener) . '"#',
|
2016-01-31 08:56:06 +00:00
|
|
|
$content,
|
|
|
|
'outputs configured shortener URL correctly'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-08-29 18:29:14 +00:00
|
|
|
/**
|
|
|
|
* @expectedException Exception
|
|
|
|
* @expectedExceptionCode 2
|
|
|
|
*/
|
|
|
|
public function testConf()
|
|
|
|
{
|
2015-09-22 21:21:31 +00:00
|
|
|
file_put_contents(CONF, '');
|
2020-10-11 08:31:24 +00:00
|
|
|
$this->expectException(Exception::class);
|
|
|
|
$this->expectExceptionCode(2);
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-08-29 18:29:14 +00:00
|
|
|
}
|
|
|
|
|
2015-08-27 21:30:35 +00:00
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testCreate()
|
|
|
|
{
|
2016-10-29 08:24:08 +00:00
|
|
|
$options = parse_ini_file(CONF, true);
|
2015-10-03 13:52:37 +00:00
|
|
|
$options['traffic']['limit'] = 0;
|
2016-08-09 09:54:42 +00:00
|
|
|
Helper::createIniFile(CONF, $options);
|
2019-05-13 20:31:52 +00:00
|
|
|
$paste = Helper::getPasteJson();
|
|
|
|
$file = tempnam(sys_get_temp_dir(), 'FOO');
|
|
|
|
file_put_contents($file, $paste);
|
|
|
|
Request::setInputStream($file);
|
2015-09-27 18:34:39 +00:00
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
2016-10-29 08:24:08 +00:00
|
|
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
2015-08-27 21:30:35 +00:00
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-08-27 21:30:35 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2015-08-27 21:30:35 +00:00
|
|
|
$response = json_decode($content, true);
|
2015-08-29 18:29:14 +00:00
|
|
|
$this->assertEquals(0, $response['status'], 'outputs status');
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->assertTrue($this->_data->exists($response['id']), 'paste exists after posting data');
|
|
|
|
$paste = $this->_data->read($response['id']);
|
2015-08-27 21:30:35 +00:00
|
|
|
$this->assertEquals(
|
2019-05-10 05:55:39 +00:00
|
|
|
hash_hmac('sha256', $response['id'], $paste['meta']['salt']),
|
2015-08-27 21:30:35 +00:00
|
|
|
$response['deletetoken'],
|
2015-08-29 18:29:14 +00:00
|
|
|
'outputs valid delete token'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-09-03 20:55:36 +00:00
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testCreateInvalidTimelimit()
|
|
|
|
{
|
2016-10-29 08:24:08 +00:00
|
|
|
$options = parse_ini_file(CONF, true);
|
2016-07-15 15:02:59 +00:00
|
|
|
$options['traffic']['limit'] = 0;
|
2016-08-09 09:54:42 +00:00
|
|
|
Helper::createIniFile(CONF, $options);
|
2019-05-13 20:31:52 +00:00
|
|
|
$paste = Helper::getPasteJson(2, array('expire' => 25));
|
|
|
|
$file = tempnam(sys_get_temp_dir(), 'FOO');
|
|
|
|
file_put_contents($file, $paste);
|
|
|
|
Request::setInputStream($file);
|
2015-09-27 18:34:39 +00:00
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
2016-10-29 08:24:08 +00:00
|
|
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
2016-08-09 09:54:42 +00:00
|
|
|
TrafficLimiter::canPass();
|
2015-09-03 20:55:36 +00:00
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-09-03 20:55:36 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2015-09-03 20:55:36 +00:00
|
|
|
$response = json_decode($content, true);
|
2016-07-15 15:02:59 +00:00
|
|
|
$this->assertEquals(0, $response['status'], 'outputs status');
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->assertTrue($this->_data->exists($response['id']), 'paste exists after posting data');
|
|
|
|
$paste = $this->_data->read($response['id']);
|
2016-07-15 15:02:59 +00:00
|
|
|
$this->assertEquals(
|
2019-05-10 05:55:39 +00:00
|
|
|
hash_hmac('sha256', $response['id'], $paste['meta']['salt']),
|
2016-07-15 15:02:59 +00:00
|
|
|
$response['deletetoken'],
|
|
|
|
'outputs valid delete token'
|
|
|
|
);
|
2015-09-03 20:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testCreateInvalidSize()
|
|
|
|
{
|
2016-10-29 08:24:08 +00:00
|
|
|
$options = parse_ini_file(CONF, true);
|
2015-09-03 20:55:36 +00:00
|
|
|
$options['main']['sizelimit'] = 10;
|
2016-10-29 08:24:08 +00:00
|
|
|
$options['traffic']['limit'] = 0;
|
2016-08-09 09:54:42 +00:00
|
|
|
Helper::createIniFile(CONF, $options);
|
2019-05-13 20:31:52 +00:00
|
|
|
$paste = Helper::getPasteJson();
|
|
|
|
$file = tempnam(sys_get_temp_dir(), 'FOO');
|
|
|
|
file_put_contents($file, $paste);
|
|
|
|
Request::setInputStream($file);
|
2015-09-27 18:34:39 +00:00
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
2016-10-29 08:24:08 +00:00
|
|
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
2015-09-03 20:55:36 +00:00
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-09-03 20:55:36 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2015-09-03 20:55:36 +00:00
|
|
|
$response = json_decode($content, true);
|
|
|
|
$this->assertEquals(1, $response['status'], 'outputs error status');
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->assertFalse($this->_data->exists(Helper::getPasteId()), 'paste exists after posting data');
|
2015-09-03 20:55:36 +00:00
|
|
|
}
|
|
|
|
|
2015-09-19 15:23:10 +00:00
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testCreateProxyHeader()
|
|
|
|
{
|
2016-10-29 08:24:08 +00:00
|
|
|
$options = parse_ini_file(CONF, true);
|
2015-09-19 15:23:10 +00:00
|
|
|
$options['traffic']['header'] = 'X_FORWARDED_FOR';
|
2016-08-09 09:54:42 +00:00
|
|
|
Helper::createIniFile(CONF, $options);
|
2019-05-13 20:31:52 +00:00
|
|
|
$paste = Helper::getPasteJson();
|
|
|
|
$file = tempnam(sys_get_temp_dir(), 'FOO');
|
|
|
|
file_put_contents($file, $paste);
|
|
|
|
Request::setInputStream($file);
|
2016-10-29 08:24:08 +00:00
|
|
|
$_SERVER['HTTP_X_FORWARDED_FOR'] = '::2';
|
2015-09-27 18:34:39 +00:00
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
2016-10-29 08:24:08 +00:00
|
|
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
2015-09-19 15:23:10 +00:00
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-09-19 15:23:10 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2015-09-19 15:23:10 +00:00
|
|
|
$response = json_decode($content, true);
|
2016-07-15 15:02:59 +00:00
|
|
|
$this->assertEquals(0, $response['status'], 'outputs status');
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->assertTrue($this->_data->exists($response['id']), 'paste exists after posting data');
|
|
|
|
$paste = $this->_data->read($response['id']);
|
2016-07-15 15:02:59 +00:00
|
|
|
$this->assertEquals(
|
2019-05-10 05:55:39 +00:00
|
|
|
hash_hmac('sha256', $response['id'], $paste['meta']['salt']),
|
2016-07-15 15:02:59 +00:00
|
|
|
$response['deletetoken'],
|
|
|
|
'outputs valid delete token'
|
|
|
|
);
|
2015-09-19 15:23:10 +00:00
|
|
|
}
|
|
|
|
|
2015-09-03 20:55:36 +00:00
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testCreateDuplicateId()
|
|
|
|
{
|
2016-10-29 08:24:08 +00:00
|
|
|
$options = parse_ini_file(CONF, true);
|
2015-09-03 20:55:36 +00:00
|
|
|
$options['traffic']['limit'] = 0;
|
2016-08-09 09:54:42 +00:00
|
|
|
Helper::createIniFile(CONF, $options);
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->_data->create(Helper::getPasteId(), Helper::getPaste());
|
2019-05-13 20:31:52 +00:00
|
|
|
$paste = Helper::getPasteJson();
|
|
|
|
$file = tempnam(sys_get_temp_dir(), 'FOO');
|
|
|
|
file_put_contents($file, $paste);
|
|
|
|
Request::setInputStream($file);
|
2015-09-27 18:34:39 +00:00
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
2016-10-29 08:24:08 +00:00
|
|
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
2015-09-03 20:55:36 +00:00
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-09-03 20:55:36 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2015-09-03 20:55:36 +00:00
|
|
|
$response = json_decode($content, true);
|
|
|
|
$this->assertEquals(1, $response['status'], 'outputs error status');
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->assertTrue($this->_data->exists(Helper::getPasteId()), 'paste exists after posting data');
|
2015-09-03 20:55:36 +00:00
|
|
|
}
|
|
|
|
|
2015-08-29 18:29:14 +00:00
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testCreateValidExpire()
|
|
|
|
{
|
2016-10-29 08:24:08 +00:00
|
|
|
$options = parse_ini_file(CONF, true);
|
2015-09-03 20:55:36 +00:00
|
|
|
$options['traffic']['limit'] = 0;
|
2016-08-09 09:54:42 +00:00
|
|
|
Helper::createIniFile(CONF, $options);
|
2019-05-13 20:31:52 +00:00
|
|
|
$paste = Helper::getPasteJson();
|
|
|
|
$file = tempnam(sys_get_temp_dir(), 'FOO');
|
|
|
|
file_put_contents($file, $paste);
|
|
|
|
Request::setInputStream($file);
|
2015-09-27 18:34:39 +00:00
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
2016-10-29 08:24:08 +00:00
|
|
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
|
|
|
$time = time();
|
2015-08-29 18:29:14 +00:00
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-08-29 18:29:14 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2015-08-29 18:29:14 +00:00
|
|
|
$response = json_decode($content, true);
|
|
|
|
$this->assertEquals(0, $response['status'], 'outputs status');
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->assertTrue($this->_data->exists($response['id']), 'paste exists after posting data');
|
|
|
|
$paste = $this->_data->read($response['id']);
|
2015-08-29 18:29:14 +00:00
|
|
|
$this->assertEquals(
|
2019-05-10 05:55:39 +00:00
|
|
|
hash_hmac('sha256', $response['id'], $paste['meta']['salt']),
|
2015-08-29 18:29:14 +00:00
|
|
|
$response['deletetoken'],
|
2015-08-27 21:30:35 +00:00
|
|
|
'outputs valid delete token'
|
|
|
|
);
|
2019-05-10 05:55:39 +00:00
|
|
|
$this->assertGreaterThanOrEqual($time + 300, $paste['meta']['expire_date'], 'time is set correctly');
|
2015-10-03 15:54:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testCreateValidExpireWithDiscussion()
|
|
|
|
{
|
2016-10-29 08:24:08 +00:00
|
|
|
$options = parse_ini_file(CONF, true);
|
2015-10-03 15:54:18 +00:00
|
|
|
$options['traffic']['limit'] = 0;
|
2016-08-09 09:54:42 +00:00
|
|
|
Helper::createIniFile(CONF, $options);
|
2019-05-13 20:31:52 +00:00
|
|
|
$paste = Helper::getPasteJson();
|
|
|
|
$file = tempnam(sys_get_temp_dir(), 'FOO');
|
|
|
|
file_put_contents($file, $paste);
|
|
|
|
Request::setInputStream($file);
|
2015-10-03 15:54:18 +00:00
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
2016-10-29 08:24:08 +00:00
|
|
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
|
|
|
$time = time();
|
2015-10-03 15:54:18 +00:00
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-10-03 15:54:18 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2015-10-03 15:54:18 +00:00
|
|
|
$response = json_decode($content, true);
|
|
|
|
$this->assertEquals(0, $response['status'], 'outputs status');
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->assertTrue($this->_data->exists($response['id']), 'paste exists after posting data');
|
|
|
|
$paste = $this->_data->read($response['id']);
|
2015-10-03 15:54:18 +00:00
|
|
|
$this->assertEquals(
|
2019-05-10 05:55:39 +00:00
|
|
|
hash_hmac('sha256', $response['id'], $paste['meta']['salt']),
|
2015-10-03 15:54:18 +00:00
|
|
|
$response['deletetoken'],
|
|
|
|
'outputs valid delete token'
|
|
|
|
);
|
2019-05-10 05:55:39 +00:00
|
|
|
$this->assertGreaterThanOrEqual($time + 300, $paste['meta']['expire_date'], 'time is set correctly');
|
|
|
|
$this->assertEquals(1, $paste['adata'][2], 'discussion is enabled');
|
2015-08-27 21:30:35 +00:00
|
|
|
}
|
|
|
|
|
2015-08-29 18:29:14 +00:00
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testCreateInvalidExpire()
|
|
|
|
{
|
2016-10-29 08:24:08 +00:00
|
|
|
$options = parse_ini_file(CONF, true);
|
2015-09-03 20:55:36 +00:00
|
|
|
$options['traffic']['limit'] = 0;
|
2016-08-09 09:54:42 +00:00
|
|
|
Helper::createIniFile(CONF, $options);
|
2019-05-13 20:31:52 +00:00
|
|
|
$paste = Helper::getPasteJson(2, array('expire' => 'foo'));
|
|
|
|
$file = tempnam(sys_get_temp_dir(), 'FOO');
|
|
|
|
file_put_contents($file, $paste);
|
|
|
|
Request::setInputStream($file);
|
2015-09-27 18:34:39 +00:00
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
2016-10-29 08:24:08 +00:00
|
|
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
2015-08-29 18:29:14 +00:00
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-08-29 18:29:14 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2015-08-29 18:29:14 +00:00
|
|
|
$response = json_decode($content, true);
|
|
|
|
$this->assertEquals(0, $response['status'], 'outputs status');
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->assertTrue($this->_data->exists($response['id']), 'paste exists after posting data');
|
|
|
|
$paste = $this->_data->read($response['id']);
|
2015-08-29 18:29:14 +00:00
|
|
|
$this->assertEquals(
|
2019-05-10 05:55:39 +00:00
|
|
|
hash_hmac('sha256', $response['id'], $paste['meta']['salt']),
|
2015-08-29 18:29:14 +00:00
|
|
|
$response['deletetoken'],
|
|
|
|
'outputs valid delete token'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testCreateInvalidBurn()
|
|
|
|
{
|
2016-10-29 08:24:08 +00:00
|
|
|
$options = parse_ini_file(CONF, true);
|
2015-09-03 20:55:36 +00:00
|
|
|
$options['traffic']['limit'] = 0;
|
2016-08-09 09:54:42 +00:00
|
|
|
Helper::createIniFile(CONF, $options);
|
2019-05-19 06:36:37 +00:00
|
|
|
$paste = Helper::getPastePost();
|
2019-05-13 20:31:52 +00:00
|
|
|
$paste['adata'][3] = 'neither 1 nor 0';
|
2019-05-19 06:36:37 +00:00
|
|
|
$file = tempnam(sys_get_temp_dir(), 'FOO');
|
2019-05-13 20:31:52 +00:00
|
|
|
file_put_contents($file, json_encode($paste));
|
|
|
|
Request::setInputStream($file);
|
2015-09-27 18:34:39 +00:00
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
2016-10-29 08:24:08 +00:00
|
|
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
2015-08-29 18:29:14 +00:00
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-08-29 18:29:14 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2015-08-29 18:29:14 +00:00
|
|
|
$response = json_decode($content, true);
|
|
|
|
$this->assertEquals(1, $response['status'], 'outputs error status');
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->assertFalse($this->_data->exists(Helper::getPasteId()), 'paste exists after posting data');
|
2015-08-29 18:29:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testCreateInvalidOpenDiscussion()
|
|
|
|
{
|
2016-10-29 08:24:08 +00:00
|
|
|
$options = parse_ini_file(CONF, true);
|
2015-09-03 20:55:36 +00:00
|
|
|
$options['traffic']['limit'] = 0;
|
2016-08-09 09:54:42 +00:00
|
|
|
Helper::createIniFile(CONF, $options);
|
2019-05-19 06:36:37 +00:00
|
|
|
$paste = Helper::getPastePost();
|
2019-05-13 20:31:52 +00:00
|
|
|
$paste['adata'][2] = 'neither 1 nor 0';
|
2019-05-19 06:36:37 +00:00
|
|
|
$file = tempnam(sys_get_temp_dir(), 'FOO');
|
2019-05-13 20:31:52 +00:00
|
|
|
file_put_contents($file, json_encode($paste));
|
|
|
|
Request::setInputStream($file);
|
2015-09-27 18:34:39 +00:00
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
2016-10-29 08:24:08 +00:00
|
|
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
2015-08-29 18:29:14 +00:00
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-08-29 18:29:14 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2015-08-29 18:29:14 +00:00
|
|
|
$response = json_decode($content, true);
|
|
|
|
$this->assertEquals(1, $response['status'], 'outputs error status');
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->assertFalse($this->_data->exists(Helper::getPasteId()), 'paste exists after posting data');
|
2015-08-29 18:29:14 +00:00
|
|
|
}
|
|
|
|
|
2016-07-19 13:26:41 +00:00
|
|
|
/**
|
|
|
|
* In some webserver setups (found with Suhosin) overly long POST params are
|
|
|
|
* silently removed, check that this case is handled
|
|
|
|
*
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
2019-05-10 05:55:39 +00:00
|
|
|
public function testCreateBrokenUpload()
|
2016-07-19 13:26:41 +00:00
|
|
|
{
|
2019-05-13 20:31:52 +00:00
|
|
|
$paste = substr(Helper::getPasteJson(), 0, -10);
|
|
|
|
$file = tempnam(sys_get_temp_dir(), 'FOO');
|
|
|
|
file_put_contents($file, $paste);
|
|
|
|
Request::setInputStream($file);
|
2016-07-19 13:26:41 +00:00
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
2016-10-29 08:24:08 +00:00
|
|
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->assertFalse($this->_data->exists(Helper::getPasteId()), 'paste does not exists before posting data');
|
2022-12-12 19:46:47 +00:00
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2022-12-12 19:46:47 +00:00
|
|
|
$content = ob_get_contents();
|
|
|
|
ob_end_clean();
|
|
|
|
$response = json_decode($content, true);
|
|
|
|
$this->assertEquals(1, $response['status'], 'outputs error status');
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->assertFalse($this->_data->exists(Helper::getPasteId()), 'paste exists after posting data');
|
2016-07-19 13:26:41 +00:00
|
|
|
}
|
|
|
|
|
2016-07-18 12:47:32 +00:00
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testCreateTooSoon()
|
|
|
|
{
|
2019-05-13 20:31:52 +00:00
|
|
|
$paste = Helper::getPasteJson();
|
|
|
|
$file = tempnam(sys_get_temp_dir(), 'FOO');
|
|
|
|
file_put_contents($file, $paste);
|
|
|
|
Request::setInputStream($file);
|
2016-07-18 12:47:32 +00:00
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
2016-10-29 08:24:08 +00:00
|
|
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
2016-07-18 12:47:32 +00:00
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2016-07-18 12:47:32 +00:00
|
|
|
ob_end_clean();
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->_data->delete(Helper::getPasteId());
|
2016-07-18 12:47:32 +00:00
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2016-07-18 12:47:32 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2016-07-18 12:47:32 +00:00
|
|
|
$response = json_decode($content, true);
|
|
|
|
$this->assertEquals(1, $response['status'], 'outputs error status');
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->assertFalse($this->_data->exists(Helper::getPasteId()), 'paste exists after posting data');
|
2016-07-18 12:47:32 +00:00
|
|
|
}
|
|
|
|
|
2021-06-13 08:44:26 +00:00
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testCreateInvalidFormat()
|
|
|
|
{
|
|
|
|
$options = parse_ini_file(CONF, true);
|
|
|
|
$options['traffic']['limit'] = 0;
|
|
|
|
Helper::createIniFile(CONF, $options);
|
|
|
|
$file = tempnam(sys_get_temp_dir(), 'FOO');
|
|
|
|
file_put_contents($file, Helper::getPasteJson(1));
|
|
|
|
Request::setInputStream($file);
|
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
|
|
|
ob_start();
|
|
|
|
new Controller;
|
|
|
|
$content = ob_get_contents();
|
|
|
|
ob_end_clean();
|
|
|
|
$response = json_decode($content, true);
|
|
|
|
$this->assertEquals(1, $response['status'], 'outputs error status');
|
|
|
|
$this->assertFalse($this->_data->exists(Helper::getPasteId()), 'paste exists after posting data');
|
|
|
|
}
|
|
|
|
|
2015-08-29 18:29:14 +00:00
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testCreateComment()
|
|
|
|
{
|
2016-10-29 08:24:08 +00:00
|
|
|
$options = parse_ini_file(CONF, true);
|
2015-09-03 20:55:36 +00:00
|
|
|
$options['traffic']['limit'] = 0;
|
2016-08-09 09:54:42 +00:00
|
|
|
Helper::createIniFile(CONF, $options);
|
2019-05-13 20:31:52 +00:00
|
|
|
$comment = Helper::getCommentJson();
|
2019-05-19 06:36:37 +00:00
|
|
|
$file = tempnam(sys_get_temp_dir(), 'FOO');
|
2019-05-13 20:31:52 +00:00
|
|
|
file_put_contents($file, $comment);
|
|
|
|
Request::setInputStream($file);
|
2015-09-27 18:34:39 +00:00
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
2016-10-29 08:24:08 +00:00
|
|
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->_data->create(Helper::getPasteId(), Helper::getPaste());
|
2015-08-29 18:29:14 +00:00
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-08-29 18:29:14 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2015-08-29 18:29:14 +00:00
|
|
|
$response = json_decode($content, true);
|
|
|
|
$this->assertEquals(0, $response['status'], 'outputs status');
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->assertTrue($this->_data->existsComment(Helper::getPasteId(), Helper::getPasteId(), $response['id']), 'paste exists after posting data');
|
2015-08-29 18:29:14 +00:00
|
|
|
}
|
|
|
|
|
2015-09-03 20:55:36 +00:00
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testCreateInvalidComment()
|
|
|
|
{
|
2016-10-29 08:24:08 +00:00
|
|
|
$options = parse_ini_file(CONF, true);
|
2015-09-03 20:55:36 +00:00
|
|
|
$options['traffic']['limit'] = 0;
|
2016-08-09 09:54:42 +00:00
|
|
|
Helper::createIniFile(CONF, $options);
|
2019-05-19 06:36:37 +00:00
|
|
|
$comment = Helper::getCommentPost();
|
2019-05-13 20:31:52 +00:00
|
|
|
$comment['parentid'] = 'foo';
|
2019-05-19 06:36:37 +00:00
|
|
|
$file = tempnam(sys_get_temp_dir(), 'FOO');
|
2019-05-13 20:31:52 +00:00
|
|
|
file_put_contents($file, json_encode($comment));
|
|
|
|
Request::setInputStream($file);
|
2015-09-27 18:34:39 +00:00
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
2016-10-29 08:24:08 +00:00
|
|
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->_data->create(Helper::getPasteId(), Helper::getPaste());
|
2015-09-03 20:55:36 +00:00
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-09-03 20:55:36 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2015-09-03 20:55:36 +00:00
|
|
|
$response = json_decode($content, true);
|
|
|
|
$this->assertEquals(1, $response['status'], 'outputs error status');
|
2021-06-13 08:44:26 +00:00
|
|
|
$this->assertFalse($this->_data->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId()), 'comment exists after posting data');
|
2015-09-03 20:55:36 +00:00
|
|
|
}
|
|
|
|
|
2015-08-29 18:29:14 +00:00
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testCreateCommentDiscussionDisabled()
|
|
|
|
{
|
2016-10-29 08:24:08 +00:00
|
|
|
$options = parse_ini_file(CONF, true);
|
2015-09-03 20:55:36 +00:00
|
|
|
$options['traffic']['limit'] = 0;
|
2016-08-09 09:54:42 +00:00
|
|
|
Helper::createIniFile(CONF, $options);
|
2019-05-13 20:31:52 +00:00
|
|
|
$comment = Helper::getCommentJson();
|
2019-05-19 06:36:37 +00:00
|
|
|
$file = tempnam(sys_get_temp_dir(), 'FOO');
|
2019-05-13 20:31:52 +00:00
|
|
|
file_put_contents($file, $comment);
|
|
|
|
Request::setInputStream($file);
|
2015-09-27 18:34:39 +00:00
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
2016-10-29 08:24:08 +00:00
|
|
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
2019-05-10 05:55:39 +00:00
|
|
|
$paste = Helper::getPaste();
|
2019-05-10 19:45:34 +00:00
|
|
|
$paste['adata'][2] = 0;
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->_data->create(Helper::getPasteId(), $paste);
|
2015-08-29 18:29:14 +00:00
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-08-29 18:29:14 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2015-08-29 18:29:14 +00:00
|
|
|
$response = json_decode($content, true);
|
|
|
|
$this->assertEquals(1, $response['status'], 'outputs error status');
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->assertFalse($this->_data->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId()), 'paste exists after posting data');
|
2015-08-29 18:29:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testCreateCommentInvalidPaste()
|
|
|
|
{
|
2016-10-29 08:24:08 +00:00
|
|
|
$options = parse_ini_file(CONF, true);
|
2015-09-03 20:55:36 +00:00
|
|
|
$options['traffic']['limit'] = 0;
|
2016-08-09 09:54:42 +00:00
|
|
|
Helper::createIniFile(CONF, $options);
|
2019-05-13 20:31:52 +00:00
|
|
|
$comment = Helper::getCommentJson();
|
2019-05-19 06:36:37 +00:00
|
|
|
$file = tempnam(sys_get_temp_dir(), 'FOO');
|
2019-05-13 20:31:52 +00:00
|
|
|
file_put_contents($file, $comment);
|
|
|
|
Request::setInputStream($file);
|
2015-09-27 18:34:39 +00:00
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
2016-10-29 08:24:08 +00:00
|
|
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
2015-08-29 18:29:14 +00:00
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-08-29 18:29:14 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2015-08-29 18:29:14 +00:00
|
|
|
$response = json_decode($content, true);
|
|
|
|
$this->assertEquals(1, $response['status'], 'outputs error status');
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->assertFalse($this->_data->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId()), 'paste exists after posting data');
|
2015-08-29 18:29:14 +00:00
|
|
|
}
|
|
|
|
|
2015-09-03 20:55:36 +00:00
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testCreateDuplicateComment()
|
|
|
|
{
|
2016-10-29 08:24:08 +00:00
|
|
|
$options = parse_ini_file(CONF, true);
|
2015-09-03 20:55:36 +00:00
|
|
|
$options['traffic']['limit'] = 0;
|
2016-08-09 09:54:42 +00:00
|
|
|
Helper::createIniFile(CONF, $options);
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->_data->create(Helper::getPasteId(), Helper::getPaste());
|
|
|
|
$this->_data->createComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getPasteId(), Helper::getComment());
|
|
|
|
$this->assertTrue($this->_data->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getPasteId()), 'comment exists before posting data');
|
2019-05-13 20:31:52 +00:00
|
|
|
$comment = Helper::getCommentJson();
|
2019-05-19 06:36:37 +00:00
|
|
|
$file = tempnam(sys_get_temp_dir(), 'FOO');
|
2019-05-13 20:31:52 +00:00
|
|
|
file_put_contents($file, $comment);
|
|
|
|
Request::setInputStream($file);
|
2015-09-27 18:34:39 +00:00
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
2016-10-29 08:24:08 +00:00
|
|
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
2015-09-03 20:55:36 +00:00
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-09-03 20:55:36 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2015-09-03 20:55:36 +00:00
|
|
|
$response = json_decode($content, true);
|
|
|
|
$this->assertEquals(1, $response['status'], 'outputs error status');
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->assertTrue($this->_data->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getPasteId()), 'paste exists after posting data');
|
2015-09-03 20:55:36 +00:00
|
|
|
}
|
|
|
|
|
2015-08-29 18:29:14 +00:00
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testReadInvalidId()
|
|
|
|
{
|
2018-05-27 12:36:30 +00:00
|
|
|
$_SERVER['QUERY_STRING'] = 'foo';
|
2019-01-21 23:12:02 +00:00
|
|
|
$_GET['foo'] = '';
|
2018-05-27 12:36:30 +00:00
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
2015-08-29 18:29:14 +00:00
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-08-29 18:29:14 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2018-05-27 12:36:30 +00:00
|
|
|
$response = json_decode($content, true);
|
|
|
|
$this->assertEquals(1, $response['status'], 'outputs error status');
|
|
|
|
$this->assertEquals('Invalid paste ID.', $response['message'], 'outputs error message');
|
2015-08-29 18:29:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testReadNonexisting()
|
|
|
|
{
|
2018-05-27 12:36:30 +00:00
|
|
|
$_SERVER['QUERY_STRING'] = Helper::getPasteId();
|
2019-01-21 22:49:33 +00:00
|
|
|
$_GET[Helper::getPasteId()] = '';
|
2018-05-27 12:36:30 +00:00
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
2015-08-29 18:29:14 +00:00
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-08-29 18:29:14 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2018-05-27 12:36:30 +00:00
|
|
|
$response = json_decode($content, true);
|
|
|
|
$this->assertEquals(1, $response['status'], 'outputs error status');
|
|
|
|
$this->assertEquals('Paste does not exist, has expired or has been deleted.', $response['message'], 'outputs error message');
|
2015-08-29 18:29:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testReadExpired()
|
|
|
|
{
|
2019-05-10 05:55:39 +00:00
|
|
|
$expiredPaste = Helper::getPaste(2, array('expire_date' => 1344803344));
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->_data->create(Helper::getPasteId(), $expiredPaste);
|
2018-05-27 12:16:47 +00:00
|
|
|
$_SERVER['QUERY_STRING'] = Helper::getPasteId();
|
2019-01-21 22:49:33 +00:00
|
|
|
$_GET[Helper::getPasteId()] = '';
|
2018-05-27 12:10:54 +00:00
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
2015-08-29 18:29:14 +00:00
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-08-29 18:29:14 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2018-05-27 12:10:54 +00:00
|
|
|
$response = json_decode($content, true);
|
|
|
|
$this->assertEquals(1, $response['status'], 'outputs error status');
|
|
|
|
$this->assertEquals('Paste does not exist, has expired or has been deleted.', $response['message'], 'outputs error message');
|
2015-08-29 18:29:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testReadBurn()
|
|
|
|
{
|
2019-05-10 19:45:34 +00:00
|
|
|
$paste = Helper::getPaste();
|
2019-05-10 05:55:39 +00:00
|
|
|
$paste['adata'][3] = 1;
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->_data->create(Helper::getPasteId(), $paste);
|
2018-04-30 18:01:38 +00:00
|
|
|
$_SERVER['QUERY_STRING'] = Helper::getPasteId();
|
2019-01-21 22:49:33 +00:00
|
|
|
$_GET[Helper::getPasteId()] = '';
|
2018-04-30 18:01:38 +00:00
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
2015-08-29 18:29:14 +00:00
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-08-29 18:29:14 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2018-04-30 18:01:38 +00:00
|
|
|
$response = json_decode($content, true);
|
|
|
|
$this->assertEquals(0, $response['status'], 'outputs success status');
|
|
|
|
$this->assertEquals(Helper::getPasteId(), $response['id'], 'outputs data correctly');
|
|
|
|
$this->assertStringEndsWith('?' . $response['id'], $response['url'], 'returned URL points to new paste');
|
2019-05-10 05:55:39 +00:00
|
|
|
$this->assertEquals($paste['ct'], $response['ct'], 'outputs ct correctly');
|
|
|
|
$this->assertEquals($paste['adata'][1], $response['adata'][1], 'outputs formatter correctly');
|
|
|
|
$this->assertEquals($paste['adata'][2], $response['adata'][2], 'outputs opendiscussion correctly');
|
|
|
|
$this->assertEquals($paste['adata'][3], $response['adata'][3], 'outputs burnafterreading correctly');
|
|
|
|
$this->assertEquals($paste['meta']['created'], $response['meta']['created'], 'outputs created correctly');
|
2018-04-30 18:01:38 +00:00
|
|
|
$this->assertEquals(0, $response['comment_count'], 'outputs comment_count correctly');
|
|
|
|
$this->assertEquals(0, $response['comment_offset'], 'outputs comment_offset correctly');
|
|
|
|
// by default it will be deleted instantly after it is read
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->assertFalse($this->_data->exists(Helper::getPasteId()), 'paste exists after reading');
|
2015-08-29 18:29:14 +00:00
|
|
|
}
|
|
|
|
|
2015-09-01 20:33:07 +00:00
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testReadJson()
|
|
|
|
{
|
2016-08-09 09:54:42 +00:00
|
|
|
$paste = Helper::getPaste();
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->_data->create(Helper::getPasteId(), $paste);
|
2016-10-29 08:24:08 +00:00
|
|
|
$_SERVER['QUERY_STRING'] = Helper::getPasteId();
|
2019-01-21 22:49:33 +00:00
|
|
|
$_GET[Helper::getPasteId()] = '';
|
2015-09-27 18:34:39 +00:00
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
2015-09-01 20:33:07 +00:00
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-09-01 20:33:07 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2015-09-01 20:33:07 +00:00
|
|
|
$response = json_decode($content, true);
|
|
|
|
$this->assertEquals(0, $response['status'], 'outputs success status');
|
2016-08-09 09:54:42 +00:00
|
|
|
$this->assertEquals(Helper::getPasteId(), $response['id'], 'outputs data correctly');
|
2015-10-18 09:08:28 +00:00
|
|
|
$this->assertStringEndsWith('?' . $response['id'], $response['url'], 'returned URL points to new paste');
|
2019-05-10 05:55:39 +00:00
|
|
|
$this->assertEquals($paste['ct'], $response['ct'], 'outputs ct correctly');
|
|
|
|
$this->assertEquals($paste['adata'][1], $response['adata'][1], 'outputs formatter correctly');
|
|
|
|
$this->assertEquals($paste['adata'][2], $response['adata'][2], 'outputs opendiscussion correctly');
|
|
|
|
$this->assertEquals($paste['adata'][3], $response['adata'][3], 'outputs burnafterreading correctly');
|
|
|
|
$this->assertEquals($paste['meta']['created'], $response['meta']['created'], 'outputs created correctly');
|
2015-10-18 09:08:28 +00:00
|
|
|
$this->assertEquals(0, $response['comment_count'], 'outputs comment_count correctly');
|
|
|
|
$this->assertEquals(0, $response['comment_offset'], 'outputs comment_offset correctly');
|
2015-09-01 20:33:07 +00:00
|
|
|
}
|
|
|
|
|
2015-09-19 15:23:10 +00:00
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testReadOldSyntax()
|
|
|
|
{
|
2019-05-10 05:55:39 +00:00
|
|
|
$paste = Helper::getPaste(1);
|
2018-04-30 18:01:38 +00:00
|
|
|
$paste['meta'] = array(
|
2015-10-03 13:52:37 +00:00
|
|
|
'syntaxcoloring' => true,
|
2018-04-30 18:01:38 +00:00
|
|
|
'postdate' => $paste['meta']['postdate'],
|
|
|
|
'opendiscussion' => $paste['meta']['opendiscussion'],
|
2015-09-19 15:23:10 +00:00
|
|
|
);
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->_data->create(Helper::getPasteId(), $paste);
|
2018-04-30 18:01:38 +00:00
|
|
|
$_SERVER['QUERY_STRING'] = Helper::getPasteId();
|
2019-01-21 22:49:33 +00:00
|
|
|
$_GET[Helper::getPasteId()] = '';
|
2018-04-30 18:01:38 +00:00
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
2015-09-19 15:23:10 +00:00
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-09-19 15:23:10 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2018-04-30 18:01:38 +00:00
|
|
|
$response = json_decode($content, true);
|
|
|
|
$this->assertEquals(0, $response['status'], 'outputs success status');
|
|
|
|
$this->assertEquals(Helper::getPasteId(), $response['id'], 'outputs data correctly');
|
|
|
|
$this->assertStringEndsWith('?' . $response['id'], $response['url'], 'returned URL points to new paste');
|
|
|
|
$this->assertEquals($paste['data'], $response['data'], 'outputs data correctly');
|
|
|
|
$this->assertEquals('syntaxhighlighting', $response['meta']['formatter'], 'outputs format correctly');
|
|
|
|
$this->assertEquals($paste['meta']['postdate'], $response['meta']['postdate'], 'outputs postdate correctly');
|
|
|
|
$this->assertEquals($paste['meta']['opendiscussion'], $response['meta']['opendiscussion'], 'outputs opendiscussion correctly');
|
|
|
|
$this->assertEquals(0, $response['comment_count'], 'outputs comment_count correctly');
|
|
|
|
$this->assertEquals(0, $response['comment_offset'], 'outputs comment_offset correctly');
|
2015-09-19 15:23:10 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 05:55:39 +00:00
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testReadBurnAfterReading()
|
|
|
|
{
|
2019-05-10 19:45:34 +00:00
|
|
|
$burnPaste = Helper::getPaste();
|
2019-05-10 05:55:39 +00:00
|
|
|
$burnPaste['adata'][3] = 1;
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->_data->create(Helper::getPasteId(), $burnPaste);
|
|
|
|
$this->assertTrue($this->_data->exists(Helper::getPasteId()), 'paste exists before deleting data');
|
2019-05-10 05:55:39 +00:00
|
|
|
$_SERVER['QUERY_STRING'] = Helper::getPasteId();
|
|
|
|
$_GET[Helper::getPasteId()] = '';
|
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
|
|
|
ob_start();
|
|
|
|
new Controller;
|
|
|
|
$content = ob_get_contents();
|
|
|
|
ob_end_clean();
|
|
|
|
$response = json_decode($content, true);
|
|
|
|
$this->assertEquals(0, $response['status'], 'outputs status');
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->assertFalse($this->_data->exists(Helper::getPasteId()), 'paste successfully deleted');
|
2019-05-10 05:55:39 +00:00
|
|
|
}
|
|
|
|
|
2015-08-27 21:30:35 +00:00
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testDelete()
|
|
|
|
{
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->_data->create(Helper::getPasteId(), Helper::getPaste());
|
|
|
|
$this->assertTrue($this->_data->exists(Helper::getPasteId()), 'paste exists before deleting data');
|
|
|
|
$paste = $this->_data->read(Helper::getPasteId());
|
2016-10-29 08:24:08 +00:00
|
|
|
$_GET['pasteid'] = Helper::getPasteId();
|
2019-05-10 05:55:39 +00:00
|
|
|
$_GET['deletetoken'] = hash_hmac('sha256', Helper::getPasteId(), $paste['meta']['salt']);
|
2015-08-27 21:30:35 +00:00
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-08-27 21:30:35 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2020-10-11 08:31:24 +00:00
|
|
|
$this->assertMatchesRegularExpression(
|
2017-03-12 13:16:08 +00:00
|
|
|
'#<div[^>]*id="status"[^>]*>.*Paste was properly deleted\.#s',
|
2015-08-27 21:30:35 +00:00
|
|
|
$content,
|
|
|
|
'outputs deleted status correctly'
|
|
|
|
);
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->assertFalse($this->_data->exists(Helper::getPasteId()), 'paste successfully deleted');
|
2015-08-27 21:30:35 +00:00
|
|
|
}
|
2015-08-29 18:29:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testDeleteInvalidId()
|
|
|
|
{
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->_data->create(Helper::getPasteId(), Helper::getPaste());
|
2016-10-29 08:24:08 +00:00
|
|
|
$_GET['pasteid'] = 'foo';
|
2015-08-29 18:29:14 +00:00
|
|
|
$_GET['deletetoken'] = 'bar';
|
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-08-29 18:29:14 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2020-10-11 08:31:24 +00:00
|
|
|
$this->assertMatchesRegularExpression(
|
2017-03-12 13:16:08 +00:00
|
|
|
'#<div[^>]*id="errormessage"[^>]*>.*Invalid paste ID\.#s',
|
2015-08-29 18:29:14 +00:00
|
|
|
$content,
|
|
|
|
'outputs delete error correctly'
|
|
|
|
);
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->assertTrue($this->_data->exists(Helper::getPasteId()), 'paste exists after failing to delete data');
|
2015-08-29 18:29:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testDeleteInexistantId()
|
|
|
|
{
|
2016-10-29 08:24:08 +00:00
|
|
|
$_GET['pasteid'] = Helper::getPasteId();
|
2015-08-29 18:29:14 +00:00
|
|
|
$_GET['deletetoken'] = 'bar';
|
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-08-29 18:29:14 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2020-10-11 08:31:24 +00:00
|
|
|
$this->assertMatchesRegularExpression(
|
2017-03-12 13:16:08 +00:00
|
|
|
'#<div[^>]*id="errormessage"[^>]*>.*Paste does not exist, has expired or has been deleted\.#s',
|
2015-08-29 18:29:14 +00:00
|
|
|
$content,
|
|
|
|
'outputs delete error correctly'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testDeleteInvalidToken()
|
|
|
|
{
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->_data->create(Helper::getPasteId(), Helper::getPaste());
|
2016-10-29 08:24:08 +00:00
|
|
|
$_GET['pasteid'] = Helper::getPasteId();
|
2015-08-29 18:29:14 +00:00
|
|
|
$_GET['deletetoken'] = 'bar';
|
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-08-29 18:29:14 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2020-10-11 08:31:24 +00:00
|
|
|
$this->assertMatchesRegularExpression(
|
2017-03-12 13:16:08 +00:00
|
|
|
'#<div[^>]*id="errormessage"[^>]*>.*Wrong deletion token\. Paste was not deleted\.#s',
|
2015-08-29 18:29:14 +00:00
|
|
|
$content,
|
|
|
|
'outputs delete error correctly'
|
|
|
|
);
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->assertTrue($this->_data->exists(Helper::getPasteId()), 'paste exists after failing to delete data');
|
2015-08-29 18:29:14 +00:00
|
|
|
}
|
2015-08-31 20:10:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testDeleteInvalidBurnAfterReading()
|
|
|
|
{
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->_data->create(Helper::getPasteId(), Helper::getPaste());
|
|
|
|
$this->assertTrue($this->_data->exists(Helper::getPasteId()), 'paste exists before deleting data');
|
2019-05-13 20:31:52 +00:00
|
|
|
$file = tempnam(sys_get_temp_dir(), 'FOO');
|
|
|
|
file_put_contents($file, json_encode(array(
|
|
|
|
'deletetoken' => 'burnafterreading',
|
|
|
|
)));
|
|
|
|
Request::setInputStream($file);
|
2016-10-29 08:24:08 +00:00
|
|
|
$_SERVER['QUERY_STRING'] = Helper::getPasteId();
|
2019-01-21 22:49:33 +00:00
|
|
|
$_GET[Helper::getPasteId()] = '';
|
2015-09-27 18:34:39 +00:00
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
2016-10-29 08:24:08 +00:00
|
|
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
2015-08-31 20:10:41 +00:00
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-08-31 20:10:41 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2015-08-31 20:10:41 +00:00
|
|
|
$response = json_decode($content, true);
|
|
|
|
$this->assertEquals(1, $response['status'], 'outputs status');
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->assertTrue($this->_data->exists(Helper::getPasteId()), 'paste exists after failing to delete data');
|
2015-08-31 20:10:41 +00:00
|
|
|
}
|
2015-09-03 20:55:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testDeleteExpired()
|
|
|
|
{
|
2019-05-10 05:55:39 +00:00
|
|
|
$expiredPaste = Helper::getPaste(2, array('expire_date' => 1000));
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->assertFalse($this->_data->exists(Helper::getPasteId()), 'paste does not exist before being created');
|
|
|
|
$this->_data->create(Helper::getPasteId(), $expiredPaste);
|
|
|
|
$this->assertTrue($this->_data->exists(Helper::getPasteId()), 'paste exists before deleting data');
|
2016-10-29 08:24:08 +00:00
|
|
|
$_GET['pasteid'] = Helper::getPasteId();
|
2015-09-06 17:21:17 +00:00
|
|
|
$_GET['deletetoken'] = 'does not matter in this context, but has to be set';
|
2015-09-03 20:55:36 +00:00
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2015-09-03 20:55:36 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2020-10-11 08:31:24 +00:00
|
|
|
$this->assertMatchesRegularExpression(
|
2017-03-12 13:16:08 +00:00
|
|
|
'#<div[^>]*id="errormessage"[^>]*>.*Paste does not exist, has expired or has been deleted\.#s',
|
2015-09-03 20:55:36 +00:00
|
|
|
$content,
|
|
|
|
'outputs error correctly'
|
|
|
|
);
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->assertFalse($this->_data->exists(Helper::getPasteId()), 'paste successfully deleted');
|
2015-09-03 20:55:36 +00:00
|
|
|
}
|
2016-07-06 09:37:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testDeleteMissingPerPasteSalt()
|
|
|
|
{
|
2016-08-09 09:54:42 +00:00
|
|
|
$paste = Helper::getPaste();
|
2016-07-06 09:37:13 +00:00
|
|
|
unset($paste['meta']['salt']);
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->_data->create(Helper::getPasteId(), $paste);
|
|
|
|
$this->assertTrue($this->_data->exists(Helper::getPasteId()), 'paste exists before deleting data');
|
2016-10-29 08:24:08 +00:00
|
|
|
$_GET['pasteid'] = Helper::getPasteId();
|
2016-08-09 09:54:42 +00:00
|
|
|
$_GET['deletetoken'] = hash_hmac('sha256', Helper::getPasteId(), ServerSalt::get());
|
2016-07-06 09:37:13 +00:00
|
|
|
ob_start();
|
2018-07-29 13:17:35 +00:00
|
|
|
new Controller;
|
2016-07-06 09:37:13 +00:00
|
|
|
$content = ob_get_contents();
|
2016-08-02 08:29:25 +00:00
|
|
|
ob_end_clean();
|
2020-10-11 08:31:24 +00:00
|
|
|
$this->assertMatchesRegularExpression(
|
2017-03-12 13:16:08 +00:00
|
|
|
'#<div[^>]*id="status"[^>]*>.*Paste was properly deleted\.#s',
|
2016-07-06 09:37:13 +00:00
|
|
|
$content,
|
|
|
|
'outputs deleted status correctly'
|
|
|
|
);
|
2019-05-15 05:44:03 +00:00
|
|
|
$this->assertFalse($this->_data->exists(Helper::getPasteId()), 'paste successfully deleted');
|
2016-07-06 09:37:13 +00:00
|
|
|
}
|
2016-07-05 15:23:25 +00:00
|
|
|
}
|