/** * @group server * @medium */ public function testPasswordAuthentication() { $connection = new Connection(\properties::$host, \properties::$port, new PasswordCredential(\properties::$user, \properties::$pass)); $this->assertTrue($connection->connect()); $this->assertTrue($connection->authenticate()); $this->assertTrue($connection->isAuthenticated()); $connection->disconnect(); }
/** * @dataProvider keyFileProvider * @group server * @medium */ public function testNoPublicKey($public, $private, $password) { $credential = new KeyCredential(\properties::$user, null, $private, $password); $connection = new Connection(\properties::$host, \properties::$port, $credential); $this->assertTrue($connection->connect()); $this->assertTrue($connection->authenticate()); $this->assertTrue($connection->isAuthenticated()); $connection->disconnect(); }
/** * Typically called from Connection::getShell() * * @param Connection $connection * @param Terminal $terminal */ function __construct(Connection $connection, Terminal $terminal) { if (!$connection->isConnected()) { throw new NotConnectedException(); } if (!$connection->isAuthenticated()) { throw new NotAuthenticatedException(); } $this->shell_type = null; $this->connection = $connection; $this->terminal = $terminal; $this->resource = ssh2_shell($connection->getResource(), $terminal->getTerminalType(), $terminal->getEnv(), $terminal->getWidth(), $terminal->getHeight(), $terminal->getDimensionUnitType()); }
/** * Typically called from Connection::execute() * * @param string $command * @param Connection $connection * @param Terminal $terminal * @param string $pty */ function __construct($command, Connection $connection, Terminal $terminal, $pty = null) { $this->command = $command; $this->connection = $connection; $this->terminal = $terminal; if (!$connection->isConnected()) { throw new NotConnectedException(); } if (!$connection->isAuthenticated()) { throw new NotAuthenticatedException(); } $this->resource = ssh2_exec($connection->getResource(), $command, $pty, $terminal->getEnv(), $terminal->getWidth(), $terminal->getHeight(), $terminal->getDimensionUnitType()); }
/** * Tests the connection procedure including checking fingerprint - requires working SSH server * * @group server * @medium */ public function testConnection() { $logger = new Logger(); $connection = new Connection(\properties::$host, \properties::$port); $connection->setLogger($logger); $this->assertTrue($connection->connect()); $fp = $connection->getFingerprint(); $this->assertEquals(32, strlen($fp)); // 32 byte MD5 HEX encoded fingerprint $this->assertTrue($connection->checkFingerprint($fp)); $this->assertFalse($connection->checkFingerprint(self::BAD_FINGERPRINT)); $this->assertNotEmpty($connection->getResource()); $this->assertFalse($connection->isAuthenticated()); $connection->disconnect(); $this->assertContains('Disconnected', $logger->getHistory()); }