mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-11-16 10:15:14 +00:00
Merge branch 'ssh2-identifier' into php5
This commit is contained in:
commit
05077cf0f3
@ -156,7 +156,7 @@ class Net_SSH2
|
||||
* @var String
|
||||
* @access private
|
||||
*/
|
||||
var $identifier = 'SSH-2.0-phpseclib_0.3';
|
||||
var $identifier;
|
||||
|
||||
/**
|
||||
* The Socket Object
|
||||
@ -919,19 +919,7 @@ class Net_SSH2
|
||||
return false;
|
||||
}
|
||||
|
||||
$ext = array();
|
||||
if (extension_loaded('mcrypt')) {
|
||||
$ext[] = 'mcrypt';
|
||||
}
|
||||
if (extension_loaded('gmp')) {
|
||||
$ext[] = 'gmp';
|
||||
} else if (extension_loaded('bcmath')) {
|
||||
$ext[] = 'bcmath';
|
||||
}
|
||||
|
||||
if (!empty($ext)) {
|
||||
$this->identifier.= ' (' . implode(', ', $ext) . ')';
|
||||
}
|
||||
$this->identifier = $this->_generate_identifier();
|
||||
|
||||
if (defined('NET_SSH2_LOGGING')) {
|
||||
$this->_append_log('<-', $extra . $temp);
|
||||
@ -968,6 +956,36 @@ class Net_SSH2
|
||||
$this->bitmap = NET_SSH2_MASK_CONSTRUCTOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the SSH identifier
|
||||
*
|
||||
* You should overwrite this method in your own class if you want to use another identifier
|
||||
*
|
||||
* @access protected
|
||||
* @return String
|
||||
*/
|
||||
function _generate_identifier()
|
||||
{
|
||||
$identifier = 'SSH-2.0-phpseclib_0.3';
|
||||
|
||||
$ext = array();
|
||||
if (extension_loaded('mcrypt')) {
|
||||
$ext[] = 'mcrypt';
|
||||
}
|
||||
|
||||
if (extension_loaded('gmp')) {
|
||||
$ext[] = 'gmp';
|
||||
} elseif (extension_loaded('bcmath')) {
|
||||
$ext[] = 'bcmath';
|
||||
}
|
||||
|
||||
if (!empty($ext)) {
|
||||
$identifier .= ' (' . implode(', ', $ext) . ')';
|
||||
}
|
||||
|
||||
return $identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Key Exchange
|
||||
*
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Marc Scholten <marc@pedigital.de>
|
||||
* @copyright MMXIII Marc Scholten
|
||||
@ -7,6 +8,17 @@
|
||||
|
||||
class Net_SSH2Test extends PhpseclibTestCase
|
||||
{
|
||||
/**
|
||||
* @return Net_SSH2
|
||||
*/
|
||||
private function createSSHMock()
|
||||
{
|
||||
return $this->getMockBuilder('Net_SSH2')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('__destruct'))
|
||||
->getMock();
|
||||
}
|
||||
|
||||
public function formatLogDataProvider()
|
||||
{
|
||||
return array(
|
||||
@ -29,13 +41,44 @@ class Net_SSH2Test extends PhpseclibTestCase
|
||||
*/
|
||||
public function testFormatLog(array $message_log, array $message_number_log, $expected)
|
||||
{
|
||||
$ssh = $this->getMockBuilder('Net_SSH2')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('__destruct'))
|
||||
->getMock();
|
||||
$ssh = $this->createSSHMock();
|
||||
|
||||
$result = $ssh->_format_log($message_log, $message_number_log);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function generateIdentifierProvider()
|
||||
{
|
||||
return array(
|
||||
array('SSH-2.0-phpseclib_0.3', array()),
|
||||
array('SSH-2.0-phpseclib_0.3 (gmp)', array('gmp')),
|
||||
array('SSH-2.0-phpseclib_0.3 (bcmath)', array('bcmath')),
|
||||
array('SSH-2.0-phpseclib_0.3 (mcrypt)', array('mcrypt')),
|
||||
array('SSH-2.0-phpseclib_0.3 (mcrypt, gmp)', array('mcrypt', 'gmp')),
|
||||
array('SSH-2.0-phpseclib_0.3 (mcrypt, bcmath)', array('mcrypt', 'bcmath')),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider generateIdentifierProvider
|
||||
*/
|
||||
public function testGenerateIdentifier($expected, array $requiredExtensions)
|
||||
{
|
||||
$notAllowed = array('gmp', 'bcmath', 'mcrypt', 'gmp');
|
||||
foreach($notAllowed as $notAllowedExtension) {
|
||||
if(in_array($notAllowedExtension, $requiredExtensions)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(extension_loaded($notAllowedExtension)) {
|
||||
$this->markTestSkipped('Extension ' . $notAllowedExtension . ' is not allowed for this data-set');
|
||||
}
|
||||
}
|
||||
|
||||
$ssh = $this->createSSHMock();
|
||||
$identifier = $ssh->_generate_identifier();
|
||||
|
||||
$this->assertEquals($expected, $identifier);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user