Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc50624c

Browse files
committed
Refactor all TAP test suites doing connection checks
This commit refactors more TAP tests to adapt with the recentintroduction of connect_ok() and connect_fails() in PostgresNode,introduced by0d1a334. This changes the following test suites to usethe same code paths for connection checks:- Kerberos- LDAP- SSL- AuthenticationThose routines are extended to be able to handle optional parametersthat are set depending on each suite's needs, as of:- custom SQL query.- expected stderr matching pattern.- expected stdout matching pattern.The new design is extensible with more parameters, and there are someplans for those routines in the future with checks based on the contentsof the backend logs.Author: Jacob Champion, Michael PaquierDiscussion:https://postgr.es/m/d17b919e27474abfa55d97786cb9cfadfe2b59e9.camel@vmware.com
1 parentdfc843d commitc50624c

File tree

7 files changed

+211
-130
lines changed

7 files changed

+211
-130
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,19 @@ sub test_role
4646

4747
$status_string ='success'if ($expected_reseq 0);
4848

49-
local$Test::Builder::Level =$Test::Builder::Level + 1;
50-
51-
my$res =$node->psql('postgres',undef,extra_params=> ['-U',$role,'-w' ]);
52-
is($res,$expected_res,
53-
"authentication$status_string for method$method, role$role");
54-
return;
49+
my$connstr ="user=$role";
50+
my$testname =
51+
"authentication$status_string for method$method, role$role";
52+
53+
if ($expected_reseq 0)
54+
{
55+
$node->connect_ok($connstr,$testname);
56+
}
57+
else
58+
{
59+
# No checks of the error message, only the status code.
60+
$node->connect_fails($connstr,$testname);
61+
}
5562
}
5663

5764
# Initialize primary node

‎src/test/authentication/t/002_saslprep.pl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,20 @@ sub test_login
4141

4242
$status_string ='success'if ($expected_reseq 0);
4343

44+
my$connstr ="user=$role";
45+
my$testname =
46+
"authentication$status_string for role$role with password$password";
47+
4448
$ENV{"PGPASSWORD"} =$password;
45-
my$res =$node->psql('postgres',undef,extra_params=> ['-U',$role ]);
46-
is($res,$expected_res,
47-
"authentication$status_string for role$role with password$password"
48-
);
49-
return;
49+
if ($expected_reseq 0)
50+
{
51+
$node->connect_ok($connstr,$testname);
52+
}
53+
else
54+
{
55+
# No checks of the error message, only the status code.
56+
$node->connect_fails($connstr,$testname);
57+
}
5058
}
5159

5260
# Initialize primary node. Force UTF-8 encoding, so that we can use non-ASCII

‎src/test/kerberos/t/001_auth.pl

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
if ($ENV{with_gssapi}eq'yes')
2222
{
23-
plantests=>26;
23+
plantests=>30;
2424
}
2525
else
2626
{
@@ -182,28 +182,25 @@ END
182182
# Test connection success or failure, and if success, that query returns true.
183183
subtest_access
184184
{
185-
my ($node,$role,$query,$expected_res,$gssencmode,$test_name,$expect_log_msg) =@_;
185+
my ($node,$role,$query,$expected_res,$gssencmode,$test_name,
186+
$expect_log_msg)
187+
=@_;
186188

187189
# need to connect over TCP/IP for Kerberos
188-
my ($res,$stdoutres,$stderrres) =$node->psql(
189-
'postgres',
190-
"$query",
191-
extra_params=> [
192-
'-XAtd',
193-
$node->connstr('postgres')
194-
." host=$host hostaddr=$hostaddr$gssencmode",
195-
'-U',
196-
$role
197-
]);
198-
199-
# If we get a query result back, it should be true.
200-
if ($res ==$expected_resand$reseq 0)
190+
my$connstr =$node->connstr('postgres')
191+
." user=$role host=$host hostaddr=$hostaddr$gssencmode";
192+
193+
if ($expected_reseq 0)
201194
{
202-
is($stdoutres,"t",$test_name);
195+
# The result is assumed to match "true", or "t", here.
196+
$node->connect_ok(
197+
$connstr,$test_name,
198+
sql=>$query,
199+
expected_stdout=>qr/t/);
203200
}
204201
else
205202
{
206-
is($res,$expected_res,$test_name);
203+
$node->connect_fails($connstr,$test_name);
207204
}
208205

209206
# Verify specified log message is logged in the log file.
@@ -227,20 +224,12 @@ sub test_query
227224
my ($node,$role,$query,$expected,$gssencmode,$test_name) =@_;
228225

229226
# need to connect over TCP/IP for Kerberos
230-
my ($res,$stdoutres,$stderrres) =$node->psql(
231-
'postgres',
232-
"$query",
233-
extra_params=> [
234-
'-XAtd',
235-
$node->connstr('postgres')
236-
." host=$host hostaddr=$hostaddr$gssencmode",
237-
'-U',
238-
$role
239-
]);
240-
241-
is($res, 0,$test_name);
242-
like($stdoutres,$expected,$test_name);
243-
is($stderrres,"",$test_name);
227+
my$connstr =$node->connstr('postgres')
228+
." user=$role host=$host hostaddr=$hostaddr$gssencmode";
229+
230+
my ($stdoutres,$stderrres);
231+
232+
$node->connect_ok($connstr,$test_name,$query,$expected);
244233
return;
245234
}
246235

‎src/test/ldap/t/001_auth.pl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,17 @@ END
163163
subtest_access
164164
{
165165
my ($node,$role,$expected_res,$test_name) =@_;
166-
167-
my$res =
168-
$node->psql('postgres',undef,
169-
extra_params=> ['-U',$role,'-c','SELECT 1' ]);
170-
is($res,$expected_res,$test_name);
171-
return;
166+
my$connstr ="user=$role";
167+
168+
if ($expected_reseq 0)
169+
{
170+
$node->connect_ok($connstr,$test_name);
171+
}
172+
else
173+
{
174+
# No checks of the error message, only the status code.
175+
$node->connect_fails($connstr,$test_name);
176+
}
172177
}
173178

174179
note"simple bind";

‎src/test/perl/PostgresNode.pm

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,47 +1860,94 @@ sub interactive_psql
18601860

18611861
=pod
18621862
1863-
=item$node->connect_ok($connstr, $test_name)
1863+
=item$node->connect_ok($connstr, $test_name, %params)
18641864
18651865
Attempt a connection with a custom connection string. This is expected
18661866
to succeed.
18671867
1868+
=over
1869+
1870+
=itemsql =>B<value>
1871+
1872+
If this parameter is set, this query is used for the connection attempt
1873+
instead of the default.
1874+
1875+
=itemexpected_stdout =>B<value>
1876+
1877+
If this regular expression is set, matches it with the output generated.
1878+
1879+
=back
1880+
18681881
=cut
18691882

18701883
subconnect_ok
18711884
{
18721885
local$Test::Builder::Level =$Test::Builder::Level + 1;
1873-
my ($self,$connstr,$test_name) =@_;
1874-
my ($ret,$stdout,$stderr) =$self->psql(
1886+
my ($self,$connstr,$test_name,%params) =@_;
1887+
1888+
my$sql;
1889+
if (defined($params{sql}))
1890+
{
1891+
$sql =$params{sql};
1892+
}
1893+
else
1894+
{
1895+
$sql ="SELECT\$\$connected with$connstr\$\$";
1896+
}
1897+
1898+
# Never prompt for a password, any callers of this routine should
1899+
# have set up things properly, and this should not block.
1900+
my ($ret,$stdout,$stderr) =$self->psql(
18751901
'postgres',
1876-
"SELECT\$\$connected with$connstr\$\$",
1902+
$sql,
1903+
extra_params=> ['-w'],
18771904
connstr=>"$connstr",
18781905
on_error_stop=> 0);
18791906

1880-
ok($ret == 0,$test_name);
1907+
is($ret, 0,$test_name);
1908+
1909+
if (defined($params{expected_stdout}))
1910+
{
1911+
like($stdout,$params{expected_stdout},"$test_name: matches");
1912+
}
18811913
}
18821914

18831915
=pod
18841916
1885-
=item$node->connect_fails($connstr, $expected_stderr, $test_name)
1917+
=item$node->connect_fails($connstr, $test_name, %params)
18861918
18871919
Attempt a connection with a custom connection string. This is expected
1888-
to fail with a message that matches the regular expression
1889-
$expected_stderr.
1920+
to fail.
1921+
1922+
=over
1923+
1924+
=itemexpected_stderr =>B<value>
1925+
1926+
If this regular expression is set, matches it with the output generated.
1927+
1928+
=back
18901929
18911930
=cut
18921931

18931932
subconnect_fails
18941933
{
18951934
local$Test::Builder::Level =$Test::Builder::Level + 1;
1896-
my ($self,$connstr,$expected_stderr,$test_name) =@_;
1935+
my ($self,$connstr,$test_name,%params) =@_;
1936+
1937+
# Never prompt for a password, any callers of this routine should
1938+
# have set up things properly, and this should not block.
18971939
my ($ret,$stdout,$stderr) =$self->psql(
18981940
'postgres',
18991941
"SELECT\$\$connected with$connstr\$\$",
1900-
connstr=>"$connstr");
1942+
extra_params=> ['-w'],
1943+
connstr=>"$connstr");
19011944

1902-
ok($ret != 0,$test_name);
1903-
like($stderr,$expected_stderr,"$test_name: matches");
1945+
isnt($ret, 0,$test_name);
1946+
1947+
if (defined($params{expected_stderr}))
1948+
{
1949+
like($stderr,$params{expected_stderr},"$test_name: matches");
1950+
}
19041951
}
19051952

19061953
=pod

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp