Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ac9100f

Browse files
committed
More regression tests for LEAKPROOF/NOT LEAKPROOF stuff.
Along the way, move create_function_3 into a parallel schedule. KaiGai Kohei
1 parent 73a4b99 commit ac9100f

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

src/test/regress/expected/create_function_3.out

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
--
44
-- sanity check of pg_proc catalog to the given parameters
55
--
6+
CREATE USER regtest_unpriv_user;
67
CREATE SCHEMA temp_func_test;
8+
GRANT ALL ON SCHEMA temp_func_test TO public;
79
SET search_path TO temp_func_test, public;
810
--
911
-- ARGUMENT and RETURN TYPES
@@ -125,6 +127,28 @@ SELECT proname, proleakproof FROM pg_proc
125127
functext_e_2 | t
126128
(2 rows)
127129

130+
ALTER FUNCTION functext_E_2(int) NOT LEAKPROOF; -- remove leakproog attribute
131+
SELECT proname, proleakproof FROM pg_proc
132+
WHERE oid in ('functext_E_1'::regproc,
133+
'functext_E_2'::regproc) ORDER BY proname;
134+
proname | proleakproof
135+
--------------+--------------
136+
functext_e_1 | t
137+
functext_e_2 | f
138+
(2 rows)
139+
140+
-- it takes superuser privilege to turn on leakproof, but not for turn off
141+
ALTER FUNCTION functext_E_1(int) OWNER TO regtest_unpriv_user;
142+
ALTER FUNCTION functext_E_2(int) OWNER TO regtest_unpriv_user;
143+
SET SESSION AUTHORIZATION regtest_unpriv_user;
144+
SET search_path TO temp_func_test, public;
145+
ALTER FUNCTION functext_E_1(int) NOT LEAKPROOF;
146+
ALTER FUNCTION functext_E_2(int) LEAKPROOF;
147+
ERROR: only superuser can define a leakproof function
148+
CREATE FUNCTION functext_E_3(int) RETURNS bool LANGUAGE 'sql'
149+
LEAKPROOF AS 'SELECT $1 < 200'; -- failed
150+
ERROR: only superuser can define a leakproof function
151+
RESET SESSION AUTHORIZATION;
128152
-- list of built-in leakproof functions
129153
SELECT proname, prorettype::regtype, proargtypes::regtype[]
130154
FROM pg_proc JOIN pg_namespace ON pronamespace = pg_namespace.oid
@@ -420,4 +444,5 @@ drop cascades to function functext_f_1(integer)
420444
drop cascades to function functext_f_2(integer)
421445
drop cascades to function functext_f_3(integer)
422446
drop cascades to function functext_f_4(integer)
447+
DROP USER regtest_unpriv_user;
423448
RESET search_path;

src/test/regress/parallel_schedule

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ test: create_function_1
4040
test: create_type
4141
test: create_table
4242
test: create_function_2
43-
test: create_function_3
4443

4544
# ----------
4645
# Load huge amounts of data
@@ -60,7 +59,7 @@ test: create_index create_view
6059
# ----------
6160
# Another group of parallel tests
6261
# ----------
63-
test: create_aggregate create_cast constraints triggers inherit create_table_like typed_table vacuum drop_if_exists
62+
test: create_aggregate create_function_3 create_cast constraints triggers inherit create_table_like typed_table vacuum drop_if_exists
6463

6564
# ----------
6665
# sanity_check does a vacuum, affecting the sort order of SELECT *

src/test/regress/sql/create_function_3.sql

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
--
44
-- sanity check of pg_proc catalog to the given parameters
55
--
6+
CREATE USER regtest_unpriv_user;
7+
68
CREATE SCHEMA temp_func_test;
9+
GRANT ALL ON SCHEMA temp_func_test TO public;
710

811
SET search_path TO temp_func_test, public;
912

@@ -85,6 +88,25 @@ SELECT proname, proleakproof FROM pg_proc
8588
WHERE oid in ('functext_E_1'::regproc,
8689
'functext_E_2'::regproc) ORDER BY proname;
8790

91+
ALTER FUNCTION functext_E_2(int) NOT LEAKPROOF; -- remove leakproog attribute
92+
SELECT proname, proleakproof FROM pg_proc
93+
WHERE oid in ('functext_E_1'::regproc,
94+
'functext_E_2'::regproc) ORDER BY proname;
95+
96+
-- it takes superuser privilege to turn on leakproof, but not for turn off
97+
ALTER FUNCTION functext_E_1(int) OWNER TO regtest_unpriv_user;
98+
ALTER FUNCTION functext_E_2(int) OWNER TO regtest_unpriv_user;
99+
100+
SET SESSION AUTHORIZATION regtest_unpriv_user;
101+
SET search_path TO temp_func_test, public;
102+
ALTER FUNCTION functext_E_1(int) NOT LEAKPROOF;
103+
ALTER FUNCTION functext_E_2(int) LEAKPROOF;
104+
105+
CREATE FUNCTION functext_E_3(int) RETURNS bool LANGUAGE 'sql'
106+
LEAKPROOF AS 'SELECT $1 < 200'; -- failed
107+
108+
RESET SESSION AUTHORIZATION;
109+
88110
-- list of built-in leakproof functions
89111
SELECT proname, prorettype::regtype, proargtypes::regtype[]
90112
FROM pg_proc JOIN pg_namespace ON pronamespace = pg_namespace.oid
@@ -118,4 +140,5 @@ SELECT proname, proisstrict FROM pg_proc
118140

119141
-- Cleanups
120142
DROP SCHEMA temp_func_test CASCADE;
143+
DROP USER regtest_unpriv_user;
121144
RESET search_path;

0 commit comments

Comments
 (0)