summaryrefslogtreecommitdiffstats
path: root/tests/unit
diff options
context:
space:
mode:
authorZhongyue Luo <zhongyue.nah@intel.com>2013-07-31 16:46:00 +0800
committerZhongyue Luo <zhongyue.nah@intel.com>2013-08-02 21:26:50 +0900
commit3f2f70e0785e11434f6f863ce8eacc1b0ef1782d (patch)
tree70644962c44af86aab244e5660efa52780583dba /tests/unit
parent466f1391545d4a01b31b12c5dac1c0d84b0ad2d6 (diff)
downloadoslo-3f2f70e0785e11434f6f863ce8eacc1b0ef1782d.tar.gz
oslo-3f2f70e0785e11434f6f863ce8eacc1b0ef1782d.tar.xz
oslo-3f2f70e0785e11434f6f863ce8eacc1b0ef1782d.zip
Helper function to sanitize db url credentials
The database url is sanitized in logfiles because of security issues. However the connected url itself is useful information to devs and admins. This patch provides a helper function to sanitize only the credentials in a database url. All projects must process the CONF.database.connection value using "sanitize_db_url" when updating the db package Fixes bug #1076833 Change-Id: Id6cf7b120ef6c3fcda7f33fd26676b62a4475bb2
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/db/sqlalchemy/test_utils.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/unit/db/sqlalchemy/test_utils.py b/tests/unit/db/sqlalchemy/test_utils.py
index 78e99da..5f46f3f 100644
--- a/tests/unit/db/sqlalchemy/test_utils.py
+++ b/tests/unit/db/sqlalchemy/test_utils.py
@@ -33,6 +33,20 @@ from tests.unit.db.sqlalchemy import test_migrations
from tests import utils as testutils
+class TestSanitizeDbUrl(testutils.BaseTestCase):
+
+ def test_url_with_cred(self):
+ db_url = 'myproto://johndoe:secret@localhost/myschema'
+ expected = 'myproto://****:****@localhost/myschema'
+ actual = utils.sanitize_db_url(db_url)
+ self.assertEqual(expected, actual)
+
+ def test_url_with_no_cred(self):
+ db_url = 'sqlite:///mysqlitefile'
+ actual = utils.sanitize_db_url(db_url)
+ self.assertEqual(db_url, actual)
+
+
class CustomType(UserDefinedType):
"""Dummy column type for testing unsupported types."""
def get_col_spec(self):