2015-08-27 15:41:21 -04:00
|
|
|
<?php
|
2016-07-21 11:09:48 -04:00
|
|
|
|
2020-10-10 06:08:58 -04:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2018-07-29 09:17:35 -04:00
|
|
|
use PrivateBin\Controller;
|
2018-07-29 10:15:52 -04:00
|
|
|
use PrivateBin\Data\Database;
|
2021-06-09 01:47:40 -04:00
|
|
|
use PrivateBin\Data\Filesystem;
|
|
|
|
use PrivateBin\Persistence\ServerSalt;
|
2016-07-21 11:09:48 -04:00
|
|
|
|
2020-10-10 06:08:58 -04:00
|
|
|
class DatabaseTest extends TestCase
|
2015-08-27 15:41:21 -04:00
|
|
|
{
|
|
|
|
private $_model;
|
|
|
|
|
2016-08-09 05:54:42 -04:00
|
|
|
private $_path;
|
|
|
|
|
2015-09-27 08:36:20 -04:00
|
|
|
private $_options = array(
|
|
|
|
'dsn' => 'sqlite::memory:',
|
|
|
|
'usr' => null,
|
|
|
|
'pwd' => null,
|
|
|
|
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION),
|
|
|
|
);
|
|
|
|
|
2020-10-10 06:22:20 -04:00
|
|
|
public function setUp(): void
|
2015-08-27 15:41:21 -04:00
|
|
|
{
|
|
|
|
/* Setup Routine */
|
2016-10-29 04:24:08 -04:00
|
|
|
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
|
2022-10-27 19:01:02 -04:00
|
|
|
$this->_model = new Database($this->_options);
|
2015-08-27 15:41:21 -04:00
|
|
|
}
|
|
|
|
|
2020-10-10 06:22:20 -04:00
|
|
|
public function tearDown(): void
|
2016-07-15 11:02:59 -04:00
|
|
|
{
|
|
|
|
/* Tear Down Routine */
|
2016-08-09 05:54:42 -04:00
|
|
|
if (is_dir($this->_path)) {
|
|
|
|
Helper::rmDir($this->_path);
|
2016-07-26 02:19:35 -04:00
|
|
|
}
|
2016-07-15 11:02:59 -04:00
|
|
|
}
|
|
|
|
|
2021-06-09 01:47:40 -04:00
|
|
|
public function testSaltMigration()
|
|
|
|
{
|
2022-10-27 19:01:02 -04:00
|
|
|
ServerSalt::setStore(new Filesystem(array('dir' => 'data')));
|
2021-06-09 01:47:40 -04:00
|
|
|
$salt = ServerSalt::get();
|
|
|
|
$file = 'data' . DIRECTORY_SEPARATOR . 'salt.php';
|
|
|
|
$this->assertFileExists($file, 'ServerSalt got initialized and stored on disk');
|
|
|
|
$this->assertNotEquals($salt, '');
|
|
|
|
ServerSalt::setStore($this->_model);
|
|
|
|
ServerSalt::get();
|
2021-10-07 16:34:15 -04:00
|
|
|
$this->assertFileDoesNotExist($file, 'legacy ServerSalt got removed');
|
2021-06-09 01:47:40 -04:00
|
|
|
$this->assertEquals($salt, ServerSalt::get(), 'ServerSalt got preserved & migrated');
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:41:21 -04:00
|
|
|
public function testDatabaseBasedDataStoreWorks()
|
|
|
|
{
|
2016-08-09 05:54:42 -04:00
|
|
|
$this->_model->delete(Helper::getPasteId());
|
2015-09-26 06:29:27 -04:00
|
|
|
|
|
|
|
// storing pastes
|
2019-05-05 08:36:47 -04:00
|
|
|
$paste = Helper::getPaste();
|
2016-08-09 05:54:42 -04:00
|
|
|
$this->assertFalse($this->_model->exists(Helper::getPasteId()), 'paste does not yet exist');
|
|
|
|
$this->assertTrue($this->_model->create(Helper::getPasteId(), $paste), 'store new paste');
|
|
|
|
$this->assertTrue($this->_model->exists(Helper::getPasteId()), 'paste exists after storing it');
|
|
|
|
$this->assertFalse($this->_model->create(Helper::getPasteId(), $paste), 'unable to store the same paste twice');
|
2019-05-05 15:03:58 -04:00
|
|
|
$this->assertEquals($paste, $this->_model->read(Helper::getPasteId()));
|
2015-08-27 15:41:21 -04:00
|
|
|
|
|
|
|
// storing comments
|
2019-05-05 08:36:47 -04:00
|
|
|
$this->assertFalse($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId()), 'v1 comment does not yet exist');
|
|
|
|
$this->assertTrue($this->_model->createComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId(), Helper::getComment(1)) !== false, 'store v1 comment');
|
|
|
|
$this->assertTrue($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId()), 'v1 comment exists after storing it');
|
|
|
|
$this->assertFalse($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getPasteId()), 'v2 comment does not yet exist');
|
|
|
|
$this->assertTrue($this->_model->createComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getPasteId(), Helper::getComment(2)) !== false, 'store v2 comment');
|
|
|
|
$this->assertTrue($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getPasteId()), 'v2 comment exists after storing it');
|
2019-05-05 15:03:58 -04:00
|
|
|
$comment1 = Helper::getComment(1);
|
|
|
|
$comment1['id'] = Helper::getCommentId();
|
|
|
|
$comment1['parentid'] = Helper::getPasteId();
|
|
|
|
$comment2 = Helper::getComment(2);
|
|
|
|
$comment2['id'] = Helper::getPasteId();
|
|
|
|
$comment2['parentid'] = Helper::getPasteId();
|
2015-08-27 15:41:21 -04:00
|
|
|
$this->assertEquals(
|
2019-05-05 08:36:47 -04:00
|
|
|
array(
|
2019-05-05 15:03:58 -04:00
|
|
|
$comment1['meta']['postdate'] => $comment1,
|
|
|
|
$comment2['meta']['created'] . '.1' => $comment2,
|
2019-05-05 08:36:47 -04:00
|
|
|
),
|
2016-08-09 05:54:42 -04:00
|
|
|
$this->_model->readComments(Helper::getPasteId())
|
2015-08-27 15:41:21 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
// deleting pastes
|
2016-08-09 05:54:42 -04:00
|
|
|
$this->_model->delete(Helper::getPasteId());
|
|
|
|
$this->assertFalse($this->_model->exists(Helper::getPasteId()), 'paste successfully deleted');
|
|
|
|
$this->assertFalse($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId()), 'comment was deleted with paste');
|
|
|
|
$this->assertFalse($this->_model->read(Helper::getPasteId()), 'paste can no longer be found');
|
2015-08-27 15:41:21 -04:00
|
|
|
}
|
|
|
|
|
2015-09-26 06:29:27 -04:00
|
|
|
public function testDatabaseBasedAttachmentStoreWorks()
|
|
|
|
{
|
2019-05-05 08:36:47 -04:00
|
|
|
// this assumes a version 1 formatted paste
|
2016-08-09 05:54:42 -04:00
|
|
|
$this->_model->delete(Helper::getPasteId());
|
2019-05-05 08:36:47 -04:00
|
|
|
$original = $paste = Helper::getPasteWithAttachment(1, array('expire_date' => 1344803344));
|
2015-09-27 08:36:20 -04:00
|
|
|
$paste['meta']['burnafterreading'] = $original['meta']['burnafterreading'] = true;
|
2016-10-29 04:24:08 -04:00
|
|
|
$paste['meta']['attachment'] = $paste['attachment'];
|
|
|
|
$paste['meta']['attachmentname'] = $paste['attachmentname'];
|
2015-09-26 06:29:27 -04:00
|
|
|
unset($paste['attachment'], $paste['attachmentname']);
|
2016-08-09 05:54:42 -04:00
|
|
|
$this->assertFalse($this->_model->exists(Helper::getPasteId()), 'paste does not yet exist');
|
|
|
|
$this->assertTrue($this->_model->create(Helper::getPasteId(), $paste), 'store new paste');
|
|
|
|
$this->assertTrue($this->_model->exists(Helper::getPasteId()), 'paste exists after storing it');
|
|
|
|
$this->assertFalse($this->_model->create(Helper::getPasteId(), $paste), 'unable to store the same paste twice');
|
2019-05-05 15:03:58 -04:00
|
|
|
$this->assertEquals($original, $this->_model->read(Helper::getPasteId()));
|
2015-09-26 06:29:27 -04:00
|
|
|
}
|
|
|
|
|
2016-12-25 06:04:47 -05:00
|
|
|
/**
|
|
|
|
* pastes a-g are expired and should get deleted, x never expires and y-z expire in an hour
|
|
|
|
*/
|
2016-07-15 11:02:59 -04:00
|
|
|
public function testPurge()
|
|
|
|
{
|
2016-08-09 05:54:42 -04:00
|
|
|
$this->_model->delete(Helper::getPasteId());
|
2019-05-05 08:36:47 -04:00
|
|
|
$expired = Helper::getPaste(2, array('expire_date' => 1344803344));
|
|
|
|
$paste = Helper::getPaste(2, array('expire_date' => time() + 3600));
|
2016-12-25 06:04:47 -05:00
|
|
|
$keys = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'x', 'y', 'z');
|
2016-10-29 04:24:08 -04:00
|
|
|
$ids = array();
|
2016-07-26 02:19:35 -04:00
|
|
|
foreach ($keys as $key) {
|
2019-05-10 16:46:39 -04:00
|
|
|
$ids[$key] = hash('fnv164', $key);
|
2016-07-18 08:47:32 -04:00
|
|
|
$this->_model->delete($ids[$key]);
|
2016-07-15 11:02:59 -04:00
|
|
|
$this->assertFalse($this->_model->exists($ids[$key]), "paste $key does not yet exist");
|
2016-12-25 06:04:47 -05:00
|
|
|
if (in_array($key, array('y', 'z'))) {
|
2016-07-15 11:02:59 -04:00
|
|
|
$this->assertTrue($this->_model->create($ids[$key], $paste), "store $key paste");
|
2016-12-25 06:04:47 -05:00
|
|
|
} elseif ($key === 'x') {
|
|
|
|
$this->assertTrue($this->_model->create($ids[$key], Helper::getPaste()), "store $key paste");
|
2016-07-26 02:19:35 -04:00
|
|
|
} else {
|
2016-07-15 11:02:59 -04:00
|
|
|
$this->assertTrue($this->_model->create($ids[$key], $expired), "store $key paste");
|
|
|
|
}
|
|
|
|
$this->assertTrue($this->_model->exists($ids[$key]), "paste $key exists after storing it");
|
|
|
|
}
|
|
|
|
$this->_model->purge(10);
|
2016-07-26 02:19:35 -04:00
|
|
|
foreach ($ids as $key => $id) {
|
|
|
|
if (in_array($key, array('x', 'y', 'z'))) {
|
2016-07-19 02:40:33 -04:00
|
|
|
$this->assertTrue($this->_model->exists($id), "paste $key exists after purge");
|
|
|
|
$this->_model->delete($id);
|
2016-07-26 02:19:35 -04:00
|
|
|
} else {
|
2016-07-19 02:40:33 -04:00
|
|
|
$this->assertFalse($this->_model->exists($id), "paste $key was purged");
|
2016-07-15 11:02:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:41:21 -04:00
|
|
|
public function testGetIbmInstance()
|
|
|
|
{
|
2020-10-11 04:31:24 -04:00
|
|
|
$this->expectException(PDOException::class);
|
2022-10-27 19:01:02 -04:00
|
|
|
new Database(array(
|
2015-08-27 15:41:21 -04:00
|
|
|
'dsn' => 'ibm:', 'usr' => null, 'pwd' => null,
|
2016-10-29 04:24:08 -04:00
|
|
|
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION),
|
2015-08-27 15:41:21 -04:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetInformixInstance()
|
|
|
|
{
|
2020-10-11 04:31:24 -04:00
|
|
|
$this->expectException(PDOException::class);
|
2022-10-27 19:01:02 -04:00
|
|
|
new Database(array(
|
2015-08-27 15:41:21 -04:00
|
|
|
'dsn' => 'informix:', 'usr' => null, 'pwd' => null,
|
2016-10-29 04:24:08 -04:00
|
|
|
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION),
|
2015-08-27 15:41:21 -04:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetMssqlInstance()
|
|
|
|
{
|
2020-10-11 04:31:24 -04:00
|
|
|
$this->expectException(PDOException::class);
|
2022-10-27 19:01:02 -04:00
|
|
|
new Database(array(
|
2015-08-27 15:41:21 -04:00
|
|
|
'dsn' => 'mssql:', 'usr' => null, 'pwd' => null,
|
2016-10-29 04:24:08 -04:00
|
|
|
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION),
|
2015-08-27 15:41:21 -04:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetMysqlInstance()
|
|
|
|
{
|
2020-10-11 04:31:24 -04:00
|
|
|
$this->expectException(PDOException::class);
|
2022-10-27 19:01:02 -04:00
|
|
|
new Database(array(
|
2015-08-27 15:41:21 -04:00
|
|
|
'dsn' => 'mysql:', 'usr' => null, 'pwd' => null,
|
2016-10-29 04:24:08 -04:00
|
|
|
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION),
|
2015-08-27 15:41:21 -04:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetOciInstance()
|
|
|
|
{
|
2020-10-11 04:31:24 -04:00
|
|
|
$this->expectException(PDOException::class);
|
2022-10-27 19:01:02 -04:00
|
|
|
new Database(array(
|
2015-08-27 15:41:21 -04:00
|
|
|
'dsn' => 'oci:', 'usr' => null, 'pwd' => null,
|
2016-10-29 04:24:08 -04:00
|
|
|
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION),
|
2015-08-27 15:41:21 -04:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPgsqlInstance()
|
|
|
|
{
|
2020-10-11 04:31:24 -04:00
|
|
|
$this->expectException(PDOException::class);
|
2022-10-27 19:01:02 -04:00
|
|
|
new Database(array(
|
2015-08-27 15:41:21 -04:00
|
|
|
'dsn' => 'pgsql:', 'usr' => null, 'pwd' => null,
|
2016-10-29 04:24:08 -04:00
|
|
|
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION),
|
2015-08-27 15:41:21 -04:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetFooInstance()
|
|
|
|
{
|
2020-10-11 04:31:24 -04:00
|
|
|
$this->expectException(Exception::class);
|
|
|
|
$this->expectExceptionCode(5);
|
2022-10-27 19:01:02 -04:00
|
|
|
new Database(array(
|
2016-10-29 04:24:08 -04:00
|
|
|
'dsn' => 'foo:', 'usr' => null, 'pwd' => null, 'opt' => null,
|
2015-08-27 15:41:21 -04:00
|
|
|
));
|
|
|
|
}
|
2015-09-27 08:36:20 -04:00
|
|
|
|
2016-07-13 03:41:45 -04:00
|
|
|
public function testMissingDsn()
|
|
|
|
{
|
|
|
|
$options = $this->_options;
|
|
|
|
unset($options['dsn']);
|
2020-10-11 04:31:24 -04:00
|
|
|
$this->expectException(Exception::class);
|
|
|
|
$this->expectExceptionCode(6);
|
2022-10-27 19:01:02 -04:00
|
|
|
new Database($options);
|
2016-07-13 03:41:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testMissingUsr()
|
|
|
|
{
|
|
|
|
$options = $this->_options;
|
|
|
|
unset($options['usr']);
|
2020-10-11 04:31:24 -04:00
|
|
|
$this->expectException(Exception::class);
|
|
|
|
$this->expectExceptionCode(6);
|
2022-10-27 19:01:02 -04:00
|
|
|
new Database($options);
|
2016-07-13 03:41:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testMissingPwd()
|
|
|
|
{
|
|
|
|
$options = $this->_options;
|
|
|
|
unset($options['pwd']);
|
2020-10-11 04:31:24 -04:00
|
|
|
$this->expectException(Exception::class);
|
|
|
|
$this->expectExceptionCode(6);
|
2022-10-27 19:01:02 -04:00
|
|
|
new Database($options);
|
2016-07-13 03:41:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testMissingOpt()
|
|
|
|
{
|
|
|
|
$options = $this->_options;
|
|
|
|
unset($options['opt']);
|
2020-10-11 04:31:24 -04:00
|
|
|
$this->expectException(Exception::class);
|
|
|
|
$this->expectExceptionCode(6);
|
2022-10-27 19:01:02 -04:00
|
|
|
new Database($options);
|
2016-07-13 03:41:45 -04:00
|
|
|
}
|
|
|
|
|
2016-07-18 08:47:32 -04:00
|
|
|
public function testOldAttachments()
|
|
|
|
{
|
2016-08-09 05:54:42 -04:00
|
|
|
mkdir($this->_path);
|
|
|
|
$path = $this->_path . DIRECTORY_SEPARATOR . 'attachement-test.sq3';
|
2016-10-29 04:24:08 -04:00
|
|
|
if (is_file($path)) {
|
|
|
|
unlink($path);
|
|
|
|
}
|
2016-07-18 08:47:32 -04:00
|
|
|
$this->_options['dsn'] = 'sqlite:' . $path;
|
|
|
|
$this->_options['tbl'] = 'bar_';
|
2022-10-27 19:01:02 -04:00
|
|
|
$model = new Database($this->_options);
|
2016-07-18 08:47:32 -04:00
|
|
|
|
2019-05-05 08:36:47 -04:00
|
|
|
$original = $paste = Helper::getPasteWithAttachment(1, array('expire_date' => 1344803344));
|
|
|
|
$meta = $paste['meta'];
|
|
|
|
$meta['attachment'] = $paste['attachment'];
|
|
|
|
$meta['attachmentname'] = $paste['attachmentname'];
|
2016-07-18 08:47:32 -04:00
|
|
|
unset($paste['attachment'], $paste['attachmentname']);
|
|
|
|
|
|
|
|
$db = new PDO(
|
|
|
|
$this->_options['dsn'],
|
|
|
|
$this->_options['usr'],
|
|
|
|
$this->_options['pwd'],
|
|
|
|
$this->_options['opt']
|
|
|
|
);
|
|
|
|
$statement = $db->prepare('INSERT INTO bar_paste VALUES(?,?,?,?,?,?,?,?,?)');
|
|
|
|
$statement->execute(
|
|
|
|
array(
|
2016-08-09 05:54:42 -04:00
|
|
|
Helper::getPasteId(),
|
2016-07-18 08:47:32 -04:00
|
|
|
$paste['data'],
|
|
|
|
$paste['meta']['postdate'],
|
2019-05-05 08:36:47 -04:00
|
|
|
$paste['meta']['expire_date'],
|
2016-07-18 08:47:32 -04:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
json_encode($meta),
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$statement->closeCursor();
|
|
|
|
|
2016-08-09 05:54:42 -04:00
|
|
|
$this->assertTrue($model->exists(Helper::getPasteId()), 'paste exists after storing it');
|
2019-05-05 15:03:58 -04:00
|
|
|
$this->assertEquals($original, $model->read(Helper::getPasteId()));
|
2016-07-18 08:47:32 -04:00
|
|
|
|
2016-08-09 05:54:42 -04:00
|
|
|
Helper::rmDir($this->_path);
|
2016-07-18 08:47:32 -04:00
|
|
|
}
|
|
|
|
|
2021-06-13 04:44:26 -04:00
|
|
|
public function testCorruptMeta()
|
|
|
|
{
|
|
|
|
mkdir($this->_path);
|
|
|
|
$path = $this->_path . DIRECTORY_SEPARATOR . 'meta-test.sq3';
|
|
|
|
if (is_file($path)) {
|
|
|
|
unlink($path);
|
|
|
|
}
|
|
|
|
$this->_options['dsn'] = 'sqlite:' . $path;
|
|
|
|
$this->_options['tbl'] = 'baz_';
|
2022-10-27 19:01:02 -04:00
|
|
|
$model = new Database($this->_options);
|
2021-06-13 04:44:26 -04:00
|
|
|
$paste = Helper::getPaste(1, array('expire_date' => 1344803344));
|
|
|
|
unset($paste['meta']['formatter'], $paste['meta']['opendiscussion'], $paste['meta']['salt']);
|
|
|
|
$model->delete(Helper::getPasteId());
|
|
|
|
|
|
|
|
$db = new PDO(
|
|
|
|
$this->_options['dsn'],
|
|
|
|
$this->_options['usr'],
|
|
|
|
$this->_options['pwd'],
|
|
|
|
$this->_options['opt']
|
|
|
|
);
|
|
|
|
$statement = $db->prepare('INSERT INTO baz_paste VALUES(?,?,?,?,?,?,?,?,?)');
|
|
|
|
$statement->execute(
|
|
|
|
array(
|
|
|
|
Helper::getPasteId(),
|
|
|
|
$paste['data'],
|
|
|
|
$paste['meta']['postdate'],
|
|
|
|
$paste['meta']['expire_date'],
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
'{',
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$statement->closeCursor();
|
|
|
|
|
|
|
|
$this->assertTrue($model->exists(Helper::getPasteId()), 'paste exists after storing it');
|
|
|
|
$this->assertEquals($paste, $model->read(Helper::getPasteId()));
|
|
|
|
|
|
|
|
Helper::rmDir($this->_path);
|
|
|
|
}
|
|
|
|
|
2015-09-27 08:36:20 -04:00
|
|
|
public function testTableUpgrade()
|
|
|
|
{
|
2016-08-09 05:54:42 -04:00
|
|
|
mkdir($this->_path);
|
|
|
|
$path = $this->_path . DIRECTORY_SEPARATOR . 'db-test.sq3';
|
2016-10-29 04:24:08 -04:00
|
|
|
if (is_file($path)) {
|
|
|
|
unlink($path);
|
|
|
|
}
|
2015-09-27 08:36:20 -04:00
|
|
|
$this->_options['dsn'] = 'sqlite:' . $path;
|
|
|
|
$this->_options['tbl'] = 'foo_';
|
2016-10-29 04:24:08 -04:00
|
|
|
$db = new PDO(
|
2015-09-27 08:36:20 -04:00
|
|
|
$this->_options['dsn'],
|
|
|
|
$this->_options['usr'],
|
|
|
|
$this->_options['pwd'],
|
|
|
|
$this->_options['opt']
|
|
|
|
);
|
|
|
|
$db->exec(
|
|
|
|
'CREATE TABLE foo_paste ( ' .
|
|
|
|
'dataid CHAR(16), ' .
|
|
|
|
'data TEXT, ' .
|
|
|
|
'postdate INT, ' .
|
|
|
|
'expiredate INT, ' .
|
|
|
|
'opendiscussion INT, ' .
|
|
|
|
'burnafterreading INT );'
|
|
|
|
);
|
2016-07-18 08:47:32 -04:00
|
|
|
$db->exec(
|
|
|
|
'CREATE TABLE foo_comment ( ' .
|
2016-10-29 04:24:08 -04:00
|
|
|
'dataid CHAR(16) NOT NULL, ' .
|
2016-07-18 08:47:32 -04:00
|
|
|
'pasteid CHAR(16), ' .
|
|
|
|
'parentid CHAR(16), ' .
|
|
|
|
'data BLOB, ' .
|
|
|
|
'nickname BLOB, ' .
|
|
|
|
'vizhash BLOB, ' .
|
2016-10-29 04:24:08 -04:00
|
|
|
'postdate INT );'
|
2016-07-18 08:47:32 -04:00
|
|
|
);
|
2022-10-27 19:01:02 -04:00
|
|
|
$this->assertInstanceOf('PrivateBin\\Data\\Database', new Database($this->_options));
|
2016-08-25 03:53:31 -04:00
|
|
|
|
|
|
|
// check if version number was upgraded in created configuration table
|
|
|
|
$statement = $db->prepare('SELECT value FROM foo_config WHERE id LIKE ?');
|
|
|
|
$statement->execute(array('VERSION'));
|
|
|
|
$result = $statement->fetch(PDO::FETCH_ASSOC);
|
|
|
|
$statement->closeCursor();
|
2018-07-29 09:17:35 -04:00
|
|
|
$this->assertEquals(Controller::VERSION, $result['value']);
|
2016-08-09 05:54:42 -04:00
|
|
|
Helper::rmDir($this->_path);
|
2015-09-27 08:36:20 -04:00
|
|
|
}
|
2022-01-22 02:45:12 -05:00
|
|
|
|
|
|
|
public function testOciClob()
|
|
|
|
{
|
2022-01-22 02:47:34 -05:00
|
|
|
$int = (int) random_bytes(1);
|
2022-01-22 02:45:12 -05:00
|
|
|
$string = random_bytes(10);
|
2022-01-22 02:47:34 -05:00
|
|
|
$clob = fopen('php://memory', 'r+');
|
2022-01-22 02:45:12 -05:00
|
|
|
fwrite($clob, $string);
|
|
|
|
rewind($clob);
|
|
|
|
$this->assertEquals($int, Database::_sanitizeClob($int));
|
|
|
|
$this->assertEquals($string, Database::_sanitizeClob($string));
|
|
|
|
$this->assertEquals($string, Database::_sanitizeClob($clob));
|
|
|
|
}
|
2015-08-27 15:41:21 -04:00
|
|
|
}
|