summaryrefslogtreecommitdiff
path: root/src/libs/ssh/sshconnection.cpp
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2022-03-17 08:48:28 +0100
committerEike Ziller <eike.ziller@qt.io>2022-03-17 08:48:28 +0100
commit9fd2a059f61dcdfd48011ab45f9b5cd20b5addd0 (patch)
tree98509c4713ee534908a2c7551e87fcff5bc50025 /src/libs/ssh/sshconnection.cpp
parent68faedd62fcac74206f412cbd24b8881fd6373f7 (diff)
parent976653cd9382ce0d7fac35b6c2f5b51feba7cd1c (diff)
downloadqt-creator-9fd2a059f61dcdfd48011ab45f9b5cd20b5addd0.tar.gz
Merge remote-tracking branch 'origin/7.0'
Conflicts: src/plugins/android/androiddevice.cpp src/plugins/docker/dockerdevice.cpp Change-Id: Id16ba0d9993c9f608242622aceae0a2a6691e05e
Diffstat (limited to 'src/libs/ssh/sshconnection.cpp')
-rw-r--r--src/libs/ssh/sshconnection.cpp91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/libs/ssh/sshconnection.cpp b/src/libs/ssh/sshconnection.cpp
index 4e695cbbfc..2e07e12bba 100644
--- a/src/libs/ssh/sshconnection.cpp
+++ b/src/libs/ssh/sshconnection.cpp
@@ -404,4 +404,95 @@ SftpTransferPtr SshConnection::setupTransfer(
d->connectionArgs(SshSettings::sftpFilePath())));
}
+#ifdef WITH_TESTS
+namespace SshTest {
+const QString getHostFromEnvironment()
+{
+ const QString host = QString::fromLocal8Bit(qgetenv("QTC_SSH_TEST_HOST"));
+ if (host.isEmpty() && qEnvironmentVariableIsSet("QTC_SSH_TEST_DEFAULTS"))
+ return QString("127.0.0.1");
+ return host;
+}
+
+quint16 getPortFromEnvironment()
+{
+ const int port = qEnvironmentVariableIntValue("QTC_SSH_TEST_PORT");
+ return port != 0 ? quint16(port) : 22;
+}
+
+const QString getUserFromEnvironment()
+{
+ return QString::fromLocal8Bit(qgetenv("QTC_SSH_TEST_USER"));
+}
+
+const QString getKeyFileFromEnvironment()
+{
+ const FilePath defaultKeyFile = FileUtils::homePath() / ".ssh/id_rsa";
+ const QString keyFile = QString::fromLocal8Bit(qgetenv("QTC_SSH_TEST_KEYFILE"));
+ if (keyFile.isEmpty()) {
+ if (qEnvironmentVariableIsSet("QTC_SSH_TEST_DEFAULTS"))
+ return defaultKeyFile.toString();
+ }
+ return keyFile;
+}
+
+const QString userAtHost()
+{
+ QString userMidFix = getUserFromEnvironment();
+ if (!userMidFix.isEmpty())
+ userMidFix.append('@');
+ return userMidFix + getHostFromEnvironment();
+}
+
+SshConnectionParameters getParameters()
+{
+ SshConnectionParameters params;
+ if (!qEnvironmentVariableIsSet("QTC_SSH_TEST_DEFAULTS")) {
+ params.setUserName(getUserFromEnvironment());
+ params.privateKeyFile = Utils::FilePath::fromUserInput(getKeyFileFromEnvironment());
+ }
+ params.setHost(getHostFromEnvironment());
+ params.setPort(getPortFromEnvironment());
+ params.timeout = 10;
+ params.authenticationType = !params.privateKeyFile.isEmpty()
+ ? QSsh::SshConnectionParameters::AuthenticationTypeSpecificKey
+ : QSsh::SshConnectionParameters::AuthenticationTypeAll;
+ return params;
+}
+
+bool checkParameters(const QSsh::SshConnectionParameters &params)
+{
+ if (qEnvironmentVariableIsSet("QTC_SSH_TEST_DEFAULTS"))
+ return true;
+ if (params.host().isEmpty()) {
+ qWarning("No hostname provided. Set QTC_SSH_TEST_HOST.");
+ return false;
+ }
+ if (params.userName().isEmpty())
+ qWarning("No user name provided - test may fail with empty default. Set QTC_SSH_TEST_USER.");
+ if (params.privateKeyFile.isEmpty()) {
+ qWarning("No key file provided. Set QTC_SSH_TEST_KEYFILE.");
+ return false;
+ }
+ return true;
+}
+
+void printSetupHelp()
+{
+ qInfo() << "In order to run this test properly it requires some setup (example for fedora):\n"
+ "1. Run a server on the host to connect to:\n"
+ " systemctl start sshd\n"
+ "2. Create your own ssh key (needed only once). For fedora it needs ecdsa type:\n"
+ " ssh-keygen -t ecdsa\n"
+ "3. Make your public key known to the server (needed only once):\n"
+ " ssh-copy-id -i [full path to your public key] [user@host]\n"
+ "4. Set the env variables before executing test:\n"
+ " QTC_SSH_TEST_HOST=127.0.0.1\n"
+ " QTC_SSH_TEST_KEYFILE=[full path to your private key]\n"
+ " QTC_SSH_TEST_USER=[your user name]\n";
+}
+
+} // namespace SshTest
+#endif
+
} // namespace QSsh