Skip to content

Commit

Permalink
[ADD] Tests to check if new feature works
Browse files Browse the repository at this point in the history
  • Loading branch information
josep-tecnativa committed Nov 28, 2024
1 parent 41e5558 commit 88f47d9
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,49 @@ def test_certs_falsy_lan(self):
with self.assertRaises(ProcessExecutionError):
self._check_password_auth("example.localdomain")

def test_hba_extra_rules_added(self):
"""Test that HBA_EXTRA_RULES lines are added to pg_hba.conf."""
pg_version = os.environ.get("TEST_PG_VERSION", "")
if pg_version == "9.6":
self.skipTest("HBA_EXTRA_RULES not supported in PostgreSQL 9.6")
# Define custom HBA rules
hba_extra_rules = [
"host test_db custom_user 0.0.0.0/0 trust",
"hostssl all all 192.168.0.0/16 md5",
]

# Start the Postgres container with HBA_EXTRA_RULES
self.postgres_container = docker(
"run",
"-d",
"--name",
"postgres_test_hba_extra_rules",
"--network",
"lan",
"-e",
"POSTGRES_DB=test_db",
"-e",
"POSTGRES_USER=test_user",
"-e",
"POSTGRES_PASSWORD=test_password",
"-e",
"HBA_EXTRA_RULES=" + json.dumps(hba_extra_rules),
CONF_EXTRA,
self.image,
).strip()

# Give the container some time to initialize
time.sleep(10)

# Read the pg_hba.conf file content from the container
hba_conf = docker(
"exec", self.postgres_container, "cat", "/etc/postgres/pg_hba.conf"
).strip()

# Check that each rule in hba_extra_rules is present in the file
for rule in hba_extra_rules:
self.assertIn(rule, hba_conf)


if __name__ == "__main__":
unittest.main()

0 comments on commit 88f47d9

Please sign in to comment.