Skip to content

Commit dd3ca8c

Browse files
committed
Fix buildfarm error from commit 5c31669.
Skip test when not using unix domain sockets. Discussion: https://postgr.es/m/CALDaNm29-8OozsBWo9H6DN_Tb_3yA1QjRJput-KhaN8ncDJtJA@mail.gmail.com Backpatch-through: 16
1 parent 4b31063 commit dd3ca8c

File tree

1 file changed

+81
-70
lines changed

1 file changed

+81
-70
lines changed

src/test/subscription/t/027_nosuperuser.pl

Lines changed: 81 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use strict;
66
use warnings FATAL => 'all';
77
use PostgreSQL::Test::Cluster;
8+
use PostgreSQL::Test::Utils;
89
use Test::More;
910

1011
my ($node_publisher, $node_subscriber, $publisher_connstr, $result, $offset);
@@ -330,81 +331,91 @@ sub grant_superuser
330331
# If the subscription connection requires a password ('password_required'
331332
# is true) then a non-superuser must specify that password in the connection
332333
# string.
333-
$ENV{"PGPASSWORD"} = 'secret';
334-
335-
my $node_publisher1 = PostgreSQL::Test::Cluster->new('publisher1');
336-
my $node_subscriber1 = PostgreSQL::Test::Cluster->new('subscriber1');
337-
$node_publisher1->init(allows_streaming => 'logical');
338-
$node_subscriber1->init;
339-
$node_publisher1->start;
340-
$node_subscriber1->start;
341-
my $publisher_connstr1 =
342-
$node_publisher1->connstr . ' user=regress_test_user dbname=postgres';
343-
my $publisher_connstr2 =
344-
$node_publisher1->connstr
345-
. ' user=regress_test_user dbname=postgres password=secret';
346-
347-
for my $node ($node_publisher1, $node_subscriber1)
334+
SKIP:
348335
{
349-
$node->safe_psql(
336+
skip
337+
"subscription password_required test cannot run without Unix-domain sockets",
338+
3
339+
unless $use_unix_sockets;
340+
341+
my $node_publisher1 = PostgreSQL::Test::Cluster->new('publisher1');
342+
my $node_subscriber1 = PostgreSQL::Test::Cluster->new('subscriber1');
343+
$node_publisher1->init(allows_streaming => 'logical');
344+
$node_subscriber1->init;
345+
$node_publisher1->start;
346+
$node_subscriber1->start;
347+
my $publisher_connstr1 =
348+
$node_publisher1->connstr . ' user=regress_test_user dbname=postgres';
349+
my $publisher_connstr2 =
350+
$node_publisher1->connstr
351+
. ' user=regress_test_user dbname=postgres password=secret';
352+
353+
for my $node ($node_publisher1, $node_subscriber1)
354+
{
355+
$node->safe_psql(
356+
'postgres', qq(
357+
CREATE ROLE regress_test_user PASSWORD 'secret' LOGIN REPLICATION;
358+
GRANT CREATE ON DATABASE postgres TO regress_test_user;
359+
GRANT PG_CREATE_SUBSCRIPTION TO regress_test_user;
360+
));
361+
}
362+
363+
$node_publisher1->safe_psql(
350364
'postgres', qq(
351-
CREATE ROLE regress_test_user PASSWORD 'secret' LOGIN REPLICATION;
352-
GRANT CREATE ON DATABASE postgres TO regress_test_user;
353-
GRANT PG_CREATE_SUBSCRIPTION TO regress_test_user;
354-
));
355-
}
365+
SET SESSION AUTHORIZATION regress_test_user;
366+
CREATE PUBLICATION regress_test_pub;
367+
));
368+
$node_subscriber1->safe_psql(
369+
'postgres', qq(
370+
CREATE SUBSCRIPTION regress_test_sub CONNECTION '$publisher_connstr1' PUBLICATION regress_test_pub;
371+
));
356372

357-
$node_publisher1->safe_psql(
358-
'postgres', qq(
359-
SET SESSION AUTHORIZATION regress_test_user;
360-
CREATE PUBLICATION regress_test_pub;
361-
));
362-
$node_subscriber1->safe_psql(
363-
'postgres', qq(
364-
CREATE SUBSCRIPTION regress_test_sub CONNECTION '$publisher_connstr1' PUBLICATION regress_test_pub;
365-
));
373+
# Wait for initial sync to finish
374+
$node_subscriber1->wait_for_subscription_sync($node_publisher1,
375+
'regress_test_sub');
366376

367-
# Wait for initial sync to finish
368-
$node_subscriber1->wait_for_subscription_sync($node_publisher1,
369-
'regress_test_sub');
370-
371-
# Setup pg_hba configuration so that logical replication connection without
372-
# password is not allowed.
373-
unlink($node_publisher1->data_dir . '/pg_hba.conf');
374-
$node_publisher1->append_conf('pg_hba.conf',
375-
qq{local all regress_test_user md5});
376-
$node_publisher1->reload;
377-
378-
# Change the subscription owner to a non-superuser
379-
$node_subscriber1->safe_psql(
380-
'postgres', qq(
381-
ALTER SUBSCRIPTION regress_test_sub OWNER TO regress_test_user;
382-
));
377+
my $save_pgpassword = $ENV{"PGPASSWORD"};
378+
$ENV{"PGPASSWORD"} = 'secret';
383379

384-
# Non-superuser must specify password in the connection string
385-
my ($ret, $stdout, $stderr) = $node_subscriber1->psql(
386-
'postgres', qq(
387-
SET SESSION AUTHORIZATION regress_test_user;
388-
ALTER SUBSCRIPTION regress_test_sub REFRESH PUBLICATION;
389-
));
390-
isnt($ret, 0,
391-
"non zero exit for subscription whose owner is a non-superuser must specify password parameter of the connection string"
392-
);
393-
ok( $stderr =~ m/DETAIL: Non-superusers must provide a password in the connection string./,
394-
'subscription whose owner is a non-superuser must specify password parameter of the connection string'
395-
);
380+
# Setup pg_hba configuration so that logical replication connection without
381+
# password is not allowed.
382+
unlink($node_publisher1->data_dir . '/pg_hba.conf');
383+
$node_publisher1->append_conf('pg_hba.conf',
384+
qq{local all regress_test_user md5});
385+
$node_publisher1->reload;
396386

397-
delete $ENV{"PGPASSWORD"};
387+
# Change the subscription owner to a non-superuser
388+
$node_subscriber1->safe_psql(
389+
'postgres', qq(
390+
ALTER SUBSCRIPTION regress_test_sub OWNER TO regress_test_user;
391+
));
398392

399-
# It should succeed after including the password parameter of the connection
400-
# string.
401-
($ret, $stdout, $stderr) = $node_subscriber1->psql(
402-
'postgres', qq(
403-
SET SESSION AUTHORIZATION regress_test_user;
404-
ALTER SUBSCRIPTION regress_test_sub CONNECTION '$publisher_connstr2';
405-
ALTER SUBSCRIPTION regress_test_sub REFRESH PUBLICATION;
406-
));
407-
is($ret, 0,
408-
"Non-superuser will be able to refresh the publication after specifying the password parameter of the connection string"
409-
);
393+
# Non-superuser must specify password in the connection string
394+
my ($ret, $stdout, $stderr) = $node_subscriber1->psql(
395+
'postgres', qq(
396+
SET SESSION AUTHORIZATION regress_test_user;
397+
ALTER SUBSCRIPTION regress_test_sub REFRESH PUBLICATION;
398+
));
399+
isnt($ret, 0,
400+
"non zero exit for subscription whose owner is a non-superuser must specify password parameter of the connection string"
401+
);
402+
ok( $stderr =~
403+
m/DETAIL: Non-superusers must provide a password in the connection string./,
404+
'subscription whose owner is a non-superuser must specify password parameter of the connection string'
405+
);
406+
407+
$ENV{"PGPASSWORD"} = $save_pgpassword;
408+
409+
# It should succeed after including the password parameter of the connection
410+
# string.
411+
($ret, $stdout, $stderr) = $node_subscriber1->psql(
412+
'postgres', qq(
413+
SET SESSION AUTHORIZATION regress_test_user;
414+
ALTER SUBSCRIPTION regress_test_sub CONNECTION '$publisher_connstr2';
415+
ALTER SUBSCRIPTION regress_test_sub REFRESH PUBLICATION;
416+
));
417+
is($ret, 0,
418+
"Non-superuser will be able to refresh the publication after specifying the password parameter of the connection string"
419+
);
420+
}
410421
done_testing();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy