summaryrefslogtreecommitdiffstats
path: root/tests/test_main.py
diff options
context:
space:
mode:
authorStuart Quin <stuart.quin@gmail.com>2015-10-18 21:55:56 +0100
committerStuart Quin <stuart.quin@gmail.com>2015-10-18 21:56:52 +0100
commit748fcb76778b618d232b1c829f72d4ef65392441 (patch)
tree0b58106420215f0e1654ace4e96adf6564030957 /tests/test_main.py
parentb3e109d5185381f3a000fa8397c55c5f38a7bda0 (diff)
Issue #355 Use setproctitle to hide command line passwords
Diffstat (limited to 'tests/test_main.py')
-rw-r--r--tests/test_main.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/tests/test_main.py b/tests/test_main.py
index e25f7f08..6e8d14b0 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -1,5 +1,5 @@
import pytest
-from pgcli.main import need_completion_refresh
+from pgcli.main import need_completion_refresh, obscure_process_password
@pytest.mark.parametrize('sql', [
@@ -7,4 +7,22 @@ from pgcli.main import need_completion_refresh
'SELECT * FROM foo; DROP TABLE foo',
])
def test_need_completion_refresh(sql):
- assert need_completion_refresh(sql) \ No newline at end of file
+ assert need_completion_refresh(sql)
+
+def test_obscure_process_password():
+ import setproctitle
+ original_title = setproctitle.getproctitle()
+
+ setproctitle.setproctitle("pgcli user=root password=secret host=localhost")
+ obscure_process_password()
+ title = setproctitle.getproctitle()
+ expected = "pgcli user=root password=xxxx host=localhost"
+ assert title == expected
+
+ setproctitle.setproctitle("pgcli postgres://root:secret@localhost/db")
+ obscure_process_password()
+ title = setproctitle.getproctitle()
+ expected = "pgcli postgres://root:xxxx@localhost/db"
+ assert title == expected
+
+ setproctitle.setproctitle(original_title)