test_valid_group_names and test_not_valid_group_names

This commit is contained in:
Juan Ignacio Sánchez Lara 2015-08-11 14:49:12 +02:00
parent 1915e28a0f
commit e2dd1e014e
2 changed files with 24 additions and 4 deletions

View File

@ -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;

View File

@ -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 ####################################################