Skip to content

Commit bd4eb3c

Browse files
committed
fix authentication for replication in pg_hba.conf
1 parent a0fa95e commit bd4eb3c

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

Diff for: testgres/testgres.py

+12-3
Original file line numberDiff line numberDiff 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\treplication\tall\t\t\ttrust\n",
557-
"host\treplication\tall\t127.0.0.1/32\ttrust\n",
558-
"host\treplication\tall\t::1/128\t\ttrust\n"
565+
"local\treplication\tall\t\t\t{}\n".format(auth_local),
566+
"host\treplication\tall\t127.0.0.1/32\t{}\n".format(auth_host),
567+
"host\treplication\tall\t::1/128\t\t{}\n".format(auth_host)
559568
]
560569

561570
# write missing lines

Diff for: tests/test_simple.py

+15
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)