Fix and improve TAP tests for pg_hba.conf and regexps
authorMichael Paquier <[email protected]>
Mon, 24 Oct 2022 04:48:34 +0000 (13:48 +0900)
committerMichael Paquier <[email protected]>
Mon, 24 Oct 2022 04:56:34 +0000 (13:56 +0900)
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.

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

index 6c0c753b56c05c7b88ecd232164f79b5f4ca31d8..42d3d4c79b5e1b2e11065ad1b50354fc43ca4cb0 100644 (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$',