From ab05de48df8764479df5a17ddbe9ad65c29417b0 Mon Sep 17 00:00:00 2001 From: Jiri Drbalek Date: Thu, 3 May 2018 10:21:10 +0200 Subject: [PATCH] postgis: Exclude password from ConnectionCreator::id() - Password is not necessary for connection identification - When password is not required by the database, user can accidentally use multiple different passwords without noticing. This leads to allocating more connection pools and increase of connection consumption. --- plugins/input/postgis/connection_manager.hpp | 2 +- test/unit/datasource/postgis.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/plugins/input/postgis/connection_manager.hpp b/plugins/input/postgis/connection_manager.hpp index 942a1abf2..0096f794b 100644 --- a/plugins/input/postgis/connection_manager.hpp +++ b/plugins/input/postgis/connection_manager.hpp @@ -67,7 +67,7 @@ public: inline std::string id() const { - return connection_string(); + return connection_string_safe(); } inline std::string connection_string() const diff --git a/test/unit/datasource/postgis.cpp b/test/unit/datasource/postgis.cpp index 5d43bbacc..f5a5add36 100644 --- a/test/unit/datasource/postgis.cpp +++ b/test/unit/datasource/postgis.cpp @@ -28,6 +28,7 @@ #include #include #include +#include "../../../plugins/input/postgis/connection_manager.hpp" /* Compile and run just this test: @@ -406,3 +407,20 @@ TEST_CASE("postgis") { } } + + +TEST_CASE("ConnectionCreator") { + +SECTION("ConnectionCreator::id() should not expose password") +{ + ConnectionCreator creator(boost::optional("host"), + boost::optional("12345"), + boost::optional("dbname"), + boost::optional("user"), + boost::optional("pass"), + boost::optional("111")); + + CHECK(creator.id() == "host=host port=12345 dbname=dbname user=user connect_timeout=111"); +} + +}