Skip to content

Commit 2343016

Browse files
committed
Add dropdb TAP test
1 parent 9910eee commit 2343016

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

src/test/mdb_admin/t/dropdb.pl

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
# Copyright (c) 2024-2024, MDB, Mother Russia
3+
4+
# Minimal test testing drop database restrictions
5+
use strict;
6+
use warnings;
7+
use PostgreSQL::Test::Cluster;
8+
use PostgreSQL::Test::Utils;
9+
use Test::More;
10+
11+
# Initialize primary node
12+
my $node_primary = PostgreSQL::Test::Cluster->new('primary');
13+
$node_primary->init();
14+
$node_primary->start;
15+
16+
# Create some content on primary and check its presence in standby nodes
17+
$node_primary->safe_psql('postgres',
18+
"
19+
CREATE ROLE mdb_admin;
20+
CREATE ROLE mdb_superuser;
21+
CREATE ROLE mdb_reg_lh_1;
22+
GRANT mdb_admin TO mdb_reg_lh_1;
23+
GRANT mdb_superuser TO mdb_reg_lh_1;
24+
ALTER ROLE mdb_reg_lh_1 CREATEDB;
25+
");
26+
27+
# Create some content on primary
28+
$node_primary->safe_psql('postgres',
29+
"
30+
SET ROLE mdb_reg_lh_1;
31+
CREATE DATABASE regress_db1;
32+
");
33+
34+
35+
my ($res_reg_lh_1, $stdout_reg_lh_1, $stderr_reg_lh_1) = $node_primary->psql('postgres',
36+
"
37+
SET ROLE mdb_reg_lh_1;
38+
DROP DATABASE regress_db1;
39+
");
40+
41+
# print ($res_reg_lh_1, $stdout_reg_lh_1, $stderr_reg_lh_1, "\n");
42+
43+
ok($res_reg_lh_1 != 0, "should fail for non-superuser");
44+
like($stderr_reg_lh_1, qr/ERROR: permission denied for database regress_db1/, "matches");
45+
46+
my ($res_reg_lh_2, $stdout_reg_lh_2, $stderr_reg_lh_2) = $node_primary->psql('postgres',
47+
"
48+
DROP DATABASE regress_db1;
49+
");
50+
51+
ok($res_reg_lh_2 == 0, "should success for superuser");
52+
53+
# print ($res_reg_lh_2, $stdout_reg_lh_2, $stderr_reg_lh_2, "\n");
54+
55+
done_testing();

0 commit comments

Comments
 (0)