2014-12-04 19:13:27 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Andreas Fischer <bantu@phpbb.com>
|
2014-12-10 00:02:44 +01:00
|
|
|
* @copyright 2014 Andreas Fischer
|
2014-12-04 19:13:27 +01:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
|
|
*/
|
|
|
|
|
2014-12-10 02:31:41 +01:00
|
|
|
use phpseclib\Net\SCP;
|
|
|
|
use phpseclib\Net\SSH2;
|
|
|
|
|
2014-12-04 19:13:27 +01:00
|
|
|
class Functional_Net_SCPSSH2UserStoryTest extends PhpseclibFunctionalTestCase
|
|
|
|
{
|
|
|
|
static protected $remoteFile;
|
|
|
|
static protected $exampleData;
|
|
|
|
static protected $exampleDataLength;
|
|
|
|
|
2015-07-15 03:52:31 +02:00
|
|
|
public static function setUpBeforeClass()
|
2014-12-04 19:13:27 +01:00
|
|
|
{
|
|
|
|
parent::setUpBeforeClass();
|
|
|
|
self::$remoteFile = uniqid('phpseclib-scp-ssh2-') . '.txt';
|
|
|
|
self::$exampleData = str_repeat('abscp12345', 1000);
|
|
|
|
self::$exampleDataLength = 10000;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testConstructSSH2()
|
|
|
|
{
|
2014-12-10 02:31:41 +01:00
|
|
|
$ssh = new SSH2($this->getEnv('SSH_HOSTNAME'));
|
2014-12-04 19:13:27 +01:00
|
|
|
$this->assertTrue(
|
|
|
|
$ssh->login(
|
|
|
|
$this->getEnv('SSH_USERNAME'),
|
|
|
|
$this->getEnv('SSH_PASSWORD')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
return $ssh;
|
|
|
|
}
|
|
|
|
|
2014-12-10 02:31:41 +01:00
|
|
|
/**
|
|
|
|
* @depends testConstructSSH2
|
|
|
|
* @param \phpseclib\Net\SSH2 $ssh
|
|
|
|
*/
|
2014-12-04 19:13:27 +01:00
|
|
|
public function testConstructor($ssh)
|
|
|
|
{
|
2014-12-10 02:31:41 +01:00
|
|
|
$scp = new SCP($ssh);
|
2014-12-04 19:13:27 +01:00
|
|
|
$this->assertTrue(
|
|
|
|
is_object($scp),
|
2014-12-10 02:31:41 +01:00
|
|
|
'Could not construct \phpseclib\Net\SCP object.'
|
2014-12-04 19:13:27 +01:00
|
|
|
);
|
|
|
|
return $scp;
|
|
|
|
}
|
|
|
|
|
2014-12-10 02:31:41 +01:00
|
|
|
/**
|
|
|
|
* @depends testConstructor
|
|
|
|
* @param \phpseclib\Net\SCP $scp
|
|
|
|
*/
|
2014-12-04 19:13:27 +01:00
|
|
|
public function testPutGetString($scp)
|
|
|
|
{
|
|
|
|
$this->assertTrue(
|
|
|
|
$scp->put(self::$remoteFile, self::$exampleData),
|
|
|
|
'Failed asserting that data could successfully be put() into file.'
|
|
|
|
);
|
|
|
|
$content = $scp->get(self::$remoteFile);
|
2014-12-09 12:32:25 +01:00
|
|
|
// TODO: Address https://github.com/phpseclib/phpseclib/issues/146
|
|
|
|
$this->assertContains(
|
2014-12-04 19:13:27 +01:00
|
|
|
strlen($content),
|
2014-12-09 12:32:25 +01:00
|
|
|
array(self::$exampleDataLength, self::$exampleDataLength + 1),
|
2014-12-04 19:13:27 +01:00
|
|
|
'Failed asserting that string length matches expected length.'
|
|
|
|
);
|
2014-12-09 12:32:25 +01:00
|
|
|
$this->assertContains(
|
2014-12-04 19:13:27 +01:00
|
|
|
$content,
|
2014-12-09 12:32:25 +01:00
|
|
|
array(self::$exampleData, self::$exampleData . "\0"),
|
2014-12-04 19:13:27 +01:00
|
|
|
'Failed asserting that string content matches expected content.'
|
|
|
|
);
|
|
|
|
return $scp;
|
|
|
|
}
|
|
|
|
|
2014-12-10 02:31:41 +01:00
|
|
|
/**
|
|
|
|
* @depends testPutGetString
|
|
|
|
* @param \phpseclib\Net\SCP $scp
|
|
|
|
*/
|
2014-12-04 19:13:27 +01:00
|
|
|
public function testGetFile($scp)
|
|
|
|
{
|
|
|
|
$localFilename = $this->createTempFile();
|
|
|
|
$this->assertTrue(
|
|
|
|
$scp->get(self::$remoteFile, $localFilename),
|
|
|
|
'Failed asserting that get() into file was successful.'
|
|
|
|
);
|
2014-12-09 12:32:25 +01:00
|
|
|
// TODO: Address https://github.com/phpseclib/phpseclib/issues/146
|
|
|
|
$this->assertContains(
|
2014-12-04 19:13:27 +01:00
|
|
|
filesize($localFilename),
|
2014-12-09 12:32:25 +01:00
|
|
|
array(self::$exampleDataLength, self::$exampleDataLength + 1),
|
2014-12-04 19:13:27 +01:00
|
|
|
'Failed asserting that filesize matches expected data size.'
|
|
|
|
);
|
2014-12-09 12:32:25 +01:00
|
|
|
$this->assertContains(
|
2014-12-04 19:13:27 +01:00
|
|
|
file_get_contents($localFilename),
|
2014-12-09 12:32:25 +01:00
|
|
|
array(self::$exampleData, self::$exampleData . "\0"),
|
2014-12-04 19:13:27 +01:00
|
|
|
'Failed asserting that file content matches expected content.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|