Skip to content
Permalink
Browse files

Fix unreported sslmode storage from connections API

Related to #37479
  • Loading branch information
elpaso committed Jul 1, 2020
1 parent fb9df9f commit a621d55e406fbdc37bdb16ef9e66b2bca0b2f14e
@@ -38,7 +38,7 @@ class CORE_EXPORT QgsDataSourceUri
public:

/**
* Available SSQL connection modes.
* Available SSL connection modes.
*/
enum SslMode
{
@@ -540,7 +540,7 @@ void QgsPostgresProviderConnection::store( const QString &name ) const
settings.setValue( "username", dsUri.username() );
settings.setValue( "password", dsUri.password() );
settings.setValue( "authcfg", dsUri.authConfigId() );
settings.setValue( "sslmode", dsUri.sslMode() );
settings.setEnumValue( "sslmode", dsUri.sslMode() );

// From configuration
static const QStringList configurationParameters
@@ -24,6 +24,7 @@
QgsCoordinateReferenceSystem,
QgsRasterLayer,
QgsDataSourceUri,
QgsSettings,
)
from qgis.testing import unittest
from osgeo import gdal
@@ -69,6 +70,16 @@ def test_postgis_connections_from_uri(self):
rl = QgsRasterLayer(conn.tableUri('qgis_test', 'Raster1'), 'r1', 'postgresraster')
self.assertTrue(rl.isValid())

def test_sslmode_store(self):
"""Test that sslmode is stored as a string in the settings"""
md = QgsProviderRegistry.instance().providerMetadata('postgres')
conn = md.createConnection('database=\'mydb\' username=\'myuser\' password=\'mypasswd\' sslmode=verify-ca', {})
conn.store('my_sslmode_test')
settings = QgsSettings()
settings.beginGroup('/PostgreSQL/connections/my_sslmode_test')
self.assertEqual(settings.value("sslmode"), 'SslVerifyCa')
self.assertEqual(settings.enumValue("sslmode", QgsDataSourceUri.SslPrefer), QgsDataSourceUri.SslVerifyCa)

def test_postgis_geometry_filter(self):
"""Make sure the postgres provider only returns one matching geometry record and no polygons etc."""
vl = QgsVectorLayer(self.postgres_conn + ' srid=4326 type=POINT table="qgis_test"."geometries_table" (geom) sql=', 'test', 'postgres')

0 comments on commit a621d55

Please sign in to comment.
You can’t perform that action at this time.