Added tests

This commit is contained in:
Mario de Frutos Dieguez 2019-07-03 18:00:57 +02:00
parent fe66b2865a
commit f4be59cae0
No known key found for this signature in database
GPG Key ID: C9738009A2E89223
3 changed files with 64 additions and 1 deletions

View File

@ -1,5 +1,5 @@
-- Function that reassign the owner of a table to their ownership_role
CREATE OR REPLACE FUNCTION @extschema.CDB_OAuthReassignTableOwnerOnCreation()
CREATE OR REPLACE FUNCTION @extschema@.CDB_OAuthReassignTableOwnerOnCreation()
RETURNS event_trigger
SECURITY DEFINER
AS $$

48
test/CDB_OAuth.sql Normal file
View File

@ -0,0 +1,48 @@
-- Create user and enable OAuth event trigger
\set QUIET on
SET client_min_messages TO error;
CREATE ROLE "creator_role" LOGIN;
CREATE ROLE "ownership_role" LOGIN;
GRANT ALL ON SCHEMA cartodb TO "creator_role";
SELECT CDB_Conf_SetConf('api_keys_creator_role', '{"username": "creator_role", "permissions":[], "ownership_role_name": "ownership_role"}');
SET SESSION AUTHORIZATION "creator_role";
SET client_min_messages TO notice;
\set QUIET off
CREATE TABLE test(id INT);
INSERT INTO test VALUES(1);
SELECT * FROM test;
\set QUIET on
SET SESSION AUTHORIZATION "ownership_role";
\set QUIET off
SELECT * FROM test2;
\set QUIET on
SET SESSION AUTHORIZATION postgres;
SELECT CDB_EnableOAuthReassignTablesTrigger();
SET SESSION AUTHORIZATION "creator_role";
\set QUIET off
CREATE TABLE test2(id INT);
INSERT INTO test2 VALUES(1);
SELECT * FROM test2;
\set QUIET on
SET SESSION AUTHORIZATION "ownership_role";
\set QUIET off
SELECT * FROM test2;
-- Cleanup
\set QUIET on
SET SESSION AUTHORIZATION postgres;
SELECT CDB_DisableOAuthReassignTablesTrigger();
DROP TABLE test;
DROP TABLE test2;
DROP ROLE "ownership_role";
REVOKE ALL ON SCHEMA cartodb FROM "creator_role";
DROP ROLE "creator_role";
DELETE FROM cdb_conf WHERE key = 'api_keys_creator_role';
\set QUIET off

15
test/CDB_OAuth_expect Normal file
View File

@ -0,0 +1,15 @@
\set ECHO none
CREATE TABLE
INSERT 0 1
1
ERROR: relation "test2" does not exist
LINE 1: SELECT * FROM test2;
^
NOTICE: event trigger "oauth_reassign_tables_trigger" does not exist, skipping
CREATE TABLE
INSERT 0 1
1
1