@@ -299,6 +299,46 @@ 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+ # Define custom HBA rules
305+ hba_extra_rules = [
306+ "host test_db custom_user 0.0.0.0/0 trust" ,
307+ "hostssl all all 192.168.0.0/16 md5" ,
308+ ]
309+
310+ # Start the Postgres container with HBA_EXTRA_RULES
311+ self .postgres_container = docker (
312+ "run" ,
313+ "-d" ,
314+ "--name" ,
315+ "postgres_test_hba_extra_rules" ,
316+ "--network" ,
317+ "lan" ,
318+ "-e" ,
319+ "POSTGRES_DB=test_db" ,
320+ "-e" ,
321+ "POSTGRES_USER=test_user" ,
322+ "-e" ,
323+ "POSTGRES_PASSWORD=test_password" ,
324+ "-e" ,
325+ "HBA_EXTRA_RULES=" + json .dumps (hba_extra_rules ),
326+ CONF_EXTRA ,
327+ self .image ,
328+ ).strip ()
329+
330+ # Give the container some time to initialize
331+ time .sleep (10 )
332+
333+ # Read the pg_hba.conf file content from the container
334+ hba_conf = docker (
335+ "exec" , self .postgres_container , "cat" , "/etc/postgres/pg_hba.conf"
336+ ).strip ()
337+
338+ # Check that each rule in hba_extra_rules is present in the file
339+ for rule in hba_extra_rules :
340+ self .assertIn (rule , hba_conf )
341+
302342
303343if __name__ == "__main__" :
304344 unittest .main ()
0 commit comments