Skip to content

Commit 3f650ed

Browse files
committed
fix auth_test
1 parent d86778d commit 3f650ed

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

tests/auth_test.py

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
"""
2-
Description:
3-
The Test suite check behavior of pg_probackup utility,
4-
if password is required for connection to PostgreSQL instance.
5-
- https://confluence.postgrespro.ru/pages/viewpage.action?pageId=16777522
2+
The Test suite check behavior of pg_probackup utility, if password is required for connection to PostgreSQL instance.
3+
- https://confluence.postgrespro.ru/pages/viewpage.action?pageId=16777522
64
"""
75

86
import os
@@ -94,7 +92,7 @@ def test_empty_password(self):
9492
try:
9593
self.assertIn("ERROR: no password supplied",
9694
"".join(map(lambda x: x.decode("utf-8"),
97-
self.run_pb_with_auth(self.cmd, '\0\r\n'))
95+
run_pb_with_auth([self.pb.probackup_path] + self.cmd, '\0\r\n'))
9896
)
9997
)
10098
except (TIMEOUT, ExceptionPexpect) as e:
@@ -105,7 +103,7 @@ def test_wrong_password(self):
105103
try:
106104
self.assertIn("password authentication failed",
107105
"".join(map(lambda x: x.decode("utf-8"),
108-
self.run_pb_with_auth(self.cmd, 'wrong_password\r\n'))
106+
run_pb_with_auth([self.pb.probackup_path] + self.cmd, 'wrong_password\r\n'))
109107
)
110108
)
111109
except (TIMEOUT, ExceptionPexpect) as e:
@@ -116,7 +114,7 @@ def test_right_password(self):
116114
try:
117115
self.assertIn("completed",
118116
"".join(map(lambda x: x.decode("utf-8"),
119-
self.run_pb_with_auth(self.cmd, 'password\r\n'))
117+
run_pb_with_auth([self.pb.probackup_path] + self.cmd, 'password\r\n'))
120118
)
121119
)
122120
except (TIMEOUT, ExceptionPexpect) as e:
@@ -125,7 +123,7 @@ def test_right_password(self):
125123
def test_ctrl_c_event(self):
126124
""" Test case: PGPB_AUTH02 - send interrupt signal """
127125
try:
128-
self.run_pb_with_auth(self.cmd, kill=True)
126+
run_pb_with_auth([self.pb.probackup_path] + self.cmd, kill=True)
129127
except TIMEOUT:
130128
self.fail("Error: CTRL+C event ignored")
131129

@@ -170,21 +168,22 @@ def test_pgpassword(self):
170168
except ProbackupException as e:
171169
self.fail(e)
172170

173-
def run_pb_with_auth(self, password=None, kill=False):
174-
try:
175-
with spawn(" ".join([self.pb.probackup_path] + self.cmd), timeout=10) as probackup:
176-
result = probackup.expect("Password for user .*:", 5)
177-
if kill:
178-
probackup.kill(signal.SIGINT)
179-
elif result == 0:
180-
probackup.sendline(password)
181-
return probackup.readlines()
182-
else:
183-
raise TIMEOUT("")
184-
except TIMEOUT:
185-
raise TIMEOUT("Timeout error.")
186-
except ExceptionPexpect:
187-
raise ExceptionPexpect("Pexpect error.")
171+
172+
def run_pb_with_auth(cmd, password=None, kill=False):
173+
try:
174+
with spawn(" ".join(cmd), timeout=10) as probackup:
175+
result = probackup.expect("Password for user .*:", 5)
176+
if kill:
177+
probackup.kill(signal.SIGINT)
178+
elif result == 0:
179+
probackup.sendline(password)
180+
return probackup.readlines()
181+
else:
182+
raise TIMEOUT("")
183+
except TIMEOUT:
184+
raise TIMEOUT("Timeout error.")
185+
except ExceptionPexpect:
186+
raise ExceptionPexpect("Pexpect error.")
188187

189188

190189
def modify_pg_hba(node):
@@ -202,7 +201,7 @@ def modify_pg_hba(node):
202201

203202

204203
def create_pgpass(path, line):
205-
with open(path, 'w') as passfile:
204+
with open(path, 'w+') as passfile:
206205
# host:port:db:username:password
207206
passfile.write(line)
208-
os.chmod(path, 600)
207+
os.chmod(path, 0600)

0 commit comments

Comments
 (0)