Esempio n. 1
0
 /**
  * @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();
 }
Esempio n. 2
0
 /**
  * @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();
 }
Esempio n. 3
0
 /**
  * Get an authenticated connection ready for transaction testing
  *
  * @param bool $doAuth
  * @throws \Exception
  * @return Connection
  */
 protected function getConnection($doAuth = true)
 {
     $connection = new Connection(\properties::$host, \properties::$port, new PasswordCredential(\properties::$user, \properties::$pass));
     if (!$connection->connect()) {
         throw new \Exception("Error connecting to test server");
     }
     if ($doAuth) {
         if (!$connection->authenticate()) {
             throw new \Exception("Error authenticating on test server");
         }
     }
     return $connection;
 }
Esempio n. 4
0
File: Shell.php Progetto: bravo3/ssh
 /**
  * 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());
 }
Esempio n. 5
0
 /**
  * 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());
 }
Esempio n. 6
0
 /**
  * @small
  */
 public function testBadConnection()
 {
     $logger = new Logger();
     $connection = new Connection('invalid.host');
     $connection->setLogger($logger);
     $this->assertFalse($connection->connect());
     $this->assertFalse($connection->isConnected());
     $this->assertContains('Disconnected', $logger->getHistory());
 }
Esempio n. 7
0
 /**
  * @medium
  * @expectedException \Bravo3\SSH\Exceptions\NotAuthenticatedException
  * @group server
  */
 public function testNoAuth()
 {
     $connection = new Connection(\properties::$host, \properties::$port, new PasswordCredential(\properties::$user, \properties::$pass));
     if (!$connection->connect()) {
         throw new \Exception("Error connecting to test server");
     }
     $shell = new Shell($connection, new Terminal());
     // exception here
     $shell->sendln("hello");
     $this->fail();
 }
Esempio n. 8
0
 /**
  * Connect to the host via all tunnel nodes
  *
  * @return Connection|null
  */
 protected function connect()
 {
     // Connect to target host
     $this->status(Phase::CONNECTION(), 0, 0, "Connecting to target host " . $this->host->getHostname() . ':' . $this->host->getPort());
     $con = new Connection($this->host->getHostname(), $this->host->getPort(), $this->host->getCredential());
     $con->setLogger($this->logger);
     if (!$con->connect()) {
         $this->status(Phase::ERROR(), 0, 0, "Failed to connect to target host");
         $con->disconnectChain();
         return null;
     }
     if (!$con->authenticate()) {
         $this->status(Phase::ERROR(), 0, 0, "Failed to authenticate on target host");
         $con->disconnectChain();
         return null;
     }
     return $con;
 }