Compare commits
4 Commits
php8
...
jdenticons
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b2ef205411 | ||
|
|
c0758e7bbb | ||
|
|
89d575ace3 | ||
|
|
1892264cf0 |
8
.github/workflows/tests.yml
vendored
8
.github/workflows/tests.yml
vendored
@@ -1,7 +1,5 @@
|
||||
name: Tests
|
||||
on:
|
||||
push:
|
||||
workflow_dispatch:
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
|
||||
@@ -19,7 +17,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
php-versions: ['7.3', '7.4', '8.0', '8.1', '8.2']
|
||||
php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4']
|
||||
name: PHP ${{ matrix.php-versions }} unit tests on ${{ matrix.operating-system }}
|
||||
env:
|
||||
extensions: gd, sqlite3
|
||||
@@ -68,6 +66,7 @@ jobs:
|
||||
- name: Get composer cache directory
|
||||
id: composer-cache
|
||||
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
|
||||
|
||||
# http://man7.org/linux/man-pages/man1/date.1.html
|
||||
# https://github.com/actions/cache#creating-a-cache-key
|
||||
- name: Get Date
|
||||
@@ -118,3 +117,4 @@ jobs:
|
||||
- name: Run unit tests
|
||||
run: npm test
|
||||
working-directory: js
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* **1.4.1 (not yet released)**
|
||||
* ADDED: Translations for Turkish, Slovak and Greek
|
||||
* ADDED: S3 Storage backend (#994)
|
||||
* CHANGED: Switched to Jdenticons as the default for comment icons (#793)
|
||||
* ADDED: Jdenticons as an option for comment icons (#793)
|
||||
* CHANGED: Avoid `SUPER` privilege for setting the `sql_mode` for MariaDB/MySQL (#919)
|
||||
* CHANGED: Upgrading libraries to: zlib 1.2.13
|
||||
* FIXED: Revert to CREATE INDEX without IF NOT EXISTS clauses, to support MySQL (#943)
|
||||
|
||||
@@ -26,7 +26,7 @@ install and configure PrivateBin on your server. It's available on
|
||||
- `open_basedir` access to `/dev/urandom`
|
||||
- mcrypt extension AND `open_basedir` access to `/dev/urandom`
|
||||
- com_dotnet extension
|
||||
- GD extension
|
||||
- GD extension (when using identicon or vizhash icons, jdenticon works without it)
|
||||
- zlib extension
|
||||
- some disk space or a database supported by [PDO](https://php.net/manual/book.pdo.php)
|
||||
- ability to create files and folders in the installation directory and the PATH
|
||||
|
||||
@@ -7,10 +7,9 @@
|
||||
; (optional) set a project name to be displayed on the website
|
||||
; name = "PrivateBin"
|
||||
|
||||
; The full URL, with the domain name and directories that point to the
|
||||
; PrivateBin files, including an ending slash (/). This URL is essential to
|
||||
; allow Opengraph images to be displayed on social networks.
|
||||
; basepath = "https://privatebin.example.com/"
|
||||
; The full URL, with the domain name and directories that point to the PrivateBin files
|
||||
; This URL is essential to allow Opengraph images to be displayed on social networks
|
||||
; basepath = ""
|
||||
|
||||
; enable or disable the discussion feature, defaults to true
|
||||
discussion = true
|
||||
@@ -56,9 +55,9 @@ languageselection = false
|
||||
; if this is set and language selection is disabled, this will be the only language
|
||||
; languagedefault = "en"
|
||||
|
||||
; (optional) URL shortener address to offer after a new paste is created.
|
||||
; It is suggested to only use this with self-hosted shorteners as this will leak
|
||||
; the pastes encryption key.
|
||||
; (optional) URL shortener address to offer after a new paste is created
|
||||
; it is suggested to only use this with self-hosted shorteners as this will leak
|
||||
; the pastes encryption key
|
||||
; urlshortener = "https://shortener.example.com/api?link="
|
||||
|
||||
; (optional) Let users create a QR code for sharing the paste URL with one click.
|
||||
@@ -70,7 +69,7 @@ languageselection = false
|
||||
; used to get the IP of a comment poster if the server salt is leaked and a
|
||||
; SHA512 HMAC rainbow table is generated for all (relevant) IPs.
|
||||
; Can be set to one these values:
|
||||
; "none" / "vizhash" / "identicon" / "jdenticon" (default).
|
||||
; "none" / "identicon" (default) / "jdenticon" / "vizhash".
|
||||
; icon = "none"
|
||||
|
||||
; Content Security Policy headers allow a website to restrict what sources are
|
||||
@@ -231,18 +230,18 @@ dir = PATH "data"
|
||||
;secretkey = "secret access key"
|
||||
|
||||
[yourls]
|
||||
; When using YOURLS as a "urlshortener" config item:
|
||||
; - By default, "urlshortener" will point to the YOURLS API URL, with or without
|
||||
; credentials, and will be visible in public on the PrivateBin web page.
|
||||
; Only use this if you allow short URL creation without credentials.
|
||||
; - Alternatively, using the parameters in this section ("signature" and
|
||||
; "apiurl"), "urlshortener" needs to point to the base URL of your PrivateBin
|
||||
; instance with "shortenviayourls?link=" appended. For example:
|
||||
; urlshortener = "${basepath}shortenviayourls?link="
|
||||
; This URL will in turn call YOURLS on the server side, using the URL from
|
||||
; "apiurl" and the "access signature" from the "signature" parameters below.
|
||||
; don't mix this up with "urlshortener" config item:
|
||||
; - when using a standard configuration, "urlshortener" will point to the YOURLS
|
||||
; API, including access credentials, and will be part of the PrivateBin public
|
||||
; web page (insecure!)
|
||||
; - when using the parameters in this section ("signature" and "apiurl"),
|
||||
; "urlshortener" will point to a fixed PrivateBin page
|
||||
; ("$basepath/shortenviayourls?link=") and that URL will in turn call YOURLS
|
||||
; server-side, using the URL from "apiurl" and the "access signature" from the
|
||||
; "signature" parameters below.
|
||||
|
||||
; (optional) the "signature" (access key) issued by YOURLS for the using account
|
||||
; signature = ""
|
||||
|
||||
; (optional) the URL of the YOURLS API, called to shorten a PrivateBin URL
|
||||
; apiurl = "https://yourls.example.com/yourls-api.php"
|
||||
; apiurl = ""
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
"aws/aws-sdk-php" : "3.239.0"
|
||||
},
|
||||
"require-dev" : {
|
||||
"phpunit/phpunit" : "^9"
|
||||
"phpunit/phpunit" : "^4.6 || ^5.0"
|
||||
},
|
||||
"autoload" : {
|
||||
"psr-4" : {
|
||||
|
||||
1463
composer.lock
generated
1463
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -53,7 +53,7 @@ class Configuration
|
||||
'languagedefault' => '',
|
||||
'urlshortener' => '',
|
||||
'qrcode' => true,
|
||||
'icon' => 'jdenticon',
|
||||
'icon' => 'identicon',
|
||||
'cspheader' => 'default-src \'none\'; base-uri \'self\'; form-action \'none\'; manifest-src \'self\'; connect-src * blob:; script-src \'self\' \'unsafe-eval\'; style-src \'self\'; font-src \'self\'; frame-ancestors \'none\'; img-src \'self\' data: blob:; media-src blob:; object-src blob:; sandbox allow-same-origin allow-scripts allow-forms allow-popups allow-modals allow-downloads',
|
||||
'zerobincompatibility' => false,
|
||||
'httpwarning' => true,
|
||||
@@ -236,14 +236,6 @@ class Configuration
|
||||
if (!array_key_exists($this->_configuration['expire']['default'], $this->_configuration['expire_options'])) {
|
||||
$this->_configuration['expire']['default'] = key($this->_configuration['expire_options']);
|
||||
}
|
||||
|
||||
// ensure the basepath ends in a slash, if one is set
|
||||
if (
|
||||
strlen($this->_configuration['main']['basepath']) &&
|
||||
substr_compare($this->_configuration['main']['basepath'], '/', -1) !== 0
|
||||
) {
|
||||
$this->_configuration['main']['basepath'] .= '/';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -165,7 +165,10 @@ class Comment extends AbstractModel
|
||||
if ($icon != 'none') {
|
||||
$pngdata = '';
|
||||
$hmac = TrafficLimiter::getHash();
|
||||
if ($icon == 'jdenticon') {
|
||||
if ($icon == 'identicon') {
|
||||
$identicon = new Identicon();
|
||||
$pngdata = $identicon->getImageDataUri($hmac, 16);
|
||||
} elseif ($icon == 'jdenticon') {
|
||||
$jdenticon = new Jdenticon(array(
|
||||
'hash' => $hmac,
|
||||
'size' => 16,
|
||||
@@ -175,9 +178,6 @@ class Comment extends AbstractModel
|
||||
),
|
||||
));
|
||||
$pngdata = $jdenticon->getImageDataUri('png');
|
||||
} elseif ($icon == 'identicon') {
|
||||
$identicon = new Identicon();
|
||||
$pngdata = $identicon->getImageDataUri($hmac, 16);
|
||||
} elseif ($icon == 'vizhash') {
|
||||
$vh = new Vizhash16x16();
|
||||
$pngdata = 'data:image/png;base64,' . base64_encode(
|
||||
|
||||
@@ -48,7 +48,7 @@ class YourlsProxy
|
||||
*/
|
||||
public function __construct(Configuration $conf, $link)
|
||||
{
|
||||
if (strpos($link, $conf->getKey('basepath') . '?') === false) {
|
||||
if (strpos($link, $conf->getKey('basepath') . '/?') === false) {
|
||||
$this->_error = 'Trying to shorten a URL that isn\'t pointing at our instance.';
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PrivateBin\Configuration;
|
||||
|
||||
class ConfigurationTest extends TestCase
|
||||
class ConfigurationTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $_minimalConfig;
|
||||
|
||||
@@ -11,7 +10,7 @@ class ConfigurationTest extends TestCase
|
||||
|
||||
private $_path;
|
||||
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
/* Setup Routine */
|
||||
Helper::confBackup();
|
||||
@@ -24,7 +23,7 @@ class ConfigurationTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
public function tearDown()
|
||||
{
|
||||
/* Tear Down Routine */
|
||||
Helper::rmDir($this->_path);
|
||||
@@ -56,11 +55,13 @@ class ConfigurationTest extends TestCase
|
||||
$this->assertEquals($this->_options, $conf->get(), 'returns correct defaults on missing file');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionCode 2
|
||||
*/
|
||||
public function testHandleBlankConfigFile()
|
||||
{
|
||||
file_put_contents(CONF, '');
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionCode(2);
|
||||
new Configuration;
|
||||
}
|
||||
|
||||
@@ -71,21 +72,25 @@ class ConfigurationTest extends TestCase
|
||||
$this->assertEquals($this->_options, $conf->get(), 'returns correct defaults on empty file');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionCode 3
|
||||
*/
|
||||
public function testHandleInvalidSection()
|
||||
{
|
||||
file_put_contents(CONF, $this->_minimalConfig);
|
||||
$conf = new Configuration;
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionCode(3);
|
||||
$conf->getKey('foo', 'bar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionCode 4
|
||||
*/
|
||||
public function testHandleInvalidKey()
|
||||
{
|
||||
file_put_contents(CONF, $this->_minimalConfig);
|
||||
$conf = new Configuration;
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionCode(4);
|
||||
$conf->getKey('foo');
|
||||
}
|
||||
|
||||
|
||||
@@ -408,14 +408,13 @@ class ConfigurationTestGenerator
|
||||
* DO NOT EDIT: This file is generated automatically using configGenerator.php
|
||||
*/
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PrivateBin\Controller;
|
||||
use PrivateBin\Data\Filesystem;
|
||||
use PrivateBin\Persistence\ServerSalt;
|
||||
use PrivateBin\Persistence\TrafficLimiter;
|
||||
use PrivateBin\Request;
|
||||
|
||||
class ConfigurationCombinationsTest extends TestCase
|
||||
class ConfigurationCombinationsTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $_conf;
|
||||
|
||||
@@ -423,7 +422,7 @@ class ConfigurationCombinationsTest extends TestCase
|
||||
|
||||
private $_path;
|
||||
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
/* Setup Routine */
|
||||
Helper::confBackup();
|
||||
@@ -432,7 +431,7 @@ class ConfigurationCombinationsTest extends TestCase
|
||||
$this->reset();
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
public function tearDown()
|
||||
{
|
||||
/* Tear Down Routine */
|
||||
unlink(CONF);
|
||||
@@ -561,7 +560,7 @@ EOT;
|
||||
case 'Delete':
|
||||
$code .= <<<'EOT'
|
||||
|
||||
$this->assertMatchesRegularExpression(
|
||||
$this->assertRegExp(
|
||||
'#<div[^>]*id="status"[^>]*>.*Paste was properly deleted[^<]*</div>#s',
|
||||
$content,
|
||||
'outputs deleted status correctly'
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PrivateBin\Controller;
|
||||
use PrivateBin\Data\Filesystem;
|
||||
use PrivateBin\Persistence\ServerSalt;
|
||||
use PrivateBin\Persistence\TrafficLimiter;
|
||||
use PrivateBin\Request;
|
||||
|
||||
class ControllerTest extends TestCase
|
||||
class ControllerTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $_data;
|
||||
|
||||
protected $_path;
|
||||
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
/* Setup Routine */
|
||||
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
|
||||
@@ -23,7 +22,7 @@ class ControllerTest extends TestCase
|
||||
$this->reset();
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
public function tearDown()
|
||||
{
|
||||
/* Tear Down Routine */
|
||||
unlink(CONF);
|
||||
@@ -56,17 +55,17 @@ class ControllerTest extends TestCase
|
||||
new Controller;
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
$this->assertStringContainsString(
|
||||
$this->assertContains(
|
||||
'<title>PrivateBin</title>',
|
||||
$content,
|
||||
'outputs title correctly'
|
||||
);
|
||||
$this->assertStringNotContainsString(
|
||||
$this->assertNotContains(
|
||||
'id="shortenbutton"',
|
||||
$content,
|
||||
'doesn\'t output shortener button'
|
||||
);
|
||||
$this->assertMatchesRegularExpression(
|
||||
$this->assertRegExp(
|
||||
'# href="https://' . preg_quote($_SERVER['HTTP_HOST']) . '/">switching to HTTPS#',
|
||||
$content,
|
||||
'outputs configured https URL correctly'
|
||||
@@ -86,7 +85,7 @@ class ControllerTest extends TestCase
|
||||
new Controller;
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
$this->assertStringContainsString(
|
||||
$this->assertContains(
|
||||
'<title>PrivateBin</title>',
|
||||
$content,
|
||||
'outputs title correctly'
|
||||
@@ -107,7 +106,7 @@ class ControllerTest extends TestCase
|
||||
new Controller;
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
$this->assertStringContainsString(
|
||||
$this->assertContains(
|
||||
'<title>PrivateBin</title>',
|
||||
$content,
|
||||
'outputs title correctly'
|
||||
@@ -128,7 +127,7 @@ class ControllerTest extends TestCase
|
||||
new Controller;
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
$this->assertMatchesRegularExpression(
|
||||
$this->assertRegExp(
|
||||
'#id="shortenbutton"[^>]*data-shortener="' . preg_quote($shortener) . '"#',
|
||||
$content,
|
||||
'outputs configured shortener URL correctly'
|
||||
@@ -142,8 +141,6 @@ class ControllerTest extends TestCase
|
||||
public function testConf()
|
||||
{
|
||||
file_put_contents(CONF, '');
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionCode(2);
|
||||
new Controller;
|
||||
}
|
||||
|
||||
@@ -439,6 +436,8 @@ class ControllerTest extends TestCase
|
||||
* silently removed, check that this case is handled
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionCode 90
|
||||
*/
|
||||
public function testCreateBrokenUpload()
|
||||
{
|
||||
@@ -450,8 +449,6 @@ class ControllerTest extends TestCase
|
||||
$_SERVER['REQUEST_METHOD'] = 'POST';
|
||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||
$this->assertFalse($this->_data->exists(Helper::getPasteId()), 'paste does not exists before posting data');
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionCode(90);
|
||||
new Controller;
|
||||
$this->assertFalse($this->_data->exists(Helper::getPasteId()), 'paste exists after posting data');
|
||||
}
|
||||
@@ -809,7 +806,7 @@ class ControllerTest extends TestCase
|
||||
new Controller;
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
$this->assertMatchesRegularExpression(
|
||||
$this->assertRegExp(
|
||||
'#<div[^>]*id="status"[^>]*>.*Paste was properly deleted\.#s',
|
||||
$content,
|
||||
'outputs deleted status correctly'
|
||||
@@ -829,7 +826,7 @@ class ControllerTest extends TestCase
|
||||
new Controller;
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
$this->assertMatchesRegularExpression(
|
||||
$this->assertRegExp(
|
||||
'#<div[^>]*id="errormessage"[^>]*>.*Invalid paste ID\.#s',
|
||||
$content,
|
||||
'outputs delete error correctly'
|
||||
@@ -848,7 +845,7 @@ class ControllerTest extends TestCase
|
||||
new Controller;
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
$this->assertMatchesRegularExpression(
|
||||
$this->assertRegExp(
|
||||
'#<div[^>]*id="errormessage"[^>]*>.*Paste does not exist, has expired or has been deleted\.#s',
|
||||
$content,
|
||||
'outputs delete error correctly'
|
||||
@@ -867,7 +864,7 @@ class ControllerTest extends TestCase
|
||||
new Controller;
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
$this->assertMatchesRegularExpression(
|
||||
$this->assertRegExp(
|
||||
'#<div[^>]*id="errormessage"[^>]*>.*Wrong deletion token\. Paste was not deleted\.#s',
|
||||
$content,
|
||||
'outputs delete error correctly'
|
||||
@@ -915,7 +912,7 @@ class ControllerTest extends TestCase
|
||||
new Controller;
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
$this->assertMatchesRegularExpression(
|
||||
$this->assertRegExp(
|
||||
'#<div[^>]*id="errormessage"[^>]*>.*Paste does not exist, has expired or has been deleted\.#s',
|
||||
$content,
|
||||
'outputs error correctly'
|
||||
@@ -938,7 +935,7 @@ class ControllerTest extends TestCase
|
||||
new Controller;
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
$this->assertMatchesRegularExpression(
|
||||
$this->assertRegExp(
|
||||
'#<div[^>]*id="status"[^>]*>.*Paste was properly deleted\.#s',
|
||||
$content,
|
||||
'outputs deleted status correctly'
|
||||
|
||||
@@ -17,7 +17,7 @@ class ControllerWithDbTest extends ControllerTest
|
||||
),
|
||||
);
|
||||
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
/* Setup Routine */
|
||||
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
|
||||
|
||||
@@ -14,7 +14,7 @@ class ControllerWithGcsTest extends ControllerTest
|
||||
private static $_bucket;
|
||||
private $_options = array();
|
||||
|
||||
public static function setUpBeforeClass(): void
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$httpClient = new Client(array('debug'=>false));
|
||||
$handler = HttpHandlerFactory::build($httpClient);
|
||||
@@ -28,7 +28,7 @@ class ControllerWithGcsTest extends ControllerTest
|
||||
self::$_bucket = self::$_client->createBucket($name);
|
||||
}
|
||||
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
/* Setup Routine */
|
||||
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PrivateBin\Controller;
|
||||
use PrivateBin\Data\Database;
|
||||
use PrivateBin\Data\Filesystem;
|
||||
use PrivateBin\Persistence\ServerSalt;
|
||||
|
||||
class DatabaseTest extends TestCase
|
||||
class DatabaseTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $_model;
|
||||
|
||||
@@ -19,14 +18,14 @@ class DatabaseTest extends TestCase
|
||||
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION),
|
||||
);
|
||||
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
/* Setup Routine */
|
||||
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
|
||||
$this->_model = Database::getInstance($this->_options);
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
public function tearDown()
|
||||
{
|
||||
/* Tear Down Routine */
|
||||
if (is_dir($this->_path)) {
|
||||
@@ -43,7 +42,7 @@ class DatabaseTest extends TestCase
|
||||
$this->assertNotEquals($salt, '');
|
||||
ServerSalt::setStore($this->_model);
|
||||
ServerSalt::get();
|
||||
$this->assertFileDoesNotExist($file, 'legacy ServerSalt got removed');
|
||||
$this->assertFileNotExists($file, 'legacy ServerSalt got removed');
|
||||
$this->assertEquals($salt, ServerSalt::get(), 'ServerSalt got preserved & migrated');
|
||||
}
|
||||
|
||||
@@ -137,102 +136,124 @@ class DatabaseTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PDOException
|
||||
*/
|
||||
public function testGetIbmInstance()
|
||||
{
|
||||
$this->expectException(PDOException::class);
|
||||
Database::getInstance(array(
|
||||
'dsn' => 'ibm:', 'usr' => null, 'pwd' => null,
|
||||
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PDOException
|
||||
*/
|
||||
public function testGetInformixInstance()
|
||||
{
|
||||
$this->expectException(PDOException::class);
|
||||
Database::getInstance(array(
|
||||
'dsn' => 'informix:', 'usr' => null, 'pwd' => null,
|
||||
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PDOException
|
||||
*/
|
||||
public function testGetMssqlInstance()
|
||||
{
|
||||
$this->expectException(PDOException::class);
|
||||
Database::getInstance(array(
|
||||
'dsn' => 'mssql:', 'usr' => null, 'pwd' => null,
|
||||
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PDOException
|
||||
*/
|
||||
public function testGetMysqlInstance()
|
||||
{
|
||||
$this->expectException(PDOException::class);
|
||||
Database::getInstance(array(
|
||||
'dsn' => 'mysql:', 'usr' => null, 'pwd' => null,
|
||||
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PDOException
|
||||
*/
|
||||
public function testGetOciInstance()
|
||||
{
|
||||
$this->expectException(PDOException::class);
|
||||
Database::getInstance(array(
|
||||
'dsn' => 'oci:', 'usr' => null, 'pwd' => null,
|
||||
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PDOException
|
||||
*/
|
||||
public function testGetPgsqlInstance()
|
||||
{
|
||||
$this->expectException(PDOException::class);
|
||||
Database::getInstance(array(
|
||||
'dsn' => 'pgsql:', 'usr' => null, 'pwd' => null,
|
||||
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionCode 5
|
||||
*/
|
||||
public function testGetFooInstance()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionCode(5);
|
||||
Database::getInstance(array(
|
||||
'dsn' => 'foo:', 'usr' => null, 'pwd' => null, 'opt' => null,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionCode 6
|
||||
*/
|
||||
public function testMissingDsn()
|
||||
{
|
||||
$options = $this->_options;
|
||||
unset($options['dsn']);
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionCode(6);
|
||||
Database::getInstance($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionCode 6
|
||||
*/
|
||||
public function testMissingUsr()
|
||||
{
|
||||
$options = $this->_options;
|
||||
unset($options['usr']);
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionCode(6);
|
||||
Database::getInstance($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionCode 6
|
||||
*/
|
||||
public function testMissingPwd()
|
||||
{
|
||||
$options = $this->_options;
|
||||
unset($options['pwd']);
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionCode(6);
|
||||
Database::getInstance($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionCode 6
|
||||
*/
|
||||
public function testMissingOpt()
|
||||
{
|
||||
$options = $this->_options;
|
||||
unset($options['opt']);
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionCode(6);
|
||||
Database::getInstance($options);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PrivateBin\Data\Filesystem;
|
||||
|
||||
class FilesystemTest extends TestCase
|
||||
class FilesystemTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $_model;
|
||||
|
||||
@@ -11,7 +10,7 @@ class FilesystemTest extends TestCase
|
||||
|
||||
private $_invalidPath;
|
||||
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
/* Setup Routine */
|
||||
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
|
||||
@@ -25,7 +24,7 @@ class FilesystemTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
public function tearDown()
|
||||
{
|
||||
/* Tear Down Routine */
|
||||
chmod($this->_invalidPath, 0700);
|
||||
@@ -163,13 +162,13 @@ class FilesystemTest extends TestCase
|
||||
$this->_model->purge(10);
|
||||
foreach ($ids as $dataid => $storagedir) {
|
||||
$this->assertFileExists($storagedir . $dataid . '.php', "paste $dataid exists in new format");
|
||||
$this->assertFileDoesNotExist($storagedir . $dataid, "old format paste $dataid got removed");
|
||||
$this->assertFileNotExists($storagedir . $dataid, "old format paste $dataid got removed");
|
||||
$this->assertTrue($this->_model->exists($dataid), "paste $dataid exists");
|
||||
$this->assertEquals($this->_model->read($dataid), $paste, "paste $dataid wasn't modified in the conversion");
|
||||
|
||||
$storagedir .= $dataid . '.discussion' . DIRECTORY_SEPARATOR;
|
||||
$this->assertFileExists($storagedir . $dataid . '.' . $commentid . '.' . $dataid . '.php', "comment of $dataid exists in new format");
|
||||
$this->assertFileDoesNotExist($storagedir . $dataid . '.' . $commentid . '.' . $dataid, "old format comment of $dataid got removed");
|
||||
$this->assertFileNotExists($storagedir . $dataid . '.' . $commentid . '.' . $dataid, "old format comment of $dataid got removed");
|
||||
$this->assertTrue($this->_model->existsComment($dataid, $dataid, $commentid), "comment in paste $dataid exists");
|
||||
$comment = $comment;
|
||||
$comment['id'] = $commentid;
|
||||
|
||||
@@ -2,15 +2,14 @@
|
||||
|
||||
use Google\Auth\HttpHandler\HttpHandlerFactory;
|
||||
use GuzzleHttp\Client;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PrivateBin\Data\GoogleCloudStorage;
|
||||
|
||||
class GoogleCloudStorageTest extends TestCase
|
||||
class GoogleCloudStorageTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private static $_client;
|
||||
private static $_bucket;
|
||||
|
||||
public static function setUpBeforeClass(): void
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$httpClient = new Client(array('debug'=>false));
|
||||
$handler = HttpHandlerFactory::build($httpClient);
|
||||
@@ -24,7 +23,7 @@ class GoogleCloudStorageTest extends TestCase
|
||||
self::$_bucket = self::$_client->createBucket($name);
|
||||
}
|
||||
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
ini_set('error_log', stream_get_meta_data(tmpfile())['uri']);
|
||||
$this->_model = GoogleCloudStorage::getInstance(array(
|
||||
@@ -33,14 +32,14 @@ class GoogleCloudStorageTest extends TestCase
|
||||
));
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
public function tearDown()
|
||||
{
|
||||
foreach (self::$_bucket->objects() as $object) {
|
||||
$object->delete();
|
||||
}
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass(): void
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
self::$_bucket->delete();
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PrivateBin\Filter;
|
||||
|
||||
class FilterTest extends TestCase
|
||||
class FilterTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testFilterMakesTimesHumanlyReadable()
|
||||
{
|
||||
@@ -13,10 +12,12 @@ class FilterTest extends TestCase
|
||||
$this->assertEquals('6 months', Filter::formatHumanReadableTime('6months'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionCode 30
|
||||
*/
|
||||
public function testFilterFailTimesHumanlyReadable()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionCode(30);
|
||||
Filter::formatHumanReadableTime('five_minutes');
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PrivateBin\FormatV2;
|
||||
|
||||
class FormatV2Test extends TestCase
|
||||
class FormatV2Test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testFormatV2ValidatorValidatesCorrectly()
|
||||
{
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PrivateBin\I18n;
|
||||
|
||||
class I18nTest extends TestCase
|
||||
class I18nTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $_translations = array();
|
||||
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
/* Setup Routine */
|
||||
$this->_translations = json_decode(
|
||||
@@ -16,9 +15,9 @@ class I18nTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
public function tearDown()
|
||||
{
|
||||
unset($_COOKIE['lang'], $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||||
/* Tear Down Routine */
|
||||
}
|
||||
|
||||
public function testTranslationFallback()
|
||||
|
||||
72
tst/IconTest
72
tst/IconTest
@@ -9,6 +9,7 @@ use Identicon\Generator\GdGenerator;
|
||||
use Identicon\Generator\ImageMagickGenerator;
|
||||
use Identicon\Generator\SvgGenerator;
|
||||
use Identicon\Identicon;
|
||||
use Jdenticon\Identicon as Jdenticon;
|
||||
use PrivateBin\Vizhash16x16;
|
||||
|
||||
|
||||
@@ -17,7 +18,19 @@ $vizhash = new Vizhash16x16();
|
||||
$identiconGenerators = array(
|
||||
'identicon GD' => new Identicon(new GdGenerator()),
|
||||
'identicon ImageMagick' => new Identicon(new ImageMagickGenerator()),
|
||||
'identicon SVG' => new Identicon(new SvgGenerator())
|
||||
'identicon SVG' => new Identicon(new SvgGenerator()),
|
||||
);
|
||||
$jdenticon = new Jdenticon(array(
|
||||
'size' => 16,
|
||||
'style' => array(
|
||||
'backgroundColor' => '#fff0', // fully transparent, for dark mode
|
||||
'padding' => 0,
|
||||
),
|
||||
));
|
||||
$jdenticonGenerators = array(
|
||||
'jdenticon' => 'png',
|
||||
'jdenticon ImageMagick' => 'png',
|
||||
'jdenticon SVG' => 'svg',
|
||||
);
|
||||
$results = array(
|
||||
'vizhash' => array(
|
||||
@@ -35,20 +48,29 @@ $results = array(
|
||||
'identicon SVG' => array(
|
||||
'lengths' => array(),
|
||||
'time' => 0
|
||||
)
|
||||
),
|
||||
'jdenticon' => array(
|
||||
'lengths' => array(),
|
||||
'time' => 0
|
||||
),
|
||||
'jdenticon ImageMagick' => array(
|
||||
'lengths' => array(),
|
||||
'time' => 0
|
||||
),
|
||||
'jdenticon SVG' => array(
|
||||
'lengths' => array(),
|
||||
'time' => 0
|
||||
),
|
||||
);
|
||||
$hmacs = array();
|
||||
|
||||
echo 'generate ', ITERATIONS, ' hmacs and pre-populate the result array, so tests wont be slowed down', PHP_EOL;
|
||||
for ($i = 0; $i < ITERATIONS; ++$i) {
|
||||
$hmacs[$i] = hash_hmac('sha512', '127.0.0.1', bin2hex(random_bytes(256)));
|
||||
$results['vizhash']['lengths'][$i] = 0;
|
||||
$results['identicon GD']['lengths'][$i] = 0;
|
||||
$results['identicon ImageMagick']['lengths'][$i] = 0;
|
||||
$results['identicon SVG']['lengths'][$i] = 0;
|
||||
foreach (array_keys($results) as $test) {
|
||||
$results[$test]['lengths'][$i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
echo 'run vizhash tests', PHP_EOL;
|
||||
$start = microtime(true);
|
||||
@@ -60,7 +82,6 @@ foreach ($hmacs as $i => $hmac) {
|
||||
}
|
||||
$results['vizhash']['time'] = microtime(true) - $start;
|
||||
|
||||
|
||||
foreach ($identiconGenerators as $key => $identicon) {
|
||||
echo 'run ', $key,' tests', PHP_EOL;
|
||||
$start = microtime(true);
|
||||
@@ -71,9 +92,35 @@ foreach ($identiconGenerators as $key => $identicon) {
|
||||
$results[$key]['time'] = microtime(true) - $start;
|
||||
}
|
||||
|
||||
foreach ($jdenticonGenerators as $key => $format) {
|
||||
echo 'run ', $key,' tests', PHP_EOL;
|
||||
if ($key === 'jdenticon ImageMagick') {
|
||||
$jdenticon->enableImageMagick = true;
|
||||
} else {
|
||||
$jdenticon->enableImageMagick = false;
|
||||
}
|
||||
$start = microtime(true);
|
||||
foreach ($hmacs as $i => $hmac) {
|
||||
$jdenticon->setHash($hmac);
|
||||
$data = $jdenticon->getImageDataUri($format);
|
||||
$results[$key]['lengths'][$i] = strlen($data);
|
||||
}
|
||||
$results[$key]['time'] = microtime(true) - $start;
|
||||
}
|
||||
|
||||
|
||||
define('PADDING_LENGTH', max(array_map(function ($key) { return strlen($key); }, array_keys($results))) + 1);
|
||||
define(
|
||||
'PADDING_LENGTH',
|
||||
max(
|
||||
array_map(
|
||||
function ($key) {
|
||||
return strlen($key);
|
||||
},
|
||||
array_keys($results)
|
||||
)
|
||||
) + 1
|
||||
);
|
||||
|
||||
function format_result_line($generator, $min, $max, $avg, $sec) {
|
||||
echo str_pad($generator, PADDING_LENGTH, ' '), "\t",
|
||||
str_pad($min, 4, ' ', STR_PAD_LEFT), "\t",
|
||||
@@ -84,7 +131,10 @@ function format_result_line($generator, $min, $max, $avg, $sec) {
|
||||
|
||||
echo PHP_EOL;
|
||||
format_result_line('Generator:', 'min', 'max', 'avg', 'seconds');
|
||||
format_result_line(str_repeat('─', PADDING_LENGTH), str_repeat('─', 4), str_repeat('─', 4), str_repeat('─', 4), str_repeat('─', 7));
|
||||
format_result_line(
|
||||
str_repeat('─', PADDING_LENGTH), str_repeat('─', 4), str_repeat('─', 4),
|
||||
str_repeat('─', 4), str_repeat('─', 7)
|
||||
);
|
||||
foreach ($results as $generator => $result) {
|
||||
sort($result['lengths']);
|
||||
format_result_line(
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PrivateBin\Controller;
|
||||
use PrivateBin\Data\Filesystem;
|
||||
use PrivateBin\Persistence\ServerSalt;
|
||||
use PrivateBin\Request;
|
||||
|
||||
class JsonApiTest extends TestCase
|
||||
class JsonApiTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $_model;
|
||||
|
||||
protected $_path;
|
||||
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
/* Setup Routine */
|
||||
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
|
||||
@@ -34,7 +33,7 @@ class JsonApiTest extends TestCase
|
||||
Helper::createIniFile(CONF, $options);
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
public function tearDown()
|
||||
{
|
||||
/* Tear Down Routine */
|
||||
unlink(CONF);
|
||||
@@ -273,7 +272,7 @@ class JsonApiTest extends TestCase
|
||||
{
|
||||
$mock_yourls_service = $this->_path . DIRECTORY_SEPARATOR . 'yourls.json';
|
||||
$options = parse_ini_file(CONF, true);
|
||||
$options['main']['basepath'] = 'https://example.com/path'; // missing slash gets added by Configuration constructor
|
||||
$options['main']['basepath'] = 'https://example.com/path';
|
||||
$options['main']['urlshortener'] = 'https://example.com/path/shortenviayourls?link=';
|
||||
$options['yourls']['apiurl'] = $mock_yourls_service;
|
||||
Helper::createIniFile(CONF, $options);
|
||||
@@ -287,7 +286,7 @@ class JsonApiTest extends TestCase
|
||||
new Controller;
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
$this->assertStringContainsString('id="pasteurl" href="https://example.com/1"', $content, 'outputs shortened URL correctly');
|
||||
$this->assertContains('id="pasteurl" href="https://example.com/1"', $content, 'outputs shortened URL correctly');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -301,6 +300,6 @@ class JsonApiTest extends TestCase
|
||||
new Controller;
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
$this->assertStringContainsString('Error calling YOURLS.', $content, 'outputs error correctly');
|
||||
$this->assertContains('Error calling YOURLS.', $content, 'outputs error correctly');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
|
||||
use Jdenticon\Identicon;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Identicon\Identicon;
|
||||
use PrivateBin\Configuration;
|
||||
use PrivateBin\Data\Database;
|
||||
use PrivateBin\Model;
|
||||
@@ -11,7 +10,7 @@ use PrivateBin\Persistence\ServerSalt;
|
||||
use PrivateBin\Persistence\TrafficLimiter;
|
||||
use PrivateBin\Vizhash16x16;
|
||||
|
||||
class ModelTest extends TestCase
|
||||
class ModelTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $_conf;
|
||||
|
||||
@@ -19,7 +18,7 @@ class ModelTest extends TestCase
|
||||
|
||||
protected $_path;
|
||||
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
/* Setup Routine */
|
||||
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
|
||||
@@ -45,7 +44,7 @@ class ModelTest extends TestCase
|
||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
public function tearDown()
|
||||
{
|
||||
/* Tear Down Routine */
|
||||
unlink(CONF);
|
||||
@@ -168,6 +167,10 @@ class ModelTest extends TestCase
|
||||
$this->assertEquals(Helper::getPasteId(), $comment->getParentId(), 'comment parent ID gets initialized to paste ID');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionCode 75
|
||||
*/
|
||||
public function testPasteDuplicate()
|
||||
{
|
||||
$pasteData = Helper::getPastePost();
|
||||
@@ -179,11 +182,13 @@ class ModelTest extends TestCase
|
||||
|
||||
$paste = $this->_model->getPaste();
|
||||
$paste->setData($pasteData);
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionCode(75);
|
||||
$paste->store();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionCode 76
|
||||
*/
|
||||
public function testStoreFail()
|
||||
{
|
||||
$path = $this->_path . DIRECTORY_SEPARATOR . 'model-store-test.sq3';
|
||||
@@ -220,11 +225,13 @@ class ModelTest extends TestCase
|
||||
|
||||
$paste = $model->getPaste();
|
||||
$paste->setData($pasteData);
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionCode(76);
|
||||
$paste->store();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionCode 70
|
||||
*/
|
||||
public function testCommentStoreFail()
|
||||
{
|
||||
$path = $this->_path . DIRECTORY_SEPARATOR . 'model-test.sq3';
|
||||
@@ -266,11 +273,13 @@ class ModelTest extends TestCase
|
||||
|
||||
$comment = $paste->getComment(Helper::getPasteId());
|
||||
$comment->setData($commentData);
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionCode(70);
|
||||
$comment->store();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionCode 69
|
||||
*/
|
||||
public function testCommentDuplicate()
|
||||
{
|
||||
$pasteData = Helper::getPastePost();
|
||||
@@ -287,8 +296,6 @@ class ModelTest extends TestCase
|
||||
|
||||
$comment = $paste->getComment(Helper::getPasteId());
|
||||
$comment->setData($commentData);
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionCode(69);
|
||||
$comment->store();
|
||||
}
|
||||
|
||||
@@ -307,15 +314,8 @@ class ModelTest extends TestCase
|
||||
$comment->get();
|
||||
$comment->store();
|
||||
|
||||
$identicon = new Identicon(array(
|
||||
'hash' => TrafficLimiter::getHash(),
|
||||
'size' => 16,
|
||||
'style' => array(
|
||||
'backgroundColor' => '#fff0', // fully transparent, for dark mode
|
||||
'padding' => 0,
|
||||
),
|
||||
));
|
||||
$pngdata = $identicon->getImageDataUri('png');
|
||||
$identicon = new Identicon();
|
||||
$pngdata = $identicon->getImageDataUri(TrafficLimiter::getHash(), 16);
|
||||
$comment = current($this->_model->getPaste(Helper::getPasteId())->get()['comments']);
|
||||
$this->assertEquals($pngdata, $comment['meta']['icon'], 'icon gets set');
|
||||
}
|
||||
@@ -327,40 +327,52 @@ class ModelTest extends TestCase
|
||||
$this->assertFalse(Paste::isValidId('../bar/baz'), 'path attack');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionCode 64
|
||||
*/
|
||||
public function testInvalidPaste()
|
||||
{
|
||||
$this->_model->getPaste(Helper::getPasteId())->delete();
|
||||
$paste = $this->_model->getPaste(Helper::getPasteId());
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionCode(64);
|
||||
$paste->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionCode 75
|
||||
*/
|
||||
public function testInvalidPasteFormat()
|
||||
{
|
||||
$pasteData = Helper::getPastePost();
|
||||
$pasteData['adata'][1] = 'format does not exist';
|
||||
$paste = $this->_model->getPaste();
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionCode(75);
|
||||
$paste->setData($pasteData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionCode 60
|
||||
*/
|
||||
public function testInvalidPasteId()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionCode(60);
|
||||
$this->_model->getPaste('');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionCode 62
|
||||
*/
|
||||
public function testInvalidComment()
|
||||
{
|
||||
$paste = $this->_model->getPaste();
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionCode(62);
|
||||
$paste->getComment(Helper::getPasteId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionCode 67
|
||||
*/
|
||||
public function testInvalidCommentDeletedPaste()
|
||||
{
|
||||
$pasteData = Helper::getPastePost();
|
||||
@@ -370,11 +382,13 @@ class ModelTest extends TestCase
|
||||
|
||||
$comment = $paste->getComment(Helper::getPasteId());
|
||||
$paste->delete();
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionCode(67);
|
||||
$comment->store();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionCode 68
|
||||
*/
|
||||
public function testInvalidCommentData()
|
||||
{
|
||||
$pasteData = Helper::getPastePost();
|
||||
@@ -384,17 +398,18 @@ class ModelTest extends TestCase
|
||||
$paste->store();
|
||||
|
||||
$comment = $paste->getComment(Helper::getPasteId());
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionCode(68);
|
||||
$comment->store();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionCode 65
|
||||
*/
|
||||
public function testInvalidCommentParent()
|
||||
{
|
||||
$paste = $this->_model->getPaste(Helper::getPasteId());
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionCode(65);
|
||||
$paste->getComment('');
|
||||
$comment = $paste->getComment('');
|
||||
$comment->store();
|
||||
}
|
||||
|
||||
public function testExpiration()
|
||||
@@ -412,6 +427,10 @@ class ModelTest extends TestCase
|
||||
$this->assertEquals((float) 300, (float) $paste['meta']['time_to_live'], 'remaining time is set correctly', 1.0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionCode 64
|
||||
*/
|
||||
public function testCommentDeletion()
|
||||
{
|
||||
$pasteData = Helper::getPastePost();
|
||||
@@ -420,8 +439,6 @@ class ModelTest extends TestCase
|
||||
$paste = $this->_model->getPaste();
|
||||
$paste->setData($pasteData);
|
||||
$paste->store();
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionCode(64);
|
||||
$paste->getComment(Helper::getPasteId())->delete();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PrivateBin\Data\Filesystem;
|
||||
use PrivateBin\Persistence\PurgeLimiter;
|
||||
|
||||
class PurgeLimiterTest extends TestCase
|
||||
class PurgeLimiterTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $_path;
|
||||
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
/* Setup Routine */
|
||||
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
|
||||
@@ -20,7 +19,7 @@ class PurgeLimiterTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
public function tearDown()
|
||||
{
|
||||
/* Tear Down Routine */
|
||||
Helper::rmDir($this->_path);
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PrivateBin\Data\Filesystem;
|
||||
use PrivateBin\Persistence\ServerSalt;
|
||||
|
||||
class ServerSaltTest extends TestCase
|
||||
class ServerSaltTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $_path;
|
||||
|
||||
@@ -14,7 +13,7 @@ class ServerSaltTest extends TestCase
|
||||
|
||||
private $_invalidFile;
|
||||
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
/* Setup Routine */
|
||||
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
|
||||
@@ -34,7 +33,7 @@ class ServerSaltTest extends TestCase
|
||||
$this->_invalidFile = $this->_invalidPath . DIRECTORY_SEPARATOR . 'salt.php';
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
public function tearDown()
|
||||
{
|
||||
/* Tear Down Routine */
|
||||
chmod($this->_invalidPath, 0700);
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PrivateBin\Data\Filesystem;
|
||||
use PrivateBin\Persistence\ServerSalt;
|
||||
use PrivateBin\Persistence\TrafficLimiter;
|
||||
|
||||
class TrafficLimiterTest extends TestCase
|
||||
class TrafficLimiterTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $_path;
|
||||
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
/* Setup Routine */
|
||||
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'trafficlimit';
|
||||
@@ -18,7 +17,7 @@ class TrafficLimiterTest extends TestCase
|
||||
TrafficLimiter::setStore($store);
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
public function tearDown()
|
||||
{
|
||||
/* Tear Down Routine */
|
||||
Helper::rmDir($this->_path . DIRECTORY_SEPARATOR);
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PrivateBin\Request;
|
||||
|
||||
class RequestTest extends TestCase
|
||||
class RequestTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
/* Setup Routine */
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
/* Tear Down Routine */
|
||||
}
|
||||
|
||||
public function reset()
|
||||
{
|
||||
$_SERVER = array();
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PrivateBin\I18n;
|
||||
use PrivateBin\View;
|
||||
|
||||
class ViewTest extends TestCase
|
||||
class ViewTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private static $error = 'foo bar';
|
||||
|
||||
@@ -30,7 +29,7 @@ class ViewTest extends TestCase
|
||||
|
||||
private $_content = array();
|
||||
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
/* Setup Routine */
|
||||
$page = new View;
|
||||
@@ -94,10 +93,15 @@ class ViewTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
/* Tear Down Routine */
|
||||
}
|
||||
|
||||
public function testTemplateRendersCorrectly()
|
||||
{
|
||||
foreach ($this->_content as $template => $content) {
|
||||
$this->assertMatchesRegularExpression(
|
||||
$this->assertRegExp(
|
||||
'#<div[^>]+id="errormessage"[^>]*>.*' . self::$error . '#s',
|
||||
$content,
|
||||
$template . ': outputs error correctly'
|
||||
@@ -106,23 +110,23 @@ class ViewTest extends TestCase
|
||||
// yourlsproxy template only displays error message
|
||||
continue;
|
||||
}
|
||||
$this->assertMatchesRegularExpression(
|
||||
$this->assertRegExp(
|
||||
'#<[^>]+id="password"[^>]*>#',
|
||||
$content,
|
||||
$template . ': password available if configured'
|
||||
);
|
||||
$this->assertMatchesRegularExpression(
|
||||
$this->assertRegExp(
|
||||
'#<input[^>]+id="opendiscussion"[^>]*checked="checked"[^>]*>#',
|
||||
$content,
|
||||
$template . ': checked discussion if configured'
|
||||
);
|
||||
$this->assertMatchesRegularExpression(
|
||||
$this->assertRegExp(
|
||||
'#<[^>]+id="opendiscussionoption"[^>]*>#',
|
||||
$content,
|
||||
$template . ': discussions available if configured'
|
||||
);
|
||||
// testing version number in JS address, since other instances may not be present in different templates
|
||||
$this->assertMatchesRegularExpression(
|
||||
$this->assertRegExp(
|
||||
'#<script[^>]+src="js/privatebin.js\\?' . rawurlencode(self::$version) . '"[^>]*>#',
|
||||
$content,
|
||||
$template . ': outputs version correctly'
|
||||
@@ -130,11 +134,13 @@ class ViewTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionCode 80
|
||||
*/
|
||||
public function testMissingTemplate()
|
||||
{
|
||||
$test = new View;
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionCode(80);
|
||||
$test->draw('123456789 does not exist!');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PrivateBin\Data\Filesystem;
|
||||
use PrivateBin\Persistence\ServerSalt;
|
||||
use PrivateBin\Vizhash16x16;
|
||||
|
||||
class Vizhash16x16Test extends TestCase
|
||||
class Vizhash16x16Test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $_file;
|
||||
|
||||
private $_path;
|
||||
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
/* Setup Routine */
|
||||
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
|
||||
@@ -22,7 +21,7 @@ class Vizhash16x16Test extends TestCase
|
||||
ServerSalt::setStore(Filesystem::getInstance(array('dir' => $this->_path)));
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
public function tearDown()
|
||||
{
|
||||
/* Tear Down Routine */
|
||||
chmod($this->_path, 0700);
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PrivateBin\Configuration;
|
||||
use PrivateBin\YourlsProxy;
|
||||
|
||||
class YourlsProxyTest extends TestCase
|
||||
class YourlsProxyTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $_conf;
|
||||
|
||||
@@ -12,7 +11,7 @@ class YourlsProxyTest extends TestCase
|
||||
|
||||
private $_mock_yourls_service;
|
||||
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
/* Setup Routine */
|
||||
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
|
||||
@@ -21,7 +20,7 @@ class YourlsProxyTest extends TestCase
|
||||
}
|
||||
$this->_mock_yourls_service = $this->_path . DIRECTORY_SEPARATOR . 'yourls.json';
|
||||
$options = parse_ini_file(CONF_SAMPLE, true);
|
||||
$options['main']['basepath'] = 'https://example.com/';
|
||||
$options['main']['basepath'] = 'https://example.com';
|
||||
$options['main']['urlshortener'] = 'https://example.com/shortenviayourls?link=';
|
||||
$options['yourls']['apiurl'] = $this->_mock_yourls_service;
|
||||
Helper::confBackup();
|
||||
@@ -29,7 +28,7 @@ class YourlsProxyTest extends TestCase
|
||||
$this->_conf = new Configuration;
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
public function tearDown()
|
||||
{
|
||||
/* Tear Down Routine */
|
||||
unlink(CONF);
|
||||
|
||||
@@ -1,22 +1,19 @@
|
||||
<?xml version="1.0"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="Bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
|
||||
<coverage>
|
||||
<include>
|
||||
<directory suffix=".php">../lib</directory>
|
||||
</include>
|
||||
<exclude>
|
||||
<file>../lib/Data/AbstractData.php</file>
|
||||
</exclude>
|
||||
<report>
|
||||
<clover outputFile="log/coverage-clover.xml"/>
|
||||
<html outputDirectory="log/php-coverage-report" lowUpperBound="50" highLowerBound="80"/>
|
||||
</report>
|
||||
</coverage>
|
||||
<phpunit bootstrap="Bootstrap.php" colors="true">
|
||||
<testsuite name="PrivateBin Test Suite">
|
||||
<directory suffix=".php">./</directory>
|
||||
<exclude>ConfigurationTestGenerator.php</exclude>
|
||||
</testsuite>
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory suffix=".php">../lib</directory>
|
||||
<exclude>
|
||||
<file>../lib/Data/AbstractData.php</file>
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
<logging>
|
||||
<testdoxHtml outputFile="log/testdox.html"/>
|
||||
<log type="coverage-clover" target="log/coverage-clover.xml" />
|
||||
<log type="coverage-html" target="log/php-coverage-report" lowUpperBound="50" highLowerBound="80" />
|
||||
<log type="testdox-html" target="log/testdox.html" />
|
||||
</logging>
|
||||
</phpunit>
|
||||
|
||||
10
vendor/composer/installed.php
vendored
10
vendor/composer/installed.php
vendored
@@ -5,18 +5,18 @@
|
||||
'type' => 'project',
|
||||
'install_path' => __DIR__ . '/../../',
|
||||
'aliases' => array(),
|
||||
'reference' => '46013df6201304840c8dab82af63cc9000a6d239',
|
||||
'reference' => '78aa70e3ab9277172489f9d88f8fd08cc1d03c97',
|
||||
'name' => 'privatebin/privatebin',
|
||||
'dev' => false,
|
||||
),
|
||||
'versions' => array(
|
||||
'jdenticon/jdenticon' => array(
|
||||
'pretty_version' => '1.0.2',
|
||||
'version' => '1.0.2.0',
|
||||
'pretty_version' => '1.0.1',
|
||||
'version' => '1.0.1.0',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../jdenticon/jdenticon',
|
||||
'aliases' => array(),
|
||||
'reference' => 'cabb7a44c413c318392a341c5d3ca30fcdd57a6f',
|
||||
'reference' => '994ee07293fb978f983393ffcb2c0250592a6ac4',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'mlocati/ip-lib' => array(
|
||||
@@ -43,7 +43,7 @@
|
||||
'type' => 'project',
|
||||
'install_path' => __DIR__ . '/../../',
|
||||
'aliases' => array(),
|
||||
'reference' => '46013df6201304840c8dab82af63cc9000a6d239',
|
||||
'reference' => '78aa70e3ab9277172489f9d88f8fd08cc1d03c97',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'yzalis/identicon' => array(
|
||||
|
||||
@@ -21,15 +21,6 @@ class SuperSampleBuffer
|
||||
const IDX_G = 3;
|
||||
const IDX_B = 4;
|
||||
|
||||
private $samples;
|
||||
private $samplesPerPixel;
|
||||
|
||||
private $pixelOffset;
|
||||
private $subPixelOffset;
|
||||
|
||||
private $width;
|
||||
private $used;
|
||||
|
||||
/**
|
||||
* Creates a color buffer keeping an average color out of several
|
||||
* color samples per pixel.
|
||||
|
||||
Reference in New Issue
Block a user