diff --git a/client/.gitignore b/client/.gitignore index 093944e..cf79682 100644 --- a/client/.gitignore +++ b/client/.gitignore @@ -1,4 +1,8 @@ results/ regression.diffs regression.out -cdb_geocoder_client--* +20_public_functions.sql +30_plproxy_functions.sql +90_grant_execute.sql +cdb_geocoder_client--0.0.1.sql +cdb_geocoder_client--0.1.0.sql diff --git a/client/Makefile b/client/Makefile index 910e347..ee0cc6a 100644 --- a/client/Makefile +++ b/client/Makefile @@ -2,22 +2,12 @@ # Once a version is released, it is not meant to be changed. E.g: once version 0.0.1 is out, it SHALL NOT be changed. EXTENSION = cdb_geocoder_client EXTVERSION = $(shell grep default_version $(EXTENSION).control | sed -e "s/default_version[[:space:]]*=[[:space:]]*'\([^']*\)'/\1/") -SED = sed -UPGRADABLE = \ - 0.0.1 \ - $(END) +DATA = $(EXTENSION)--$(EXTVERSION).sql -UPGRADES = \ - $(shell echo $(UPGRADABLE) | \ - $(SED) 's/^/$(EXTENSION)--/' | \ - $(SED) 's/$$/--$(EXTVERSION).sql/' | \ - $(SED) 's/ /--$(EXTVERSION).sql $(EXTENSION)--/g') - -DATA = $(EXTENSION)--$(EXTVERSION).sql \ - $(UPGRADES) - -REGRESS = $(notdir $(basename $(wildcard sql/*test.sql))) +REGRESS = $(notdir $(basename $(wildcard test/$(EXTVERSION)/sql/*test.sql))) +TEST_DIR = test/$(EXTVERSION) +REGRESS_OPTS = --inputdir='$(TEST_DIR)' --outputdir='$(TEST_DIR)' # postgres build stuff PG_CONFIG = pg_config @@ -28,7 +18,7 @@ SOURCES_DATA_DIR = sql/$(EXTVERSION) # The interface definition is used along with some templates to automatically generate code RENDERER = ../sql-template-renderer -INTERFACE_FILE = ../interface.yaml +INTERFACE_FILE = ../interface_$(EXTVERSION).yaml TEMPLATE_DIR = templates TEMPLATE_FILES = $(wildcard $(TEMPLATE_DIR)/*.erb) GENERATED_SQL_FILES = $(patsubst $(TEMPLATE_DIR)/%.erb, $(SOURCES_DATA_DIR)/%.sql, $(TEMPLATE_FILES)) diff --git a/client/cdb_geocoder_client--0.0.1--0.1.0.sql b/client/cdb_geocoder_client--0.0.1--0.1.0.sql new file mode 100644 index 0000000..a4503cf --- /dev/null +++ b/client/cdb_geocoder_client--0.0.1--0.1.0.sql @@ -0,0 +1,27 @@ +CREATE OR REPLACE FUNCTION cdb_geocoder_client.cdb_geocode_street_point_v2 (searchtext text, city text DEFAULT NULL, state_province text DEFAULT NULL, country text DEFAULT NULL) +RETURNS Geometry AS $$ +DECLARE + ret Geometry; + username text; + orgname text; +BEGIN + IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN + RAISE EXCEPTION 'The api_key must be provided'; + END IF; + SELECT u, o INTO username, orgname FROM _cdb_entity_config() AS (u text, o text); + -- JSON value stored "" is taken as literal + IF username IS NULL OR username = '' OR username = '""' THEN + RAISE EXCEPTION 'Username is a mandatory argument, check it out'; + END IF; + SELECT cdb_geocoder_client._cdb_geocode_street_point_v2(username, orgname, searchtext, city, state_province, country) INTO ret; + RETURN ret; +END; +$$ LANGUAGE 'plpgsql' SECURITY DEFINER; + +CREATE OR REPLACE FUNCTION cdb_geocoder_client._cdb_geocode_street_point_v2 (username text, organization_name text, searchtext text, city text DEFAULT NULL, state_province text DEFAULT NULL, country text DEFAULT NULL) +RETURNS Geometry AS $$ + CONNECT cdb_geocoder_client._server_conn_str(); + SELECT cdb_geocoder_server.cdb_geocode_street_point_v2 (username, organization_name, searchtext, city, state_province, country); +$$ LANGUAGE plproxy; + +GRANT EXECUTE ON FUNCTION cdb_geocoder_client.cdb_geocode_street_point_v2(searchtext text, city text, state_province text, country text) TO publicuser; \ No newline at end of file diff --git a/client/cdb_geocoder_client--0.1.0--0.0.1.sql b/client/cdb_geocoder_client--0.1.0--0.0.1.sql new file mode 100644 index 0000000..b634d2f --- /dev/null +++ b/client/cdb_geocoder_client--0.1.0--0.0.1.sql @@ -0,0 +1,2 @@ +DROP FUNCTION IF EXISTS cdb_geocoder_client.cdb_geocode_street_point_v2 (text, text, text, text) +DROP FUNCTION IF EXISTS cdb_geocoder_client._cdb_geocode_street_point_v2 (text, text, text, text) \ No newline at end of file diff --git a/client/sql/0.0.1/.gitignore b/client/sql/0.0.1/.gitignore deleted file mode 100644 index 4cf1e95..0000000 --- a/client/sql/0.0.1/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -20_public_functions.sql -30_plproxy_functions.sql -90_grant_execute.sql diff --git a/client/sql/0.1.0/00_header.sql b/client/sql/0.1.0/00_header.sql new file mode 100644 index 0000000..a140c33 --- /dev/null +++ b/client/sql/0.1.0/00_header.sql @@ -0,0 +1,2 @@ +-- Complain if script is sourced in psql, rather than via CREATE EXTENSION +\echo Use "CREATE EXTENSION cdb_geocoder_client" to load this file. \quit diff --git a/client/sql/0.1.0/10_geocoder_server_conn.sql b/client/sql/0.1.0/10_geocoder_server_conn.sql new file mode 100644 index 0000000..5f3e1fc --- /dev/null +++ b/client/sql/0.1.0/10_geocoder_server_conn.sql @@ -0,0 +1,16 @@ +-- +-- Geocoder server connection config +-- +-- The purpose of this function is provide to the PL/Proxy functions +-- the connection string needed to connect with the server + +CREATE OR REPLACE FUNCTION cdb_geocoder_client._server_conn_str() +RETURNS text AS $$ +DECLARE + db_connection_str text; +BEGIN + SELECT cartodb.cdb_conf_getconf('geocoder_server_config')->'connection_str' INTO db_connection_str; + SELECT trim(both '"' FROM db_connection_str) INTO db_connection_str; + RETURN db_connection_str; +END; +$$ LANGUAGE 'plpgsql'; \ No newline at end of file diff --git a/client/sql/0.1.0/15_config_management.sql b/client/sql/0.1.0/15_config_management.sql new file mode 100644 index 0000000..6ff3c8d --- /dev/null +++ b/client/sql/0.1.0/15_config_management.sql @@ -0,0 +1,37 @@ +CREATE TYPE cdb_geocoder_client._entity_config AS ( + username text, + organization_name text +); + +-- +-- Get entity config function +-- +-- The purpose of this function is to retrieve the username and organization name from +-- a) schema where he/her is the owner in case is an organization user +-- b) entity_name from the cdb_conf database in case is a non organization user +CREATE OR REPLACE FUNCTION cdb_geocoder_client._cdb_entity_config() +RETURNS record AS $$ +DECLARE + result cdb_geocoder_client._entity_config; + is_organization boolean; + username text; + organization_name text; +BEGIN + SELECT cartodb.cdb_conf_getconf('user_config')->'is_organization' INTO is_organization; + IF is_organization IS NULL THEN + RAISE EXCEPTION 'User must have user configuration in the config table'; + ELSIF is_organization = TRUE THEN + SELECT nspname + FROM pg_namespace s + LEFT JOIN pg_roles r ON s.nspowner = r.oid + WHERE r.rolname = session_user INTO username; + SELECT cartodb.cdb_conf_getconf('user_config')->'entity_name' INTO organization_name; + ELSE + SELECT cartodb.cdb_conf_getconf('user_config')->'entity_name' INTO username; + organization_name = NULL; + END IF; + result.username = username; + result.organization_name = organization_name; + RETURN result; +END; +$$ LANGUAGE 'plpgsql' SECURITY DEFINER; \ No newline at end of file diff --git a/client/sql/0.1.0/20_public_functions.sql b/client/sql/0.1.0/20_public_functions.sql deleted file mode 100644 index ff5af39..0000000 --- a/client/sql/0.1.0/20_public_functions.sql +++ /dev/null @@ -1,260 +0,0 @@ --- --- Public geocoder API function --- --- These are the only ones with permissions to publicuser role --- and should also be the only ones with SECURITY DEFINER - -CREATE OR REPLACE FUNCTION cdb_geocoder_client.cdb_geocode_admin0_polygon (country_name text) -RETURNS Geometry AS $$ -DECLARE - ret Geometry; - username text; - orgname text; -BEGIN - IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN - RAISE EXCEPTION 'The api_key must be provided'; - END IF; - SELECT u, o INTO username, orgname FROM _cdb_entity_config() AS (u text, o text); - -- JSON value stored "" is taken as literal - IF username IS NULL OR username = '' OR username = '""' THEN - RAISE EXCEPTION 'Username is a mandatory argument, check it out'; - END IF; - SELECT cdb_geocoder_client._cdb_geocode_admin0_polygon(username, orgname, country_name) INTO ret; - RETURN ret; -END; -$$ LANGUAGE 'plpgsql' SECURITY DEFINER; - --- --- Public geocoder API function --- --- These are the only ones with permissions to publicuser role --- and should also be the only ones with SECURITY DEFINER - -CREATE OR REPLACE FUNCTION cdb_geocoder_client.cdb_geocode_admin1_polygon (admin1_name text) -RETURNS Geometry AS $$ -DECLARE - ret Geometry; - username text; - orgname text; -BEGIN - IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN - RAISE EXCEPTION 'The api_key must be provided'; - END IF; - SELECT u, o INTO username, orgname FROM _cdb_entity_config() AS (u text, o text); - -- JSON value stored "" is taken as literal - IF username IS NULL OR username = '' OR username = '""' THEN - RAISE EXCEPTION 'Username is a mandatory argument, check it out'; - END IF; - SELECT cdb_geocoder_client._cdb_geocode_admin1_polygon(username, orgname, admin1_name) INTO ret; - RETURN ret; -END; -$$ LANGUAGE 'plpgsql' SECURITY DEFINER; - --- --- Public geocoder API function --- --- These are the only ones with permissions to publicuser role --- and should also be the only ones with SECURITY DEFINER - -CREATE OR REPLACE FUNCTION cdb_geocoder_client.cdb_geocode_admin1_polygon (admin1_name text, country_name text) -RETURNS Geometry AS $$ -DECLARE - ret Geometry; - username text; - orgname text; -BEGIN - IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN - RAISE EXCEPTION 'The api_key must be provided'; - END IF; - SELECT u, o INTO username, orgname FROM _cdb_entity_config() AS (u text, o text); - -- JSON value stored "" is taken as literal - IF username IS NULL OR username = '' OR username = '""' THEN - RAISE EXCEPTION 'Username is a mandatory argument, check it out'; - END IF; - SELECT cdb_geocoder_client._cdb_geocode_admin1_polygon(username, orgname, admin1_name, country_name) INTO ret; - RETURN ret; -END; -$$ LANGUAGE 'plpgsql' SECURITY DEFINER; - --- --- Public geocoder API function --- --- These are the only ones with permissions to publicuser role --- and should also be the only ones with SECURITY DEFINER - -CREATE OR REPLACE FUNCTION cdb_geocoder_client.cdb_geocode_namedplace_point (city_name text) -RETURNS Geometry AS $$ -DECLARE - ret Geometry; - username text; - orgname text; -BEGIN - IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN - RAISE EXCEPTION 'The api_key must be provided'; - END IF; - SELECT u, o INTO username, orgname FROM _cdb_entity_config() AS (u text, o text); - -- JSON value stored "" is taken as literal - IF username IS NULL OR username = '' OR username = '""' THEN - RAISE EXCEPTION 'Username is a mandatory argument, check it out'; - END IF; - SELECT cdb_geocoder_client._cdb_geocode_namedplace_point(username, orgname, city_name) INTO ret; - RETURN ret; -END; -$$ LANGUAGE 'plpgsql' SECURITY DEFINER; - --- --- Public geocoder API function --- --- These are the only ones with permissions to publicuser role --- and should also be the only ones with SECURITY DEFINER - -CREATE OR REPLACE FUNCTION cdb_geocoder_client.cdb_geocode_namedplace_point (city_name text, country_name text) -RETURNS Geometry AS $$ -DECLARE - ret Geometry; - username text; - orgname text; -BEGIN - IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN - RAISE EXCEPTION 'The api_key must be provided'; - END IF; - SELECT u, o INTO username, orgname FROM _cdb_entity_config() AS (u text, o text); - -- JSON value stored "" is taken as literal - IF username IS NULL OR username = '' OR username = '""' THEN - RAISE EXCEPTION 'Username is a mandatory argument, check it out'; - END IF; - SELECT cdb_geocoder_client._cdb_geocode_namedplace_point(username, orgname, city_name, country_name) INTO ret; - RETURN ret; -END; -$$ LANGUAGE 'plpgsql' SECURITY DEFINER; - --- --- Public geocoder API function --- --- These are the only ones with permissions to publicuser role --- and should also be the only ones with SECURITY DEFINER - -CREATE OR REPLACE FUNCTION cdb_geocoder_client.cdb_geocode_namedplace_point (city_name text, admin1_name text, country_name text) -RETURNS Geometry AS $$ -DECLARE - ret Geometry; - username text; - orgname text; -BEGIN - IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN - RAISE EXCEPTION 'The api_key must be provided'; - END IF; - SELECT u, o INTO username, orgname FROM _cdb_entity_config() AS (u text, o text); - -- JSON value stored "" is taken as literal - IF username IS NULL OR username = '' OR username = '""' THEN - RAISE EXCEPTION 'Username is a mandatory argument, check it out'; - END IF; - SELECT cdb_geocoder_client._cdb_geocode_namedplace_point(username, orgname, city_name, admin1_name, country_name) INTO ret; - RETURN ret; -END; -$$ LANGUAGE 'plpgsql' SECURITY DEFINER; - --- --- Public geocoder API function --- --- These are the only ones with permissions to publicuser role --- and should also be the only ones with SECURITY DEFINER - -CREATE OR REPLACE FUNCTION cdb_geocoder_client.cdb_geocode_postalcode_polygon (postal_code text, country_name text) -RETURNS Geometry AS $$ -DECLARE - ret Geometry; - username text; - orgname text; -BEGIN - IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN - RAISE EXCEPTION 'The api_key must be provided'; - END IF; - SELECT u, o INTO username, orgname FROM _cdb_entity_config() AS (u text, o text); - -- JSON value stored "" is taken as literal - IF username IS NULL OR username = '' OR username = '""' THEN - RAISE EXCEPTION 'Username is a mandatory argument, check it out'; - END IF; - SELECT cdb_geocoder_client._cdb_geocode_postalcode_polygon(username, orgname, postal_code, country_name) INTO ret; - RETURN ret; -END; -$$ LANGUAGE 'plpgsql' SECURITY DEFINER; - --- --- Public geocoder API function --- --- These are the only ones with permissions to publicuser role --- and should also be the only ones with SECURITY DEFINER - -CREATE OR REPLACE FUNCTION cdb_geocoder_client.cdb_geocode_postalcode_point (postal_code text, country_name text) -RETURNS Geometry AS $$ -DECLARE - ret Geometry; - username text; - orgname text; -BEGIN - IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN - RAISE EXCEPTION 'The api_key must be provided'; - END IF; - SELECT u, o INTO username, orgname FROM _cdb_entity_config() AS (u text, o text); - -- JSON value stored "" is taken as literal - IF username IS NULL OR username = '' OR username = '""' THEN - RAISE EXCEPTION 'Username is a mandatory argument, check it out'; - END IF; - SELECT cdb_geocoder_client._cdb_geocode_postalcode_point(username, orgname, postal_code, country_name) INTO ret; - RETURN ret; -END; -$$ LANGUAGE 'plpgsql' SECURITY DEFINER; - --- --- Public geocoder API function --- --- These are the only ones with permissions to publicuser role --- and should also be the only ones with SECURITY DEFINER - -CREATE OR REPLACE FUNCTION cdb_geocoder_client.cdb_geocode_ipaddress_point (ip_address text) -RETURNS Geometry AS $$ -DECLARE - ret Geometry; - username text; - orgname text; -BEGIN - IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN - RAISE EXCEPTION 'The api_key must be provided'; - END IF; - SELECT u, o INTO username, orgname FROM _cdb_entity_config() AS (u text, o text); - -- JSON value stored "" is taken as literal - IF username IS NULL OR username = '' OR username = '""' THEN - RAISE EXCEPTION 'Username is a mandatory argument, check it out'; - END IF; - SELECT cdb_geocoder_client._cdb_geocode_ipaddress_point(username, orgname, ip_address) INTO ret; - RETURN ret; -END; -$$ LANGUAGE 'plpgsql' SECURITY DEFINER; - --- --- Public geocoder API function --- --- These are the only ones with permissions to publicuser role --- and should also be the only ones with SECURITY DEFINER - -CREATE OR REPLACE FUNCTION cdb_geocoder_client.cdb_geocode_street_point (searchtext text, city text DEFAULT NULL, state_province text DEFAULT NULL, country text DEFAULT NULL) -RETURNS Geometry AS $$ -DECLARE - ret Geometry; - username text; - orgname text; -BEGIN - IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN - RAISE EXCEPTION 'The api_key must be provided'; - END IF; - SELECT u, o INTO username, orgname FROM _cdb_entity_config() AS (u text, o text); - -- JSON value stored "" is taken as literal - IF username IS NULL OR username = '' OR username = '""' THEN - RAISE EXCEPTION 'Username is a mandatory argument, check it out'; - END IF; - SELECT cdb_geocoder_client._cdb_geocode_street_point(username, orgname, searchtext, city, state_province, country) INTO ret; - RETURN ret; -END; -$$ LANGUAGE 'plpgsql' SECURITY DEFINER; - diff --git a/client/sql/0.1.0/30_plproxy_functions.sql b/client/sql/0.1.0/30_plproxy_functions.sql deleted file mode 100644 index d87b1b9..0000000 --- a/client/sql/0.1.0/30_plproxy_functions.sql +++ /dev/null @@ -1,60 +0,0 @@ -CREATE OR REPLACE FUNCTION cdb_geocoder_client._cdb_geocode_admin0_polygon (username text, organization_name text, country_name text) -RETURNS Geometry AS $$ - CONNECT cdb_geocoder_client._server_conn_str(); - SELECT cdb_geocoder_server.cdb_geocode_admin0_polygon (username, organization_name, country_name); -$$ LANGUAGE plproxy; - -CREATE OR REPLACE FUNCTION cdb_geocoder_client._cdb_geocode_admin1_polygon (username text, organization_name text, admin1_name text) -RETURNS Geometry AS $$ - CONNECT cdb_geocoder_client._server_conn_str(); - SELECT cdb_geocoder_server.cdb_geocode_admin1_polygon (username, organization_name, admin1_name); -$$ LANGUAGE plproxy; - -CREATE OR REPLACE FUNCTION cdb_geocoder_client._cdb_geocode_admin1_polygon (username text, organization_name text, admin1_name text, country_name text) -RETURNS Geometry AS $$ - CONNECT cdb_geocoder_client._server_conn_str(); - SELECT cdb_geocoder_server.cdb_geocode_admin1_polygon (username, organization_name, admin1_name, country_name); -$$ LANGUAGE plproxy; - -CREATE OR REPLACE FUNCTION cdb_geocoder_client._cdb_geocode_namedplace_point (username text, organization_name text, city_name text) -RETURNS Geometry AS $$ - CONNECT cdb_geocoder_client._server_conn_str(); - SELECT cdb_geocoder_server.cdb_geocode_namedplace_point (username, organization_name, city_name); -$$ LANGUAGE plproxy; - -CREATE OR REPLACE FUNCTION cdb_geocoder_client._cdb_geocode_namedplace_point (username text, organization_name text, city_name text, country_name text) -RETURNS Geometry AS $$ - CONNECT cdb_geocoder_client._server_conn_str(); - SELECT cdb_geocoder_server.cdb_geocode_namedplace_point (username, organization_name, city_name, country_name); -$$ LANGUAGE plproxy; - -CREATE OR REPLACE FUNCTION cdb_geocoder_client._cdb_geocode_namedplace_point (username text, organization_name text, city_name text, admin1_name text, country_name text) -RETURNS Geometry AS $$ - CONNECT cdb_geocoder_client._server_conn_str(); - SELECT cdb_geocoder_server.cdb_geocode_namedplace_point (username, organization_name, city_name, admin1_name, country_name); -$$ LANGUAGE plproxy; - -CREATE OR REPLACE FUNCTION cdb_geocoder_client._cdb_geocode_postalcode_polygon (username text, organization_name text, postal_code text, country_name text) -RETURNS Geometry AS $$ - CONNECT cdb_geocoder_client._server_conn_str(); - SELECT cdb_geocoder_server.cdb_geocode_postalcode_polygon (username, organization_name, postal_code, country_name); -$$ LANGUAGE plproxy; - -CREATE OR REPLACE FUNCTION cdb_geocoder_client._cdb_geocode_postalcode_point (username text, organization_name text, postal_code text, country_name text) -RETURNS Geometry AS $$ - CONNECT cdb_geocoder_client._server_conn_str(); - SELECT cdb_geocoder_server.cdb_geocode_postalcode_point (username, organization_name, postal_code, country_name); -$$ LANGUAGE plproxy; - -CREATE OR REPLACE FUNCTION cdb_geocoder_client._cdb_geocode_ipaddress_point (username text, organization_name text, ip_address text) -RETURNS Geometry AS $$ - CONNECT cdb_geocoder_client._server_conn_str(); - SELECT cdb_geocoder_server.cdb_geocode_ipaddress_point (username, organization_name, ip_address); -$$ LANGUAGE plproxy; - -CREATE OR REPLACE FUNCTION cdb_geocoder_client._cdb_geocode_street_point (username text, organization_name text, searchtext text, city text DEFAULT NULL, state_province text DEFAULT NULL, country text DEFAULT NULL) -RETURNS Geometry AS $$ - CONNECT cdb_geocoder_client._server_conn_str(); - SELECT cdb_geocoder_server.cdb_geocode_street_point (username, organization_name, searchtext, city, state_province, country); -$$ LANGUAGE plproxy; - diff --git a/client/sql/0.1.0/80_permissions.sql b/client/sql/0.1.0/80_permissions.sql new file mode 100644 index 0000000..16fc021 --- /dev/null +++ b/client/sql/0.1.0/80_permissions.sql @@ -0,0 +1,9 @@ +-- Make sure by default there are no permissions for publicuser +-- NOTE: this happens at extension creation time, as part of an implicit transaction. +REVOKE ALL PRIVILEGES ON SCHEMA cdb_geocoder_client FROM PUBLIC, publicuser CASCADE; + +-- Grant permissions on the schema to publicuser (but just the schema) +GRANT USAGE ON SCHEMA cdb_geocoder_client TO publicuser; + +-- Revoke execute permissions on all functions in the schema by default +REVOKE EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_geocoder_client FROM PUBLIC, publicuser; diff --git a/client/sql/0.1.0/90_grant_execute.sql b/client/sql/0.1.0/90_grant_execute.sql deleted file mode 100644 index 01ce6a4..0000000 --- a/client/sql/0.1.0/90_grant_execute.sql +++ /dev/null @@ -1,10 +0,0 @@ -GRANT EXECUTE ON FUNCTION cdb_geocoder_client.cdb_geocode_admin0_polygon(country_name text) TO publicuser; -GRANT EXECUTE ON FUNCTION cdb_geocoder_client.cdb_geocode_admin1_polygon(admin1_name text) TO publicuser; -GRANT EXECUTE ON FUNCTION cdb_geocoder_client.cdb_geocode_admin1_polygon(admin1_name text, country_name text) TO publicuser; -GRANT EXECUTE ON FUNCTION cdb_geocoder_client.cdb_geocode_namedplace_point(city_name text) TO publicuser; -GRANT EXECUTE ON FUNCTION cdb_geocoder_client.cdb_geocode_namedplace_point(city_name text, country_name text) TO publicuser; -GRANT EXECUTE ON FUNCTION cdb_geocoder_client.cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text) TO publicuser; -GRANT EXECUTE ON FUNCTION cdb_geocoder_client.cdb_geocode_postalcode_polygon(postal_code text, country_name text) TO publicuser; -GRANT EXECUTE ON FUNCTION cdb_geocoder_client.cdb_geocode_postalcode_point(postal_code text, country_name text) TO publicuser; -GRANT EXECUTE ON FUNCTION cdb_geocoder_client.cdb_geocode_ipaddress_point(ip_address text) TO publicuser; -GRANT EXECUTE ON FUNCTION cdb_geocoder_client.cdb_geocode_street_point(searchtext text, city text, state_province text, country text) TO publicuser; diff --git a/client/expected/00_installation_test.out b/client/test/0.0.1/expected/00_installation_test.out similarity index 100% rename from client/expected/00_installation_test.out rename to client/test/0.0.1/expected/00_installation_test.out diff --git a/client/expected/10_admin0_test.out b/client/test/0.0.1/expected/10_admin0_test.out similarity index 100% rename from client/expected/10_admin0_test.out rename to client/test/0.0.1/expected/10_admin0_test.out diff --git a/client/expected/20_admin1_test.out b/client/test/0.0.1/expected/20_admin1_test.out similarity index 100% rename from client/expected/20_admin1_test.out rename to client/test/0.0.1/expected/20_admin1_test.out diff --git a/client/expected/30_namedplaces_test.out b/client/test/0.0.1/expected/30_namedplaces_test.out similarity index 100% rename from client/expected/30_namedplaces_test.out rename to client/test/0.0.1/expected/30_namedplaces_test.out diff --git a/client/expected/40_postalcodes_test.out b/client/test/0.0.1/expected/40_postalcodes_test.out similarity index 100% rename from client/expected/40_postalcodes_test.out rename to client/test/0.0.1/expected/40_postalcodes_test.out diff --git a/client/expected/50_ipaddresses_test.out b/client/test/0.0.1/expected/50_ipaddresses_test.out similarity index 100% rename from client/expected/50_ipaddresses_test.out rename to client/test/0.0.1/expected/50_ipaddresses_test.out diff --git a/client/expected/90_permissions_test.out b/client/test/0.0.1/expected/90_permissions_test.out similarity index 100% rename from client/expected/90_permissions_test.out rename to client/test/0.0.1/expected/90_permissions_test.out diff --git a/client/sql/00_installation_test.sql b/client/test/0.0.1/sql/00_installation_test.sql similarity index 100% rename from client/sql/00_installation_test.sql rename to client/test/0.0.1/sql/00_installation_test.sql diff --git a/client/sql/10_admin0_test.sql b/client/test/0.0.1/sql/10_admin0_test.sql similarity index 100% rename from client/sql/10_admin0_test.sql rename to client/test/0.0.1/sql/10_admin0_test.sql diff --git a/client/sql/20_admin1_test.sql b/client/test/0.0.1/sql/20_admin1_test.sql similarity index 100% rename from client/sql/20_admin1_test.sql rename to client/test/0.0.1/sql/20_admin1_test.sql diff --git a/client/sql/30_namedplaces_test.sql b/client/test/0.0.1/sql/30_namedplaces_test.sql similarity index 100% rename from client/sql/30_namedplaces_test.sql rename to client/test/0.0.1/sql/30_namedplaces_test.sql diff --git a/client/sql/40_postalcodes_test.sql b/client/test/0.0.1/sql/40_postalcodes_test.sql similarity index 100% rename from client/sql/40_postalcodes_test.sql rename to client/test/0.0.1/sql/40_postalcodes_test.sql diff --git a/client/sql/50_ipaddresses_test.sql b/client/test/0.0.1/sql/50_ipaddresses_test.sql similarity index 100% rename from client/sql/50_ipaddresses_test.sql rename to client/test/0.0.1/sql/50_ipaddresses_test.sql diff --git a/client/sql/90_permissions_test.sql b/client/test/0.0.1/sql/90_permissions_test.sql similarity index 100% rename from client/sql/90_permissions_test.sql rename to client/test/0.0.1/sql/90_permissions_test.sql diff --git a/client/test/0.1.0/expected/00_installation_test.out b/client/test/0.1.0/expected/00_installation_test.out new file mode 100644 index 0000000..cbeef05 --- /dev/null +++ b/client/test/0.1.0/expected/00_installation_test.out @@ -0,0 +1,29 @@ +-- Install dependencies +CREATE EXTENSION postgis; +CREATE EXTENSION schema_triggers; +CREATE EXTENSION plpythonu; +CREATE EXTENSION cartodb; +CREATE EXTENSION plproxy; +-- Install the extension +CREATE EXTENSION cdb_geocoder_client; +-- Mock the server connection to point to this very test db +SELECT cartodb.cdb_conf_setconf('geocoder_server_config', '{"connection_str": "dbname=contrib_regression host=127.0.0.1 user=postgres"}'); + cdb_conf_setconf +------------------ + +(1 row) + +-- Mock the user configuration +SELECT cartodb.cdb_conf_setconf('user_config', '{"is_organization": false, "entity_name": "test_user"}'); + cdb_conf_setconf +------------------ + +(1 row) + +-- Mock the server schema +CREATE SCHEMA cdb_geocoder_server; +-- Create a test user to check permissions +DROP ROLE IF EXISTS test_regular_user; +CREATE ROLE test_regular_user; +GRANT publicuser TO test_regular_user; +ALTER ROLE test_regular_user SET search_path TO public,cartodb,cdb_geocoder_client; diff --git a/client/test/0.1.0/expected/10_admin0_test.out b/client/test/0.1.0/expected/10_admin0_test.out new file mode 100644 index 0000000..63dfbe0 --- /dev/null +++ b/client/test/0.1.0/expected/10_admin0_test.out @@ -0,0 +1,20 @@ +-- Add to the search path the schema +SET search_path TO public,cartodb,cdb_geocoder_client; +-- Mock the server function +CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin0_polygon(username text, orgname text, country_name text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_admin0_polygon invoked with params (%, %, %)', username, orgname, country_name; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; +-- Exercise the public and the proxied function +SELECT cdb_geocode_admin0_polygon('Spain'); +NOTICE: cdb_geocoder_client._cdb_geocode_admin0_polygon(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_admin0_polygon invoked with params ("test_user", , Spain) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_admin0_polygon(username, orgname, country_name)" +PL/pgSQL function cdb_geocode_admin0_polygon(text) line 15 at SQL statement + cdb_geocode_admin0_polygon +---------------------------- + +(1 row) + diff --git a/client/test/0.1.0/expected/20_admin1_test.out b/client/test/0.1.0/expected/20_admin1_test.out new file mode 100644 index 0000000..3d5d055 --- /dev/null +++ b/client/test/0.1.0/expected/20_admin1_test.out @@ -0,0 +1,36 @@ +-- Add to the search path the schema +SET search_path TO public,cartodb,cdb_geocoder_client; +-- Mock the server functions +CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_admin1_polygon invoked with params (%, %, %)', username, orgname, admin1_name; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; +CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text, country_name text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_admin1_polygon invoked with params (%, %, %, %)', username, orgname, admin1_name, country_name; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; +-- Exercise the public and the proxied function +SELECT cdb_geocode_admin1_polygon('California'); +NOTICE: cdb_geocoder_client._cdb_geocode_admin1_polygon(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_admin1_polygon invoked with params ("test_user", , California) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_admin1_polygon(username, orgname, admin1_name)" +PL/pgSQL function cdb_geocode_admin1_polygon(text) line 15 at SQL statement + cdb_geocode_admin1_polygon +---------------------------- + +(1 row) + +SELECT cdb_geocode_admin1_polygon('California', 'United States'); +NOTICE: cdb_geocoder_client._cdb_geocode_admin1_polygon(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_admin1_polygon invoked with params ("test_user", , California, United States) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_admin1_polygon(username, orgname, admin1_name, country_name)" +PL/pgSQL function cdb_geocode_admin1_polygon(text,text) line 15 at SQL statement + cdb_geocode_admin1_polygon +---------------------------- + +(1 row) + diff --git a/client/test/0.1.0/expected/30_namedplaces_test.out b/client/test/0.1.0/expected/30_namedplaces_test.out new file mode 100644 index 0000000..3ca1a77 --- /dev/null +++ b/client/test/0.1.0/expected/30_namedplaces_test.out @@ -0,0 +1,52 @@ +-- Add to the search path the schema +SET search_path TO public,cartodb,cdb_geocoder_client; +-- Mock the server functions +CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params (%, %, %)', username, orgname, city_name; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; +CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, country_name text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params (%, %, %, %)', username, orgname, city_name, country_name; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; +CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, admin1_name text, country_name text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params (%, %, %, %, %)', username, orgname, city_name, admin1_name, country_name; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; +-- Exercise the public and the proxied function +SELECT cdb_geocode_namedplace_point('Elx'); +NOTICE: cdb_geocoder_client._cdb_geocode_namedplace_point(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params ("test_user", , Elx) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_namedplace_point(username, orgname, city_name)" +PL/pgSQL function cdb_geocode_namedplace_point(text) line 15 at SQL statement + cdb_geocode_namedplace_point +------------------------------ + +(1 row) + +SELECT cdb_geocode_namedplace_point('Elx', 'Spain'); +NOTICE: cdb_geocoder_client._cdb_geocode_namedplace_point(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params ("test_user", , Elx, Spain) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_namedplace_point(username, orgname, city_name, country_name)" +PL/pgSQL function cdb_geocode_namedplace_point(text,text) line 15 at SQL statement + cdb_geocode_namedplace_point +------------------------------ + +(1 row) + +SELECT cdb_geocode_namedplace_point('Elx', 'Valencia', 'Spain'); +NOTICE: cdb_geocoder_client._cdb_geocode_namedplace_point(5): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params ("test_user", , Elx, Valencia, Spain) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_namedplace_point(username, orgname, city_name, admin1_name, country_name)" +PL/pgSQL function cdb_geocode_namedplace_point(text,text,text) line 15 at SQL statement + cdb_geocode_namedplace_point +------------------------------ + +(1 row) + diff --git a/client/test/0.1.0/expected/40_postalcodes_test.out b/client/test/0.1.0/expected/40_postalcodes_test.out new file mode 100644 index 0000000..1415fdd --- /dev/null +++ b/client/test/0.1.0/expected/40_postalcodes_test.out @@ -0,0 +1,36 @@ +-- Add to the search path the schema +SET search_path TO public,cartodb,cdb_geocoder_client; +-- Mock the server functions +CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_polygon(username text, orgname text, postal_code text, country_name text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_postalcode_polygon invoked with params (%, %, %, %)', username, orgname, postal_code, country_name; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; +CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_point(username text, orgname text, postal_code text, country_name text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_postalcode_point invoked with params (%, %, %, %)', username, orgname, postal_code, country_name; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; +-- Exercise the public and the proxied function +SELECT cdb_geocode_postalcode_polygon('03204', 'Spain'); +NOTICE: cdb_geocoder_client._cdb_geocode_postalcode_polygon(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_postalcode_polygon invoked with params ("test_user", , 03204, Spain) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_postalcode_polygon(username, orgname, postal_code, country_name)" +PL/pgSQL function cdb_geocode_postalcode_polygon(text,text) line 15 at SQL statement + cdb_geocode_postalcode_polygon +-------------------------------- + +(1 row) + +SELECT cdb_geocode_postalcode_point('03204', 'Spain'); +NOTICE: cdb_geocoder_client._cdb_geocode_postalcode_point(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_postalcode_point invoked with params ("test_user", , 03204, Spain) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_postalcode_point(username, orgname, postal_code, country_name)" +PL/pgSQL function cdb_geocode_postalcode_point(text,text) line 15 at SQL statement + cdb_geocode_postalcode_point +------------------------------ + +(1 row) + diff --git a/client/test/0.1.0/expected/50_ipaddresses_test.out b/client/test/0.1.0/expected/50_ipaddresses_test.out new file mode 100644 index 0000000..624712d --- /dev/null +++ b/client/test/0.1.0/expected/50_ipaddresses_test.out @@ -0,0 +1,20 @@ +-- Add to the search path the schema +SET search_path TO public,cartodb,cdb_geocoder_client; +-- Mock the server functions +CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_ipaddress_point(username text, orgname text, ip_address text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_ipaddress_point invoked with params (%, %, %)', username, orgname, ip_address; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; +-- Exercise the public and the proxied function +SELECT cdb_geocode_ipaddress_point('8.8.8.8'); +NOTICE: cdb_geocoder_client._cdb_geocode_ipaddress_point(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_ipaddress_point invoked with params ("test_user", , 8.8.8.8) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_ipaddress_point(username, orgname, ip_address)" +PL/pgSQL function cdb_geocode_ipaddress_point(text) line 15 at SQL statement + cdb_geocode_ipaddress_point +----------------------------- + +(1 row) + diff --git a/client/test/0.1.0/expected/60_street_v2_test.out b/client/test/0.1.0/expected/60_street_v2_test.out new file mode 100644 index 0000000..ad4e270 --- /dev/null +++ b/client/test/0.1.0/expected/60_street_v2_test.out @@ -0,0 +1,101 @@ +-- Add to the search path the schema +SET search_path TO public,cartodb,cdb_geocoder_client; +-- Mock the server functions +CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_street_point_v2 (username text, orgname text, searchtext text, city text DEFAULT NULL, state_province text DEFAULT NULL, country text DEFAULT NULL) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_geocoder_street_point_v2 invoked with params (%, %, %, %, %, %)', username, orgname, searchtext, city, state_province, country; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; +-- Exercise the public and the proxied function +SELECT cdb_geocode_street_point_v2('One street, 1'); +NOTICE: cdb_geocoder_client._cdb_geocode_street_point_v2(6): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_geocoder_street_point_v2 invoked with params ("test_user", , One street, 1, , , ) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_street_point_v2(username, orgname, searchtext, city, state_province, country)" +PL/pgSQL function cdb_geocode_street_point_v2(text,text,text,text) line 15 at SQL statement + cdb_geocode_street_point_v2 +----------------------------- + +(1 row) + +SELECT cdb_geocode_street_point_v2('One street', 'city'); +NOTICE: cdb_geocoder_client._cdb_geocode_street_point_v2(6): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_geocoder_street_point_v2 invoked with params ("test_user", , One street, city, , ) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_street_point_v2(username, orgname, searchtext, city, state_province, country)" +PL/pgSQL function cdb_geocode_street_point_v2(text,text,text,text) line 15 at SQL statement + cdb_geocode_street_point_v2 +----------------------------- + +(1 row) + +SELECT cdb_geocode_street_point_v2('One street', 'city', 'state'); +NOTICE: cdb_geocoder_client._cdb_geocode_street_point_v2(6): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_geocoder_street_point_v2 invoked with params ("test_user", , One street, city, state, ) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_street_point_v2(username, orgname, searchtext, city, state_province, country)" +PL/pgSQL function cdb_geocode_street_point_v2(text,text,text,text) line 15 at SQL statement + cdb_geocode_street_point_v2 +----------------------------- + +(1 row) + +SELECT cdb_geocode_street_point_v2('One street', 'city', 'state', 'country'); +NOTICE: cdb_geocoder_client._cdb_geocode_street_point_v2(6): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_geocoder_street_point_v2 invoked with params ("test_user", , One street, city, state, country) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_street_point_v2(username, orgname, searchtext, city, state_province, country)" +PL/pgSQL function cdb_geocode_street_point_v2(text,text,text,text) line 15 at SQL statement + cdb_geocode_street_point_v2 +----------------------------- + +(1 row) + +SELECT cdb_geocode_street_point_v2('One street', 'city', NULL, 'country'); +NOTICE: cdb_geocoder_client._cdb_geocode_street_point_v2(6): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_geocoder_street_point_v2 invoked with params ("test_user", , One street, city, , country) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_street_point_v2(username, orgname, searchtext, city, state_province, country)" +PL/pgSQL function cdb_geocode_street_point_v2(text,text,text,text) line 15 at SQL statement + cdb_geocode_street_point_v2 +----------------------------- + +(1 row) + +SELECT cdb_geocode_street_point_v2('One street, 1'); +NOTICE: cdb_geocoder_client._cdb_geocode_street_point_v2(6): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_geocoder_street_point_v2 invoked with params ("test_user", , One street, 1, , , ) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_street_point_v2(username, orgname, searchtext, city, state_province, country)" +PL/pgSQL function cdb_geocode_street_point_v2(text,text,text,text) line 15 at SQL statement + cdb_geocode_street_point_v2 +----------------------------- + +(1 row) + +SELECT cdb_geocode_street_point_v2('One street', 'city'); +NOTICE: cdb_geocoder_client._cdb_geocode_street_point_v2(6): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_geocoder_street_point_v2 invoked with params ("test_user", , One street, city, , ) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_street_point_v2(username, orgname, searchtext, city, state_province, country)" +PL/pgSQL function cdb_geocode_street_point_v2(text,text,text,text) line 15 at SQL statement + cdb_geocode_street_point_v2 +----------------------------- + +(1 row) + +SELECT cdb_geocode_street_point_v2('One street', 'city', 'state'); +NOTICE: cdb_geocoder_client._cdb_geocode_street_point_v2(6): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_geocoder_street_point_v2 invoked with params ("test_user", , One street, city, state, ) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_street_point_v2(username, orgname, searchtext, city, state_province, country)" +PL/pgSQL function cdb_geocode_street_point_v2(text,text,text,text) line 15 at SQL statement + cdb_geocode_street_point_v2 +----------------------------- + +(1 row) + +SELECT cdb_geocode_street_point_v2('One street', 'city', 'state', 'country'); +NOTICE: cdb_geocoder_client._cdb_geocode_street_point_v2(6): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_geocoder_street_point_v2 invoked with params ("test_user", , One street, city, state, country) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_street_point_v2(username, orgname, searchtext, city, state_province, country)" +PL/pgSQL function cdb_geocode_street_point_v2(text,text,text,text) line 15 at SQL statement + cdb_geocode_street_point_v2 +----------------------------- + +(1 row) + +SELECT cdb_geocode_street_point_v2('One street', 'city', NULL, 'country'); +NOTICE: cdb_geocoder_client._cdb_geocode_street_point_v2(6): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_geocoder_street_point_v2 invoked with params ("test_user", , One street, city, , country) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_street_point_v2(username, orgname, searchtext, city, state_province, country)" +PL/pgSQL function cdb_geocode_street_point_v2(text,text,text,text) line 15 at SQL statement + cdb_geocode_street_point_v2 +----------------------------- + +(1 row) + diff --git a/client/test/0.1.0/expected/90_permissions_test.out b/client/test/0.1.0/expected/90_permissions_test.out new file mode 100644 index 0000000..351d0f9 --- /dev/null +++ b/client/test/0.1.0/expected/90_permissions_test.out @@ -0,0 +1,117 @@ +-- Use regular user role +SET ROLE test_regular_user; +-- Add to the search path the schema +SET search_path TO public,cartodb,cdb_geocoder_client; +-- Exercise the public function +-- it is public, it shall work +SELECT cdb_geocode_admin0_polygon('Spain'); +NOTICE: cdb_geocoder_client._cdb_geocode_admin0_polygon(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_admin0_polygon invoked with params ("test_user", , Spain) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_admin0_polygon(username, orgname, country_name)" +PL/pgSQL function cdb_geocode_admin0_polygon(text) line 15 at SQL statement + cdb_geocode_admin0_polygon +---------------------------- + +(1 row) + +SELECT cdb_geocode_admin1_polygon('California'); +NOTICE: cdb_geocoder_client._cdb_geocode_admin1_polygon(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_admin1_polygon invoked with params ("test_user", , California) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_admin1_polygon(username, orgname, admin1_name)" +PL/pgSQL function cdb_geocode_admin1_polygon(text) line 15 at SQL statement + cdb_geocode_admin1_polygon +---------------------------- + +(1 row) + +SELECT cdb_geocode_admin1_polygon('California', 'United States'); +NOTICE: cdb_geocoder_client._cdb_geocode_admin1_polygon(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_admin1_polygon invoked with params ("test_user", , California, United States) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_admin1_polygon(username, orgname, admin1_name, country_name)" +PL/pgSQL function cdb_geocode_admin1_polygon(text,text) line 15 at SQL statement + cdb_geocode_admin1_polygon +---------------------------- + +(1 row) + +SELECT cdb_geocode_namedplace_point('Elx'); +NOTICE: cdb_geocoder_client._cdb_geocode_namedplace_point(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params ("test_user", , Elx) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_namedplace_point(username, orgname, city_name)" +PL/pgSQL function cdb_geocode_namedplace_point(text) line 15 at SQL statement + cdb_geocode_namedplace_point +------------------------------ + +(1 row) + +SELECT cdb_geocode_namedplace_point('Elx', 'Valencia'); +NOTICE: cdb_geocoder_client._cdb_geocode_namedplace_point(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params ("test_user", , Elx, Valencia) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_namedplace_point(username, orgname, city_name, country_name)" +PL/pgSQL function cdb_geocode_namedplace_point(text,text) line 15 at SQL statement + cdb_geocode_namedplace_point +------------------------------ + +(1 row) + +SELECT cdb_geocode_namedplace_point('Elx', 'Valencia', 'Spain'); +NOTICE: cdb_geocoder_client._cdb_geocode_namedplace_point(5): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params ("test_user", , Elx, Valencia, Spain) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_namedplace_point(username, orgname, city_name, admin1_name, country_name)" +PL/pgSQL function cdb_geocode_namedplace_point(text,text,text) line 15 at SQL statement + cdb_geocode_namedplace_point +------------------------------ + +(1 row) + +SELECT cdb_geocode_postalcode_polygon('03204', 'Spain'); +NOTICE: cdb_geocoder_client._cdb_geocode_postalcode_polygon(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_postalcode_polygon invoked with params ("test_user", , 03204, Spain) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_postalcode_polygon(username, orgname, postal_code, country_name)" +PL/pgSQL function cdb_geocode_postalcode_polygon(text,text) line 15 at SQL statement + cdb_geocode_postalcode_polygon +-------------------------------- + +(1 row) + +SELECT cdb_geocode_postalcode_point('03204', 'Spain'); +NOTICE: cdb_geocoder_client._cdb_geocode_postalcode_point(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_postalcode_point invoked with params ("test_user", , 03204, Spain) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_postalcode_point(username, orgname, postal_code, country_name)" +PL/pgSQL function cdb_geocode_postalcode_point(text,text) line 15 at SQL statement + cdb_geocode_postalcode_point +------------------------------ + +(1 row) + +SELECT cdb_geocode_ipaddress_point('8.8.8.8'); +NOTICE: cdb_geocoder_client._cdb_geocode_ipaddress_point(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_ipaddress_point invoked with params ("test_user", , 8.8.8.8) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_ipaddress_point(username, orgname, ip_address)" +PL/pgSQL function cdb_geocode_ipaddress_point(text) line 15 at SQL statement + cdb_geocode_ipaddress_point +----------------------------- + +(1 row) + +SELECT cdb_geocode_street_point_v2('one street, 1'); +NOTICE: cdb_geocoder_client._cdb_geocode_street_point_v2(6): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_geocoder_street_point_v2 invoked with params ("test_user", , one street, 1, , , ) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_street_point_v2(username, orgname, searchtext, city, state_province, country)" +PL/pgSQL function cdb_geocode_street_point_v2(text,text,text,text) line 15 at SQL statement + cdb_geocode_street_point_v2 +----------------------------- + +(1 row) + +-- Check the regular user has no permissions on private functions +SELECT _cdb_geocode_admin0_polygon('evil_user', 'evil_orgname', 'Hell'); +ERROR: permission denied for function _cdb_geocode_admin0_polygon +SELECT _cdb_geocode_admin1_polygon('evil_user', 'evil_orgname', 'Hell'); +ERROR: permission denied for function _cdb_geocode_admin1_polygon +SELECT _cdb_geocode_admin1_polygon('evil_user', 'evil_orgname', 'Sheol', 'Hell'); +ERROR: permission denied for function _cdb_geocode_admin1_polygon +SELECT _cdb_geocode_namedplace_point('evil_user', 'evil_orgname', 'Sheol'); +ERROR: permission denied for function _cdb_geocode_namedplace_point +SELECT _cdb_geocode_namedplace_point('evil_user', 'evil_orgname', 'Sheol', 'Hell'); +ERROR: permission denied for function _cdb_geocode_namedplace_point +SELECT _cdb_geocode_namedplace_point('evil_user', 'evil_orgname', 'Sheol', 'Hell', 'Ugly world'); +ERROR: permission denied for function _cdb_geocode_namedplace_point +SELECT _cdb_geocode_postalcode_polygon('evil_user', 'evil_orgname', '66666', 'Hell'); +ERROR: permission denied for function _cdb_geocode_postalcode_polygon +SELECT _cdb_geocode_postalcode_point('evil_user', 'evil_orgname', '66666', 'Hell'); +ERROR: permission denied for function _cdb_geocode_postalcode_point +SELECT _cdb_geocode_ipaddress_point('evil_user', 'evil_orgname', '8.8.8.8'); +ERROR: permission denied for function _cdb_geocode_ipaddress_point +SELECT _cdb_geocode_street_point_v2('evil_user', 'evil_orgname', 'one street, 1'); +ERROR: permission denied for function _cdb_geocode_street_point_v2 diff --git a/client/test/0.1.0/sql/00_installation_test.sql b/client/test/0.1.0/sql/00_installation_test.sql new file mode 100644 index 0000000..784fa03 --- /dev/null +++ b/client/test/0.1.0/sql/00_installation_test.sql @@ -0,0 +1,23 @@ +-- Install dependencies +CREATE EXTENSION postgis; +CREATE EXTENSION schema_triggers; +CREATE EXTENSION plpythonu; +CREATE EXTENSION cartodb; +CREATE EXTENSION plproxy; + +-- Install the extension +CREATE EXTENSION cdb_geocoder_client; + +-- Mock the server connection to point to this very test db +SELECT cartodb.cdb_conf_setconf('geocoder_server_config', '{"connection_str": "dbname=contrib_regression host=127.0.0.1 user=postgres"}'); +-- Mock the user configuration +SELECT cartodb.cdb_conf_setconf('user_config', '{"is_organization": false, "entity_name": "test_user"}'); + +-- Mock the server schema +CREATE SCHEMA cdb_geocoder_server; + +-- Create a test user to check permissions +DROP ROLE IF EXISTS test_regular_user; +CREATE ROLE test_regular_user; +GRANT publicuser TO test_regular_user; +ALTER ROLE test_regular_user SET search_path TO public,cartodb,cdb_geocoder_client; \ No newline at end of file diff --git a/client/test/0.1.0/sql/10_admin0_test.sql b/client/test/0.1.0/sql/10_admin0_test.sql new file mode 100644 index 0000000..5c3e488 --- /dev/null +++ b/client/test/0.1.0/sql/10_admin0_test.sql @@ -0,0 +1,15 @@ +-- Add to the search path the schema +SET search_path TO public,cartodb,cdb_geocoder_client; + +-- Mock the server function +CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin0_polygon(username text, orgname text, country_name text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_admin0_polygon invoked with params (%, %, %)', username, orgname, country_name; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; + + +-- Exercise the public and the proxied function +SELECT cdb_geocode_admin0_polygon('Spain'); diff --git a/client/test/0.1.0/sql/20_admin1_test.sql b/client/test/0.1.0/sql/20_admin1_test.sql new file mode 100644 index 0000000..a8a2075 --- /dev/null +++ b/client/test/0.1.0/sql/20_admin1_test.sql @@ -0,0 +1,24 @@ +-- Add to the search path the schema +SET search_path TO public,cartodb,cdb_geocoder_client; + +-- Mock the server functions +CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_admin1_polygon invoked with params (%, %, %)', username, orgname, admin1_name; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; + +CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text, country_name text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_admin1_polygon invoked with params (%, %, %, %)', username, orgname, admin1_name, country_name; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; + + +-- Exercise the public and the proxied function +SELECT cdb_geocode_admin1_polygon('California'); +SELECT cdb_geocode_admin1_polygon('California', 'United States'); diff --git a/client/test/0.1.0/sql/30_namedplaces_test.sql b/client/test/0.1.0/sql/30_namedplaces_test.sql new file mode 100644 index 0000000..3309cf5 --- /dev/null +++ b/client/test/0.1.0/sql/30_namedplaces_test.sql @@ -0,0 +1,33 @@ +-- Add to the search path the schema +SET search_path TO public,cartodb,cdb_geocoder_client; + +-- Mock the server functions +CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params (%, %, %)', username, orgname, city_name; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; + +CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, country_name text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params (%, %, %, %)', username, orgname, city_name, country_name; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; + +CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, admin1_name text, country_name text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params (%, %, %, %, %)', username, orgname, city_name, admin1_name, country_name; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; + +-- Exercise the public and the proxied function +SELECT cdb_geocode_namedplace_point('Elx'); +SELECT cdb_geocode_namedplace_point('Elx', 'Spain'); +SELECT cdb_geocode_namedplace_point('Elx', 'Valencia', 'Spain'); + diff --git a/client/test/0.1.0/sql/40_postalcodes_test.sql b/client/test/0.1.0/sql/40_postalcodes_test.sql new file mode 100644 index 0000000..b5aafc6 --- /dev/null +++ b/client/test/0.1.0/sql/40_postalcodes_test.sql @@ -0,0 +1,23 @@ +-- Add to the search path the schema +SET search_path TO public,cartodb,cdb_geocoder_client; + +-- Mock the server functions +CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_polygon(username text, orgname text, postal_code text, country_name text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_postalcode_polygon invoked with params (%, %, %, %)', username, orgname, postal_code, country_name; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; + +CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_point(username text, orgname text, postal_code text, country_name text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_postalcode_point invoked with params (%, %, %, %)', username, orgname, postal_code, country_name; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; + +-- Exercise the public and the proxied function +SELECT cdb_geocode_postalcode_polygon('03204', 'Spain'); +SELECT cdb_geocode_postalcode_point('03204', 'Spain'); diff --git a/client/test/0.1.0/sql/50_ipaddresses_test.sql b/client/test/0.1.0/sql/50_ipaddresses_test.sql new file mode 100644 index 0000000..09a3342 --- /dev/null +++ b/client/test/0.1.0/sql/50_ipaddresses_test.sql @@ -0,0 +1,15 @@ +-- Add to the search path the schema +SET search_path TO public,cartodb,cdb_geocoder_client; + +-- Mock the server functions +CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_ipaddress_point(username text, orgname text, ip_address text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_ipaddress_point invoked with params (%, %, %)', username, orgname, ip_address; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; + + +-- Exercise the public and the proxied function +SELECT cdb_geocode_ipaddress_point('8.8.8.8'); diff --git a/client/test/0.1.0/sql/60_street_v2_test.sql b/client/test/0.1.0/sql/60_street_v2_test.sql new file mode 100644 index 0000000..99078c9 --- /dev/null +++ b/client/test/0.1.0/sql/60_street_v2_test.sql @@ -0,0 +1,24 @@ +-- Add to the search path the schema +SET search_path TO public,cartodb,cdb_geocoder_client; + +-- Mock the server functions +CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_street_point_v2 (username text, orgname text, searchtext text, city text DEFAULT NULL, state_province text DEFAULT NULL, country text DEFAULT NULL) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_geocoder_street_point_v2 invoked with params (%, %, %, %, %, %)', username, orgname, searchtext, city, state_province, country; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; + + +-- Exercise the public and the proxied function +SELECT cdb_geocode_street_point_v2('One street, 1'); +SELECT cdb_geocode_street_point_v2('One street', 'city'); +SELECT cdb_geocode_street_point_v2('One street', 'city', 'state'); +SELECT cdb_geocode_street_point_v2('One street', 'city', 'state', 'country'); +SELECT cdb_geocode_street_point_v2('One street', 'city', NULL, 'country'); +SELECT cdb_geocode_street_point_v2('One street, 1'); +SELECT cdb_geocode_street_point_v2('One street', 'city'); +SELECT cdb_geocode_street_point_v2('One street', 'city', 'state'); +SELECT cdb_geocode_street_point_v2('One street', 'city', 'state', 'country'); +SELECT cdb_geocode_street_point_v2('One street', 'city', NULL, 'country'); \ No newline at end of file diff --git a/client/test/0.1.0/sql/90_permissions_test.sql b/client/test/0.1.0/sql/90_permissions_test.sql new file mode 100644 index 0000000..675867f --- /dev/null +++ b/client/test/0.1.0/sql/90_permissions_test.sql @@ -0,0 +1,30 @@ +-- Use regular user role +SET ROLE test_regular_user; + +-- Add to the search path the schema +SET search_path TO public,cartodb,cdb_geocoder_client; + +-- Exercise the public function +-- it is public, it shall work +SELECT cdb_geocode_admin0_polygon('Spain'); +SELECT cdb_geocode_admin1_polygon('California'); +SELECT cdb_geocode_admin1_polygon('California', 'United States'); +SELECT cdb_geocode_namedplace_point('Elx'); +SELECT cdb_geocode_namedplace_point('Elx', 'Valencia'); +SELECT cdb_geocode_namedplace_point('Elx', 'Valencia', 'Spain'); +SELECT cdb_geocode_postalcode_polygon('03204', 'Spain'); +SELECT cdb_geocode_postalcode_point('03204', 'Spain'); +SELECT cdb_geocode_ipaddress_point('8.8.8.8'); +SELECT cdb_geocode_street_point_v2('one street, 1'); + +-- Check the regular user has no permissions on private functions +SELECT _cdb_geocode_admin0_polygon('evil_user', 'evil_orgname', 'Hell'); +SELECT _cdb_geocode_admin1_polygon('evil_user', 'evil_orgname', 'Hell'); +SELECT _cdb_geocode_admin1_polygon('evil_user', 'evil_orgname', 'Sheol', 'Hell'); +SELECT _cdb_geocode_namedplace_point('evil_user', 'evil_orgname', 'Sheol'); +SELECT _cdb_geocode_namedplace_point('evil_user', 'evil_orgname', 'Sheol', 'Hell'); +SELECT _cdb_geocode_namedplace_point('evil_user', 'evil_orgname', 'Sheol', 'Hell', 'Ugly world'); +SELECT _cdb_geocode_postalcode_polygon('evil_user', 'evil_orgname', '66666', 'Hell'); +SELECT _cdb_geocode_postalcode_point('evil_user', 'evil_orgname', '66666', 'Hell'); +SELECT _cdb_geocode_ipaddress_point('evil_user', 'evil_orgname', '8.8.8.8'); +SELECT _cdb_geocode_street_point_v2('evil_user', 'evil_orgname', 'one street, 1'); diff --git a/interface_0.0.1.yaml b/interface_0.0.1.yaml new file mode 100644 index 0000000..9f219fb --- /dev/null +++ b/interface_0.0.1.yaml @@ -0,0 +1,52 @@ +--- +- name: cdb_geocode_admin0_polygon + return_type: Geometry + params: + - { name: country_name, type: text } + +- name: cdb_geocode_admin1_polygon + return_type: Geometry + params: + - { name: admin1_name, type: text } + +- name: cdb_geocode_admin1_polygon + return_type: Geometry + params: + - { name: admin1_name, type: text } + - { name: country_name, type: text } + +- name: cdb_geocode_namedplace_point + return_type: Geometry + params: + - { name: city_name, type: text} + +- name: cdb_geocode_namedplace_point + return_type: Geometry + params: + - { name: city_name, type: text} + - { name: country_name, type: text} + +- name: cdb_geocode_namedplace_point + return_type: Geometry + params: + - { name: city_name, type: text} + - { name: admin1_name, type: text} + - { name: country_name, type: text} + + +- name: cdb_geocode_postalcode_polygon + return_type: Geometry + params: + - { name: postal_code, type: text} + - { name: country_name, type: text} + +- name: cdb_geocode_postalcode_point + return_type: Geometry + params: + - { name: postal_code, type: text} + - { name: country_name, type: text} + +- name: cdb_geocode_ipaddress_point + return_type: Geometry + params: + - { name: ip_address, type: text} \ No newline at end of file diff --git a/interface.yaml b/interface_0.1.0.yaml similarity index 97% rename from interface.yaml rename to interface_0.1.0.yaml index e64c504..d5e6fed 100644 --- a/interface.yaml +++ b/interface_0.1.0.yaml @@ -51,7 +51,7 @@ params: - { name: ip_address, type: text} -- name: cdb_geocode_street_point +- name: cdb_geocode_street_point_v2 return_type: Geometry params: - { name: searchtext, type: text}