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.
This commit is contained in:
Michael Paquier 2022-10-24 13:48:34 +09:00
parent 8fea86830e
commit 14a737bfdb
1 changed files with 13 additions and 6 deletions

View File

@ -204,14 +204,16 @@ test_conn($node, 'user=md5_role', 'password from pgpass', 2);
append_to_file(
$pgpassfile, qq!
*:*:*:md5_role:p\\ass
*:*:*:md5,role:p\\ass
!);
test_conn($node, 'user=md5_role', 'password from pgpass', 0);
# Testing with regular expression for username. The third regexp matches.
reset_pg_hba($node, 'all', '/^.*nomatch.*$, baduser, /^md.*$', 'password');
test_conn($node, 'user=md5_role', 'password, matching regexp for username',
0);
test_conn($node, 'user=md5_role', 'password, matching regexp for username', 0,
log_like =>
[qr/connection authenticated: identity="md5_role" method=password/]);
# The third regex does not match anymore.
reset_pg_hba($node, 'all', '/^.*nomatch.*$, baduser, /^m_d.*$', 'password');
@ -223,15 +225,20 @@ test_conn($node, 'user=md5_role',
# double quotes is mandatory so as this is not considered as two elements
# of the user name list when parsing pg_hba.conf.
reset_pg_hba($node, 'all', '"/^.*5,.*e$"', 'password');
test_conn($node, 'user=md5,role', 'password', 'matching regexp for username',
0);
test_conn($node, 'user=md5,role', 'password, matching regexp for username', 0,
log_like =>
[qr/connection authenticated: identity="md5,role" method=password/]);
# Testing with regular expression for dbname. The third regex matches.
reset_pg_hba($node, '/^.*nomatch.*$, baddb, /^regex_t.*b$', 'all',
'password');
test_conn(
$node, 'user=md5_role dbname=regex_testdb', 'password,
matching regexp for dbname', 0);
$node,
'user=md5_role dbname=regex_testdb',
'password, matching regexp for dbname',
0,
log_like =>
[qr/connection authenticated: identity="md5_role" method=password/]);
# The third regexp does not match anymore.
reset_pg_hba($node, '/^.*nomatch.*$, baddb, /^regex_t.*ba$',