🌐 AI搜索 & 代理 主页
Skip to content

Commit c3df857

Browse files
committed
oauth_validator: Avoid races in log_check()
Commit e0f373e fixed up races in Cluster::connect_fails when using log_like. t/002_client.pl didn't get the memo, though, because it doesn't use Test::Cluster to perform its custom hook tests. (This is probably not an issue at the moment, since the log check is only done after authentication success and not failure, but there's no reason to wait for someone to hit it.) Introduce the fix, based on debug2 logging, to its use of log_check() as well, and move the logic into the test() helper so that any additions don't need to continually duplicate it. Reviewed-by: Chao Li <li.evan.chao@gmail.com> Discussion: https://postgr.es/m/CAOYmi%2BmrGg%2Bn_X2MOLgeWcj3v_M00gR8uz_D7mM8z%3DdX1JYVbg%40mail.gmail.com Backpatch-through: 18
1 parent 023a3c7 commit c3df857

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/test/modules/oauth_validator/t/002_client.pl

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
$node->append_conf('postgresql.conf', "log_connections = all\n");
3030
$node->append_conf('postgresql.conf',
3131
"oauth_validator_libraries = 'validator'\n");
32+
# Needed to inspect postmaster log after connection failure:
33+
$node->append_conf('postgresql.conf', "log_min_messages = debug2");
3234
$node->start;
3335

3436
$node->safe_psql('postgres', 'CREATE USER test;');
@@ -47,7 +49,7 @@
4749
});
4850
$node->reload;
4951

50-
my $log_start = $node->wait_for_log(qr/reloading configuration files/);
52+
$node->wait_for_log(qr/reloading configuration files/);
5153

5254
$ENV{PGOAUTHDEBUG} = "UNSAFE";
5355

@@ -73,6 +75,7 @@ sub test
7375
my @cmd = ("oauth_hook_client", @{$flags}, $common_connstr);
7476
note "running '" . join("' '", @cmd) . "'";
7577

78+
my $log_start = -s $node->logfile;
7679
my ($stdout, $stderr) = run_command(\@cmd);
7780

7881
if (defined($params{expected_stdout}))
@@ -88,6 +91,18 @@ sub test
8891
{
8992
is($stderr, "", "$test_name: no stderr");
9093
}
94+
95+
if (defined($params{log_like}))
96+
{
97+
# See Cluster::connect_fails(). To avoid races, we have to wait for the
98+
# postmaster to flush the log for the finished connection.
99+
$node->wait_for_log(
100+
qr/DEBUG: (?:00000: )?forked new client backend, pid=(\d+) socket.*DEBUG: (?:00000: )?client backend \(PID \1\) exited with exit code \d/s,
101+
$log_start);
102+
103+
$node->log_check("$test_name: log matches",
104+
$log_start, log_like => $params{log_like});
105+
}
91106
}
92107

93108
test(
@@ -97,11 +112,8 @@ sub test
97112
"--expected-uri", "$issuer/.well-known/openid-configuration",
98113
"--expected-scope", $scope,
99114
],
100-
expected_stdout => qr/connection succeeded/);
101-
102-
$node->log_check("validator receives correct token",
103-
$log_start,
104-
log_like => [ qr/oauth_validator: token="my-token", role="$user"/, ]);
115+
expected_stdout => qr/connection succeeded/,
116+
log_like => [qr/oauth_validator: token="my-token", role="$user"/]);
105117

106118
if ($ENV{with_libcurl} ne 'yes')
107119
{

0 commit comments

Comments
 (0)