summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2021-04-29 13:02:52 +0200
committerMårten Nordheim <marten.nordheim@qt.io>2021-05-20 20:31:05 +0200
commit5a701f5a7ea435096836afe01905bf8c13c465e3 (patch)
treebdac080fd27db6e7cf8fbbb591e4b22ddc68b8fe
parentfe6dc9dc8549cd9de7a0ddb04d921fd3263b51df (diff)
Add function to QAuthenticatorPrivate to check method support
To see if a certain method is supported. To be used in an upcoming patch. Change-Id: I1a5c2f655585331820701bb54f6991b4aba38273 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
-rw-r--r--src/network/kernel/qauthenticator.cpp20
-rw-r--r--src/network/kernel/qauthenticator_p.h2
-rw-r--r--tests/auto/network/kernel/qauthenticator/tst_qauthenticator.cpp18
3 files changed, 40 insertions, 0 deletions
diff --git a/src/network/kernel/qauthenticator.cpp b/src/network/kernel/qauthenticator.cpp
index 4daf11cb3e..f79a7196bf 100644
--- a/src/network/kernel/qauthenticator.cpp
+++ b/src/network/kernel/qauthenticator.cpp
@@ -423,6 +423,26 @@ void QAuthenticatorPrivate::updateCredentials()
}
}
+bool QAuthenticatorPrivate::isMethodSupported(QByteArrayView method)
+{
+ Q_ASSERT(!method.startsWith(' ')); // This should be trimmed during parsing
+ auto separator = method.indexOf(' ');
+ if (separator != -1)
+ method = method.first(separator);
+ const auto isSupported = [method](QByteArrayView reference) {
+ return method.compare(reference, Qt::CaseInsensitive) == 0;
+ };
+ static const char methods[][10] = {
+ "basic",
+ "ntlm",
+ "digest",
+#if QT_CONFIG(sspi) || QT_CONFIG(gssapi)
+ "negotiate",
+#endif
+ };
+ return std::any_of(methods, methods + std::size(methods), isSupported);
+}
+
void QAuthenticatorPrivate::parseHttpResponse(const QList<QPair<QByteArray, QByteArray> > &values, bool isProxy, const QString &host)
{
#if !QT_CONFIG(gssapi)
diff --git a/src/network/kernel/qauthenticator_p.h b/src/network/kernel/qauthenticator_p.h
index 1813634ee0..9ef6330ceb 100644
--- a/src/network/kernel/qauthenticator_p.h
+++ b/src/network/kernel/qauthenticator_p.h
@@ -115,6 +115,8 @@ public:
void parseHttpResponse(const QList<QPair<QByteArray, QByteArray> >&, bool isProxy, const QString &host);
void updateCredentials();
+
+ static bool isMethodSupported(QByteArrayView method);
};
diff --git a/tests/auto/network/kernel/qauthenticator/tst_qauthenticator.cpp b/tests/auto/network/kernel/qauthenticator/tst_qauthenticator.cpp
index df5543a28e..529386f50f 100644
--- a/tests/auto/network/kernel/qauthenticator/tst_qauthenticator.cpp
+++ b/tests/auto/network/kernel/qauthenticator/tst_qauthenticator.cpp
@@ -49,6 +49,8 @@ private Q_SLOTS:
void ntlmAuth();
void equalityOperators();
+
+ void isMethodSupported();
};
tst_QAuthenticator::tst_QAuthenticator()
@@ -163,6 +165,22 @@ void tst_QAuthenticator::equalityOperators()
QVERIFY(s2 != s1);
}
+void tst_QAuthenticator::isMethodSupported()
+{
+ QVERIFY(QAuthenticatorPrivate::isMethodSupported("basic"));
+ QVERIFY(QAuthenticatorPrivate::isMethodSupported("Basic realm=\"Shadow\""));
+ QVERIFY(QAuthenticatorPrivate::isMethodSupported("DIgesT"));
+ QVERIFY(QAuthenticatorPrivate::isMethodSupported("NTLM"));
+ QVERIFY(QAuthenticatorPrivate::isMethodSupported("ntlm"));
+#if QT_CONFIG(sspi) || QT_CONFIG(gssapi)
+ QVERIFY(QAuthenticatorPrivate::isMethodSupported("negotiate"));
+#else
+ QVERIFY(!QAuthenticatorPrivate::isMethodSupported("negotiate"));
+#endif
+
+ QVERIFY(!QAuthenticatorPrivate::isMethodSupported("Bearer"));
+}
+
QTEST_MAIN(tst_QAuthenticator);
#include "tst_qauthenticator.moc"