mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2025-07-24 07:20:45 -04:00
Merge branch 'master' into php8
This commit is contained in:
commit
3f469f715f
119 changed files with 6872 additions and 790 deletions
|
@ -3,6 +3,8 @@
|
|||
use PHPUnit\Framework\TestCase;
|
||||
use PrivateBin\Controller;
|
||||
use PrivateBin\Data\Database;
|
||||
use PrivateBin\Data\Filesystem;
|
||||
use PrivateBin\Persistence\ServerSalt;
|
||||
|
||||
class DatabaseTest extends TestCase
|
||||
{
|
||||
|
@ -32,6 +34,19 @@ class DatabaseTest extends TestCase
|
|||
}
|
||||
}
|
||||
|
||||
public function testSaltMigration()
|
||||
{
|
||||
ServerSalt::setStore(Filesystem::getInstance(array('dir' => 'data')));
|
||||
$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();
|
||||
$this->assertFileNotExists($file, 'legacy ServerSalt got removed');
|
||||
$this->assertEquals($salt, ServerSalt::get(), 'ServerSalt got preserved & migrated');
|
||||
}
|
||||
|
||||
public function testDatabaseBasedDataStoreWorks()
|
||||
{
|
||||
$this->_model->delete(Helper::getPasteId());
|
||||
|
@ -266,6 +281,48 @@ class DatabaseTest extends TestCase
|
|||
Helper::rmDir($this->_path);
|
||||
}
|
||||
|
||||
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_';
|
||||
$model = Database::getInstance($this->_options);
|
||||
$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);
|
||||
}
|
||||
|
||||
public function testTableUpgrade()
|
||||
{
|
||||
mkdir($this->_path);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue