summaryrefslogtreecommitdiffstats
path: root/tests/auto/core
diff options
context:
space:
mode:
authorLeander Beernaert <leander.beernaert@qt.io>2019-05-20 11:05:51 +0200
committerLeander Beernaert <leander.beernaert@qt.io>2019-05-20 16:41:24 +0200
commit1a8e93c95de92f6a00bdf3768c5315dd032513c0 (patch)
treebd81ba43530ce5f2f0c416d23af0398f7d57f78f /tests/auto/core
parente0f5df4c4a83a2dbe44a5ee42bb3b8e6ab0d851e (diff)
Referrer HTTP Header no longer ignored when set via RequestInterceptor
Make sure the HTTP referer is properly placed on a request when it's set via the QWebEngineUrlRequestInterceptor. Added test case to catch future incidents. Fixes: QTBUG-60203 Change-Id: Ida2f713a7352c3199fc9f8e15b5d8350d50afdda Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto/core')
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/qwebengineurlrequestinterceptor.pro1
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp43
2 files changed, 44 insertions, 0 deletions
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/qwebengineurlrequestinterceptor.pro b/tests/auto/core/qwebengineurlrequestinterceptor/qwebengineurlrequestinterceptor.pro
index e99c7f493..9c239f1a7 100644
--- a/tests/auto/core/qwebengineurlrequestinterceptor/qwebengineurlrequestinterceptor.pro
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/qwebengineurlrequestinterceptor.pro
@@ -1 +1,2 @@
include(../tests.pri)
+include(../../shared/http.pri)
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp b/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp
index 23bf88417..653a1e421 100644
--- a/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp
@@ -34,6 +34,9 @@
#include <QtWebEngineWidgets/qwebengineprofile.h>
#include <QtWebEngineWidgets/qwebenginesettings.h>
+#include <httpserver.h>
+#include <httpreqrep.h>
+
class tst_QWebEngineUrlRequestInterceptor : public QObject
{
Q_OBJECT
@@ -59,6 +62,7 @@ private Q_SLOTS:
void requestInterceptorByResourceType_data();
void requestInterceptorByResourceType();
void firstPartyUrlHttp();
+ void passRefererHeader();
};
tst_QWebEngineUrlRequestInterceptor::tst_QWebEngineUrlRequestInterceptor()
@@ -97,6 +101,9 @@ struct RequestInfo {
int resourceType;
};
+static const QByteArray kHttpHeaderReferrerValue = QByteArrayLiteral("http://somereferrer.com/");
+static const QByteArray kHttpHeaderRefererName = QByteArrayLiteral("referer");
+
class TestRequestInterceptor : public QWebEngineUrlRequestInterceptor
{
public:
@@ -112,6 +119,9 @@ public:
if (shouldIntercept && info.requestUrl().toString().endsWith(QLatin1String("__placeholder__")))
info.redirect(QUrl("qrc:///resources/content.html"));
+ // Set referrer header
+ info.setHttpHeader(kHttpHeaderRefererName, kHttpHeaderReferrerValue);
+
requestInfos.append(info);
}
@@ -487,5 +497,38 @@ void tst_QWebEngineUrlRequestInterceptor::firstPartyUrlHttp()
QCOMPARE(info.firstPartyUrl, firstPartyUrl);
}
+void tst_QWebEngineUrlRequestInterceptor::passRefererHeader()
+{
+ // Create HTTP Server to parse the request.
+ HttpServer httpServer;
+
+ if (!httpServer.start())
+ QSKIP("Failed to start http server");
+
+ bool succeeded = false;
+ connect(&httpServer, &HttpServer::newRequest, [&succeeded](HttpReqRep *rr) {
+ const QByteArray headerValue = rr->requestHeader(kHttpHeaderRefererName);
+ QCOMPARE(headerValue, kHttpHeaderReferrerValue);
+ succeeded = headerValue == kHttpHeaderReferrerValue;
+ rr->setResponseStatus(200);
+ rr->sendResponse();
+ });
+
+ QWebEngineProfile profile;
+ TestRequestInterceptor interceptor(true);
+ profile.setRequestInterceptor(&interceptor);
+
+ QWebEnginePage page(&profile);
+ QSignalSpy spy(&page, SIGNAL(loadFinished(bool)));
+ QWebEngineHttpRequest httpRequest;
+ QUrl requestUrl = httpServer.url();
+ httpRequest.setUrl(requestUrl);
+ page.load(httpRequest);
+
+ QVERIFY(spy.wait());
+ (void) httpServer.stop();
+ QVERIFY(succeeded);
+}
+
QTEST_MAIN(tst_QWebEngineUrlRequestInterceptor)
#include "tst_qwebengineurlrequestinterceptor.moc"