summaryrefslogtreecommitdiffstats
path: root/tests/auto/network/kernel/qauthenticator/tst_qauthenticator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/network/kernel/qauthenticator/tst_qauthenticator.cpp')
-rw-r--r--tests/auto/network/kernel/qauthenticator/tst_qauthenticator.cpp79
1 files changed, 43 insertions, 36 deletions
diff --git a/tests/auto/network/kernel/qauthenticator/tst_qauthenticator.cpp b/tests/auto/network/kernel/qauthenticator/tst_qauthenticator.cpp
index 529386f50f..1cd1b6a63b 100644
--- a/tests/auto/network/kernel/qauthenticator/tst_qauthenticator.cpp
+++ b/tests/auto/network/kernel/qauthenticator/tst_qauthenticator.cpp
@@ -1,36 +1,12 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the FOO 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$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtCore/QString>
#include <QTest>
#include <QtCore/QCoreApplication>
#include <QtNetwork/QAuthenticator>
+#include <QtNetwork/QHttpHeaders>
#include <private/qauthenticator_p.h>
@@ -48,6 +24,8 @@ private Q_SLOTS:
void ntlmAuth_data();
void ntlmAuth();
+ void sha256AndMd5Digest();
+
void equalityOperators();
void isMethodSupported();
@@ -83,8 +61,8 @@ void tst_QAuthenticator::basicAuth()
QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(auth);
QCOMPARE(priv->phase, QAuthenticatorPrivate::Start);
- QList<QPair<QByteArray, QByteArray> > headers;
- headers << qMakePair(QByteArray("WWW-Authenticate"), "Basic " + data.toUtf8());
+ QHttpHeaders headers;
+ headers.append(QByteArray("WWW-Authenticate"), "Basic " + data.toUtf8());
priv->parseHttpResponse(headers, /*isProxy = */ false, {});
QCOMPARE(auth.realm(), realm);
@@ -95,7 +73,7 @@ void tst_QAuthenticator::basicAuth()
QCOMPARE(priv->phase, QAuthenticatorPrivate::Start);
- QCOMPARE(priv->calculateResponse("GET", "/", "").constData(), QByteArray("Basic " + expectedReply).constData());
+ QCOMPARE(priv->calculateResponse("GET", "/", u"").constData(), QByteArray("Basic " + expectedReply).constData());
}
void tst_QAuthenticator::ntlmAuth_data()
@@ -126,29 +104,58 @@ void tst_QAuthenticator::ntlmAuth()
QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(auth);
QCOMPARE(priv->phase, QAuthenticatorPrivate::Start);
- QList<QPair<QByteArray, QByteArray> > headers;
+ QHttpHeaders headers;
// NTLM phase 1: negotiate
// This phase of NTLM contains no information, other than what we're willing to negotiate
// Current implementation uses flags:
// NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_REQUEST_TARGET
- headers << qMakePair(QByteArrayLiteral("WWW-Authenticate"), QByteArrayLiteral("NTLM"));
+ headers.append(QByteArrayLiteral("WWW-Authenticate"), QByteArrayLiteral("NTLM"));
priv->parseHttpResponse(headers, /*isProxy = */ false, {});
if (sso)
- QVERIFY(priv->calculateResponse("GET", "/", "").startsWith("NTLM "));
+ QVERIFY(priv->calculateResponse("GET", "/", u"").startsWith("NTLM "));
else
- QCOMPARE(priv->calculateResponse("GET", "/", "").constData(), "NTLM TlRMTVNTUAABAAAABYIIAAAAAAAAAAAAAAAAAAAAAAA=");
+ QCOMPARE(priv->calculateResponse("GET", "/", u"").constData(), "NTLM TlRMTVNTUAABAAAABYIIAAAAAAAAAAAAAAAAAAAAAAA=");
// NTLM phase 2: challenge
headers.clear();
- headers << qMakePair(QByteArray("WWW-Authenticate"), "NTLM " + data.toUtf8());
+ headers.append(QByteArray("WWW-Authenticate"), "NTLM " + data.toUtf8());
priv->parseHttpResponse(headers, /*isProxy = */ false, {});
QEXPECT_FAIL("with-realm", "NTLM authentication code doesn't extract the realm", Continue);
QEXPECT_FAIL("with-realm-sso", "NTLM authentication code doesn't extract the realm", Continue);
QCOMPARE(auth.realm(), realm);
- QVERIFY(priv->calculateResponse("GET", "/", "").startsWith("NTLM "));
+ QVERIFY(priv->calculateResponse("GET", "/", u"").startsWith("NTLM "));
+}
+
+// We don't (currently) support SHA256. So, when presented with the option of MD5 or SHA256,
+// we should always pick MD5.
+void tst_QAuthenticator::sha256AndMd5Digest()
+{
+ QByteArray md5 = "Digest realm=\"\", nonce=\"\", algorithm=MD5, qop=\"auth\"";
+ QByteArray sha256 = "Digest realm=\"\", nonce=\"\", algorithm=SHA-256, qop=\"auth\"";
+
+ QAuthenticator auth;
+ auth.setUser("unimportant");
+ auth.setPassword("unimportant");
+
+ QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(auth);
+ QVERIFY(priv->isMethodSupported("digest")); // sanity check
+
+ QCOMPARE(priv->phase, QAuthenticatorPrivate::Start);
+ QHttpHeaders headers;
+ // Put sha256 first, so that its parsed first...
+ headers.append("WWW-Authenticate", sha256);
+ headers.append("WWW-Authenticate", md5);
+ priv->parseHttpResponse(headers, false, QString());
+
+ QByteArray response = priv->calculateResponse("GET", "/index", {});
+ QCOMPARE(priv->phase, QAuthenticatorPrivate::Done);
+
+ QVERIFY(!response.isEmpty());
+ QVERIFY(!response.contains("algorithm=SHA-256"));
+ QVERIFY(response.contains("algorithm=MD5"));
}
void tst_QAuthenticator::equalityOperators()