aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autotests/testolmaccount.cpp1
-rw-r--r--lib/connection.cpp5
-rw-r--r--lib/connection.h5
-rw-r--r--lib/connectiondata.cpp6
-rw-r--r--lib/connectiondata.h1
-rw-r--r--lib/networkaccessmanager.cpp17
-rw-r--r--lib/networkaccessmanager.h1
7 files changed, 31 insertions, 5 deletions
diff --git a/autotests/testolmaccount.cpp b/autotests/testolmaccount.cpp
index 91342241..eb44791a 100644
--- a/autotests/testolmaccount.cpp
+++ b/autotests/testolmaccount.cpp
@@ -165,6 +165,7 @@ void TestOlmAccount::encryptedFile()
#define CREATE_CONNECTION(VAR, USERNAME, SECRET, DEVICE_NAME) \
auto VAR = std::make_shared<Connection>(); \
+ VAR->ignoreSslErrors(true); \
(VAR) ->resolveServer("@alice:localhost:" + QString::number(443)); \
connect( (VAR) .get(), &Connection::loginFlowsChanged, this, [this, VAR ] () { \
(VAR) ->loginWithPassword( (USERNAME) , SECRET , DEVICE_NAME , ""); \
diff --git a/lib/connection.cpp b/lib/connection.cpp
index 704bc1b4..62427ae1 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -572,6 +572,11 @@ void Connection::sync(int timeout)
});
}
+void Connection::ignoreSslErrors(bool ignore)
+{
+ connectionData()->ignoreSslErrors(ignore);
+}
+
void Connection::syncLoop(int timeout)
{
if (d->syncLoopConnection && d->syncTimeout == timeout) {
diff --git a/lib/connection.h b/lib/connection.h
index 6729b23d..93e22da2 100644
--- a/lib/connection.h
+++ b/lib/connection.h
@@ -476,6 +476,11 @@ public:
setUserFactory(defaultUserFactory<T>());
}
+ /// Ignore ssl errors (usefull for automated testing with local synapse
+ /// instance).
+ /// \internal
+ void ignoreSslErrors(bool ignore);
+
public Q_SLOTS:
/// \brief Set the homeserver base URL and retrieve its login flows
///
diff --git a/lib/connectiondata.cpp b/lib/connectiondata.cpp
index 87ad4577..672feb06 100644
--- a/lib/connectiondata.cpp
+++ b/lib/connectiondata.cpp
@@ -128,6 +128,12 @@ bool ConnectionData::needsToken(const QString& requestName) const
!= d->needToken.cend();
}
+void ConnectionData::ignoreSslErrors(bool ignore) const
+{
+ auto quotientNam = static_cast<NetworkAccessManager>(nam());
+ quotientNam.ignoreSslErrors(ignore);
+}
+
void ConnectionData::setDeviceId(const QString& deviceId)
{
d->deviceId = deviceId;
diff --git a/lib/connectiondata.h b/lib/connectiondata.h
index e16a2dac..203dc9e8 100644
--- a/lib/connectiondata.h
+++ b/lib/connectiondata.h
@@ -29,6 +29,7 @@ public:
bool needsToken(const QString& requestName) const;
QNetworkAccessManager* nam() const;
+ void ignoreSslErrors(bool ignore = true) const;
void setBaseUrl(QUrl baseUrl);
void setToken(QByteArray accessToken);
void setDeviceId(const QString& deviceId);
diff --git a/lib/networkaccessmanager.cpp b/lib/networkaccessmanager.cpp
index 293538ee..d0380cec 100644
--- a/lib/networkaccessmanager.cpp
+++ b/lib/networkaccessmanager.cpp
@@ -40,17 +40,24 @@ public:
NetworkAccessManager::NetworkAccessManager(QObject* parent)
: QNetworkAccessManager(parent), d(std::make_unique<Private>(this))
-{
- connect(this, &QNetworkAccessManager::sslErrors, this, [](QNetworkReply *reply, const QList<QSslError> &errors) {
- reply->ignoreSslErrors();
- });
-}
+{}
QList<QSslError> NetworkAccessManager::ignoredSslErrors() const
{
return d->ignoredSslErrors;
}
+void NetworkAccessManager::ignoreSslErrors(bool ignore) const
+{
+ if (ignore) {
+ connect(this, &QNetworkAccessManager::sslErrors, this, [](QNetworkReply *reply, const QList<QSslError> &errors) {
+ reply->ignoreSslErrors();
+ });
+ } else {
+ disconnect(this, &QNetworkAccessManager::sslErrors, this, nullptr);
+ }
+}
+
void NetworkAccessManager::addIgnoredSslError(const QSslError& error)
{
d->ignoredSslErrors << error;
diff --git a/lib/networkaccessmanager.h b/lib/networkaccessmanager.h
index 87bc12a1..7643302f 100644
--- a/lib/networkaccessmanager.h
+++ b/lib/networkaccessmanager.h
@@ -19,6 +19,7 @@ public:
QList<QSslError> ignoredSslErrors() const;
void addIgnoredSslError(const QSslError& error);
void clearIgnoredSslErrors();
+ void ignoreSslErrors(bool ignore = true) const;
/** Get a pointer to the singleton */
static NetworkAccessManager* instance();