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