1
0
mirror of https://github.com/danog/tgseclib.git synced 2024-12-15 10:27:01 +01:00
tgseclib/tests/Functional/Net/SCPSSH2UserStoryTest.php
Andreas Fischer d9e9504fba Merge branch 'PSR2-1.0' into PSR2-2.0
* PSR2-1.0:
  Fix indentation phpcbf did not fix.
  Remove PSR2.Methods.FunctionCallSignature.SpaceAfterOpenBracket exception.
  Use phpcbf to fix PHP code to ruleset.
  Ignore coding guidelines in ANSI switch block.
  Base code sniffer ruleset on PSR2 rather than PEAR.
  Update PHP Code Sniffer to 2.3.3

Conflicts:
	build/code-sniffer-ruleset-tests.xml
	build/code-sniffer-ruleset.xml
	composer.lock
	phpseclib/Crypt/DES.php
	phpseclib/Crypt/Hash.php
	phpseclib/Crypt/RSA.php
	phpseclib/File/X509.php
	phpseclib/Math/BigInteger.php
	phpseclib/Net/SFTP.php
	phpseclib/Net/SSH1.php
	phpseclib/Net/SSH2.php
	tests/Functional/Net/SFTPUserStoryTest.php
	tests/Unit/Crypt/TwofishTest.php
2015-07-17 13:41:59 +02:00

101 lines
3.0 KiB
PHP

<?php
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright 2014 Andreas Fischer
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
use phpseclib\Net\SCP;
use phpseclib\Net\SSH2;
class Functional_Net_SCPSSH2UserStoryTest extends PhpseclibFunctionalTestCase
{
static protected $remoteFile;
static protected $exampleData;
static protected $exampleDataLength;
public static 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 SSH2($this->getEnv('SSH_HOSTNAME'));
$this->assertTrue(
$ssh->login(
$this->getEnv('SSH_USERNAME'),
$this->getEnv('SSH_PASSWORD')
)
);
return $ssh;
}
/**
* @depends testConstructSSH2
* @param \phpseclib\Net\SSH2 $ssh
*/
public function testConstructor($ssh)
{
$scp = new SCP($ssh);
$this->assertTrue(
is_object($scp),
'Could not construct \phpseclib\Net\SCP object.'
);
return $scp;
}
/**
* @depends testConstructor
* @param \phpseclib\Net\SCP $scp
*/
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(
strlen($content),
array(self::$exampleDataLength, self::$exampleDataLength + 1),
'Failed asserting that string length matches expected length.'
);
$this->assertContains(
$content,
array(self::$exampleData, self::$exampleData . "\0"),
'Failed asserting that string content matches expected content.'
);
return $scp;
}
/**
* @depends testPutGetString
* @param \phpseclib\Net\SCP $scp
*/
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(
filesize($localFilename),
array(self::$exampleDataLength, self::$exampleDataLength + 1),
'Failed asserting that filesize matches expected data size.'
);
$this->assertContains(
file_get_contents($localFilename),
array(self::$exampleData, self::$exampleData . "\0"),
'Failed asserting that file content matches expected content.'
);
}
}