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>
This commit is contained in:
parent
fe6dc9dc85
commit
5a701f5a7e
@ -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)
|
||||
|
@ -115,6 +115,8 @@ public:
|
||||
|
||||
void parseHttpResponse(const QList<QPair<QByteArray, QByteArray> >&, bool isProxy, const QString &host);
|
||||
void updateCredentials();
|
||||
|
||||
static bool isMethodSupported(QByteArrayView method);
|
||||
};
|
||||
|
||||
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user