88 Commits

Author SHA1 Message Date
github-actions[bot]
ba5c859d85 Merge remote-tracking branch 'origin/master' into php8 2022-11-03 18:55:30 +00:00
El RIDO
66600e5eb3 Merge pull request #1003 from PrivateBin/yourls-cleanup
improve configuration wording, adjust self check
2022-11-03 19:54:56 +01:00
El RIDO
987ead2719 ensure the basepath ends in a slash, if one is set 2022-11-03 07:47:50 +01:00
El RIDO
a731a1143c update jdenticon 2022-10-31 20:36:39 +01:00
github-actions[bot]
46013df620 Merge remote-tracking branch 'origin/master' into php8 2022-10-31 16:19:19 +00:00
El RIDO
449dbb8377 Merge pull request #1010 from PrivateBin/dependabot/composer/phpunit/phpunit-5.7.27
Bump phpunit/phpunit from 5.6.3 to 5.7.27
2022-10-31 17:18:50 +01:00
github-actions[bot]
f0bbf99306 Merge remote-tracking branch 'origin/master' into php8 2022-10-31 16:07:38 +00:00
El RIDO
606d70863e Merge pull request #1009 from PrivateBin/dependabot/composer/jdenticon/jdenticon-1.0.2
Bump jdenticon/jdenticon from 1.0.1 to 1.0.2
2022-10-31 17:07:00 +01:00
dependabot[bot]
b63de431a7 Bump phpunit/phpunit from 5.6.3 to 5.7.27
Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 5.6.3 to 5.7.27.
- [Release notes](https://github.com/sebastianbergmann/phpunit/releases)
- [Changelog](https://github.com/sebastianbergmann/phpunit/blob/5.7.27/ChangeLog-5.7.md)
- [Commits](https://github.com/sebastianbergmann/phpunit/compare/5.6.3...5.7.27)

---
updated-dependencies:
- dependency-name: phpunit/phpunit
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-31 11:33:10 +00:00
dependabot[bot]
be1989b117 Bump jdenticon/jdenticon from 1.0.1 to 1.0.2
Bumps [jdenticon/jdenticon](https://github.com/dmester/jdenticon-php) from 1.0.1 to 1.0.2.
- [Release notes](https://github.com/dmester/jdenticon-php/releases)
- [Commits](https://github.com/dmester/jdenticon-php/compare/1.0.1...1.0.2)

---
updated-dependencies:
- dependency-name: jdenticon/jdenticon
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-31 11:32:59 +00:00
El RIDO
c44b252aa8 Merge branch 'master' into php8 2022-10-29 19:38:01 +02:00
El RIDO
432d3e71d3 improve configuration wording, adjust self check 2022-10-29 07:58:40 +02:00
El RIDO
34264cb7f5 Merge branch 'master' into php8 2022-10-26 08:24:41 +02:00
El RIDO
7b98d7381f allow tests to be manually triggered 2022-10-26 05:30:37 +02:00
github-actions[bot]
fa61e4507c Merge remote-tracking branch 'origin/master' into php8 2022-10-26 02:39:53 +00:00
github-actions[bot]
f79c8c63e5 Merge remote-tracking branch 'origin/master' into php8 2022-10-25 19:12:00 +00:00
El RIDO
5b3d61cedc revert, this one actually was correct 2022-10-25 06:58:42 +02:00
El RIDO
510103fd9f make tests compatible with newer phpunit 2022-10-25 06:55:24 +02:00
El RIDO
b890d768d1 enable use of PHP 8.2 2022-10-25 06:53:26 +02:00
El RIDO
27965d0287 make tests compatible with newer phpunit 2022-10-25 06:53:07 +02:00
El RIDO
8ed9fccf25 make YourlsProxyTest compatible with newer phpunit 2022-10-25 06:43:17 +02:00
El RIDO
522c2721a2 make YourlsProxyTest compatible with newer phpunit 2022-10-25 06:41:42 +02:00
El RIDO
17d7a6967e make YourlsProxyTest compatible with newer phpunit 2022-10-25 06:39:50 +02:00
El RIDO
f6edcc1acd Merge branch 'master' into php8 2022-10-25 06:37:15 +02:00
github-actions[bot]
5b2ec7f7c2 Merge remote-tracking branch 'origin/master' into php8 2022-10-23 03:14:46 +00:00
github-actions[bot]
5768b1e4bd Merge remote-tracking branch 'origin/master' into php8 2022-10-22 16:35:34 +00:00
github-actions[bot]
23928d26f0 Merge remote-tracking branch 'origin/master' into php8 2022-10-07 05:54:07 +00:00
github-actions[bot]
cbeb30adf1 Merge remote-tracking branch 'origin/master' into php8 2022-10-07 03:59:28 +00:00
github-actions[bot]
b488359e35 Merge remote-tracking branch 'origin/master' into php8 2022-09-30 03:25:00 +00:00
github-actions[bot]
9f541e6276 Merge remote-tracking branch 'origin/master' into php8 2022-09-29 19:06:55 +00:00
github-actions[bot]
4aa95107d3 Merge remote-tracking branch 'origin/master' into php8 2022-09-26 10:16:10 +00:00
github-actions[bot]
4f7b3d2ac3 Merge remote-tracking branch 'origin/master' into php8 2022-09-24 08:06:29 +00:00
github-actions[bot]
5165845b54 Merge remote-tracking branch 'origin/master' into php8 2022-09-18 12:45:32 +00:00
github-actions[bot]
05e236ed6c Merge remote-tracking branch 'origin/master' into php8 2022-08-24 04:28:45 +00:00
El RIDO
8c2cc18b66 Merge branch 'master' into php8 2022-07-31 08:53:52 +02:00
github-actions[bot]
d7e88b236e Merge remote-tracking branch 'origin/master' into php8 2022-06-10 02:59:39 +00:00
github-actions[bot]
b48430cd4d Merge remote-tracking branch 'origin/master' into php8 2022-06-08 18:29:26 +00:00
github-actions[bot]
b5d9850bee Merge remote-tracking branch 'origin/master' into php8 2022-06-06 05:36:56 +00:00
github-actions[bot]
8b534ace28 Merge remote-tracking branch 'origin/master' into php8 2022-06-02 17:22:48 +00:00
El RIDO
2ad79ebf71 add php 8.1 unit tests 2022-06-01 20:50:38 +02:00
El RIDO
a376f894a9 Merge branch 'php8' of github.com:PrivateBin/PrivateBin into php8 2022-06-01 20:48:33 +02:00
github-actions[bot]
43cd87c417 Merge remote-tracking branch 'origin/master' into php8 2022-05-02 17:22:36 +00:00
github-actions[bot]
b8be814015 Merge remote-tracking branch 'origin/master' into php8 2022-04-30 07:45:50 +00:00
github-actions[bot]
b73f4be25e Merge remote-tracking branch 'origin/master' into php8 2022-04-30 07:23:22 +00:00
github-actions[bot]
f18770eaa6 Merge remote-tracking branch 'origin/master' into php8 2022-04-28 17:44:58 +00:00
github-actions[bot]
878374979b Merge remote-tracking branch 'origin/master' into php8 2022-04-20 17:56:55 +00:00
github-actions[bot]
abd722d0e4 Merge remote-tracking branch 'origin/master' into php8 2022-04-14 04:20:29 +00:00
github-actions[bot]
16d6cfb1ac Merge remote-tracking branch 'origin/master' into php8 2022-04-11 17:09:34 +00:00
github-actions[bot]
60bb381796 Merge remote-tracking branch 'origin/master' into php8 2022-04-10 09:16:48 +00:00
github-actions[bot]
f2397ac532 Merge remote-tracking branch 'origin/master' into php8 2022-04-09 17:56:36 +00:00
github-actions[bot]
ebf6a92c8f Merge remote-tracking branch 'origin/master' into php8 2022-04-09 12:39:05 +00:00
github-actions[bot]
634b3a6605 Merge remote-tracking branch 'origin/master' into php8 2022-04-04 17:13:18 +00:00
github-actions[bot]
e770065edf Merge remote-tracking branch 'origin/master' into php8 2022-03-30 18:49:51 +00:00
github-actions[bot]
5f53150390 Merge remote-tracking branch 'origin/master' into php8 2022-03-28 17:06:05 +00:00
github-actions[bot]
184b8b567d Merge remote-tracking branch 'origin/master' into php8 2022-03-28 17:03:38 +00:00
github-actions[bot]
de6db843ba Merge remote-tracking branch 'origin/master' into php8 2022-03-23 19:45:37 +00:00
github-actions[bot]
6caf1a5f06 Merge remote-tracking branch 'origin/master' into php8 2022-03-01 05:45:16 +00:00
github-actions[bot]
bda1ab23b8 Merge remote-tracking branch 'origin/master' into php8 2022-02-28 18:22:17 +00:00
github-actions[bot]
50fb12e3b3 Merge remote-tracking branch 'origin/master' into php8 2022-02-27 18:33:35 +00:00
github-actions[bot]
955334ff91 Merge remote-tracking branch 'origin/master' into php8 2022-02-26 10:53:14 +00:00
El RIDO
fa7aa3e88c fix composer lock 2022-02-26 07:22:32 +01:00
El RIDO
38c13398fc Merge branch 'master' into php8 2022-02-26 06:51:32 +01:00
github-actions[bot]
14de09789e Merge remote-tracking branch 'origin/master' into php8 2022-02-18 05:51:15 +00:00
github-actions[bot]
595f9cf42e Merge remote-tracking branch 'origin/master' into php8 2022-02-18 05:18:21 +00:00
github-actions[bot]
fb0d13937b Merge remote-tracking branch 'origin/master' into php8 2022-02-17 19:38:19 +00:00
github-actions[bot]
26ae7db0eb Merge remote-tracking branch 'origin/master' into php8 2022-02-13 08:04:35 +00:00
github-actions[bot]
0212429c4a Merge remote-tracking branch 'origin/master' into php8 2022-02-13 07:59:02 +00:00
github-actions[bot]
484ab3cd84 Merge remote-tracking branch 'origin/master' into php8 2022-02-12 16:29:53 +00:00
github-actions[bot]
7694c1460b Merge remote-tracking branch 'origin/master' into php8 2022-02-12 16:18:17 +00:00
github-actions[bot]
8812b09f5f Merge remote-tracking branch 'origin/master' into php8 2022-01-31 05:41:10 +00:00
github-actions[bot]
f5d8d7735f Merge remote-tracking branch 'origin/master' into php8 2022-01-10 20:29:09 +00:00
github-actions[bot]
3a801bc238 Merge remote-tracking branch 'origin/master' into php8 2021-10-30 15:26:05 +00:00
El RIDO
91462da29d update composer 2021-10-07 22:39:57 +02:00
El RIDO
5c61a442a0 phpunit compatibility 2021-10-07 22:36:11 +02:00
El RIDO
9c81d85bb7 phpunit compatibility 2021-10-07 22:34:15 +02:00
El RIDO
168ce1d85c phpunit compatibility 2021-10-07 22:25:51 +02:00
El RIDO
1f6b962468 phpunit compatibility 2021-10-07 22:24:30 +02:00
El RIDO
1f95f57be9 phpunit compatibility 2021-10-07 22:22:32 +02:00
El RIDO
a2e479192f phpunit compatibility 2021-10-07 22:20:25 +02:00
El RIDO
3f469f715f Merge branch 'master' into php8 2021-10-07 22:17:11 +02:00
El RIDO
09133f4f10 kudos StyleCI for spotting the unneccessary namespace 2020-10-11 11:39:36 +02:00
El RIDO
ec190fdcf6 phpunit 9 requires php >= 7.3 2020-10-11 10:34:03 +02:00
El RIDO
17c3cb35c0 change tests for phpunit 9 support, breaking support with phpunit 5.6 2020-10-11 10:31:24 +02:00
El RIDO
37a620df95 return type void is required as of PHPunit 7, breaking test compatibility with PHP < 7.1 2020-10-10 12:22:20 +02:00
El RIDO
6f90df9545 updating tests by dropping PHPunit 4.6 support 2020-10-10 12:08:58 +02:00
El RIDO
99f50f6de3 update composer dependencies - test phpunit 9 2020-10-10 11:50:48 +02:00
El RIDO
50f81e1d2e unlock PHP 8 for composer 2020-10-10 11:24:36 +02:00
El RIDO
4312f77385 experimentally enable PHP 8 beta unit testing 2020-10-10 11:21:53 +02:00
33 changed files with 1164 additions and 1025 deletions

View File

@@ -1,5 +1,7 @@
name: Tests
on: [push]
on:
push:
workflow_dispatch:
jobs:
@@ -17,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4']
php-versions: ['7.3', '7.4', '8.0', '8.1', '8.2']
name: PHP ${{ matrix.php-versions }} unit tests on ${{ matrix.operating-system }}
env:
extensions: gd, sqlite3
@@ -66,7 +68,6 @@ 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
@@ -117,4 +118,3 @@ jobs:
- name: Run unit tests
run: npm test
working-directory: js

View File

@@ -3,7 +3,7 @@
* **1.4.1 (not yet released)**
* ADDED: Translations for Turkish, Slovak and Greek
* ADDED: S3 Storage backend (#994)
* ADDED: Jdenticons as an option for comment icons (#793)
* CHANGED: Switched to Jdenticons as the default 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)

View File

@@ -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 (when using identicon or vizhash icons, jdenticon works without it)
- GD extension
- 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

View File

@@ -7,9 +7,10 @@
; (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
; This URL is essential to allow Opengraph images to be displayed on social networks
; basepath = ""
; 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/"
; enable or disable the discussion feature, defaults to true
discussion = true
@@ -55,9 +56,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.
@@ -69,7 +70,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" / "identicon" (default) / "jdenticon" / "vizhash".
; "none" / "vizhash" / "identicon" / "jdenticon" (default).
; icon = "none"
; Content Security Policy headers allow a website to restrict what sources are
@@ -230,18 +231,18 @@ dir = PATH "data"
;secretkey = "secret access key"
[yourls]
; 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.
; 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.
; (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 = ""
; apiurl = "https://yourls.example.com/yourls-api.php"

View File

@@ -35,7 +35,7 @@
"aws/aws-sdk-php" : "3.239.0"
},
"require-dev" : {
"phpunit/phpunit" : "^4.6 || ^5.0"
"phpunit/phpunit" : "^9"
},
"autoload" : {
"psr-4" : {

1579
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -53,7 +53,7 @@ class Configuration
'languagedefault' => '',
'urlshortener' => '',
'qrcode' => true,
'icon' => 'identicon',
'icon' => 'jdenticon',
'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,6 +236,14 @@ 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'] .= '/';
}
}
/**

View File

@@ -165,10 +165,7 @@ class Comment extends AbstractModel
if ($icon != 'none') {
$pngdata = '';
$hmac = TrafficLimiter::getHash();
if ($icon == 'identicon') {
$identicon = new Identicon();
$pngdata = $identicon->getImageDataUri($hmac, 16);
} elseif ($icon == 'jdenticon') {
if ($icon == 'jdenticon') {
$jdenticon = new Jdenticon(array(
'hash' => $hmac,
'size' => 16,
@@ -178,6 +175,9 @@ 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(

View File

@@ -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;
}

View File

@@ -1,8 +1,9 @@
<?php
use PHPUnit\Framework\TestCase;
use PrivateBin\Configuration;
class ConfigurationTest extends PHPUnit_Framework_TestCase
class ConfigurationTest extends TestCase
{
private $_minimalConfig;
@@ -10,7 +11,7 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
private $_path;
public function setUp()
public function setUp(): void
{
/* Setup Routine */
Helper::confBackup();
@@ -23,7 +24,7 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
}
}
public function tearDown()
public function tearDown(): void
{
/* Tear Down Routine */
Helper::rmDir($this->_path);
@@ -55,13 +56,11 @@ class ConfigurationTest extends PHPUnit_Framework_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;
}
@@ -72,25 +71,21 @@ class ConfigurationTest extends PHPUnit_Framework_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');
}

View File

@@ -408,13 +408,14 @@ 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 PHPUnit_Framework_TestCase
class ConfigurationCombinationsTest extends TestCase
{
private $_conf;
@@ -422,7 +423,7 @@ class ConfigurationCombinationsTest extends PHPUnit_Framework_TestCase
private $_path;
public function setUp()
public function setUp(): void
{
/* Setup Routine */
Helper::confBackup();
@@ -431,7 +432,7 @@ class ConfigurationCombinationsTest extends PHPUnit_Framework_TestCase
$this->reset();
}
public function tearDown()
public function tearDown(): void
{
/* Tear Down Routine */
unlink(CONF);
@@ -560,7 +561,7 @@ EOT;
case 'Delete':
$code .= <<<'EOT'
$this->assertRegExp(
$this->assertMatchesRegularExpression(
'#<div[^>]*id="status"[^>]*>.*Paste was properly deleted[^<]*</div>#s',
$content,
'outputs deleted status correctly'

View File

@@ -1,18 +1,19 @@
<?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 PHPUnit_Framework_TestCase
class ControllerTest extends TestCase
{
protected $_data;
protected $_path;
public function setUp()
public function setUp(): void
{
/* Setup Routine */
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
@@ -22,7 +23,7 @@ class ControllerTest extends PHPUnit_Framework_TestCase
$this->reset();
}
public function tearDown()
public function tearDown(): void
{
/* Tear Down Routine */
unlink(CONF);
@@ -55,17 +56,17 @@ class ControllerTest extends PHPUnit_Framework_TestCase
new Controller;
$content = ob_get_contents();
ob_end_clean();
$this->assertContains(
$this->assertStringContainsString(
'<title>PrivateBin</title>',
$content,
'outputs title correctly'
);
$this->assertNotContains(
$this->assertStringNotContainsString(
'id="shortenbutton"',
$content,
'doesn\'t output shortener button'
);
$this->assertRegExp(
$this->assertMatchesRegularExpression(
'# href="https://' . preg_quote($_SERVER['HTTP_HOST']) . '/">switching to HTTPS#',
$content,
'outputs configured https URL correctly'
@@ -85,7 +86,7 @@ class ControllerTest extends PHPUnit_Framework_TestCase
new Controller;
$content = ob_get_contents();
ob_end_clean();
$this->assertContains(
$this->assertStringContainsString(
'<title>PrivateBin</title>',
$content,
'outputs title correctly'
@@ -106,7 +107,7 @@ class ControllerTest extends PHPUnit_Framework_TestCase
new Controller;
$content = ob_get_contents();
ob_end_clean();
$this->assertContains(
$this->assertStringContainsString(
'<title>PrivateBin</title>',
$content,
'outputs title correctly'
@@ -127,7 +128,7 @@ class ControllerTest extends PHPUnit_Framework_TestCase
new Controller;
$content = ob_get_contents();
ob_end_clean();
$this->assertRegExp(
$this->assertMatchesRegularExpression(
'#id="shortenbutton"[^>]*data-shortener="' . preg_quote($shortener) . '"#',
$content,
'outputs configured shortener URL correctly'
@@ -141,6 +142,8 @@ class ControllerTest extends PHPUnit_Framework_TestCase
public function testConf()
{
file_put_contents(CONF, '');
$this->expectException(Exception::class);
$this->expectExceptionCode(2);
new Controller;
}
@@ -436,8 +439,6 @@ class ControllerTest extends PHPUnit_Framework_TestCase
* silently removed, check that this case is handled
*
* @runInSeparateProcess
* @expectedException Exception
* @expectedExceptionCode 90
*/
public function testCreateBrokenUpload()
{
@@ -449,6 +450,8 @@ class ControllerTest extends PHPUnit_Framework_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');
}
@@ -806,7 +809,7 @@ class ControllerTest extends PHPUnit_Framework_TestCase
new Controller;
$content = ob_get_contents();
ob_end_clean();
$this->assertRegExp(
$this->assertMatchesRegularExpression(
'#<div[^>]*id="status"[^>]*>.*Paste was properly deleted\.#s',
$content,
'outputs deleted status correctly'
@@ -826,7 +829,7 @@ class ControllerTest extends PHPUnit_Framework_TestCase
new Controller;
$content = ob_get_contents();
ob_end_clean();
$this->assertRegExp(
$this->assertMatchesRegularExpression(
'#<div[^>]*id="errormessage"[^>]*>.*Invalid paste ID\.#s',
$content,
'outputs delete error correctly'
@@ -845,7 +848,7 @@ class ControllerTest extends PHPUnit_Framework_TestCase
new Controller;
$content = ob_get_contents();
ob_end_clean();
$this->assertRegExp(
$this->assertMatchesRegularExpression(
'#<div[^>]*id="errormessage"[^>]*>.*Paste does not exist, has expired or has been deleted\.#s',
$content,
'outputs delete error correctly'
@@ -864,7 +867,7 @@ class ControllerTest extends PHPUnit_Framework_TestCase
new Controller;
$content = ob_get_contents();
ob_end_clean();
$this->assertRegExp(
$this->assertMatchesRegularExpression(
'#<div[^>]*id="errormessage"[^>]*>.*Wrong deletion token\. Paste was not deleted\.#s',
$content,
'outputs delete error correctly'
@@ -912,7 +915,7 @@ class ControllerTest extends PHPUnit_Framework_TestCase
new Controller;
$content = ob_get_contents();
ob_end_clean();
$this->assertRegExp(
$this->assertMatchesRegularExpression(
'#<div[^>]*id="errormessage"[^>]*>.*Paste does not exist, has expired or has been deleted\.#s',
$content,
'outputs error correctly'
@@ -935,7 +938,7 @@ class ControllerTest extends PHPUnit_Framework_TestCase
new Controller;
$content = ob_get_contents();
ob_end_clean();
$this->assertRegExp(
$this->assertMatchesRegularExpression(
'#<div[^>]*id="status"[^>]*>.*Paste was properly deleted\.#s',
$content,
'outputs deleted status correctly'

View File

@@ -17,7 +17,7 @@ class ControllerWithDbTest extends ControllerTest
),
);
public function setUp()
public function setUp(): void
{
/* Setup Routine */
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';

View File

@@ -14,7 +14,7 @@ class ControllerWithGcsTest extends ControllerTest
private static $_bucket;
private $_options = array();
public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
$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()
public function setUp(): void
{
/* Setup Routine */
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';

View File

@@ -1,11 +1,12 @@
<?php
use PHPUnit\Framework\TestCase;
use PrivateBin\Controller;
use PrivateBin\Data\Database;
use PrivateBin\Data\Filesystem;
use PrivateBin\Persistence\ServerSalt;
class DatabaseTest extends PHPUnit_Framework_TestCase
class DatabaseTest extends TestCase
{
private $_model;
@@ -18,14 +19,14 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION),
);
public function setUp()
public function setUp(): void
{
/* Setup Routine */
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
$this->_model = Database::getInstance($this->_options);
}
public function tearDown()
public function tearDown(): void
{
/* Tear Down Routine */
if (is_dir($this->_path)) {
@@ -42,7 +43,7 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
$this->assertNotEquals($salt, '');
ServerSalt::setStore($this->_model);
ServerSalt::get();
$this->assertFileNotExists($file, 'legacy ServerSalt got removed');
$this->assertFileDoesNotExist($file, 'legacy ServerSalt got removed');
$this->assertEquals($salt, ServerSalt::get(), 'ServerSalt got preserved & migrated');
}
@@ -136,124 +137,102 @@ class DatabaseTest extends PHPUnit_Framework_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);
}

View File

@@ -1,8 +1,9 @@
<?php
use PHPUnit\Framework\TestCase;
use PrivateBin\Data\Filesystem;
class FilesystemTest extends PHPUnit_Framework_TestCase
class FilesystemTest extends TestCase
{
private $_model;
@@ -10,7 +11,7 @@ class FilesystemTest extends PHPUnit_Framework_TestCase
private $_invalidPath;
public function setUp()
public function setUp(): void
{
/* Setup Routine */
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
@@ -24,7 +25,7 @@ class FilesystemTest extends PHPUnit_Framework_TestCase
}
}
public function tearDown()
public function tearDown(): void
{
/* Tear Down Routine */
chmod($this->_invalidPath, 0700);
@@ -162,13 +163,13 @@ class FilesystemTest extends PHPUnit_Framework_TestCase
$this->_model->purge(10);
foreach ($ids as $dataid => $storagedir) {
$this->assertFileExists($storagedir . $dataid . '.php', "paste $dataid exists in new format");
$this->assertFileNotExists($storagedir . $dataid, "old format paste $dataid got removed");
$this->assertFileDoesNotExist($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->assertFileNotExists($storagedir . $dataid . '.' . $commentid . '.' . $dataid, "old format comment of $dataid got removed");
$this->assertFileDoesNotExist($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;

View File

@@ -2,14 +2,15 @@
use Google\Auth\HttpHandler\HttpHandlerFactory;
use GuzzleHttp\Client;
use PHPUnit\Framework\TestCase;
use PrivateBin\Data\GoogleCloudStorage;
class GoogleCloudStorageTest extends PHPUnit_Framework_TestCase
class GoogleCloudStorageTest extends TestCase
{
private static $_client;
private static $_bucket;
public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
$httpClient = new Client(array('debug'=>false));
$handler = HttpHandlerFactory::build($httpClient);
@@ -23,7 +24,7 @@ class GoogleCloudStorageTest extends PHPUnit_Framework_TestCase
self::$_bucket = self::$_client->createBucket($name);
}
public function setUp()
public function setUp(): void
{
ini_set('error_log', stream_get_meta_data(tmpfile())['uri']);
$this->_model = GoogleCloudStorage::getInstance(array(
@@ -32,14 +33,14 @@ class GoogleCloudStorageTest extends PHPUnit_Framework_TestCase
));
}
public function tearDown()
public function tearDown(): void
{
foreach (self::$_bucket->objects() as $object) {
$object->delete();
}
}
public static function tearDownAfterClass()
public static function tearDownAfterClass(): void
{
self::$_bucket->delete();
}

View File

@@ -1,8 +1,9 @@
<?php
use PHPUnit\Framework\TestCase;
use PrivateBin\Filter;
class FilterTest extends PHPUnit_Framework_TestCase
class FilterTest extends TestCase
{
public function testFilterMakesTimesHumanlyReadable()
{
@@ -12,12 +13,10 @@ class FilterTest extends PHPUnit_Framework_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');
}

View File

@@ -1,8 +1,9 @@
<?php
use PHPUnit\Framework\TestCase;
use PrivateBin\FormatV2;
class FormatV2Test extends PHPUnit_Framework_TestCase
class FormatV2Test extends TestCase
{
public function testFormatV2ValidatorValidatesCorrectly()
{

View File

@@ -1,12 +1,13 @@
<?php
use PHPUnit\Framework\TestCase;
use PrivateBin\I18n;
class I18nTest extends PHPUnit_Framework_TestCase
class I18nTest extends TestCase
{
private $_translations = array();
public function setUp()
public function setUp(): void
{
/* Setup Routine */
$this->_translations = json_decode(
@@ -15,9 +16,9 @@ class I18nTest extends PHPUnit_Framework_TestCase
);
}
public function tearDown()
public function tearDown(): void
{
/* Tear Down Routine */
unset($_COOKIE['lang'], $_SERVER['HTTP_ACCEPT_LANGUAGE']);
}
public function testTranslationFallback()

View File

@@ -9,7 +9,6 @@ use Identicon\Generator\GdGenerator;
use Identicon\Generator\ImageMagickGenerator;
use Identicon\Generator\SvgGenerator;
use Identicon\Identicon;
use Jdenticon\Identicon as Jdenticon;
use PrivateBin\Vizhash16x16;
@@ -18,19 +17,7 @@ $vizhash = new Vizhash16x16();
$identiconGenerators = array(
'identicon GD' => new Identicon(new GdGenerator()),
'identicon ImageMagick' => new Identicon(new ImageMagickGenerator()),
'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',
'identicon SVG' => new Identicon(new SvgGenerator())
);
$results = array(
'vizhash' => array(
@@ -48,30 +35,21 @@ $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)));
foreach (array_keys($results) as $test) {
$results[$test]['lengths'][$i] = 0;
}
$results['vizhash']['lengths'][$i] = 0;
$results['identicon GD']['lengths'][$i] = 0;
$results['identicon ImageMagick']['lengths'][$i] = 0;
$results['identicon SVG']['lengths'][$i] = 0;
}
echo 'run vizhash tests', PHP_EOL;
$start = microtime(true);
foreach ($hmacs as $i => $hmac) {
@@ -82,6 +60,7 @@ 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);
@@ -92,35 +71,9 @@ 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",
@@ -131,10 +84,7 @@ 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(

View File

@@ -1,17 +1,18 @@
<?php
use PHPUnit\Framework\TestCase;
use PrivateBin\Controller;
use PrivateBin\Data\Filesystem;
use PrivateBin\Persistence\ServerSalt;
use PrivateBin\Request;
class JsonApiTest extends PHPUnit_Framework_TestCase
class JsonApiTest extends TestCase
{
protected $_model;
protected $_path;
public function setUp()
public function setUp(): void
{
/* Setup Routine */
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
@@ -33,7 +34,7 @@ class JsonApiTest extends PHPUnit_Framework_TestCase
Helper::createIniFile(CONF, $options);
}
public function tearDown()
public function tearDown(): void
{
/* Tear Down Routine */
unlink(CONF);
@@ -272,7 +273,7 @@ class JsonApiTest extends PHPUnit_Framework_TestCase
{
$mock_yourls_service = $this->_path . DIRECTORY_SEPARATOR . 'yourls.json';
$options = parse_ini_file(CONF, true);
$options['main']['basepath'] = 'https://example.com/path';
$options['main']['basepath'] = 'https://example.com/path'; // missing slash gets added by Configuration constructor
$options['main']['urlshortener'] = 'https://example.com/path/shortenviayourls?link=';
$options['yourls']['apiurl'] = $mock_yourls_service;
Helper::createIniFile(CONF, $options);
@@ -286,7 +287,7 @@ class JsonApiTest extends PHPUnit_Framework_TestCase
new Controller;
$content = ob_get_contents();
ob_end_clean();
$this->assertContains('id="pasteurl" href="https://example.com/1"', $content, 'outputs shortened URL correctly');
$this->assertStringContainsString('id="pasteurl" href="https://example.com/1"', $content, 'outputs shortened URL correctly');
}
/**
@@ -300,6 +301,6 @@ class JsonApiTest extends PHPUnit_Framework_TestCase
new Controller;
$content = ob_get_contents();
ob_end_clean();
$this->assertContains('Error calling YOURLS.', $content, 'outputs error correctly');
$this->assertStringContainsString('Error calling YOURLS.', $content, 'outputs error correctly');
}
}

View File

@@ -1,6 +1,7 @@
<?php
use Identicon\Identicon;
use Jdenticon\Identicon;
use PHPUnit\Framework\TestCase;
use PrivateBin\Configuration;
use PrivateBin\Data\Database;
use PrivateBin\Model;
@@ -10,7 +11,7 @@ use PrivateBin\Persistence\ServerSalt;
use PrivateBin\Persistence\TrafficLimiter;
use PrivateBin\Vizhash16x16;
class ModelTest extends PHPUnit_Framework_TestCase
class ModelTest extends TestCase
{
private $_conf;
@@ -18,7 +19,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
protected $_path;
public function setUp()
public function setUp(): void
{
/* Setup Routine */
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
@@ -44,7 +45,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
$_SERVER['REMOTE_ADDR'] = '::1';
}
public function tearDown()
public function tearDown(): void
{
/* Tear Down Routine */
unlink(CONF);
@@ -167,10 +168,6 @@ class ModelTest extends PHPUnit_Framework_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();
@@ -182,13 +179,11 @@ class ModelTest extends PHPUnit_Framework_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';
@@ -225,13 +220,11 @@ class ModelTest extends PHPUnit_Framework_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';
@@ -273,13 +266,11 @@ class ModelTest extends PHPUnit_Framework_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();
@@ -296,6 +287,8 @@ class ModelTest extends PHPUnit_Framework_TestCase
$comment = $paste->getComment(Helper::getPasteId());
$comment->setData($commentData);
$this->expectException(Exception::class);
$this->expectExceptionCode(69);
$comment->store();
}
@@ -314,8 +307,15 @@ class ModelTest extends PHPUnit_Framework_TestCase
$comment->get();
$comment->store();
$identicon = new Identicon();
$pngdata = $identicon->getImageDataUri(TrafficLimiter::getHash(), 16);
$identicon = new Identicon(array(
'hash' => TrafficLimiter::getHash(),
'size' => 16,
'style' => array(
'backgroundColor' => '#fff0', // fully transparent, for dark mode
'padding' => 0,
),
));
$pngdata = $identicon->getImageDataUri('png');
$comment = current($this->_model->getPaste(Helper::getPasteId())->get()['comments']);
$this->assertEquals($pngdata, $comment['meta']['icon'], 'icon gets set');
}
@@ -327,52 +327,40 @@ class ModelTest extends PHPUnit_Framework_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();
@@ -382,13 +370,11 @@ class ModelTest extends PHPUnit_Framework_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();
@@ -398,18 +384,17 @@ class ModelTest extends PHPUnit_Framework_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());
$comment = $paste->getComment('');
$comment->store();
$this->expectException(Exception::class);
$this->expectExceptionCode(65);
$paste->getComment('');
}
public function testExpiration()
@@ -427,10 +412,6 @@ class ModelTest extends PHPUnit_Framework_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();
@@ -439,6 +420,8 @@ class ModelTest extends PHPUnit_Framework_TestCase
$paste = $this->_model->getPaste();
$paste->setData($pasteData);
$paste->store();
$this->expectException(Exception::class);
$this->expectExceptionCode(64);
$paste->getComment(Helper::getPasteId())->delete();
}

View File

@@ -1,13 +1,14 @@
<?php
use PHPUnit\Framework\TestCase;
use PrivateBin\Data\Filesystem;
use PrivateBin\Persistence\PurgeLimiter;
class PurgeLimiterTest extends PHPUnit_Framework_TestCase
class PurgeLimiterTest extends TestCase
{
private $_path;
public function setUp()
public function setUp(): void
{
/* Setup Routine */
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
@@ -19,7 +20,7 @@ class PurgeLimiterTest extends PHPUnit_Framework_TestCase
);
}
public function tearDown()
public function tearDown(): void
{
/* Tear Down Routine */
Helper::rmDir($this->_path);

View File

@@ -1,9 +1,10 @@
<?php
use PHPUnit\Framework\TestCase;
use PrivateBin\Data\Filesystem;
use PrivateBin\Persistence\ServerSalt;
class ServerSaltTest extends PHPUnit_Framework_TestCase
class ServerSaltTest extends TestCase
{
private $_path;
@@ -13,7 +14,7 @@ class ServerSaltTest extends PHPUnit_Framework_TestCase
private $_invalidFile;
public function setUp()
public function setUp(): void
{
/* Setup Routine */
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
@@ -33,7 +34,7 @@ class ServerSaltTest extends PHPUnit_Framework_TestCase
$this->_invalidFile = $this->_invalidPath . DIRECTORY_SEPARATOR . 'salt.php';
}
public function tearDown()
public function tearDown(): void
{
/* Tear Down Routine */
chmod($this->_invalidPath, 0700);

View File

@@ -1,14 +1,15 @@
<?php
use PHPUnit\Framework\TestCase;
use PrivateBin\Data\Filesystem;
use PrivateBin\Persistence\ServerSalt;
use PrivateBin\Persistence\TrafficLimiter;
class TrafficLimiterTest extends PHPUnit_Framework_TestCase
class TrafficLimiterTest extends TestCase
{
private $_path;
public function setUp()
public function setUp(): void
{
/* Setup Routine */
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'trafficlimit';
@@ -17,7 +18,7 @@ class TrafficLimiterTest extends PHPUnit_Framework_TestCase
TrafficLimiter::setStore($store);
}
public function tearDown()
public function tearDown(): void
{
/* Tear Down Routine */
Helper::rmDir($this->_path . DIRECTORY_SEPARATOR);

View File

@@ -1,19 +1,10 @@
<?php
use PHPUnit\Framework\TestCase;
use PrivateBin\Request;
class RequestTest extends PHPUnit_Framework_TestCase
class RequestTest extends TestCase
{
public function setUp()
{
/* Setup Routine */
}
public function tearDown()
{
/* Tear Down Routine */
}
public function reset()
{
$_SERVER = array();

View File

@@ -1,9 +1,10 @@
<?php
use PHPUnit\Framework\TestCase;
use PrivateBin\I18n;
use PrivateBin\View;
class ViewTest extends PHPUnit_Framework_TestCase
class ViewTest extends TestCase
{
private static $error = 'foo bar';
@@ -29,7 +30,7 @@ class ViewTest extends PHPUnit_Framework_TestCase
private $_content = array();
public function setUp()
public function setUp(): void
{
/* Setup Routine */
$page = new View;
@@ -93,15 +94,10 @@ class ViewTest extends PHPUnit_Framework_TestCase
}
}
public function tearDown()
{
/* Tear Down Routine */
}
public function testTemplateRendersCorrectly()
{
foreach ($this->_content as $template => $content) {
$this->assertRegExp(
$this->assertMatchesRegularExpression(
'#<div[^>]+id="errormessage"[^>]*>.*' . self::$error . '#s',
$content,
$template . ': outputs error correctly'
@@ -110,23 +106,23 @@ class ViewTest extends PHPUnit_Framework_TestCase
// yourlsproxy template only displays error message
continue;
}
$this->assertRegExp(
$this->assertMatchesRegularExpression(
'#<[^>]+id="password"[^>]*>#',
$content,
$template . ': password available if configured'
);
$this->assertRegExp(
$this->assertMatchesRegularExpression(
'#<input[^>]+id="opendiscussion"[^>]*checked="checked"[^>]*>#',
$content,
$template . ': checked discussion if configured'
);
$this->assertRegExp(
$this->assertMatchesRegularExpression(
'#<[^>]+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->assertRegExp(
$this->assertMatchesRegularExpression(
'#<script[^>]+src="js/privatebin.js\\?' . rawurlencode(self::$version) . '"[^>]*>#',
$content,
$template . ': outputs version correctly'
@@ -134,13 +130,11 @@ class ViewTest extends PHPUnit_Framework_TestCase
}
}
/**
* @expectedException Exception
* @expectedExceptionCode 80
*/
public function testMissingTemplate()
{
$test = new View;
$this->expectException(Exception::class);
$this->expectExceptionCode(80);
$test->draw('123456789 does not exist!');
}
}

View File

@@ -1,16 +1,17 @@
<?php
use PHPUnit\Framework\TestCase;
use PrivateBin\Data\Filesystem;
use PrivateBin\Persistence\ServerSalt;
use PrivateBin\Vizhash16x16;
class Vizhash16x16Test extends PHPUnit_Framework_TestCase
class Vizhash16x16Test extends TestCase
{
private $_file;
private $_path;
public function setUp()
public function setUp(): void
{
/* Setup Routine */
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
@@ -21,7 +22,7 @@ class Vizhash16x16Test extends PHPUnit_Framework_TestCase
ServerSalt::setStore(Filesystem::getInstance(array('dir' => $this->_path)));
}
public function tearDown()
public function tearDown(): void
{
/* Tear Down Routine */
chmod($this->_path, 0700);

View File

@@ -1,9 +1,10 @@
<?php
use PHPUnit\Framework\TestCase;
use PrivateBin\Configuration;
use PrivateBin\YourlsProxy;
class YourlsProxyTest extends PHPUnit_Framework_TestCase
class YourlsProxyTest extends TestCase
{
private $_conf;
@@ -11,7 +12,7 @@ class YourlsProxyTest extends PHPUnit_Framework_TestCase
private $_mock_yourls_service;
public function setUp()
public function setUp(): void
{
/* Setup Routine */
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
@@ -20,7 +21,7 @@ class YourlsProxyTest extends PHPUnit_Framework_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();
@@ -28,7 +29,7 @@ class YourlsProxyTest extends PHPUnit_Framework_TestCase
$this->_conf = new Configuration;
}
public function tearDown()
public function tearDown(): void
{
/* Tear Down Routine */
unlink(CONF);

View File

@@ -1,19 +1,22 @@
<phpunit bootstrap="Bootstrap.php" colors="true">
<?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>
<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>
<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" />
<testdoxHtml outputFile="log/testdox.html"/>
</logging>
</phpunit>

View File

@@ -5,18 +5,18 @@
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => '78aa70e3ab9277172489f9d88f8fd08cc1d03c97',
'reference' => '46013df6201304840c8dab82af63cc9000a6d239',
'name' => 'privatebin/privatebin',
'dev' => false,
),
'versions' => array(
'jdenticon/jdenticon' => array(
'pretty_version' => '1.0.1',
'version' => '1.0.1.0',
'pretty_version' => '1.0.2',
'version' => '1.0.2.0',
'type' => 'library',
'install_path' => __DIR__ . '/../jdenticon/jdenticon',
'aliases' => array(),
'reference' => '994ee07293fb978f983393ffcb2c0250592a6ac4',
'reference' => 'cabb7a44c413c318392a341c5d3ca30fcdd57a6f',
'dev_requirement' => false,
),
'mlocati/ip-lib' => array(
@@ -43,7 +43,7 @@
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => '78aa70e3ab9277172489f9d88f8fd08cc1d03c97',
'reference' => '46013df6201304840c8dab82af63cc9000a6d239',
'dev_requirement' => false,
),
'yzalis/identicon' => array(

View File

@@ -21,6 +21,15 @@ 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.