Skip to content

Commit

Permalink
Correctly mask the DSN in logs when the password is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Pracucci committed Dec 11, 2018
1 parent 702cdde commit b1b899e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Changelog

- [BUGFIX] Correctly mask the DSN in logs when the password is empty

### 2.0.0 (2018-12-05)
- [BREAKING CHANGE] Renamed `pgbouncer_stats_queries_total` to `pgbouncer_stats_requests_total` on pgbouncer <= 1.7
- [FEATURE] Added pgbouncer >= 1.8 support [#8](https://github.com/spreaker/prometheus-pgbouncer-exporter/pull/8) (thanks to [bitglue](https://github.com/bitglue)), including the following new metrics:
Expand Down
2 changes: 1 addition & 1 deletion prometheus_pgbouncer_exporter/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
ENV_VAR_REPLACER_PATTERN = re.compile(r'\$\(([^\)]+)\)')

# Define the regex used to mask the password in the DSN
DSN_PASSWORD_MASK_PATTERN = re.compile(r'^(.*:)([^@]+)(@.*)$')
DSN_PASSWORD_MASK_PATTERN = re.compile(r'^(.*:)([^@]*)(@.*)$')


class Config():
Expand Down
8 changes: 8 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ def testValidateShouldPassOnTwoPgbouncersWithDifferentExtraLabels(self):

class TestPgbouncerConfig(unittest.TestCase):

def testGetDsnWithMaskedPasswordShouldReturnDsnWithThreeAsterisksInsteadOfThePassword(self):
config = PgbouncerConfig({"dsn": "postgresql://pgbouncer:secret@localhost:6431/pgbouncer"})
self.assertEqual(config.getDsnWithMaskedPassword(), "postgresql://pgbouncer:***@localhost:6431/pgbouncer")

def testGetDsnWithMaskedPasswordShouldWorkEvenIfThePasswordIsEmpty(self):
config = PgbouncerConfig({"dsn": "postgresql://pgbouncer:@localhost:6431/pgbouncer"})
self.assertEqual(config.getDsnWithMaskedPassword(), "postgresql://pgbouncer:***@localhost:6431/pgbouncer")

def testValidateShouldPassOnConfigContainingOnlyDsn(self):
config = PgbouncerConfig({"dsn": "postgresql://"})
config.validate()
Expand Down

0 comments on commit b1b899e

Please sign in to comment.