phpseclib/tests/Functional/Net/SCPSSH2UserStoryTest.php

89 lines
2.8 KiB
PHP
Raw Normal View History

2014-12-04 18:13:27 +00:00
<?php
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright 2014 Andreas Fischer
2014-12-04 18:13:27 +00:00
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
class Functional_Net_SCPSSH2UserStoryTest extends PhpseclibFunctionalTestCase
{
static protected $remoteFile;
static protected $exampleData;
static protected $exampleDataLength;
static public function setUpBeforeClass()
{
parent::setUpBeforeClass();
self::$remoteFile = uniqid('phpseclib-scp-ssh2-') . '.txt';
self::$exampleData = str_repeat('abscp12345', 1000);
self::$exampleDataLength = 10000;
}
public function testConstructSSH2()
{
$ssh = new Net_SSH2($this->getEnv('SSH_HOSTNAME'));
$this->assertTrue(
$ssh->login(
$this->getEnv('SSH_USERNAME'),
$this->getEnv('SSH_PASSWORD')
)
);
return $ssh;
}
/** @depends testConstructSSH2 */
public function testConstructor($ssh)
{
$scp = new Net_SCP($ssh);
$this->assertTrue(
is_object($scp),
'Could not construct Net_SCP object.'
);
return $scp;
}
/** @depends testConstructor */
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);
// TODO: Address https://github.com/phpseclib/phpseclib/issues/146
$this->assertContains(
2014-12-04 18:13:27 +00:00
strlen($content),
array(self::$exampleDataLength, self::$exampleDataLength + 1),
2014-12-04 18:13:27 +00:00
'Failed asserting that string length matches expected length.'
);
$this->assertContains(
2014-12-04 18:13:27 +00:00
$content,
array(self::$exampleData, self::$exampleData . "\0"),
2014-12-04 18:13:27 +00:00
'Failed asserting that string content matches expected content.'
);
return $scp;
}
/** @depends testPutGetString */
public function testGetFile($scp)
{
$localFilename = $this->createTempFile();
$this->assertTrue(
$scp->get(self::$remoteFile, $localFilename),
'Failed asserting that get() into file was successful.'
);
// TODO: Address https://github.com/phpseclib/phpseclib/issues/146
$this->assertContains(
2014-12-04 18:13:27 +00:00
filesize($localFilename),
array(self::$exampleDataLength, self::$exampleDataLength + 1),
2014-12-04 18:13:27 +00:00
'Failed asserting that filesize matches expected data size.'
);
$this->assertContains(
2014-12-04 18:13:27 +00:00
file_get_contents($localFilename),
array(self::$exampleData, self::$exampleData . "\0"),
2014-12-04 18:13:27 +00:00
'Failed asserting that file content matches expected content.'
);
}
}