File tree Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -552,10 +552,19 @@ def default_conf(self,
552552
553553 # replication-related settings
554554 if allow_streaming :
555+ # get auth method for host or local users
556+ def get_auth_method (t ):
557+ return next ((s .split ()[- 1 ] for s in lines
558+ if s .startswith (t )), 'trust' )
559+
560+ # get auth methods
561+ auth_local = get_auth_method ('local' )
562+ auth_host = get_auth_method ('host' )
563+
555564 new_lines = [
556- "local\t replication\t all\t \t \t trust \n " ,
557- "host\t replication\t all\t 127.0.0.1/32\t trust \n " ,
558- "host\t replication\t all\t ::1/128\t \t trust \n "
565+ "local\t replication\t all\t \t \t {} \n " . format ( auth_local ) ,
566+ "host\t replication\t all\t 127.0.0.1/32\t {} \n " . format ( auth_host ) ,
567+ "host\t replication\t all\t ::1/128\t \t {} \n " . format ( auth_host )
559568 ]
560569
561570 # write missing lines
Original file line number Diff line number Diff line change @@ -35,6 +35,21 @@ def test_custom_init(self):
3535 node .init (initdb_params = ['-k' ]).start ()
3636 node .safe_psql ('postgres' , 'select 1' )
3737
38+ with get_new_node ('test' ) as node :
39+ node .init (allow_streaming = True ,
40+ initdb_params = ['--auth-local=reject' ,
41+ '--auth-host=reject' ])
42+
43+ hba_file = os .path .join (node .data_dir , 'pg_hba.conf' )
44+ with open (hba_file , 'r' ) as conf :
45+ lines = conf .readlines ()
46+
47+ # check number of lines
48+ self .assertGreaterEqual (len (lines ), 6 )
49+
50+ # there should be no trust entries at all
51+ self .assertFalse (any ('trust' in s for s in lines ))
52+
3853 def test_double_init (self ):
3954 with get_new_node ('test' ) as node :
4055 # can't initialize node more than once
You can’t perform that action at this time.
0 commit comments