Skip to content

Commit

Permalink
Fix unreported sslmode storage from connections API
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored and nyalldawson committed Jul 7, 2020
1 parent df111bf commit 0f82482
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core/qgsdatasourceuri.h
Expand Up @@ -38,7 +38,7 @@ class CORE_EXPORT QgsDataSourceUri
public:

/**
* Available SSQL connection modes.
* Available SSL connection modes.
*/
enum SslMode
{
Expand Down
2 changes: 1 addition & 1 deletion src/providers/postgres/qgspostgresproviderconnection.cpp
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions tests/src/python/test_qgsproviderconnection_postgres.py
Expand Up @@ -24,6 +24,7 @@
QgsCoordinateReferenceSystem,
QgsRasterLayer,
QgsDataSourceUri,
QgsSettings,
)
from qgis.testing import unittest
from osgeo import gdal
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 0f82482

Please sign in to comment.