/** * @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(); }
/** * Get an authenticated connection ready for transaction testing * * @param bool $doAuth * @throws \Exception * @return Shell */ protected function getShell() { $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 (!$connection->authenticate()) { throw new \Exception("Error authenticating on test server"); } return $connection->getShell(); }
/** * @small */ public function testLogger() { $logger = new Logger(); $connection = new Connection(self::DEFAULT_HOST); $connection->setLogger($logger); try { $connection->authenticate(); // will fail - not connected } catch (NotConnectedException $e) { } $this->assertEquals("error: Not connected\n", $logger->getHistory()); }
/** * 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; }