1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
CREATE FUNCTION start() RETURNS void AS
$$
pljs.elog(NOTICE, 'start function executed');
pljs.current_scope = {
"name": "current_scope"
};
$$ LANGUAGE pljs;
SET pljs.start_proc = 'start';
DO $$ pljs.elog(NOTICE, pljs.current_scope.name); $$ language pljs;
NOTICE: start function executed
NOTICE: current_scope
-- setting a start proc after the context is created should change do anything
SET pljs.start_proc = 'end';
DO $$ pljs.elog(NOTICE, pljs.current_scope.name); $$ language pljs;
NOTICE: current_scope
-- a missing start proc should cause an error
-- force the creation of a new context
CREATE ROLE new_context;
SET ROLE new_context;
SET pljs.start_proc = 'end';
DO $$ pljs.elog(NOTICE, pljs.current_scope.name); $$ language pljs;
WARNING: failed to find pljs function function "end" does not exist:
ERROR: execution error
DETAIL: TypeError: cannot read property 'name' of undefined
at <anonymous> (<function>:1:52)
at <eval> (<function>:1:62)
RESET ROLE;
DROP ROLE new_context;
-- reset the start_proc
SET pljs.start_proc = '';
DROP FUNCTION start;
-- test startup permissions failure
CREATE FUNCTION start() RETURNS void AS $$ pljs.elog(NOTICE, 'nope'); $$ LANGUAGE pljs;
CREATE ROLE someone_else;
REVOKE EXECUTE ON FUNCTION start() FROM public;
SET pljs.start_proc = 'start';
REVOKE EXECUTE ON FUNCTION start() FROM public;
SET ROLE TO someone_else;
DO $$ pljs.elog(NOTICE, 'hello') $$ LANGUAGE pljs;
WARNING: failed to find or no permission for js function start
NOTICE: hello
RESET ROLE;
DROP ROLE someone_else;
RESET pljs.start_proc;
DROP FUNCTION start;
|