From 320c7316b75be22112cb4802187c3873c9934eab Mon Sep 17 00:00:00 2001 From: Michal Klocek <michal.klocek@qt.io> Date: Wed, 3 Apr 2019 15:16:35 +0200 Subject: [PATCH] Fix tst_Dialogs::authenticationDialogRequested Chromium returns unexpected proxy reply if localhost is used. Since proxy resolver works now, the workaround to trigger dialog with "localhost proxy" can be skipped. Change-Id: I26d88c43779809e4f481101266e6b8784a6b196d Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> --- tests/auto/quick/dialogs/BLACKLIST | 2 -- tests/auto/quick/dialogs/server.cpp | 13 ++++++------- tests/auto/quick/dialogs/server.h | 2 ++ tests/auto/quick/dialogs/tst_dialogs.cpp | 17 +++++++++++++---- 4 files changed, 21 insertions(+), 13 deletions(-) delete mode 100644 tests/auto/quick/dialogs/BLACKLIST diff --git a/tests/auto/quick/dialogs/BLACKLIST b/tests/auto/quick/dialogs/BLACKLIST deleted file mode 100644 index 19380e01e..000000000 --- a/tests/auto/quick/dialogs/BLACKLIST +++ /dev/null @@ -1,2 +0,0 @@ -[authenticationDialogRequested:Proxy Authentication Dialog] -* diff --git a/tests/auto/quick/dialogs/server.cpp b/tests/auto/quick/dialogs/server.cpp index dc9cfe582..dfc7c97ad 100644 --- a/tests/auto/quick/dialogs/server.cpp +++ b/tests/auto/quick/dialogs/server.cpp @@ -33,7 +33,6 @@ Server::Server(QObject *parent) : QObject(parent) { - m_data.clear(); connect(&m_server, &QTcpServer::newConnection, this, &Server::handleNewConnection); } @@ -42,6 +41,11 @@ bool Server::isListening() return m_server.isListening(); } +void Server::setReply(const QByteArray &reply) +{ + m_reply = reply; +} + void Server::run() { if (!m_server.listen(QHostAddress::LocalHost, 5555)) @@ -69,12 +73,7 @@ void Server::handleReadReady() if (!m_data.endsWith("\r\n\r\n")) return; - if (m_data.contains(QByteArrayLiteral("OPEN_AUTH"))) - socket->write("HTTP/1.1 401 Unauthorized\nWWW-Authenticate: " - "Basic realm=\"Very Restricted Area\"\r\n\r\n"); - if (m_data.contains(QByteArrayLiteral("OPEN_PROXY"))) - socket->write("HTTP/1.1 407 Proxy Auth Required\nProxy-Authenticate: " - "Basic realm=\"Proxy requires authentication\"\r\n\r\n"); + socket->write(m_reply); m_data.clear(); socket->disconnectFromHost(); } diff --git a/tests/auto/quick/dialogs/server.h b/tests/auto/quick/dialogs/server.h index 24da47523..fa9a73811 100644 --- a/tests/auto/quick/dialogs/server.h +++ b/tests/auto/quick/dialogs/server.h @@ -40,6 +40,7 @@ public: explicit Server(QObject *parent = nullptr); bool isListening(); + void setReply(const QByteArray &reply); public slots: void run(); @@ -50,6 +51,7 @@ private slots: private: QByteArray m_data; + QByteArray m_reply; QTcpServer m_server; }; diff --git a/tests/auto/quick/dialogs/tst_dialogs.cpp b/tests/auto/quick/dialogs/tst_dialogs.cpp index cecea1831..26a0fe034 100644 --- a/tests/auto/quick/dialogs/tst_dialogs.cpp +++ b/tests/auto/quick/dialogs/tst_dialogs.cpp @@ -145,12 +145,19 @@ void tst_Dialogs::authenticationDialogRequested_data() QTest::addColumn<QUrl>("url"); QTest::addColumn<QQuickWebEngineAuthenticationDialogRequest::AuthenticationType>("type"); QTest::addColumn<QString>("realm"); - QTest::newRow("Http Authentication Dialog") << QUrl("http://localhost:5555/OPEN_AUTH") + QTest::addColumn<QByteArray>("reply"); + QTest::newRow("Http Authentication Dialog") << QUrl("http://localhost:5555/") << QQuickWebEngineAuthenticationDialogRequest::AuthenticationTypeHTTP - << QStringLiteral("Very Restricted Area"); - QTest::newRow("Proxy Authentication Dialog") << QUrl("http://localhost.:5555/OPEN_PROXY") + << QStringLiteral("Very Restricted Area") + << QByteArrayLiteral("HTTP/1.1 401 Unauthorized\nWWW-Authenticate: " + "Basic realm=\"Very Restricted Area\"\r\n\r\n"); + QTest::newRow("Proxy Authentication Dialog")<< QUrl("http://qt.io/") << QQuickWebEngineAuthenticationDialogRequest::AuthenticationTypeProxy - << QStringLiteral("Proxy requires authentication"); + << QStringLiteral("Proxy requires authentication") + << QByteArrayLiteral("HTTP/1.1 407 Proxy Auth Required\nProxy-Authenticate: " + "Basic realm=\"Proxy requires authentication\"\r\n" + "content-length: 0\r\n\r\n"); + } void tst_Dialogs::authenticationDialogRequested() @@ -159,7 +166,9 @@ void tst_Dialogs::authenticationDialogRequested() QFETCH(QQuickWebEngineAuthenticationDialogRequest::AuthenticationType, type); QFETCH(QString, realm); + QFETCH(QByteArray, reply); Server server; + server.setReply(reply); server.run(); QTRY_VERIFY2(server.isListening(), "Could not setup authentication server"); -- GitLab