2017-10-04 22:38:54 +08:00
|
|
|
\set VERBOSITY terse
|
2016-12-14 19:53:51 +08:00
|
|
|
SET client_min_messages TO warning;
|
2016-12-14 19:39:56 +08:00
|
|
|
SET search_path TO public,cartodb,cdb_dataservices_client;
|
|
|
|
|
2016-12-14 19:53:51 +08:00
|
|
|
-- Mock the server functions to raise exceptions
|
2018-09-10 18:54:37 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_street_point (username text, orgname text, searchtext text, city text DEFAULT NULL, state_province text DEFAULT NULL, country text DEFAULT NULL)
|
2016-12-14 19:39:56 +08:00
|
|
|
RETURNS Geometry AS $$
|
|
|
|
BEGIN
|
|
|
|
RAISE EXCEPTION 'Not enough quota or any other exception whatsoever.';
|
|
|
|
RETURN NULL;
|
|
|
|
END;
|
|
|
|
$$ LANGUAGE 'plpgsql';
|
|
|
|
|
2018-09-10 18:54:37 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_isodistance(username text, orgname text, source geometry, mode text, range integer[], options text[] DEFAULT ARRAY[]::text[])
|
2016-12-14 19:53:51 +08:00
|
|
|
RETURNS SETOF isoline AS $$
|
|
|
|
BEGIN
|
|
|
|
RAISE EXCEPTION 'Not enough quota or any other exception whatsoever.';
|
|
|
|
END;
|
|
|
|
$$ LANGUAGE 'plpgsql';
|
|
|
|
|
2018-09-10 18:54:37 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_route_point_to_point (username text, orgname text, origin geometry(Point, 4326), destination geometry(Point, 4326), mode TEXT, options text[] DEFAULT ARRAY[]::text[], units text DEFAULT 'kilometers')
|
2016-12-14 19:57:51 +08:00
|
|
|
RETURNS cdb_dataservices_client.simple_route AS $$
|
|
|
|
DECLARE
|
|
|
|
ret cdb_dataservices_client.simple_route;
|
|
|
|
BEGIN
|
|
|
|
RAISE EXCEPTION 'Not enough quota or any other exception whatsoever.';
|
|
|
|
|
|
|
|
-- This code shall never be reached
|
|
|
|
SELECT NULL, 5.33, 100 INTO ret;
|
|
|
|
RETURN ret;
|
|
|
|
END;
|
|
|
|
$$ LANGUAGE 'plpgsql';
|
|
|
|
|
|
|
|
|
2018-09-06 22:40:05 +08:00
|
|
|
-- Exercise the exception safe and the proxied functions
|
2016-12-14 19:53:51 +08:00
|
|
|
|
2018-09-06 22:40:05 +08:00
|
|
|
-- No permissions granted
|
|
|
|
SET ROLE test_regular_user; -- Use regular user role
|
|
|
|
SELECT _cdb_geocode_street_point_exception_safe('One street, 1');
|
|
|
|
SELECT * FROM _cdb_isodistance_exception_safe('POINT(-3.70568 40.42028)'::geometry, 'walk', ARRAY[300]::integer[]);
|
|
|
|
SELECT * FROM _cdb_route_point_to_point_exception_safe('POINT(-3.70237112 40.41706163)'::geometry,'POINT(-3.69909883 40.41236875)'::geometry, 'car', ARRAY['mode_type=shortest']::text[]);
|
2016-12-14 19:39:56 +08:00
|
|
|
|
2018-09-06 22:40:05 +08:00
|
|
|
-- No permissions granted but conf created
|
|
|
|
SET ROLE postgres;
|
2018-09-10 19:47:35 +08:00
|
|
|
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"permissions": []}');
|
2018-09-06 22:40:05 +08:00
|
|
|
SET ROLE test_regular_user; -- Use regular user role
|
2016-12-14 19:39:56 +08:00
|
|
|
SELECT _cdb_geocode_street_point_exception_safe('One street, 1');
|
2016-12-14 20:30:28 +08:00
|
|
|
SELECT * FROM _cdb_isodistance_exception_safe('POINT(-3.70568 40.42028)'::geometry, 'walk', ARRAY[300]::integer[]);
|
|
|
|
SELECT * FROM _cdb_route_point_to_point_exception_safe('POINT(-3.70237112 40.41706163)'::geometry,'POINT(-3.69909883 40.41236875)'::geometry, 'car', ARRAY['mode_type=shortest']::text[]);
|
2018-09-06 22:40:05 +08:00
|
|
|
|
|
|
|
-- Grant geocoding permissions
|
|
|
|
SET ROLE postgres;
|
2018-09-10 19:40:15 +08:00
|
|
|
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"permissions": ["geocoding", "routing", "isolines"]}');
|
2018-09-06 22:40:05 +08:00
|
|
|
SET ROLE test_regular_user; -- Use regular user role
|
|
|
|
SELECT _cdb_geocode_street_point_exception_safe('One street, 1');
|
|
|
|
SELECT * FROM _cdb_isodistance_exception_safe('POINT(-3.70568 40.42028)'::geometry, 'walk', ARRAY[300]::integer[]);
|
|
|
|
SELECT * FROM _cdb_route_point_to_point_exception_safe('POINT(-3.70237112 40.41706163)'::geometry,'POINT(-3.69909883 40.41236875)'::geometry, 'car', ARRAY['mode_type=shortest']::text[]);
|
|
|
|
|
|
|
|
-- Remove permissions
|
|
|
|
SET ROLE postgres;
|
|
|
|
SELECT CDB_Conf_RemoveConf('api_keys_postgres');
|