Skip to content

Commit 829702b

Browse files
authoredSep 27, 2017
Merge pull request #5253 from boundlessgeo/auth_proxy
[auth][feature][needs-docs] Proxy authentication integration with QGIS authentication system
2 parents 6ce8b4c + 385cca6 commit 829702b

14 files changed

+324
-74
lines changed
 

‎python/core/auth/qgsauthmanager.sip

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,17 @@ Get list of authentication ids from database
359359
:rtype: bool
360360
%End
361361

362+
bool updateNetworkProxy( QNetworkProxy &proxy /In,Out/, const QString &authcfg,
363+
const QString &dataprovider = QString() );
364+
%Docstring
365+
Provider call to update a QNetworkProxy with an authentication config
366+
\param proxy the QNetworkProxy
367+
\param authcfg Associated authentication config id
368+
\param dataprovider Provider key filter, offering logic branching in authentication method
369+
:return: Whether operation succeeded
370+
:rtype: bool
371+
%End
372+
362373

363374
bool storeAuthSetting( const QString &key, const QVariant &value, bool encrypt = false );
364375
%Docstring

‎python/core/auth/qgsauthmethod.sip

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class QgsAuthMethod : QObject
2828
NetworkReply,
2929
DataSourceUri,
3030
GenericDataSourceUri,
31+
NetworkProxy,
3132
All
3233
};
3334
typedef QFlags<QgsAuthMethod::Expansion> Expansions;
@@ -110,6 +111,18 @@ Increment this if method is significantly updated, allow updater code to be writ
110111
:rtype: bool
111112
%End
112113

114+
virtual bool updateNetworkProxy( QNetworkProxy &proxy, const QString &authcfg,
115+
const QString &dataprovider = QString() );
116+
%Docstring
117+
Update proxy settings with authentication components
118+
\param proxy
119+
\param authcfg Authentication configuration ID
120+
\param dataprovider Textual key for a data provider, e.g. 'proxy', that allows
121+
for custom updater code specific to the provider
122+
:return: Whether the update succeeded
123+
:rtype: bool
124+
%End
125+
113126
virtual void clearCachedConfig( const QString &authcfg ) = 0;
114127
%Docstring
115128
Clear any cached configuration. Called when the QgsAuthManager deletes an authentication configuration (authcfg).

‎src/app/qgisapp.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -630,8 +630,6 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
630630
connect( mUserProfileManager, &QgsUserProfileManager::profilesChanged, this, &QgisApp::refreshProfileMenu );
631631
endProfile();
632632

633-
namSetup();
634-
635633
// load GUI: actions, menus, toolbars
636634
profiler->beginGroup( QStringLiteral( "qgisapp" ) );
637635
profiler->beginGroup( QStringLiteral( "startup" ) );
@@ -656,6 +654,10 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
656654
}
657655
endProfile();
658656

657+
mTray = new QSystemTrayIcon();
658+
mTray->setIcon( QIcon( QgsApplication::appIconPath() ) );
659+
mTray->hide();
660+
659661
startProfile( QStringLiteral( "Initializing authentication" ) );
660662
mSplash->showMessage( tr( "Initializing authentication" ), Qt::AlignHCenter | Qt::AlignBottom );
661663
qApp->processEvents();
@@ -666,6 +668,9 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
666668
}
667669
endProfile();
668670

671+
// Setup QgsNetworkAccessManager (this needs to happen after authentication, for proxy settings)
672+
namSetup();
673+
669674
// Create the themes folder for the user
670675
startProfile( QStringLiteral( "Creating theme folder" ) );
671676
QgsApplication::createThemeFolder();
@@ -1156,11 +1161,6 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
11561161
grabGesture( Qt::TapAndHoldGesture );
11571162
}
11581163

1159-
1160-
mTray = new QSystemTrayIcon();
1161-
mTray->setIcon( QIcon( QgsApplication::appIconPath() ) );
1162-
mTray->hide();
1163-
11641164
connect( QgsApplication::taskManager(), &QgsTaskManager::statusChanged, this, &QgisApp::onTaskCompleteShowNotify );
11651165

11661166
#ifdef Q_OS_WIN

‎src/app/qgsoptions.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "qgstolerance.h"
2929
#include "qgsscaleutils.h"
3030
#include "qgsnetworkaccessmanager.h"
31+
#include "qgsauthconfigselect.h"
3132
#include "qgsproject.h"
3233
#include "qgsdualview.h"
3334
#include "qgsrasterlayer.h"
@@ -307,6 +308,16 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
307308
// WMS/WMS-C default max retry in case of tile request errors
308309
mDefaultTileMaxRetrySpinBox->setValue( mSettings->value( QStringLiteral( "/qgis/defaultTileMaxRetry" ), "3" ).toInt() );
309310

311+
// Proxy stored authentication configurations
312+
mProxyAuthConfigSelect = new QgsAuthConfigSelect( this, QStringLiteral( "proxy" ) );
313+
tabAuth->insertTab( 1, mProxyAuthConfigSelect, tr( "Configurations" ) );
314+
QString authcfg = mSettings->value( QStringLiteral( "proxy/authcfg" ) ).toString();
315+
mProxyAuthConfigSelect->setConfigId( authcfg );
316+
if ( !authcfg.isEmpty() )
317+
{
318+
tabAuth->setCurrentIndex( tabAuth->indexOf( mProxyAuthConfigSelect ) );
319+
}
320+
310321
//Web proxy settings
311322
grpProxy->setChecked( mSettings->value( QStringLiteral( "proxy/proxyEnabled" ), "0" ).toBool() );
312323
leProxyHost->setText( mSettings->value( QStringLiteral( "proxy/proxyHost" ), "" ).toString() );
@@ -1162,6 +1173,9 @@ void QgsOptions::saveOptions()
11621173
// WMS/WMS-C default max retry in case of tile request errors
11631174
mSettings->setValue( QStringLiteral( "/qgis/defaultTileMaxRetry" ), mDefaultTileMaxRetrySpinBox->value() );
11641175

1176+
// Proxy stored authentication configurations
1177+
mSettings->setValue( QStringLiteral( "proxy/authcfg" ), mProxyAuthConfigSelect->configId( ) );
1178+
11651179
//Web proxy settings
11661180
mSettings->setValue( QStringLiteral( "proxy/proxyEnabled" ), grpProxy->isChecked() );
11671181
mSettings->setValue( QStringLiteral( "proxy/proxyHost" ), leProxyHost->text() );

‎src/app/qgsoptions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
class QgsExpressionContext;
3333
class QgsOptionsPageWidget;
3434
class QgsLocatorOptionsWidget;
35+
class QgsAuthConfigSelect;
3536

3637
/**
3738
* \class QgsOptions
@@ -255,6 +256,7 @@ class APP_EXPORT QgsOptions : public QgsOptionsDialogBase, private Ui::QgsOption
255256

256257
QList< QgsOptionsPageWidget * > mAdditionalOptionWidgets;
257258
QgsLocatorOptionsWidget *mLocatorOptionsWidget = nullptr;
259+
QgsAuthConfigSelect *mProxyAuthConfigSelect = nullptr;
258260

259261
};
260262

‎src/auth/basic/qgsauthbasicmethod.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "qgsauthmanager.h"
2121
#include "qgslogger.h"
2222

23+
#include <QNetworkProxy>
24+
2325
static const QString AUTH_METHOD_KEY = QStringLiteral( "Basic" );
2426
static const QString AUTH_METHOD_DESCRIPTION = QStringLiteral( "Basic authentication" );
2527

@@ -37,7 +39,8 @@ QgsAuthBasicMethod::QgsAuthBasicMethod()
3739
<< QStringLiteral( "ows" )
3840
<< QStringLiteral( "wfs" ) // convert to lowercase
3941
<< QStringLiteral( "wcs" )
40-
<< QStringLiteral( "wms" ) );
42+
<< QStringLiteral( "wms" )
43+
<< QStringLiteral( "proxy" ) );
4144
}
4245

4346
QgsAuthBasicMethod::~QgsAuthBasicMethod()
@@ -126,6 +129,28 @@ bool QgsAuthBasicMethod::updateDataSourceUriItems( QStringList &connectionItems,
126129
return true;
127130
}
128131

132+
bool QgsAuthBasicMethod::updateNetworkProxy( QNetworkProxy &proxy, const QString &authcfg, const QString &dataprovider )
133+
{
134+
Q_UNUSED( dataprovider )
135+
136+
QgsAuthMethodConfig mconfig = getMethodConfig( authcfg );
137+
if ( !mconfig.isValid() )
138+
{
139+
QgsDebugMsg( QString( "Update proxy config FAILED for authcfg: %1: config invalid" ).arg( authcfg ) );
140+
return false;
141+
}
142+
143+
QString username = mconfig.config( QStringLiteral( "username" ) );
144+
QString password = mconfig.config( QStringLiteral( "password" ) );
145+
146+
if ( !username.isEmpty() )
147+
{
148+
proxy.setUser( username );
149+
proxy.setPassword( password );
150+
}
151+
return true;
152+
}
153+
129154
void QgsAuthBasicMethod::updateMethodConfig( QgsAuthMethodConfig &mconfig )
130155
{
131156
if ( mconfig.hasConfig( QStringLiteral( "oldconfigstyle" ) ) )

‎src/auth/basic/qgsauthbasicmethod.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ class QgsAuthBasicMethod : public QgsAuthMethod
4444
bool updateDataSourceUriItems( QStringList &connectionItems, const QString &authcfg,
4545
const QString &dataprovider = QString() ) override;
4646

47+
48+
bool updateNetworkProxy( QNetworkProxy &proxy, const QString &authcfg,
49+
const QString &dataprovider = QString() ) override;
50+
4751
void clearCachedConfig( const QString &authcfg ) override;
4852

4953
void updateMethodConfig( QgsAuthMethodConfig &mconfig ) override;

‎src/core/auth/qgsauthmanager.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,32 @@ bool QgsAuthManager::updateDataSourceUriItems( QStringList &connectionItems, con
14571457
return false;
14581458
}
14591459

1460+
bool QgsAuthManager::updateNetworkProxy( QNetworkProxy &proxy, const QString &authcfg, const QString &dataprovider )
1461+
{
1462+
if ( isDisabled() )
1463+
return false;
1464+
1465+
QgsAuthMethod *authmethod = configAuthMethod( authcfg );
1466+
if ( authmethod )
1467+
{
1468+
if ( !( authmethod->supportedExpansions() & QgsAuthMethod::NetworkProxy ) )
1469+
{
1470+
QgsDebugMsg( QStringLiteral( "Proxy updating not supported by authcfg: %1" ).arg( authcfg ) );
1471+
return true;
1472+
}
1473+
1474+
if ( !authmethod->updateNetworkProxy( proxy, authcfg, dataprovider.toLower() ) )
1475+
{
1476+
authmethod->clearCachedConfig( authcfg );
1477+
return false;
1478+
}
1479+
QgsDebugMsg( QStringLiteral( "Proxy updated successfully from authcfg: %1" ).arg( authcfg ) );
1480+
return true;
1481+
}
1482+
1483+
return false;
1484+
}
1485+
14601486
bool QgsAuthManager::storeAuthSetting( const QString &key, const QVariant &value, bool encrypt )
14611487
{
14621488
if ( key.isEmpty() )

‎src/core/auth/qgsauthmanager.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,16 @@ class CORE_EXPORT QgsAuthManager : public QObject
332332
bool updateDataSourceUriItems( QStringList &connectionItems SIP_INOUT, const QString &authcfg,
333333
const QString &dataprovider = QString() );
334334

335+
/**
336+
* Provider call to update a QNetworkProxy with an authentication config
337+
* \param proxy the QNetworkProxy
338+
* \param authcfg Associated authentication config id
339+
* \param dataprovider Provider key filter, offering logic branching in authentication method
340+
* \returns Whether operation succeeded
341+
*/
342+
bool updateNetworkProxy( QNetworkProxy &proxy SIP_INOUT, const QString &authcfg,
343+
const QString &dataprovider = QString() );
344+
335345
////////////////// Generic settings ///////////////////////
336346

337347
//! Store an authentication setting (stored as string via QVariant( value ).toString() )

‎src/core/auth/qgsauthmethod.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ class CORE_EXPORT QgsAuthMethod : public QObject
5151
NetworkReply = 0x2,
5252
DataSourceUri = 0x4,
5353
GenericDataSourceUri = 0x8,
54-
All = NetworkRequest | NetworkReply | DataSourceUri | GenericDataSourceUri
54+
NetworkProxy = 0x16,
55+
All = NetworkRequest | NetworkReply | DataSourceUri | GenericDataSourceUri | NetworkProxy
5556
};
5657
Q_DECLARE_FLAGS( Expansions, Expansion )
5758

@@ -126,6 +127,22 @@ class CORE_EXPORT QgsAuthMethod : public QObject
126127
return true; // noop
127128
}
128129

130+
/** Update proxy settings with authentication components
131+
* \param proxy
132+
* \param authcfg Authentication configuration ID
133+
* \param dataprovider Textual key for a data provider, e.g. 'proxy', that allows
134+
* for custom updater code specific to the provider
135+
* \returns Whether the update succeeded
136+
*/
137+
virtual bool updateNetworkProxy( QNetworkProxy &proxy, const QString &authcfg,
138+
const QString &dataprovider = QString() )
139+
{
140+
Q_UNUSED( proxy )
141+
Q_UNUSED( authcfg )
142+
Q_UNUSED( dataprovider )
143+
return true; // noop
144+
}
145+
129146
/** Clear any cached configuration. Called when the QgsAuthManager deletes an authentication configuration (authcfg).
130147
* \note It is highly recommended that a cache of authentication components (per requested authcfg)
131148
* be implemented, to avoid excessive queries on the auth database. Such a cache could be as

‎src/core/qgsnetworkaccessmanager.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ void QgsNetworkAccessManager::setupDefaultProxyAndCache()
321321
//read type, host, port, user, passw from settings
322322
QString proxyHost = settings.value( QStringLiteral( "proxy/proxyHost" ), "" ).toString();
323323
int proxyPort = settings.value( QStringLiteral( "proxy/proxyPort" ), "" ).toString().toInt();
324+
324325
QString proxyUser = settings.value( QStringLiteral( "proxy/proxyUser" ), "" ).toString();
325326
QString proxyPassword = settings.value( QStringLiteral( "proxy/proxyPassword" ), "" ).toString();
326327

@@ -356,7 +357,7 @@ void QgsNetworkAccessManager::setupDefaultProxyAndCache()
356357
{
357358
proxyType = QNetworkProxy::FtpCachingProxy;
358359
}
359-
QgsDebugMsg( QString( "setting proxy %1 %2:%3 %4/%5" )
360+
QgsDebugMsg( QStringLiteral( "setting proxy %1 %2:%3 %4/%5" )
360361
.arg( proxyType )
361362
.arg( proxyHost ).arg( proxyPort )
362363
.arg( proxyUser, proxyPassword )
@@ -365,6 +366,14 @@ void QgsNetworkAccessManager::setupDefaultProxyAndCache()
365366
}
366367
}
367368

369+
// Setup network proxy authentication configuration
370+
QString authcfg = settings.value( QStringLiteral( "proxy/authcfg" ), "" ).toString();
371+
if ( !authcfg.isEmpty( ) )
372+
{
373+
QgsDebugMsg( QStringLiteral( "setting proxy from stored authentication configuration %1" ).arg( authcfg ) );
374+
QgsAuthManager::instance()->updateNetworkProxy( proxy, authcfg );
375+
}
376+
368377
setFallbackProxyAndExcludes( proxy, excludes );
369378

370379
QgsNetworkDiskCache *newcache = qobject_cast<QgsNetworkDiskCache *>( cache() );

‎src/ui/qgsoptionsbase.ui

Lines changed: 76 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@
320320
<item>
321321
<widget class="QStackedWidget" name="mOptionsStackedWidget">
322322
<property name="currentIndex">
323-
<number>0</number>
323+
<number>13</number>
324324
</property>
325325
<widget class="QWidget" name="mOptionsPageGeneral">
326326
<layout class="QVBoxLayout" name="verticalLayout_3">
@@ -349,8 +349,8 @@
349349
<rect>
350350
<x>0</x>
351351
<y>0</y>
352-
<width>857</width>
353-
<height>678</height>
352+
<width>846</width>
353+
<height>672</height>
354354
</rect>
355355
</property>
356356
<layout class="QVBoxLayout" name="verticalLayout_28">
@@ -998,8 +998,8 @@
998998
<rect>
999999
<x>0</x>
10001000
<y>0</y>
1001-
<width>561</width>
1002-
<height>1079</height>
1001+
<width>537</width>
1002+
<height>1128</height>
10031003
</rect>
10041004
</property>
10051005
<layout class="QVBoxLayout" name="verticalLayout_22">
@@ -1528,8 +1528,8 @@
15281528
<rect>
15291529
<x>0</x>
15301530
<y>0</y>
1531-
<width>511</width>
1532-
<height>719</height>
1531+
<width>499</width>
1532+
<height>754</height>
15331533
</rect>
15341534
</property>
15351535
<layout class="QVBoxLayout" name="verticalLayout_27">
@@ -1896,8 +1896,8 @@
18961896
<rect>
18971897
<x>0</x>
18981898
<y>0</y>
1899-
<width>692</width>
1900-
<height>994</height>
1899+
<width>672</width>
1900+
<height>1043</height>
19011901
</rect>
19021902
</property>
19031903
<layout class="QGridLayout" name="gridLayout_22">
@@ -2647,8 +2647,8 @@
26472647
<rect>
26482648
<x>0</x>
26492649
<y>0</y>
2650-
<width>146</width>
2651-
<height>241</height>
2650+
<width>130</width>
2651+
<height>322</height>
26522652
</rect>
26532653
</property>
26542654
<layout class="QHBoxLayout" name="horizontalLayout_46">
@@ -2798,8 +2798,8 @@
27982798
<rect>
27992799
<x>0</x>
28002800
<y>0</y>
2801-
<width>514</width>
2802-
<height>334</height>
2801+
<width>500</width>
2802+
<height>340</height>
28032803
</rect>
28042804
</property>
28052805
<layout class="QVBoxLayout" name="verticalLayout_25">
@@ -3141,8 +3141,8 @@
31413141
<rect>
31423142
<x>0</x>
31433143
<y>0</y>
3144-
<width>625</width>
3145-
<height>612</height>
3144+
<width>623</width>
3145+
<height>734</height>
31463146
</rect>
31473147
</property>
31483148
<layout class="QVBoxLayout" name="verticalLayout_30">
@@ -3585,8 +3585,8 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
35853585
<rect>
35863586
<x>0</x>
35873587
<y>0</y>
3588-
<width>487</width>
3589-
<height>588</height>
3588+
<width>491</width>
3589+
<height>610</height>
35903590
</rect>
35913591
</property>
35923592
<layout class="QVBoxLayout" name="verticalLayout_39">
@@ -3854,8 +3854,8 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
38543854
<rect>
38553855
<x>0</x>
38563856
<y>0</y>
3857-
<width>556</width>
3858-
<height>740</height>
3857+
<width>548</width>
3858+
<height>785</height>
38593859
</rect>
38603860
</property>
38613861
<layout class="QVBoxLayout" name="verticalLayout_31">
@@ -4432,8 +4432,8 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
44324432
<rect>
44334433
<x>0</x>
44344434
<y>0</y>
4435-
<width>427</width>
4436-
<height>380</height>
4435+
<width>431</width>
4436+
<height>376</height>
44374437
</rect>
44384438
</property>
44394439
<layout class="QVBoxLayout" name="verticalLayout_6">
@@ -4571,8 +4571,8 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
45714571
<rect>
45724572
<x>0</x>
45734573
<y>0</y>
4574-
<width>429</width>
4575-
<height>549</height>
4574+
<width>418</width>
4575+
<height>544</height>
45764576
</rect>
45774577
</property>
45784578
<layout class="QGridLayout" name="gridLayout_15">
@@ -4784,8 +4784,8 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
47844784
<rect>
47854785
<x>0</x>
47864786
<y>0</y>
4787-
<width>282</width>
4788-
<height>234</height>
4787+
<width>268</width>
4788+
<height>232</height>
47894789
</rect>
47904790
</property>
47914791
<layout class="QVBoxLayout" name="verticalLayout_32">
@@ -4892,9 +4892,9 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
48924892
<property name="geometry">
48934893
<rect>
48944894
<x>0</x>
4895-
<y>0</y>
4896-
<width>509</width>
4897-
<height>723</height>
4895+
<y>-44</y>
4896+
<width>846</width>
4897+
<height>830</height>
48984898
</rect>
48994899
</property>
49004900
<layout class="QVBoxLayout" name="verticalLayout_33">
@@ -5125,50 +5125,19 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
51255125
<property name="rightMargin">
51265126
<number>0</number>
51275127
</property>
5128-
<item row="2" column="2">
5129-
<widget class="QLineEdit" name="leProxyUser">
5130-
<property name="toolTip">
5131-
<string>Leave this blank if no proxy username / password are required</string>
5132-
</property>
5133-
</widget>
5134-
</item>
5135-
<item row="3" column="2">
5136-
<widget class="QgsPasswordLineEdit" name="leProxyPassword">
5137-
<property name="toolTip">
5138-
<string>Leave this blank if no proxy username / password are required</string>
5139-
</property>
5140-
<property name="echoMode">
5141-
<enum>QLineEdit::Password</enum>
5142-
</property>
5143-
</widget>
5144-
</item>
5145-
<item row="2" column="1">
5146-
<widget class="QLabel" name="lblUser">
5147-
<property name="text">
5148-
<string>User</string>
5149-
</property>
5150-
</widget>
5151-
</item>
5152-
<item row="3" column="1">
5153-
<widget class="QLabel" name="lblPassword">
5154-
<property name="text">
5155-
<string>Password</string>
5156-
</property>
5157-
</widget>
5158-
</item>
51595128
<item row="0" column="2">
51605129
<widget class="QLineEdit" name="leProxyHost"/>
51615130
</item>
5131+
<item row="1" column="2">
5132+
<widget class="QLineEdit" name="leProxyPort"/>
5133+
</item>
51625134
<item row="1" column="1">
51635135
<widget class="QLabel" name="lblProxyPort">
51645136
<property name="text">
51655137
<string>Port</string>
51665138
</property>
51675139
</widget>
51685140
</item>
5169-
<item row="1" column="2">
5170-
<widget class="QLineEdit" name="leProxyPort"/>
5171-
</item>
51725141
<item row="0" column="1">
51735142
<widget class="QLabel" name="lblProxyHost">
51745143
<property name="text">
@@ -5192,6 +5161,51 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
51925161
</property>
51935162
</spacer>
51945163
</item>
5164+
<item row="4" column="1" colspan="2">
5165+
<widget class="QTabWidget" name="tabAuth">
5166+
<property name="currentIndex">
5167+
<number>0</number>
5168+
</property>
5169+
<widget class="QWidget" name="authLegacy">
5170+
<attribute name="title">
5171+
<string>Authentication</string>
5172+
</attribute>
5173+
<layout class="QGridLayout" name="gridLayout_25">
5174+
<item row="0" column="0">
5175+
<widget class="QLabel" name="lblUser">
5176+
<property name="text">
5177+
<string>User name</string>
5178+
</property>
5179+
</widget>
5180+
</item>
5181+
<item row="2" column="0">
5182+
<widget class="QLabel" name="lblPassword">
5183+
<property name="text">
5184+
<string>Password</string>
5185+
</property>
5186+
</widget>
5187+
</item>
5188+
<item row="0" column="1">
5189+
<widget class="QLineEdit" name="leProxyUser">
5190+
<property name="toolTip">
5191+
<string>Leave this blank if no proxy username / password are required</string>
5192+
</property>
5193+
</widget>
5194+
</item>
5195+
<item row="2" column="1">
5196+
<widget class="QgsPasswordLineEdit" name="leProxyPassword">
5197+
<property name="toolTip">
5198+
<string>Leave this blank if no proxy username / password are required</string>
5199+
</property>
5200+
<property name="echoMode">
5201+
<enum>QLineEdit::Password</enum>
5202+
</property>
5203+
</widget>
5204+
</item>
5205+
</layout>
5206+
</widget>
5207+
</widget>
5208+
</item>
51955209
</layout>
51965210
</widget>
51975211
</item>
@@ -5709,8 +5723,6 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
57095723
<tabstop>mProxyTypeComboBox</tabstop>
57105724
<tabstop>leProxyHost</tabstop>
57115725
<tabstop>leProxyPort</tabstop>
5712-
<tabstop>leProxyUser</tabstop>
5713-
<tabstop>leProxyPassword</tabstop>
57145726
<tabstop>mAddUrlPushButton</tabstop>
57155727
<tabstop>mRemoveUrlPushButton</tabstop>
57165728
<tabstop>mExcludeUrlListWidget</tabstop>

‎tests/src/python/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ ADD_PYTHON_TEST(PyQgsFileDownloader test_qgsfiledownloader.py)
181181
ADD_PYTHON_TEST(PyQgsSettings test_qgssettings.py)
182182
ADD_PYTHON_TEST(PyQgsZipUtils test_qgsziputils.py)
183183
ADD_PYTHON_TEST(PyQgsSourceSelectProvider test_qgssourceselectprovider.py)
184+
ADD_PYTHON_TEST(PyQgsAuthManagerProxy test_authmanager_proxy.py)
184185

185186
IF (NOT WIN32)
186187
ADD_PYTHON_TEST(PyQgsLogger test_qgslogger.py)
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Tests for auth manager Basic configuration update proxy
4+
5+
From build dir, run from test directory:
6+
LC_ALL=en_US.UTF-8 ctest -R PyQgsAuthManagerProxy -V
7+
8+
.. note:: This program is free software; you can redistribute it and/or modify
9+
it under the terms of the GNU General Public License as published by
10+
the Free Software Foundation; either version 2 of the License, or
11+
(at your option) any later version.
12+
"""
13+
import os
14+
import re
15+
import string
16+
import sys
17+
from functools import partial
18+
from shutil import rmtree
19+
import tempfile
20+
import random
21+
22+
from qgis.core import QgsAuthManager, QgsAuthMethodConfig, QgsNetworkAccessManager, QgsSettings
23+
from qgis.testing import start_app, unittest
24+
25+
from utilities import unitTestDataPath, waitServer
26+
27+
__author__ = 'Alessandro Pasotti'
28+
__date__ = '27/09/2017'
29+
__copyright__ = 'Copyright 2017, The QGIS Project'
30+
# This will get replaced with a git SHA1 when you do a git archive
31+
__revision__ = '$Format:%H$'
32+
33+
34+
QGIS_AUTH_DB_DIR_PATH = tempfile.mkdtemp()
35+
36+
os.environ['QGIS_AUTH_DB_DIR_PATH'] = QGIS_AUTH_DB_DIR_PATH
37+
38+
qgis_app = start_app()
39+
40+
41+
class TestAuthManager(unittest.TestCase):
42+
43+
@classmethod
44+
def setUpClass(cls):
45+
"""Run before all tests:
46+
Creates an auth configuration"""
47+
cls.testdata_path = unitTestDataPath('qgis_server') + '/'
48+
# Enable auth
49+
# os.environ['QGIS_AUTH_PASSWORD_FILE'] = QGIS_AUTH_PASSWORD_FILE
50+
authm = QgsAuthManager.instance()
51+
assert (authm.setMasterPassword('masterpassword', True))
52+
cls.auth_config = QgsAuthMethodConfig('Basic')
53+
cls.auth_config.setName('test_auth_config')
54+
cls.username = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6))
55+
cls.password = cls.username[::-1] # reversed
56+
cls.auth_config.setConfig('username', cls.username)
57+
cls.auth_config.setConfig('password', cls.password)
58+
assert (authm.storeAuthenticationConfig(cls.auth_config)[0])
59+
60+
@classmethod
61+
def tearDownClass(cls):
62+
"""Run after all tests"""
63+
rmtree(QGIS_AUTH_DB_DIR_PATH)
64+
65+
def setUp(self):
66+
"""Run before each test."""
67+
pass
68+
69+
def tearDown(self):
70+
"""Run after each test."""
71+
pass
72+
73+
def testProxyIsUpdated(self):
74+
"""
75+
Test that proxy is updated
76+
"""
77+
authm = QgsAuthManager.instance()
78+
nam = QgsNetworkAccessManager.instance()
79+
proxy = nam.proxy()
80+
self.assertEqual(proxy.password(), '')
81+
self.assertEqual(proxy.user(), '')
82+
self.assertTrue(authm.updateNetworkProxy(proxy, self.auth_config.id()))
83+
self.assertEqual(proxy.user(), self.username)
84+
self.assertEqual(proxy.password(), self.password)
85+
86+
def testProxyIsUpdatedByUserSettings(self):
87+
"""
88+
Test that proxy is updated
89+
"""
90+
nam = QgsNetworkAccessManager.instance()
91+
nam.setupDefaultProxyAndCache()
92+
proxy = nam.proxy()
93+
self.assertEqual(proxy.password(), '')
94+
self.assertEqual(proxy.user(), '')
95+
settings = QgsSettings()
96+
settings.setValue("proxy/authcfg", self.auth_config.id())
97+
settings.setValue("proxy/proxyEnabled", True)
98+
del(settings)
99+
nam.setupDefaultProxyAndCache()
100+
proxy = nam.fallbackProxy()
101+
self.assertEqual(proxy.password(), self.password)
102+
self.assertEqual(proxy.user(), self.username)
103+
104+
105+
if __name__ == '__main__':
106+
unittest.main()

0 commit comments

Comments
 (0)
Please sign in to comment.