Adapt tests to recent changes in certificate handling
This commit is contained in:
parent
6145268dd3
commit
76b406f4e1
|
@ -822,6 +822,18 @@ bool SyncthingConnection::loadSelfSignedCertificate(const QUrl &url)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Clears the self-signed certificate that might be loaded via loadSelfSignedCertificate().
|
||||||
|
* \remarks This function mainly exists to ease testing; one normally doesn't need to invoke it explicitly.
|
||||||
|
*/
|
||||||
|
void SyncthingConnection::clearSelfSignedCertificate()
|
||||||
|
{
|
||||||
|
m_expectedSslErrors.clear();
|
||||||
|
m_certificatePath.clear();
|
||||||
|
m_dynamicallyDeterminedCertificatePath.clear();
|
||||||
|
m_certificateLastModified = QDateTime();
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Applies the specified configuration.
|
* \brief Applies the specified configuration.
|
||||||
* \remarks
|
* \remarks
|
||||||
|
|
|
@ -182,6 +182,7 @@ public:
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
bool loadSelfSignedCertificate(const QUrl &url = QUrl());
|
bool loadSelfSignedCertificate(const QUrl &url = QUrl());
|
||||||
|
void clearSelfSignedCertificate();
|
||||||
bool applySettings(Data::SyncthingConnectionSettings &connectionSettings);
|
bool applySettings(Data::SyncthingConnectionSettings &connectionSettings);
|
||||||
|
|
||||||
// methods to initiate/close connection
|
// methods to initiate/close connection
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace Data;
|
using namespace Data;
|
||||||
using namespace CppUtilities;
|
using namespace CppUtilities;
|
||||||
|
@ -185,12 +187,18 @@ void MiscTests::testConnectionSettingsAndLoadingSelfSignedCert()
|
||||||
settings.syncthingUrl = QStringLiteral("https://localhost:8080");
|
settings.syncthingUrl = QStringLiteral("https://localhost:8080");
|
||||||
CPPUNIT_ASSERT(connection.applySettings(settings));
|
CPPUNIT_ASSERT(connection.applySettings(settings));
|
||||||
connection.m_configDir = QStringLiteral("some-non/existent-dir");
|
connection.m_configDir = QStringLiteral("some-non/existent-dir");
|
||||||
bool errorOccured = false;
|
connection.clearSelfSignedCertificate();
|
||||||
|
const auto expectedErrorMessage = QStringLiteral("Unable to load certificate used by Syncthing.");
|
||||||
|
auto expectedErrorOccured = false;
|
||||||
const function<void(const QString &)> errorHandler
|
const function<void(const QString &)> errorHandler
|
||||||
= [&errorOccured](const QString &message) { errorOccured |= message == QStringLiteral("Unable to load certificate used by Syncthing."); };
|
= [&expectedErrorOccured, &expectedErrorMessage](const QString &message) {
|
||||||
waitForSignals(bind(&SyncthingConnection::loadSelfSignedCertificate, &connection, QUrl()), 1,
|
std::cout << "\n - error: " << message.toLocal8Bit().data() << '\n';
|
||||||
signalInfo(&connection, &SyncthingConnection::error, errorHandler, &errorOccured));
|
expectedErrorOccured |= message == expectedErrorMessage;
|
||||||
|
};
|
||||||
|
waitForSignals(bind(&SyncthingConnection::loadSelfSignedCertificate, &connection, QUrl()), 1000,
|
||||||
|
signalInfo(&connection, &SyncthingConnection::error, errorHandler, &expectedErrorOccured));
|
||||||
settings.expectedSslErrors.clear();
|
settings.expectedSslErrors.clear();
|
||||||
|
settings.httpsCertPath.clear();
|
||||||
CPPUNIT_ASSERT(!connection.applySettings(settings));
|
CPPUNIT_ASSERT(!connection.applySettings(settings));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue