From 3ee4d1f676fdba979d08f184e4ad8c60a28f95ae Mon Sep 17 00:00:00 2001
From: Chris Sosnin <k.sosnin@tarantool.org>
Date: Fri, 10 Jan 2020 09:54:26 +0300
Subject: [PATCH] sql: allow accessing list of collations via pragma

'pragma collation_list' uses _collation space, although user
may have no access to it. Thus, we replace it with the
corresponding view.

Closes #4713

(cherry picked from commit 28370f19fa6106e028ede45db1697dfe8fc5137e)
---
 src/box/sql/pragma.c        |  2 +-
 test/sql/collation.result   | 10 ++++++----
 test/sql/collation.test.lua |  5 +++--
 3 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/box/sql/pragma.c b/src/box/sql/pragma.c
index 5bf24ef50b..2ca7609029 100644
--- a/src/box/sql/pragma.c
+++ b/src/box/sql/pragma.c
@@ -503,7 +503,7 @@ sqlPragma(Parse * pParse, Token * pId,	/* First part of [schema.]id field */
 
 	case PragTyp_COLLATION_LIST:{
 		int i = 0;
-		struct space *space = space_by_name("_collation");
+		struct space *space = space_by_name("_vcollation");
 		char key_buf[16]; /* 16 is enough to encode 0 len array */
 		char *key_end = key_buf;
 		key_end = mp_encode_array(key_end, 0);
diff --git a/test/sql/collation.result b/test/sql/collation.result
index 11962ef472..7f70d04b97 100644
--- a/test/sql/collation.result
+++ b/test/sql/collation.result
@@ -352,11 +352,13 @@ box.schema.user.create('tmp')
 box.session.su('tmp')
 ---
 ...
--- Error: read access to space is denied.
-box.execute("pragma collation_list")
+-- gh-4713 "PRAGMA collation_list" is not accessible to all users
+_, err = box.execute('pragma collation_list')
 ---
-- null
-- Read access to space '_collation' is denied for user 'tmp'
+...
+assert(err == nil)
+---
+- true
 ...
 box.session.su('admin')
 ---
diff --git a/test/sql/collation.test.lua b/test/sql/collation.test.lua
index 1be28b3ff2..ac6aa3dcb5 100644
--- a/test/sql/collation.test.lua
+++ b/test/sql/collation.test.lua
@@ -98,8 +98,9 @@ box.schema.user.revoke('guest', 'read,write,execute', 'universe')
 -- gh-3857 "PRAGMA collation_list" invokes segmentation fault.
 box.schema.user.create('tmp')
 box.session.su('tmp')
--- Error: read access to space is denied.
-box.execute("pragma collation_list")
+-- gh-4713 "PRAGMA collation_list" is not accessible to all users
+_, err = box.execute('pragma collation_list')
+assert(err == nil)
 box.session.su('admin')
 box.schema.user.drop('tmp')
 
-- 
GitLab