diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2017-06-14 16:31:33 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2018-11-19 09:12:31 +0000 |
commit | 424923817cd018767671e0e88b90deef3fd4917a (patch) | |
tree | 12f060fee0a92018b318c881636b2722bad48857 /tests | |
parent | 3d1d9aae2e977ef599582074e0f4faaef454a595 (diff) |
SSH: Implement X11 forwarding
Change-Id: Ia7b15e784cb098bc7c6c6be2748d772192187e97
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/ssh/ssh.pro | 2 | ||||
-rw-r--r-- | tests/auto/ssh/ssh.qbs | 1 | ||||
-rw-r--r-- | tests/auto/ssh/tst_ssh.cpp | 61 |
3 files changed, 63 insertions, 1 deletions
diff --git a/tests/auto/ssh/ssh.pro b/tests/auto/ssh/ssh.pro index 31469ad3ad..8ba850177d 100644 --- a/tests/auto/ssh/ssh.pro +++ b/tests/auto/ssh/ssh.pro @@ -1,5 +1,5 @@ QT = core network -QTC_LIB_DEPENDS += ssh +QTC_LIB_DEPENDS += ssh utils include(../qttest.pri) SOURCES += tst_ssh.cpp diff --git a/tests/auto/ssh/ssh.qbs b/tests/auto/ssh/ssh.qbs index b580f05433..c2b7072b55 100644 --- a/tests/auto/ssh/ssh.qbs +++ b/tests/auto/ssh/ssh.qbs @@ -3,5 +3,6 @@ import qbs QtcAutotest { name: "SSH autotest" Depends { name: "QtcSsh" } + Depends { name: "Utils" } files: "tst_ssh.cpp" } diff --git a/tests/auto/ssh/tst_ssh.cpp b/tests/auto/ssh/tst_ssh.cpp index b15e411066..93b8a85c13 100644 --- a/tests/auto/ssh/tst_ssh.cpp +++ b/tests/auto/ssh/tst_ssh.cpp @@ -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; |