cartodb-postgresql/test/CDB_Username.sql

25 lines
766 B
MySQL
Raw Normal View History

2019-02-20 17:38:00 +08:00
SELECT current_user; -- postgres
SELECT CDB_Username(); -- (NULL)
2019-02-20 20:34:11 +08:00
-- Add the role fulano with an api_key and connect with it
2019-02-20 17:38:00 +08:00
\set QUIET on
2019-02-20 20:34:11 +08:00
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;
2019-02-20 17:38:00 +08:00
\set QUIET off
2019-02-20 20:34:11 +08:00
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