Skip to content

Commit 14a737b

Browse files
committed
Fix and improve TAP tests for pg_hba.conf and regexps
The new tests have been reporting a warning hidden in the logs, as of "Odd number of elements in hash assignment" (perlcritic or similar did not report an issue, actually). This comes down to a typo in the test "matching regexp for username" for a double-quoted regexp using commas, where we passed an extra argument. The test is intended to pass, but this was causing the test to fail. This also pointed out that the newly-added role "md5,role" lacks an entry in the password file used to provide the password, so add one. While on it, make the tests pickier by checking the contents of the logs generated on successful authentication. Oversights in 8fea868.
1 parent 8fea868 commit 14a737b

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/test/authentication/t/001_password.pl

+13-6
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,16 @@ sub test_conn
204204
append_to_file(
205205
$pgpassfile, qq!
206206
*:*:*:md5_role:p\\ass
207+
*:*:*:md5,role:p\\ass
207208
!);
208209

209210
test_conn($node, 'user=md5_role', 'password from pgpass', 0);
210211

211212
# Testing with regular expression for username. The third regexp matches.
212213
reset_pg_hba($node, 'all', '/^.*nomatch.*$, baduser, /^md.*$', 'password');
213-
test_conn($node, 'user=md5_role', 'password, matching regexp for username',
214-
0);
214+
test_conn($node, 'user=md5_role', 'password, matching regexp for username', 0,
215+
log_like =>
216+
[qr/connection authenticated: identity="md5_role" method=password/]);
215217

216218
# The third regex does not match anymore.
217219
reset_pg_hba($node, 'all', '/^.*nomatch.*$, baduser, /^m_d.*$', 'password');
@@ -223,15 +225,20 @@ sub test_conn
223225
# double quotes is mandatory so as this is not considered as two elements
224226
# of the user name list when parsing pg_hba.conf.
225227
reset_pg_hba($node, 'all', '"/^.*5,.*e$"', 'password');
226-
test_conn($node, 'user=md5,role', 'password', 'matching regexp for username',
227-
0);
228+
test_conn($node, 'user=md5,role', 'password, matching regexp for username', 0,
229+
log_like =>
230+
[qr/connection authenticated: identity="md5,role" method=password/]);
228231

229232
# Testing with regular expression for dbname. The third regex matches.
230233
reset_pg_hba($node, '/^.*nomatch.*$, baddb, /^regex_t.*b$', 'all',
231234
'password');
232235
test_conn(
233-
$node, 'user=md5_role dbname=regex_testdb', 'password,
234-
matching regexp for dbname', 0);
236+
$node,
237+
'user=md5_role dbname=regex_testdb',
238+
'password, matching regexp for dbname',
239+
0,
240+
log_like =>
241+
[qr/connection authenticated: identity="md5_role" method=password/]);
235242

236243
# The third regexp does not match anymore.
237244
reset_pg_hba($node, '/^.*nomatch.*$, baddb, /^regex_t.*ba$',

0 commit comments

Comments
 (0)