From e2dd1e014e23c02d6b3a5e2fdbe93be2fccbb945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Ignacio=20S=C3=A1nchez=20Lara?= Date: Tue, 11 Aug 2015 14:49:12 +0200 Subject: [PATCH] test_valid_group_names and test_not_valid_group_names --- scripts-available/CDB_Groups.sql | 6 +++++- test/organization/test.sh | 22 +++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/scripts-available/CDB_Groups.sql b/scripts-available/CDB_Groups.sql index 152ba82..fffa9a5 100644 --- a/scripts-available/CDB_Groups.sql +++ b/scripts-available/CDB_Groups.sql @@ -102,13 +102,17 @@ $$ LANGUAGE PLPGSQL; ----------------------- -- Private functions ----------------------- --- Given a group name returns a role +-- Given a group name returns a role. group_name must be a valid PostgreSQL idenfifier. See http://www.postgresql.org/docs/9.2/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS CREATE OR REPLACE FUNCTION cartodb._CDB_Group_GroupRole(group_name text) RETURNS TEXT AS $$ DECLARE group_role TEXT; BEGIN + IF group_name !~ '^[a-zA-Z_][a-zA-Z0-9_]*$' + THEN + RAISE EXCEPTION 'Group name (%) must be a valid identifier. See http://www.postgresql.org/docs/9.2/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS', group_name; + END IF; RETURN 'g_' || md5(current_database()) || '_' || group_name; END $$ LANGUAGE PLPGSQL; diff --git a/test/organization/test.sh b/test/organization/test.sh index 8407b21..38cf199 100644 --- a/test/organization/test.sh +++ b/test/organization/test.sh @@ -69,10 +69,10 @@ function sql() { ;; *) ;; esac + echo -n "; Code result after warnings: " + echo -n ${CODERESULT} fi - - echo -n "; New code result: " - echo ${CODERESULT} + echo if [[ ${CODERESULT} -ne 0 ]] then @@ -238,6 +238,7 @@ function run_tests() { echo "####################################################################" clear_partial_result setup + log_info "############################# TESTS #############################" eval ${t} if [[ ${PARTIALOK} -ne 0 ]] then @@ -484,6 +485,21 @@ function test_group_management_functions_cant_be_used_by_normal_members() { sql cdb_testmember_2 'DROP TABLE cdb_testmember_2.shared_with_group;' } +function test_valid_group_names() { + sql "select cartodb._CDB_Group_GroupRole('group_1$_a');" + sql "select cartodb._CDB_Group_GroupRole('GROUP_1$_A');" + sql "select cartodb._CDB_Group_GroupRole('_group_1$_a');" +} + +function test_not_valid_group_names() { + sql postgres "select cartodb._CDB_Group_GroupRole('1$_a');" fails + sql postgres "select cartodb._CDB_Group_GroupRole(' group_1$_a');" fails + sql postgres "select cartodb._CDB_Group_GroupRole('group_1$_a ');" fails + sql postgres "select cartodb._CDB_Group_GroupRole(' group_1$_a ');" fails + sql postgres "select cartodb._CDB_Group_GroupRole('group _1$_a');" fails + sql postgres "select cartodb._CDB_Group_GroupRole('groupña');" fails +} + #################################################### TESTS END HERE ####################################################