已合并
add testcase oe_test_postgresql_create_duplicate_role #5227
liuyafei1创建于 5月15日
add testcase oe_test_postgresql_create_duplicate_role #5227
已合并
liuyafei1创建于 5月15日
已删除 :pr/pg-duplicate-role合入到openeuler/mugenmaster
3 个文件变更+82-2
Msuite2cases/admin_guide.json+1-1
@@ -648,4 +648,4 @@
648 "add disk": []648 "add disk": []
649 }649 }
650 ]650 ]
651-}651+}
Msuite2cases/postgresql.json+4-1
@@ -43,6 +43,9 @@
43 {43 {
44 "name": "oe_test_postgresql_createuser02"44 "name": "oe_test_postgresql_createuser02"
45 },45 },
46+ {
47+ "name": "oe_test_postgresql_create_duplicate_role"
48+ },
46 {49 {
47 "name": "oe_test_postgresql-devel_ecpg"50 "name": "oe_test_postgresql-devel_ecpg"
48 },51 },
@@ -122,4 +125,4 @@
122 "name": "oe_test_service_postgresql"125 "name": "oe_test_service_postgresql"
123 }126 }
124 ]127 ]
125-}128+}
Atestcases/cli-test/postgresql/oe_test_postgresql_create_duplicate_role/oe_test_postgresql_create_duplicate_role.sh+77-0
@@ -0,0 +1,77 @@
1+#!/usr/bin/bash
2+ 
3+# Copyright (c) 2026. Huawei Technologies Co.,Ltd.ALL rights reserved.
4+# This program is licensed under Mulan PSL v2.
5+# You can use it according to the terms and conditions of the Mulan PSL v2.
6+# http://license.coscl.org.cn/MulanPSL2
7+# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
8+# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
9+# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
10+# See the Mulan PSL v2 for more details.
11+ 
12+# #############################################
13+# @Author : liuyafei
14+# @Contact : liuyafei@uniontech.com
15+# @Date : 2026-05-14
16+# @License : Mulan PSL v2
17+# @Desc : Verify postgresql rejects duplicate role creation
18+# #############################################
19+source "${OET_PATH}/libs/locallibs/common_lib.sh"
20+ 
21+function pre_test() {
22+ LOG_INFO "Start environment preparation."
23+ OLD_LANG=${LANG}
24+ export LANG=en_US.UTF-8
25+ pg_data=/tmp/pgdata_duplicate_role
26+ role_name=role_duplicate_case
27+ backup_firewalld_state=$(systemctl is-active firewalld 2>/dev/null)
28+ backup_selinux_state=$(getenforce 2>/dev/null)
29+ systemctl stop firewalld >/dev/null 2>&1
30+ systemctl disable firewalld >/dev/null 2>&1
31+ command -v setenforce >/dev/null 2>&1 && setenforce 0 >/dev/null 2>&1
32+ getent group postgres >/dev/null 2>&1 || groupadd postgres
33+ id postgres >/dev/null 2>&1 || useradd -g postgres postgres
34+ DNF_INSTALL postgresql-server
35+ rm -rf "${pg_data}" duplicate_role.log
36+ mkdir -p "${pg_data}"
37+ chown -R postgres:postgres "${pg_data}"
38+ su postgres -c "/usr/bin/initdb -D ${pg_data}" >/dev/null 2>&1
39+ CHECK_RESULT $? 0 0 "initdb should initialize the temporary PostgreSQL cluster"
40+ su postgres -c "/usr/bin/pg_ctl -D ${pg_data} -l ${pg_data}/logfile start" >/dev/null 2>&1
41+ CHECK_RESULT $? 0 0 "pg_ctl should start the temporary PostgreSQL cluster"
42+ LOG_INFO "Environmental preparation is over."
43+}
44+ 
45+function run_test() {
46+ LOG_INFO "Start executing testcase."
47+ su postgres -c "psql -d postgres -c \"CREATE ROLE ${role_name} LOGIN;\"" >/dev/null 2>&1
48+ CHECK_RESULT $? 0 0 "first CREATE ROLE for ${role_name} should succeed"
49+ 
50+ su postgres -c "psql -d postgres -c \"CREATE ROLE ${role_name} LOGIN;\"" >duplicate_role.log 2>&1
51+ CHECK_RESULT $? 0 1 "duplicate CREATE ROLE for ${role_name} should fail"
52+ grep -i "already exists" duplicate_role.log
53+ CHECK_RESULT $? 0 0 "duplicate role error should mention that ${role_name} already exists"
54+ 
55+ CHECK_RESULT "$(su postgres -c "psql -d postgres -Atqc \"SELECT count(*) FROM pg_roles WHERE rolname='${role_name}';\"")" 1 0 "role ${role_name} should exist exactly once"
56+ LOG_INFO "End of testcase execution."
57+}
58+ 
59+function post_test() {
60+ LOG_INFO "start environment cleanup."
61+ su postgres -c "psql -d postgres -c \"DROP ROLE IF EXISTS ${role_name};\"" >/dev/null 2>&1
62+ su postgres -c "/usr/bin/pg_ctl -D ${pg_data} -l ${pg_data}/logfile stop" >/dev/null 2>&1
63+ rm -rf "${pg_data}" duplicate_role.log
64+ # shellcheck disable=SC2119
65+ DNF_REMOVE
66+ if [ "${backup_firewalld_state}" = "active" ]; then
67+ systemctl enable firewalld >/dev/null 2>&1
68+ systemctl start firewalld >/dev/null 2>&1
69+ fi
70+ if [ "${backup_selinux_state}" = "Enforcing" ]; then
71+ command -v setenforce >/dev/null 2>&1 && setenforce 1 >/dev/null 2>&1
72+ fi
73+ export LANG=${OLD_LANG}
74+ LOG_INFO "Finish environment cleanup."
75+}
76+ 
77+main "$@"