summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorKirill Burtsev <kirill.burtsev@qt.io>2019-08-14 18:59:23 +0200
committerKirill Burtsev <kirill.burtsev@qt.io>2019-09-05 23:32:55 +0200
commitbf3753f02402b44455038c4fa2a897d41aadf850 (patch)
treee41ec261298a4f5eff8e7b5507226301eafa3a61 /tests/auto
parent8213ea60bacb91ddfa1594e1f515abe2cfbde621 (diff)
Allow deferring QWebEngineCertificateError handling
Introduce defer() method for halting URL load on certificate errors, and methods for rejecting and ignoring these errors subsequently in async manner. [ChangeLog][QtWebEngineWidgets][QWebEngineCertificateError] New methods for asynchronous decision on certificate error during load. Fixes: QTBUG-55110 Change-Id: Ib23eb568862ccc360208922a6a581f8e7edc4a7e Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/shared/https.pri4
-rw-r--r--tests/auto/shared/httpserver.cpp31
-rw-r--r--tests/auto/shared/httpserver.h13
-rw-r--r--tests/auto/shared/httpsserver.h81
-rw-r--r--tests/auto/shared/httpsserver.qrc6
-rw-r--r--tests/auto/shared/resources/cert.pem34
-rw-r--r--tests/auto/shared/resources/key.pem52
-rw-r--r--tests/auto/widgets/certificateerror/certificateerror.pro3
-rw-r--r--tests/auto/widgets/certificateerror/tst_certificateerror.cpp122
-rw-r--r--tests/auto/widgets/widgets.pro1
10 files changed, 331 insertions, 16 deletions
diff --git a/tests/auto/shared/https.pri b/tests/auto/shared/https.pri
new file mode 100644
index 000000000..ce4c147f7
--- /dev/null
+++ b/tests/auto/shared/https.pri
@@ -0,0 +1,4 @@
+include($$PWD/http.pri)
+
+HEADERS += $$PWD/httpsserver.h
+RESOURCES += $$PWD/httpsserver.qrc
diff --git a/tests/auto/shared/httpserver.cpp b/tests/auto/shared/httpserver.cpp
index b85af9901..e282fc8b8 100644
--- a/tests/auto/shared/httpserver.cpp
+++ b/tests/auto/shared/httpserver.cpp
@@ -31,9 +31,21 @@
Q_LOGGING_CATEGORY(gHttpServerLog, "HttpServer")
-HttpServer::HttpServer(QObject *parent) : QObject(parent)
+HttpServer::HttpServer(QObject *parent) : HttpServer(new QTcpServer, "http", parent)
{
- connect(&m_tcpServer, &QTcpServer::newConnection, this, &HttpServer::handleNewConnection);
+}
+
+HttpServer::HttpServer(QTcpServer *tcpServer, const QString &protocol, QObject *parent)
+ : QObject(parent), m_tcpServer(tcpServer)
+{
+ m_url.setHost(QStringLiteral("127.0.0.1"));
+ m_url.setScheme(protocol);
+ connect(tcpServer, &QTcpServer::newConnection, this, &HttpServer::handleNewConnection);
+}
+
+HttpServer::~HttpServer()
+{
+ delete m_tcpServer;
}
bool HttpServer::start()
@@ -41,21 +53,18 @@ bool HttpServer::start()
m_error = false;
m_expectingError = false;
- if (!m_tcpServer.listen()) {
- qCWarning(gHttpServerLog).noquote() << m_tcpServer.errorString();
+ if (!m_tcpServer->listen()) {
+ qCWarning(gHttpServerLog).noquote() << m_tcpServer->errorString();
return false;
}
- m_url.setScheme(QStringLiteral("http"));
- m_url.setHost(QStringLiteral("127.0.0.1"));
- m_url.setPort(m_tcpServer.serverPort());
-
+ m_url.setPort(m_tcpServer->serverPort());
return true;
}
bool HttpServer::stop()
{
- m_tcpServer.close();
+ m_tcpServer->close();
return m_error == m_expectingError;
}
@@ -73,12 +82,12 @@ QUrl HttpServer::url(const QString &path) const
void HttpServer::handleNewConnection()
{
- auto rr = new HttpReqRep(m_tcpServer.nextPendingConnection(), this);
+ auto rr = new HttpReqRep(m_tcpServer->nextPendingConnection(), this);
connect(rr, &HttpReqRep::requestReceived, [this, rr]() {
Q_EMIT newRequest(rr);
rr->close();
});
- connect(rr, &HttpReqRep::responseSent, [this, rr]() {
+ connect(rr, &HttpReqRep::responseSent, [rr]() {
qCInfo(gHttpServerLog).noquote() << rr->requestMethod() << rr->requestPath()
<< rr->responseStatus() << rr->responseBody().size();
});
diff --git a/tests/auto/shared/httpserver.h b/tests/auto/shared/httpserver.h
index b4649244e..57f824bb5 100644
--- a/tests/auto/shared/httpserver.h
+++ b/tests/auto/shared/httpserver.h
@@ -59,19 +59,22 @@ class HttpServer : public QObject
Q_OBJECT
public:
explicit HttpServer(QObject *parent = nullptr);
+ explicit HttpServer(QTcpServer *server, const QString &protocol, QObject *parent = nullptr);
+
+ ~HttpServer() override;
// Must be called to start listening.
//
// Returns true if a TCP port has been successfully bound.
- Q_REQUIRED_RESULT bool start();
+ Q_INVOKABLE Q_REQUIRED_RESULT bool start();
// Stops listening and performs final error checks.
- Q_REQUIRED_RESULT bool stop();
+ Q_INVOKABLE Q_REQUIRED_RESULT bool stop();
- void setExpectError(bool b);
+ Q_INVOKABLE void setExpectError(bool b);
// Full URL for given relative path
- QUrl url(const QString &path = QStringLiteral("/")) const;
+ Q_INVOKABLE QUrl url(const QString &path = QStringLiteral("/")) const;
Q_SIGNALS:
// Emitted after a HTTP request has been successfully parsed.
@@ -81,7 +84,7 @@ private Q_SLOTS:
void handleNewConnection();
private:
- QTcpServer m_tcpServer;
+ QTcpServer *m_tcpServer;
QUrl m_url;
bool m_error = false;
bool m_expectingError = false;
diff --git a/tests/auto/shared/httpsserver.h b/tests/auto/shared/httpsserver.h
new file mode 100644
index 000000000..76287a7e5
--- /dev/null
+++ b/tests/auto/shared/httpsserver.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef HTTPSSERVER_H
+#define HTTPSSERVER_H
+
+#include "httpreqrep.h"
+#include "httpserver.h"
+
+#include <QDebug>
+#include <QFile>
+#include <QSslKey>
+#include <QSslSocket>
+#include <QSslConfiguration>
+#include <QTcpServer>
+
+struct SslTcpServer : QTcpServer
+{
+ SslTcpServer() {
+ sslconf.setLocalCertificate(QSslCertificate::fromPath(":/resources/cert.pem").first());
+ sslconf.setPrivateKey(readKey(":/resources/key.pem"));
+ }
+
+ void incomingConnection(qintptr d) override {
+ auto socket = new QSslSocket(this);
+ socket->setSslConfiguration(sslconf);
+
+ if (!socket->setSocketDescriptor(d)) {
+ qWarning() << "Failed to setup ssl socket!";
+ delete socket;
+ return;
+ }
+
+ connect(socket, QOverload<QSslSocket::SocketError>::of(&QSslSocket::error),
+ [] (QSslSocket::SocketError e) { qWarning() << "! Socket Error:" << e; });
+ connect(socket, QOverload<const QList<QSslError> &>::of(&QSslSocket::sslErrors),
+ [] (const QList<QSslError> &le) { qWarning() << "! SSL Errors:\n" << le; });
+
+ addPendingConnection(socket);
+ socket->startServerEncryption();
+ }
+
+ QSslKey readKey(const QString &path) const {
+ QFile file(path);
+ file.open(QIODevice::ReadOnly);
+ return QSslKey(file.readAll(), QSsl::Rsa, QSsl::Pem);
+ }
+
+ QSslConfiguration sslconf;
+};
+
+struct HttpsServer : HttpServer
+{
+ HttpsServer(QObject *parent = nullptr) : HttpServer(new SslTcpServer, "https", parent) { }
+};
+
+#endif
diff --git a/tests/auto/shared/httpsserver.qrc b/tests/auto/shared/httpsserver.qrc
new file mode 100644
index 000000000..ec57a1983
--- /dev/null
+++ b/tests/auto/shared/httpsserver.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>resources/cert.pem</file>
+ <file>resources/key.pem</file>
+</qresource>
+</RCC>
diff --git a/tests/auto/shared/resources/cert.pem b/tests/auto/shared/resources/cert.pem
new file mode 100644
index 000000000..518642d1d
--- /dev/null
+++ b/tests/auto/shared/resources/cert.pem
@@ -0,0 +1,34 @@
+-----BEGIN CERTIFICATE-----
+MIIF3zCCA8egAwIBAgIULwmp8VArl0GVaR6HLEf/U1XNdJ8wDQYJKoZIhvcNAQEL
+BQAwfzELMAkGA1UEBhMCREUxDzANBgNVBAgMBkJlcmxpbjEPMA0GA1UEBwwGQmVy
+bGluMQ0wCwYDVQQKDARUUXRDMQswCQYDVQQLDAJXRTESMBAGA1UEAwwJbG9jYWxo
+b3N0MR4wHAYJKoZIhvcNAQkBFg9ibGFja2hvbGVAcXQuaW8wHhcNOTkxMjMxMjMw
+MDAxWhcNMDAxMjMwMjMwMDAxWjB/MQswCQYDVQQGEwJERTEPMA0GA1UECAwGQmVy
+bGluMQ8wDQYDVQQHDAZCZXJsaW4xDTALBgNVBAoMBFRRdEMxCzAJBgNVBAsMAldF
+MRIwEAYDVQQDDAlsb2NhbGhvc3QxHjAcBgkqhkiG9w0BCQEWD2JsYWNraG9sZUBx
+dC5pbzCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAL15eV6DVSOFW093
+p1+FlqmneX4riOzJXiNNF8DI00+rkTv4hT37D6keJlMxLLDgq3o9YwJnGJkpxMSd
+P9uvKGaIRb9hQd7WviXCMwX07Wz3BMIogKItJfY6nEk8dkCc/FPrhbk4CCKNoZkb
+fGRv4jFoCCXL8yaffN5ii+L/xF2azaXwr4MOOJbG5810HWGYbrppBMtSQk4c1jXI
+c0eVqOjnYtcFNCmoIyXwDdTynaRizNtUgeYRSaIBk/hXQGePDL35V0ARg2EbVGzL
+sJKftJf4WBoprjX8xmfk72zYB0SF8g7uUXGWb6D5Q661c7REGB7Ha7uLIz74Pow3
+MmJVbz93YiEZ4onxDNke5AIgNrllhd1hk8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TKv0QPW36DD9Pgpge
+sMSafPouMdYc8c3HuTxh2ZwHLxpqyaKMGVN+LdzDbddsZzOiUKd7Bq9XpNtG2o9y
+K+MCKRECBkh4ZvMxd3yEJAym0w==
+-----END CERTIFICATE-----
diff --git a/tests/auto/shared/resources/key.pem b/tests/auto/shared/resources/key.pem
new file mode 100644
index 000000000..bd350d7fb
--- /dev/null
+++ b/tests/auto/shared/resources/key.pem
@@ -0,0 +1,52 @@
+-----BEGIN PRIVATE KEY-----
+MIIJRAIBADANBgkqhkiG9w0BAQEFAASCCS4wggkqAgEAAoICAQC9eXleg1UjhVtP
+d6dfhZapp3l+K4jsyV4jTRfAyNNPq5E7+IU9+w+pHiZTMSyw4Kt6PWMCZxiZKcTE
+nT/bryhmiEW/YUHe1r4lwjMF9O1s9wTCKICiLSX2OpxJPHZAnPxT64W5OAgijaGZ
+G3xkb+IxaAgly/Mmn3zeYovi/8Rdms2l8K+DDjiWxufNdB1hmG66aQTLUkJOHNY1
+yHNHlajo52LXBTQpqCMl8A3U8p2kYszbVIHmEUmiAZP4V0Bnjwy9+VdAEYNhG1Rs
+y7CSn7SX+FgaKa41/MZn5O9s2AdEhfIO7lFxlm+g+UOutXO0RBgex2u7iyM++D6M
+NzJiVW8/d2IhGeKJ8QzZHuQCIDa5ZYXdYZPFhgQTe4v/EZkdikUtuDhGto0HdLvC
+8Vr1LFqc1jubEhjeL8NTQO+X5PKSqPNCb4c9vtatgngBJ5CIVNrbB99NTFrh2rK1
+yeh2Nc6dCKHmEcLQqH/57k2wvQWDN+/NrZif+juzvAUMjjNxv+/vIYMlAvpn0ooH
+JqlW6Vm3IUsQUh2eQ5TDBxx2CUsUtBgI0hse3wuLexAYGbZ2cqywNdoGKBp4dpAu
+U0YFrX8FXSYByhkVn3jHTobu9xpVso/YhDfgWk+S5D8YsrW/stUZkXD7agaHzCpK
+VfQ+F+Yk0GwKF63VM7VXBOXQT5v1WwIDAQABAoICAGoOsM0inml/oBjfVSS21hqo
+z+y72a0R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r4h8v3MevtKmZHL2CXz1VtL
+hSwolTgSIHCm/U7zPXTb3nftXRXM/eHhEL/xhEkbvv4zGVLVsqPaKdpAxdYQCRn3
+drIOsc8n1L8VqLPoKTnK2+Ya0yZPt9M4aQQ6Nv/bZuRBF4+vj+GGdhQQ0EUGkx5N
+lKsFgrQGVd6V4YNgVi9K1GtJLUd3mR7Vh7xvcdMOQkpbSZqXqe+lB1W2+nPaxTxU
+TjPKSB0BXJMcKAMCmRgzx/61CPo83M4OYG5oltQSDskI4VeTLOI5nPi2MoXcVnX5
+zB9TRbOML1RSOJ+z+mbv7ONymoUI/Jf5
+-----END PRIVATE KEY-----
diff --git a/tests/auto/widgets/certificateerror/certificateerror.pro b/tests/auto/widgets/certificateerror/certificateerror.pro
new file mode 100644
index 000000000..73ba7515b
--- /dev/null
+++ b/tests/auto/widgets/certificateerror/certificateerror.pro
@@ -0,0 +1,3 @@
+include(../tests.pri)
+include(../../shared/https.pri)
+QT *= core-private
diff --git a/tests/auto/widgets/certificateerror/tst_certificateerror.cpp b/tests/auto/widgets/certificateerror/tst_certificateerror.cpp
new file mode 100644
index 000000000..b002dc363
--- /dev/null
+++ b/tests/auto/widgets/certificateerror/tst_certificateerror.cpp
@@ -0,0 +1,122 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <httpsserver.h>
+#include <util.h>
+
+#include <QWebEngineCertificateError>
+#include <QWebEnginePage>
+#include <QWebEngineSettings>
+
+#include <QtTest/QtTest>
+
+class tst_CertificateError : public QObject
+{
+ Q_OBJECT
+public:
+ tst_CertificateError() { }
+
+private Q_SLOTS:
+ void handleError_data();
+ void handleError();
+};
+
+struct PageWithCertificateErrorHandler : QWebEnginePage
+{
+ PageWithCertificateErrorHandler(bool defer, bool accept, QObject *p = nullptr)
+ : QWebEnginePage(p), deferError(defer), acceptCertificate(accept) {
+ connect(this, &QWebEnginePage::loadFinished, [&] (bool result) { spyLoad(result); });
+ }
+
+ bool deferError, acceptCertificate;
+
+ CallbackSpy<bool> spyLoad;
+ QScopedPointer<QWebEngineCertificateError> error;
+
+ bool certificateError(const QWebEngineCertificateError &e) override {
+ error.reset(new QWebEngineCertificateError(e));
+ if (deferError)
+ error->defer();
+ return acceptCertificate;
+ }
+};
+
+void tst_CertificateError::handleError_data()
+{
+ QTest::addColumn<bool>("deferError");
+ QTest::addColumn<bool>("acceptCertificate");
+ QTest::addColumn<QString>("expectedContent");
+ QTest::addRow("Reject") << false << false << QString();
+ QTest::addRow("DeferReject") << true << false << QString();
+ QTest::addRow("DeferAccept") << true << true << "TEST";
+}
+
+void tst_CertificateError::handleError()
+{
+ HttpsServer server;
+ server.setExpectError(true);
+ QVERIFY(server.start());
+
+ connect(&server, &HttpsServer::newRequest, [&] (HttpReqRep *rr) {
+ rr->setResponseBody(QByteArrayLiteral("<html><body>TEST</body></html>"));
+ rr->sendResponse();
+ });
+
+ QFETCH(bool, deferError);
+ QFETCH(bool, acceptCertificate);
+ QFETCH(QString, expectedContent);
+
+ PageWithCertificateErrorHandler page(deferError, acceptCertificate);
+ page.settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled, false);
+
+ page.setUrl(server.url());
+ QTRY_VERIFY(page.error);
+ QVERIFY(page.error->isOverridable());
+
+ if (deferError) {
+ QVERIFY(page.error->deferred());
+ QVERIFY(!page.error->answered());
+ QVERIFY(!page.spyLoad.wasCalled());
+ QCOMPARE(toPlainTextSync(&page), QString());
+
+ if (acceptCertificate)
+ page.error->ignoreCertificateError();
+ else
+ page.error->rejectCertificate();
+
+ QVERIFY(page.error->answered());
+ page.error.reset();
+ }
+
+ bool loadResult = page.spyLoad.waitForResult();
+ QVERIFY(page.spyLoad.wasCalled());
+ QCOMPARE(loadResult, acceptCertificate);
+ QCOMPARE(toPlainTextSync(&page), expectedContent);
+}
+
+QTEST_MAIN(tst_CertificateError)
+#include <tst_certificateerror.moc>
diff --git a/tests/auto/widgets/widgets.pro b/tests/auto/widgets/widgets.pro
index 92159bf83..df553df55 100644
--- a/tests/auto/widgets/widgets.pro
+++ b/tests/auto/widgets/widgets.pro
@@ -4,6 +4,7 @@ QT_FOR_CONFIG += webenginecore webenginecore-private
TEMPLATE = subdirs
SUBDIRS += \
+ certificateerror \
defaultsurfaceformat \
devtools \
faviconmanager \