Skip to content

Commit

Permalink
Merge branch '3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
terrafrost committed Mar 15, 2022
2 parents 57ad98e + 0a69972 commit 3e073a5
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 87 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/ci.yml
Expand Up @@ -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
Expand Down Expand Up @@ -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 changes: 0 additions & 2 deletions .gitignore
@@ -1,7 +1,5 @@
/.idea/
/build/vendor/
/build/php-cs-fixer.cache
/build/composer.lock
/composer.lock
/composer.phar
/vendor/
Expand Down
6 changes: 2 additions & 4 deletions phpseclib/Net/SFTP.php
Expand Up @@ -3099,7 +3099,7 @@ private function parseLongname($longname)
* @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)
Expand All @@ -3113,7 +3113,7 @@ private function send_sftp_packet($type, $data, $request_id = 1)
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')) {
Expand Down Expand Up @@ -3141,8 +3141,6 @@ private function send_sftp_packet($type, $data, $request_id = 1)
}
}
}

return $result;
}

/**
Expand Down
12 changes: 4 additions & 8 deletions phpseclib/Net/SSH2.php
Expand Up @@ -3027,11 +3027,10 @@ public function read($expect = '', $mode = self::READ_SIMPLE)
/**
* 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)
{
Expand All @@ -3043,7 +3042,7 @@ public function write($cmd)
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);
}

/**
Expand Down Expand Up @@ -4277,8 +4276,7 @@ private function append_log($message_number, $message)
*
* @param int $client_channel
* @param string $data
* @return bool
* @access private
* @return void
*/
protected function send_channel_packet($client_channel, $data)
{
Expand Down Expand Up @@ -4309,8 +4307,6 @@ protected function send_channel_packet($client_channel, $data)
$this->window_size_client_to_server[$client_channel] -= strlen($temp);
$this->send_binary_packet($packet);
}

return true;
}

/**
Expand Down
5 changes: 1 addition & 4 deletions tests/Functional/Net/SFTPUserStoryTest.php
Expand Up @@ -772,10 +772,7 @@ public function testRawlistDisabledStatCache($sftp)
$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;
Expand Down
10 changes: 8 additions & 2 deletions tests/Functional/Net/SSH2Test.php
Expand Up @@ -29,6 +29,7 @@ public function testConstructor()
* @depends testConstructor
* @group github408
* @group github412
* @param SSH2 $ssh
*/
public function testPreLogin($ssh)
{
Expand Down Expand Up @@ -62,6 +63,7 @@ public function testPreLogin($ssh)

/**
* @depends testPreLogin
* @param SSH2 $ssh
*/
public function testBadPassword($ssh)
{
Expand All @@ -87,6 +89,7 @@ public function testBadPassword($ssh)

/**
* @depends testBadPassword
* @param SSH2 $ssh
*/
public function testPasswordLogin($ssh)
{
Expand All @@ -108,6 +111,7 @@ public function testPasswordLogin($ssh)
/**
* @depends testPasswordLogin
* @group github280
* @param SSH2 $ssh
*/
public function testExecWithMethodCallback($ssh)
{
Expand Down Expand Up @@ -146,6 +150,7 @@ public function testOpenSocketConnect()
/**
* @depends testExecWithMethodCallback
* @group github1009
* @param SSH2 $ssh
*/
public function testDisablePTY($ssh)
{
Expand All @@ -162,6 +167,7 @@ public function testDisablePTY($ssh)
/**
* @depends testDisablePTY
* @group github1167
* @param SSH2 $ssh
*/
public function testChannelDataAfterOpen($ssh)
{
Expand All @@ -171,7 +177,7 @@ public function testChannelDataAfterOpen($ssh)
// 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], '>=');
Expand All @@ -188,6 +194,6 @@ public function testChannelDataAfterOpen($ssh)

$ssh->setTimeout(1);

$ssh->read();
$this->assertIsString($ssh->read());
}
}
50 changes: 23 additions & 27 deletions tests/PhpseclibTestCase.php
Expand Up @@ -86,27 +86,6 @@ protected static function ensureConstant($constant, $expected)
}
}

/**
* @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));
Expand All @@ -126,7 +105,7 @@ public static function callFunc($obj, $func, $params = [])
// 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;
}
Expand All @@ -137,7 +116,7 @@ public static function assertIsArray($actual, $message = '')
// 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;
}
Expand All @@ -148,7 +127,7 @@ public static function assertIsString($actual, $message = '')
// 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;
}
Expand All @@ -159,7 +138,7 @@ public static function assertIsResource($actual, $message = '')
// 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;
}
Expand All @@ -170,7 +149,7 @@ public static function assertIsObject($actual, $message = '')
// 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;
}
Expand All @@ -181,11 +160,28 @@ public static function assertStringContainsString($needle, $haystack, $message =
// 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);
}
}
}
18 changes: 12 additions & 6 deletions tests/Unit/Crypt/AES/TestCase.php
Expand Up @@ -131,7 +131,7 @@ public function testKeyPaddingAES()
/**
* Produces all combinations of test values.
*
* @return array
* @return list<array{string, string, array}>
*/
public function continuousBufferBatteryCombos()
{
Expand Down Expand Up @@ -173,6 +173,16 @@ public function continuousBufferBatteryCombos()
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
*/
Expand Down Expand Up @@ -219,14 +229,10 @@ public function testContinuousBufferBattery($op, $mode, $test)
/**
* 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);

Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Crypt/DSA/CreateKeyTest.php
Expand Up @@ -23,17 +23,17 @@ public function testCreateParameters()
{
$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;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Crypt/RSA/LoadKeyTest.php
Expand Up @@ -462,7 +462,7 @@ public function testPKCS1EncryptionChange()
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);
Expand Down
22 changes: 0 additions & 22 deletions tests/bootstrap.php

This file was deleted.

1 change: 1 addition & 0 deletions tests/make_compatible_with_new_phpunit_versions.php
Expand Up @@ -18,6 +18,7 @@
'~ 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),
Expand Down

0 comments on commit 3e073a5

Please sign in to comment.