SSH: Implement X11 forwarding

Change-Id: Ia7b15e784cb098bc7c6c6be2748d772192187e97
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Christian Kandeler
2017-06-14 16:31:33 +02:00
parent 3d1d9aae2e
commit 424923817c
24 changed files with 811 additions and 17 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
QT = core network
QTC_LIB_DEPENDS += ssh
QTC_LIB_DEPENDS += ssh utils
include(../qttest.pri)
SOURCES += tst_ssh.cpp
+1
View File
@@ -3,5 +3,6 @@ import qbs
QtcAutotest {
name: "SSH autotest"
Depends { name: "QtcSsh" }
Depends { name: "Utils" }
files: "tst_ssh.cpp"
}
+61
View File
@@ -30,6 +30,9 @@
#include <ssh/sshpseudoterminal.h>
#include <ssh/sshremoteprocessrunner.h>
#include <ssh/sshtcpipforwardserver.h>
#include <ssh/sshx11displayinfo_p.h>
#include <ssh/sshx11inforetriever_p.h>
#include <utils/environment.h>
#include <QDateTime>
#include <QDir>
@@ -152,6 +155,8 @@ private slots:
void remoteProcessChannels();
void remoteProcessInput();
void sftp();
void x11InfoRetriever_data();
void x11InfoRetriever();
private:
bool waitForConnection(SshConnection &connection);
@@ -826,6 +831,62 @@ void tst_Ssh::sftp()
QCOMPARE(sftpChannel->state(), SftpChannel::Closed);
}
void tst_Ssh::x11InfoRetriever_data()
{
QTest::addColumn<QString>("displayName");
QTest::addColumn<bool>("successExpected");
const Utils::FileName xauthCommand
= Utils::Environment::systemEnvironment().searchInPath("xauth");
const QString displayName = QLatin1String(qgetenv("DISPLAY"));
const bool canSucceed = xauthCommand.exists() && !displayName.isEmpty();
QTest::newRow(canSucceed ? "suitable host" : "unsuitable host") << displayName << canSucceed;
QTest::newRow("invalid display name") << QString("dummy") << false;
}
void tst_Ssh::x11InfoRetriever()
{
QFETCH(QString, displayName);
QFETCH(bool, successExpected);
using namespace QSsh::Internal;
SshX11InfoRetriever x11InfoRetriever(displayName);
QEventLoop loop;
bool success;
X11DisplayInfo displayInfo;
QString errorMessage;
const auto successHandler = [&loop, &success, &displayInfo](const X11DisplayInfo &di) {
success = true;
displayInfo = di;
loop.quit();
};
connect(&x11InfoRetriever, &SshX11InfoRetriever::success, successHandler);
const auto failureHandler = [&loop, &success, &errorMessage](const QString &error) {
success = false;
errorMessage = error;
loop.quit();
};
connect(&x11InfoRetriever, &SshX11InfoRetriever::failure, failureHandler);
QTimer timer;
QObject::connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
timer.setSingleShot(true);
timer.setInterval(40000);
timer.start();
x11InfoRetriever.start();
loop.exec();
QVERIFY(timer.isActive());
timer.stop();
if (successExpected) {
QVERIFY2(success, qPrintable(errorMessage));
QVERIFY(!displayInfo.protocol.isEmpty());
QVERIFY(!displayInfo.cookie.isEmpty());
QCOMPARE(displayInfo.cookie.size(), displayInfo.randomCookie.size());
QCOMPARE(displayInfo.displayName, displayName);
} else {
QVERIFY(!success);
QVERIFY(!errorMessage.isEmpty());
}
}
bool tst_Ssh::waitForConnection(SshConnection &connection)
{
QEventLoop loop;