Clean Up Tests

This commit is contained in:
Jack Worman 2022-03-08 18:59:30 -06:00 committed by terrafrost
parent 887cf97185
commit 0a69972571
13 changed files with 65 additions and 87 deletions

View File

@ -42,7 +42,8 @@ jobs:
tests:
name: Tests
timeout-minutes: 10
continue-on-error: ${{ matrix.experimental }}
# Sometimes there is a segfault on PHP 5.6.
continue-on-error: ${{ matrix.php-version == '5.6' }}
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
@ -85,8 +86,3 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
php-version: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
experimental: [false]
include:
- {os: ubuntu-latest, php-version: '8.2', experimental: true}
- {os: windows-latest, php-version: '8.2', experimental: true}
- {os: macos-latest, php-version: '8.2', experimental: true}

2
.gitignore vendored
View File

@ -1,7 +1,5 @@
/.idea/
/build/vendor/
/build/php-cs-fixer.cache
/build/composer.lock
/composer.lock
/composer.phar
/vendor/

View File

@ -3266,7 +3266,7 @@ class SFTP extends SSH2
* @param int $request_id
* @see self::_get_sftp_packet()
* @see self::send_channel_packet()
* @return bool
* @return void
* @access private
*/
private function send_sftp_packet($type, $data, $request_id = 1)
@ -3280,7 +3280,7 @@ class SFTP extends SSH2
pack('NCa*', strlen($data) + 1, $type, $data);
$start = microtime(true);
$result = $this->send_channel_packet(self::CHANNEL, $packet);
$this->send_channel_packet(self::CHANNEL, $packet);
$stop = microtime(true);
if (defined('NET_SFTP_LOGGING')) {
@ -3305,8 +3305,6 @@ class SFTP extends SSH2
}
}
}
return $result;
}
/**

View File

@ -3148,11 +3148,10 @@ class SSH2
/**
* Inputs a command into an interactive shell.
*
* @see self::read()
* @see SSH2::read()
* @param string $cmd
* @return bool
* @return void
* @throws \RuntimeException on connection error
* @access public
*/
public function write($cmd)
{
@ -3164,7 +3163,7 @@ class SSH2
throw new \RuntimeException('Unable to initiate an interactive shell session');
}
return $this->send_channel_packet($this->get_interactive_channel(), $cmd);
$this->send_channel_packet($this->get_interactive_channel(), $cmd);
}
/**
@ -4384,8 +4383,7 @@ class SSH2
*
* @param int $client_channel
* @param string $data
* @return bool
* @access private
* @return void
*/
protected function send_channel_packet($client_channel, $data)
{
@ -4416,8 +4414,6 @@ class SSH2
$this->window_size_client_to_server[$client_channel] -= strlen($temp);
$this->send_binary_packet($packet);
}
return true;
}
/**

View File

@ -771,10 +771,7 @@ class SFTPUserStoryTest extends PhpseclibFunctionalTestCase
$this->assertEquals(
$list_cache_enabled,
$list_cache_disabled,
'The files should be the same regardless of stat cache',
0.0,
10,
true
'The files should be the same regardless of stat cache'
);
return $sftp;

View File

@ -29,6 +29,7 @@ class SSH2Test extends PhpseclibFunctionalTestCase
* @depends testConstructor
* @group github408
* @group github412
* @param SSH2 $ssh
*/
public function testPreLogin($ssh)
{
@ -62,6 +63,7 @@ class SSH2Test extends PhpseclibFunctionalTestCase
/**
* @depends testPreLogin
* @param SSH2 $ssh
*/
public function testBadPassword($ssh)
{
@ -87,6 +89,7 @@ class SSH2Test extends PhpseclibFunctionalTestCase
/**
* @depends testBadPassword
* @param SSH2 $ssh
*/
public function testPasswordLogin($ssh)
{
@ -108,6 +111,7 @@ class SSH2Test extends PhpseclibFunctionalTestCase
/**
* @depends testPasswordLogin
* @group github280
* @param SSH2 $ssh
*/
public function testExecWithMethodCallback($ssh)
{
@ -146,6 +150,7 @@ class SSH2Test extends PhpseclibFunctionalTestCase
/**
* @depends testExecWithMethodCallback
* @group github1009
* @param SSH2 $ssh
*/
public function testDisablePTY($ssh)
{
@ -162,6 +167,7 @@ class SSH2Test extends PhpseclibFunctionalTestCase
/**
* @depends testDisablePTY
* @group github1167
* @param SSH2 $ssh
*/
public function testChannelDataAfterOpen($ssh)
{
@ -171,7 +177,7 @@ class SSH2Test extends PhpseclibFunctionalTestCase
// when consolekit was incorporated.
// https://marc.info/?l=openssh-unix-dev&m=163409903417589&w=2 discusses some of the
// issues with how Ubuntu incorporated consolekit
$pattern = '#^SSH-2\.0-OpenSSH_([\d\.]+)[^ ]* Ubuntu-.*$#';
$pattern = '#^SSH-2\.0-OpenSSH_([\d.]+)[^ ]* Ubuntu-.*$#';
$match = preg_match($pattern, $ssh->getServerIdentification(), $matches);
$match = $match && version_compare('5.8', $matches[1], '<=');
$match = $match && version_compare('6.9', $matches[1], '>=');
@ -188,6 +194,6 @@ class SSH2Test extends PhpseclibFunctionalTestCase
$ssh->setTimeout(1);
$ssh->read();
$this->assertIsString($ssh->read());
}
}

View File

@ -86,27 +86,6 @@ abstract class PhpseclibTestCase extends TestCase
}
}
/**
* @param string $filename Filename relative to library directory.
*
* @return null
*/
protected static function reRequireFile($filename)
{
if (extension_loaded('runkit')) {
$result = runkit_import(
sprintf('%s/../phpseclib/%s', __DIR__, $filename),
RUNKIT_IMPORT_FUNCTIONS |
RUNKIT_IMPORT_CLASS_METHODS |
RUNKIT_IMPORT_OVERRIDE
);
if (!$result) {
self::markTestSkipped("Failed to reimport file $filename");
}
}
}
protected static function getVar($obj, $var)
{
$reflection = new \ReflectionClass(get_class($obj));
@ -126,7 +105,7 @@ abstract class PhpseclibTestCase extends TestCase
// assertIsArray was not introduced until PHPUnit 8
public static function assertIsArray($actual, $message = '')
{
if (method_exists('\PHPUnit\Framework\TestCase', 'assertIsArray')) {
if (method_exists(parent::class, 'assertIsArray')) {
parent::assertIsArray($actual, $message);
return;
}
@ -137,7 +116,7 @@ abstract class PhpseclibTestCase extends TestCase
// assertIsString was not introduced until PHPUnit 8
public static function assertIsString($actual, $message = '')
{
if (method_exists('\PHPUnit\Framework\TestCase', 'assertIsString')) {
if (method_exists(parent::class, 'assertIsString')) {
parent::assertIsString($actual, $message);
return;
}
@ -148,7 +127,7 @@ abstract class PhpseclibTestCase extends TestCase
// assertIsResource was not introduced until PHPUnit 8
public static function assertIsResource($actual, $message = '')
{
if (method_exists('\PHPUnit\Framework\TestCase', 'assertIsResource')) {
if (method_exists(parent::class, 'assertIsResource')) {
parent::assertIsResource($actual, $message);
return;
}
@ -159,7 +138,7 @@ abstract class PhpseclibTestCase extends TestCase
// assertIsObject was not introduced until PHPUnit 8
public static function assertIsObject($actual, $message = '')
{
if (method_exists('\PHPUnit\Framework\TestCase', 'assertIsObject')) {
if (method_exists(parent::class, 'assertIsObject')) {
parent::assertIsObject($actual, $message);
return;
}
@ -170,7 +149,7 @@ abstract class PhpseclibTestCase extends TestCase
// assertContains is deprecated for strings in PHPUnit 8
public static function assertStringContainsString($needle, $haystack, $message = '')
{
if (method_exists('\PHPUnit\Framework\TestCase', 'assertStringContainsString')) {
if (method_exists(parent::class, 'assertStringContainsString')) {
parent::assertStringContainsString($needle, $haystack, $message);
return;
}
@ -181,11 +160,28 @@ abstract class PhpseclibTestCase extends TestCase
// assertNotContains is deprecated for strings in PHPUnit 8
public static function assertStringNotContainsString($needle, $haystack, $message = '')
{
if (method_exists('\PHPUnit\Framework\TestCase', 'assertStringContainsString')) {
if (method_exists(parent::class, 'assertStringContainsString')) {
parent::assertStringNotContainsString($needle, $haystack, $message);
return;
}
parent::assertNotContains($needle, $haystack, $message);
}
/**
* assertRegExp() was deprecated in favor of assertMatchesRegularExpression().
*
* @param string $pattern
* @param string $string
* @param string $message
* @return void
*/
public static function assertMatchesRegularExpression($pattern, $string, $message = '')
{
if (method_exists(parent::class, 'assertMatchesRegularExpression')) {
parent::assertMatchesRegularExpression($pattern, $string, $message);
} else {
parent::assertRegExp($pattern, $string, $message);
}
}
}

View File

@ -131,7 +131,7 @@ abstract class TestCase extends PhpseclibTestCase
/**
* Produces all combinations of test values.
*
* @return array
* @return list<array{string, string, array}>
*/
public function continuousBufferBatteryCombos()
{
@ -173,6 +173,16 @@ abstract class TestCase extends PhpseclibTestCase
return $result;
}
/**
* @return array<array{string, string, array}>
*/
public function continuousBufferBatteryCombosWithoutSingleCombos()
{
return array_filter($this->continuousBufferBatteryCombos(), function (array $continuousBufferBatteryCombo) {
return count($continuousBufferBatteryCombo[2]) > 1;
});
}
/**
* @dataProvider continuousBufferBatteryCombos
*/
@ -219,14 +229,10 @@ abstract class TestCase extends PhpseclibTestCase
/**
* Pretty much the same as testContinuousBufferBattery with the caveat that continuous mode is not enabled.
*
* @dataProvider continuousBufferBatteryCombos
* @dataProvider continuousBufferBatteryCombosWithoutSingleCombos
*/
public function testNonContinuousBufferBattery($op, $mode, $test)
{
if (count($test) == 1) {
self::markTestSkipped('test is 1');
}
$iv = str_repeat('x', 16);
$key = str_repeat('a', 16);

View File

@ -23,17 +23,17 @@ class CreateKeyTest extends PhpseclibTestCase
{
$dsa = DSA::createParameters();
$this->assertInstanceOf(Parameters::class, $dsa);
$this->assertRegexp('#BEGIN DSA PARAMETERS#', "$dsa");
$this->assertMatchesRegularExpression('#BEGIN DSA PARAMETERS#', "$dsa");
try {
$dsa = DSA::createParameters(100, 100);
DSA::createParameters(100, 100);
} catch (\Exception $e) {
$this->assertInstanceOf(\Exception::class, $e);
}
$dsa = DSA::createParameters(512, 160);
$this->assertInstanceOf(Parameters::class, $dsa);
$this->assertRegexp('#BEGIN DSA PARAMETERS#', "$dsa");
$this->assertMatchesRegularExpression('#BEGIN DSA PARAMETERS#', "$dsa");
return $dsa;
}

View File

@ -462,7 +462,7 @@ Private-MAC: 03e2cb74e1d67652fbad063d2ed0478f31bdf256
PKCS1::setEncryptionAlgorithm('AES-256-CBC');
$encryptedKey = $rsa->withPassword('demo')->toString('PKCS1');
$this->assertRegExp('#AES-256-CBC#', $encryptedKey);
$this->assertMatchesRegularExpression('#AES-256-CBC#', $encryptedKey);
$rsa = PublicKeyLoader::load($key, 'demo');
$this->assertInstanceOf(PrivateKey::class, $rsa);

View File

@ -1,22 +0,0 @@
<?php
/**
* Bootstrapping File for phpseclib Test Suite
*
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
date_default_timezone_set('UTC');
$loader_path = __DIR__ . '/../vendor/autoload.php';
if (!file_exists($loader_path)) {
exit(<<<EOF
Dependencies must be installed using composer:
php composer.phar install
See https://getcomposer.org for help with installing composer.
EOF
);
}
require $loader_path;

View File

@ -18,6 +18,7 @@ foreach ($files as $file) {
'~ function assertIsString\(\$actual, \$message = \'\'\)~' => ' function assertIsString($actual, string $message = \'\'): void',
'~ function assertStringContainsString\(\$needle, \$haystack, \$message = \'\'\)~' => ' function assertStringContainsString(string $needle, string $haystack, string $message = \'\'): void',
'~ function assertStringNotContainsString\(\$needle, \$haystack, \$message = \'\'\)~' => ' function assertStringNotContainsString(string $needle, string $haystack, string $message = \'\'): void',
'~ function assertMatchesRegularExpression\(\$pattern, \$string, \$message = \'\'\)~' => ' function assertMatchesRegularExpression(string $pattern, string $string, string $message = \'\'): void',
];
$updatedFileContents = preg_replace(
array_keys($patternToReplacementMap),

View File

@ -1,9 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<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"
bootstrap="../vendor/autoload.php"
failOnWarning="true"
failOnRisky="true"
failOnIncomplete="true"
failOnEmptyTestSuite="true"
>
<testsuites>
<testsuite name="phpseclib Unit Test Suite">
@ -18,4 +21,7 @@
<directory>../phpseclib/</directory>
</include>
</coverage>
<php>
<ini name="date.timezone" value="UTC"/>
</php>
</phpunit>