Skip to content

Commit

Permalink
test password sanitization
Browse files Browse the repository at this point in the history
  • Loading branch information
garyjg committed Dec 30, 2024
1 parent 21a0668 commit fa62415
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions eol_scons/postgres/testdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ def __init__(self, cwd=None, personality="postgrestestdb"):
self.debug = False
# cache the password so it can be removed from log output
self.password = None
# cache and echo the command but do not run it
self.dryrun = False
self.last_command = None

def _log(self, msg):
if self.debug:
Expand Down Expand Up @@ -260,6 +263,10 @@ def _popen(self, cmd, env=None, **args):

def _run(self, cmd, env=None):
scmd = self._sanitized_cmd(cmd)
if self.dryrun:
self.last_command = cmd
print("Dry run: %s" % (scmd))
return
p = self._popen(cmd, env=env)
retcode = p.wait()
if retcode:
Expand Down
17 changes: 17 additions & 0 deletions tests/test_testdb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

import eol_scons.postgres.testdb as testdb


def test_testdb_sanitize():
tdb = testdb.PostgresTestDB()
tdb.dryrun = True
tdb.createUser('ads', 'password')
assert tdb.PGUSER == 'ads'
xcmd = ["psql", "template1", "-c",
'CREATE USER "ads" WITH PASSWORD \'password\' CREATEDB;'
]
assert tdb.last_command == xcmd
assert tdb.password == 'password'
xs = ("psql template1 -c CREATE USER \"ads\" "
"WITH PASSWORD '*****' CREATEDB;")
assert tdb._sanitized_cmd(tdb.last_command) == xs

0 comments on commit fa62415

Please sign in to comment.