提交 4d23ab19 编写于 作者: H Heikki Linnakangas

Move test case for dropping temp tables from TINC to main test suite.

上级 32453eb5
-- MPP-24237
-- Security definer function causes temp table not to be dropped due to pg_toast access privileges
CREATE or replace FUNCTION sec_definer_create_test() RETURNS void AS $$
BEGIN
RAISE NOTICE 'Creating table';
execute 'create temporary table wmt_toast_issue_temp (name varchar, address varchar) distributed randomly';
RAISE NOTICE 'Table created';
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;
create role sec_definer_role with login ;
NOTICE: resource queue required -- using default resource queue "pg_default"
grant execute on function sec_definer_create_test() to sec_definer_role;
set role sec_definer_role;
select sec_definer_create_test() ;
NOTICE: Creating table
NOTICE: Table created
sec_definer_create_test
-------------------------
(1 row)
-- There should be one temp table, the one we created (we assume that there are no
-- other backends using temp tables running at the same time).
select count(*) from pg_tables where schemaname like 'pg_temp%';
count
-------
1
(1 row)
-- Disconnect and reconnect.
\c regression
-- Check that the temporary table was dropped at disconnect.
select count(*) from pg_tables where schemaname like 'pg_temp%';
count
-------
0
(1 row)
-- Clean up
reset role;
drop function public.sec_definer_create_test();
drop role sec_definer_role;
......@@ -110,6 +110,10 @@ test: nested_case_null sort
test: bfv_cte bfv_joins bfv_subquery bfv_planner bfv_legacy
# This test gets confused if there are other connections, with temp tables,
# active at the same time.
test: bfv_temp
test: qp_olap_mdqa qp_misc
test: qp_misc_jiras qp_with_clause qp_executor qp_olap_windowerr qp_olap_window qp_derived_table qp_bitmapscan
......
-- MPP-24237
-- Security definer function causes temp table not to be dropped due to pg_toast access privileges
CREATE or replace FUNCTION sec_definer_create_test() RETURNS void AS $$
BEGIN
RAISE NOTICE 'Creating table';
execute 'create temporary table wmt_toast_issue_temp (name varchar, address varchar) distributed randomly';
RAISE NOTICE 'Table created';
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;
create role sec_definer_role with login ;
grant execute on function sec_definer_create_test() to sec_definer_role;
set role sec_definer_role;
select sec_definer_create_test() ;
-- There should be one temp table, the one we created (we assume that there are no
-- other backends using temp tables running at the same time).
select count(*) from pg_tables where schemaname like 'pg_temp%';
-- Disconnect and reconnect.
\c regression
-- Check that the temporary table was dropped at disconnect.
select count(*) from pg_tables where schemaname like 'pg_temp%';
-- Clean up
reset role;
drop function public.sec_definer_create_test();
drop role sec_definer_role;
drop FUNCTION sec_definer_create_test();
drop role sec_definer_role;
CREATE or replace FUNCTION sec_definer_create_test() RETURNS void AS $$
BEGIN
RAISE NOTICE 'Creating table'; BEGIN
execute 'create temporary table wmt_toast_issue_temp (name varchar, address varchar) distributed randomly';
END;
RAISE NOTICE 'Table created';
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;
CREATE FUNCTION
create role sec_definer_role with login ;
psql:/path/sql_file:1: NOTICE: resource queue required -- using default resource queue "pg_default"
CREATE ROLE
grant execute on function sec_definer_create_test() to sec_definer_role;
GRANT
set role sec_definer_role;
SET
select sec_definer_create_test() ;
psql:/path/sql_file:1: NOTICE: Creating table
psql:/path/sql_file:1: NOTICE: Table created
sec_definer_create_test
-------------------------
(1 row)
select count(*) from pg_tables where schemaname like 'pg_temp%';
count
-------
1
(1 row)
CREATE or replace FUNCTION sec_definer_create_test() RETURNS void AS $$
BEGIN
RAISE NOTICE 'Creating table'; BEGIN
execute 'create temporary table wmt_toast_issue_temp (name varchar, address varchar) distributed randomly';
END;
RAISE NOTICE 'Table created';
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;
create role sec_definer_role with login ;
grant execute on function sec_definer_create_test() to sec_definer_role;
set role sec_definer_role;
select sec_definer_create_test() ;
select count(*) from pg_tables where schemaname like 'pg_temp%';
"""
Copyright (C) 2004-2015 Pivotal Software, Inc. All rights reserved.
This program and the accompanying materials are made available under
the terms of the under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import tinctest
from mpp.models import MPPTestCase
from tinctest.lib import Gpdiff
from tinctest.lib import local_path, run_shell_command
from mpp.lib.PSQL import PSQL
class SecurityDefinerTestCase(MPPTestCase):
'''
@product_version gpdb: [4.2.8.2-4.2.99.99], [4.3.3-]
'''
def test_MPP24237(self):
cmd_cleanup = "psql -Atc \"select datname from pg_database where datname != \'template0\'\" | while read a; do echo \"check for ${a}\";psql -Atc \"select \'drop schema if exists \' || nspname || \' cascade;\' from (select nspname from pg_namespace where nspname like \'pg_temp%\' union select nspname from gp_dist_random(\'pg_namespace\') where nspname like \'pg_temp%\' except select \'pg_temp_\' || sess_id::varchar from pg_stat_activity) as foo\" ${a}; done"
res = {'rc':0, 'stderr':'', 'stdout':''}
run_shell_command(cmd_cleanup, 'do_clean', res)
if res['rc'] > 0:
raise Exception("Failed to do cleanup %s" %res[stderr])
PSQL.run_sql_file(local_path('pre_script.sql'), out_file=local_path('pre_script.out'))
self.assertTrue(Gpdiff.are_files_equal(local_path('pre_script.out'), local_path('pre_script.ans')))
cmd = "select count(*) from pg_tables where schemaname like 'pg_temp%';"
out = PSQL.run_sql_command(cmd, flags ='-q -t')
if int(out) != 0:
tinctest.logger.info("temp tables found")
tinctest.logger.info(PSQL.run_sql_command("select * from pg_tables where schemaname like 'pg_temp%';"))
self.fail("temp tables were found")
PSQL.run_sql_file(local_path('clean_script.sql'))
PSQL.run_sql_file(local_path('clean_script.sql'))
run_shell_command(cmd_cleanup, 'do_clean', res)
if res['rc'] > 0:
raise Exception("Failed to do cleanup %s" %res[stderr])
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册