decouple tests from cartodb

This commit is contained in:
Gonzalo Riestra
2019-02-20 13:34:11 +01:00
parent ffaf5e4400
commit 6d122462bb
2 changed files with 20 additions and 12 deletions
+18 -11
View File
@@ -1,17 +1,24 @@
SELECT current_user; -- postgres SELECT current_user; -- postgres
SELECT CDB_Username(); -- (NULL) SELECT CDB_Username(); -- (NULL)
-- Connect with admin -- Add the role fulano with an api_key and connect with it
\set QUIET on \set QUIET on
\o log/test.log CREATE ROLE fulano LOGIN;
SELECT current_database() AS current_database; GRANT USAGE ON SCHEMA cartodb TO fulano;
\gset GRANT EXECUTE ON FUNCTION CDB_Username() TO fulano;
SELECT SUBSTRING (:'current_database', 19, 36) AS user_id; GRANT EXECUTE ON FUNCTION _CDB_Username(text) TO fulano;
\gset INSERT INTO cdb_conf (key, value) VALUES ('api_keys_fulano', '{"username": "fulanito", "permissions":[]}');
SELECT rolname AS admin_user FROM pg_roles where rolname LIKE ('%' || :'user_id'); SET ROLE fulano;
\gset
\c :current_database :admin_user
\o
\set QUIET off \set QUIET off
SELECT CDB_Username(); -- admin SELECT current_user; -- fulano
SELECT CDB_Username(); -- fulanito
-- Remove fulano
\set QUIET on
SET ROLE postgres;
REVOKE USAGE ON SCHEMA cartodb FROM fulano;
REVOKE EXECUTE ON FUNCTION CDB_Username() FROM fulano;
REVOKE EXECUTE ON FUNCTION _CDB_Username(text) FROM fulano;
DROP ROLE fulano;
\set QUIET off
+2 -1
View File
@@ -1,3 +1,4 @@
postgres postgres
admin fulano
fulanito