From 6d122462bbe64b4b3e070f2311020f64bd8b7b76 Mon Sep 17 00:00:00 2001 From: Gonzalo Riestra Date: Wed, 20 Feb 2019 13:34:11 +0100 Subject: [PATCH] decouple tests from cartodb --- test/CDB_Username.sql | 29 ++++++++++++++++++----------- test/CDB_Username_expect | 3 ++- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/test/CDB_Username.sql b/test/CDB_Username.sql index 795f689..1d187e2 100644 --- a/test/CDB_Username.sql +++ b/test/CDB_Username.sql @@ -1,17 +1,24 @@ SELECT current_user; -- postgres SELECT CDB_Username(); -- (NULL) --- Connect with admin +-- Add the role fulano with an api_key and connect with it \set QUIET on -\o log/test.log -SELECT current_database() AS current_database; -\gset -SELECT SUBSTRING (:'current_database', 19, 36) AS user_id; -\gset -SELECT rolname AS admin_user FROM pg_roles where rolname LIKE ('%' || :'user_id'); -\gset -\c :current_database :admin_user -\o +CREATE ROLE fulano LOGIN; +GRANT USAGE ON SCHEMA cartodb TO fulano; +GRANT EXECUTE ON FUNCTION CDB_Username() TO fulano; +GRANT EXECUTE ON FUNCTION _CDB_Username(text) TO fulano; +INSERT INTO cdb_conf (key, value) VALUES ('api_keys_fulano', '{"username": "fulanito", "permissions":[]}'); +SET ROLE fulano; \set QUIET off -SELECT CDB_Username(); -- admin \ No newline at end of file +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 diff --git a/test/CDB_Username_expect b/test/CDB_Username_expect index 5336c89..fe1ea5b 100644 --- a/test/CDB_Username_expect +++ b/test/CDB_Username_expect @@ -1,3 +1,4 @@ postgres -admin +fulano +fulanito