Skip to content

Commit 80ddfb7

Browse files
[ADD] Tests to check if new feature works
1 parent 41e5558 commit 80ddfb7

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/test.py

+42
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,48 @@ def test_certs_falsy_lan(self):
299299
with self.assertRaises(ProcessExecutionError):
300300
self._check_password_auth("example.localdomain")
301301

302+
def test_hba_extra_rules_added(self):
303+
"""Test that HBA_EXTRA_RULES lines are added to pg_hba.conf."""
304+
if "9.6" in self.image:
305+
self.skipTest("HBA_EXTRA_RULES not supported in PostgreSQL 9.6")
306+
# Define custom HBA rules
307+
hba_extra_rules = [
308+
"host test_db custom_user 0.0.0.0/0 trust",
309+
"hostssl all all 192.168.0.0/16 md5",
310+
]
311+
312+
# Start the Postgres container with HBA_EXTRA_RULES
313+
self.postgres_container = docker(
314+
"run",
315+
"-d",
316+
"--name",
317+
"postgres_test_hba_extra_rules",
318+
"--network",
319+
"lan",
320+
"-e",
321+
"POSTGRES_DB=test_db",
322+
"-e",
323+
"POSTGRES_USER=test_user",
324+
"-e",
325+
"POSTGRES_PASSWORD=test_password",
326+
"-e",
327+
"HBA_EXTRA_RULES=" + json.dumps(hba_extra_rules),
328+
CONF_EXTRA,
329+
self.image,
330+
).strip()
331+
332+
# Give the container some time to initialize
333+
time.sleep(10)
334+
335+
# Read the pg_hba.conf file content from the container
336+
hba_conf = docker(
337+
"exec", self.postgres_container, "cat", "/etc/postgres/pg_hba.conf"
338+
).strip()
339+
340+
# Check that each rule in hba_extra_rules is present in the file
341+
for rule in hba_extra_rules:
342+
self.assertIn(rule, hba_conf)
343+
302344

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

0 commit comments

Comments
 (0)