mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-15 00:02:52 -04:00
Add signal for logging after network authentication details have been added
This commit is contained in:
parent
8ee2e793f8
commit
cc6d88e265
@ -284,6 +284,26 @@ from any thread.
|
|||||||
This signal is for debugging and logging purposes only, and cannot be used to respond to the
|
This signal is for debugging and logging purposes only, and cannot be used to respond to the
|
||||||
requests. See QgsNetworkAuthenticationHandler for details on how to handle authentication requests.
|
requests. See QgsNetworkAuthenticationHandler for details on how to handle authentication requests.
|
||||||
|
|
||||||
|
.. seealso:: :py:func:`requestAuthDetailsAdded`
|
||||||
|
|
||||||
|
.. versionadded:: 3.6
|
||||||
|
%End
|
||||||
|
|
||||||
|
void requestAuthDetailsAdded( int requestId, const QString &realm, const QString &user, const QString &password );
|
||||||
|
%Docstring
|
||||||
|
Emitted when network authentication details have been added to a request.
|
||||||
|
|
||||||
|
The ``requestId`` argument reflects the unique ID identifying the original request which the authentication relates to.
|
||||||
|
|
||||||
|
This signal is always sent from the main thread QgsNetworkAccessManager instance, so it is necessary
|
||||||
|
only to connect to the main thread's signal in order to receive notifications about authentication requests
|
||||||
|
from any thread.
|
||||||
|
|
||||||
|
This signal is for debugging and logging purposes only, and should not be used to respond to the
|
||||||
|
requests. See QgsNetworkAuthenticationHandler for details on how to handle authentication requests.
|
||||||
|
|
||||||
|
.. seealso:: :py:func:`requestRequiresAuth`
|
||||||
|
|
||||||
.. versionadded:: 3.6
|
.. versionadded:: 3.6
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
@ -428,6 +428,9 @@ void QgsNetworkAccessManager::onAuthRequired( QNetworkReply *reply, QAuthenticat
|
|||||||
void QgsNetworkAccessManager::handleAuthRequest( QNetworkReply *reply, QAuthenticator *auth )
|
void QgsNetworkAccessManager::handleAuthRequest( QNetworkReply *reply, QAuthenticator *auth )
|
||||||
{
|
{
|
||||||
mAuthHandler->handleAuthRequest( reply, auth );
|
mAuthHandler->handleAuthRequest( reply, auth );
|
||||||
|
|
||||||
|
emit requestAuthDetailsAdded( getRequestId( reply ), auth->realm(), auth->user(), auth->password() );
|
||||||
|
|
||||||
afterAuthRequestHandled( reply );
|
afterAuthRequestHandled( reply );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,10 +426,28 @@ class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager
|
|||||||
* This signal is for debugging and logging purposes only, and cannot be used to respond to the
|
* This signal is for debugging and logging purposes only, and cannot be used to respond to the
|
||||||
* requests. See QgsNetworkAuthenticationHandler for details on how to handle authentication requests.
|
* requests. See QgsNetworkAuthenticationHandler for details on how to handle authentication requests.
|
||||||
*
|
*
|
||||||
|
* \see requestAuthDetailsAdded()
|
||||||
* \since QGIS 3.6
|
* \since QGIS 3.6
|
||||||
*/
|
*/
|
||||||
void requestRequiresAuth( int requestId, const QString &realm );
|
void requestRequiresAuth( int requestId, const QString &realm );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted when network authentication details have been added to a request.
|
||||||
|
*
|
||||||
|
* The \a requestId argument reflects the unique ID identifying the original request which the authentication relates to.
|
||||||
|
*
|
||||||
|
* This signal is always sent from the main thread QgsNetworkAccessManager instance, so it is necessary
|
||||||
|
* only to connect to the main thread's signal in order to receive notifications about authentication requests
|
||||||
|
* from any thread.
|
||||||
|
*
|
||||||
|
* This signal is for debugging and logging purposes only, and should not be used to respond to the
|
||||||
|
* requests. See QgsNetworkAuthenticationHandler for details on how to handle authentication requests.
|
||||||
|
*
|
||||||
|
* \see requestRequiresAuth()
|
||||||
|
* \since QGIS 3.6
|
||||||
|
*/
|
||||||
|
void requestAuthDetailsAdded( int requestId, const QString &realm, const QString &user, const QString &password );
|
||||||
|
|
||||||
#ifndef QT_NO_SSL
|
#ifndef QT_NO_SSL
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -520,6 +520,9 @@ void TestQgsNetworkAccessManager::testAuthRequestHandler()
|
|||||||
bool loaded = false;
|
bool loaded = false;
|
||||||
bool gotRequestAboutToBeCreatedSignal = false;
|
bool gotRequestAboutToBeCreatedSignal = false;
|
||||||
bool gotAuthRequest = false;
|
bool gotAuthRequest = false;
|
||||||
|
bool gotAuthDetailsAdded = false;
|
||||||
|
QString expectedUser;
|
||||||
|
QString expectedPassword;
|
||||||
int requestId = -1;
|
int requestId = -1;
|
||||||
QUrl u = QUrl( QStringLiteral( "http://httpbin.org/basic-auth/me/secret" ) );
|
QUrl u = QUrl( QStringLiteral( "http://httpbin.org/basic-auth/me/secret" ) );
|
||||||
QNetworkReply::NetworkError expectedError = QNetworkReply::NoError;
|
QNetworkReply::NetworkError expectedError = QNetworkReply::NoError;
|
||||||
@ -546,10 +549,19 @@ void TestQgsNetworkAccessManager::testAuthRequestHandler()
|
|||||||
gotAuthRequest = true;
|
gotAuthRequest = true;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
connect( QgsNetworkAccessManager::instance(), &QgsNetworkAccessManager::requestAuthDetailsAdded, &context, [&]( int authRequestId, const QString & realm, const QString & user, const QString & password )
|
||||||
|
{
|
||||||
|
QCOMPARE( authRequestId, requestId );
|
||||||
|
QCOMPARE( realm, QStringLiteral( "Fake Realm" ) );
|
||||||
|
QCOMPARE( user, expectedUser );
|
||||||
|
QCOMPARE( password, expectedPassword );
|
||||||
|
gotAuthDetailsAdded = true;
|
||||||
|
} );
|
||||||
|
|
||||||
expectedError = QNetworkReply::AuthenticationRequiredError;
|
expectedError = QNetworkReply::AuthenticationRequiredError;
|
||||||
QgsNetworkAccessManager::instance()->get( QNetworkRequest( u ) );
|
QgsNetworkAccessManager::instance()->get( QNetworkRequest( u ) );
|
||||||
|
|
||||||
while ( !loaded || !gotAuthRequest || !gotRequestAboutToBeCreatedSignal )
|
while ( !loaded || !gotAuthRequest || !gotRequestAboutToBeCreatedSignal || !gotAuthDetailsAdded )
|
||||||
{
|
{
|
||||||
qApp->processEvents();
|
qApp->processEvents();
|
||||||
}
|
}
|
||||||
@ -560,13 +572,13 @@ void TestQgsNetworkAccessManager::testAuthRequestHandler()
|
|||||||
loaded = false;
|
loaded = false;
|
||||||
gotAuthRequest = false;
|
gotAuthRequest = false;
|
||||||
gotRequestAboutToBeCreatedSignal = false;
|
gotRequestAboutToBeCreatedSignal = false;
|
||||||
|
gotAuthDetailsAdded = false;
|
||||||
|
|
||||||
BackgroundRequest *thread = new BackgroundRequest( QNetworkRequest( u ) );
|
BackgroundRequest *thread = new BackgroundRequest( QNetworkRequest( u ) );
|
||||||
|
|
||||||
thread->start();
|
thread->start();
|
||||||
|
|
||||||
while ( !loaded || !gotAuthRequest || !gotRequestAboutToBeCreatedSignal )
|
while ( !loaded || !gotAuthRequest || !gotRequestAboutToBeCreatedSignal || !gotAuthDetailsAdded )
|
||||||
{
|
{
|
||||||
qApp->processEvents();
|
qApp->processEvents();
|
||||||
}
|
}
|
||||||
@ -580,10 +592,13 @@ void TestQgsNetworkAccessManager::testAuthRequestHandler()
|
|||||||
loaded = false;
|
loaded = false;
|
||||||
gotAuthRequest = false;
|
gotAuthRequest = false;
|
||||||
gotRequestAboutToBeCreatedSignal = false;
|
gotRequestAboutToBeCreatedSignal = false;
|
||||||
|
gotAuthDetailsAdded = false;
|
||||||
expectedError = QNetworkReply::NoError;
|
expectedError = QNetworkReply::NoError;
|
||||||
|
expectedUser = QStringLiteral( "me" );
|
||||||
|
expectedPassword = QStringLiteral( "secret" );
|
||||||
QgsNetworkAccessManager::instance()->get( QNetworkRequest( u ) );
|
QgsNetworkAccessManager::instance()->get( QNetworkRequest( u ) );
|
||||||
|
|
||||||
while ( !loaded || !gotAuthRequest || !gotRequestAboutToBeCreatedSignal )
|
while ( !loaded || !gotAuthRequest || !gotRequestAboutToBeCreatedSignal || !gotAuthDetailsAdded )
|
||||||
{
|
{
|
||||||
qApp->processEvents();
|
qApp->processEvents();
|
||||||
}
|
}
|
||||||
@ -594,11 +609,14 @@ void TestQgsNetworkAccessManager::testAuthRequestHandler()
|
|||||||
loaded = false;
|
loaded = false;
|
||||||
gotAuthRequest = false;
|
gotAuthRequest = false;
|
||||||
gotRequestAboutToBeCreatedSignal = false;
|
gotRequestAboutToBeCreatedSignal = false;
|
||||||
|
gotAuthDetailsAdded = false;
|
||||||
expectedError = QNetworkReply::NoError;
|
expectedError = QNetworkReply::NoError;
|
||||||
|
expectedUser = QStringLiteral( "me2" );
|
||||||
|
expectedPassword = QStringLiteral( "secret2" );
|
||||||
|
|
||||||
thread = new BackgroundRequest( QNetworkRequest( u ) );
|
thread = new BackgroundRequest( QNetworkRequest( u ) );
|
||||||
thread->start();
|
thread->start();
|
||||||
while ( !loaded || !gotAuthRequest || !gotRequestAboutToBeCreatedSignal )
|
while ( !loaded || !gotAuthRequest || !gotRequestAboutToBeCreatedSignal || !gotAuthDetailsAdded )
|
||||||
{
|
{
|
||||||
qApp->processEvents();
|
qApp->processEvents();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user