diff --git a/src/box/errcode.h b/src/box/errcode.h index 6f6e28c6c121469d3acd079d7e464b00d59b66b7..cac8447e2e491f8286dcecb5e9012948f655fe8c 100644 --- a/src/box/errcode.h +++ b/src/box/errcode.h @@ -141,7 +141,7 @@ struct errcode_record { /* 86 */_(ER_SESSION_CLOSED, "Session is closed") \ /* 87 */_(ER_ROLE_LOOP, "Granting role '%s' to role '%s' would create a loop") \ /* 88 */_(ER_GRANT, "Incorrect grant arguments: %s") \ - /* 89 */_(ER_PRIV_GRANTED, "User '%s' already has %s access on %s '%s'") \ + /* 89 */_(ER_PRIV_GRANTED, "User '%s' already has %s access on %s%s") \ /* 90 */_(ER_ROLE_GRANTED, "User '%s' already has role '%s'") \ /* 91 */_(ER_PRIV_NOT_GRANTED, "User '%s' does not have %s access on %s '%s'") \ /* 92 */_(ER_ROLE_NOT_GRANTED, "User '%s' does not have role '%s'") \ diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua index 50c96a33564253980bdb465b7dd2d988694d0cc5..f537c3cec3302eee1e8b2e9460829712a66c9a19 100644 --- a/src/box/lua/schema.lua +++ b/src/box/lua/schema.lua @@ -2408,6 +2408,9 @@ local function grant(uid, name, privilege, object_type, privilege == 'execute' then box.error(box.error.ROLE_GRANTED, name, object_name) else + if object_type ~= 'universe' then + object_name = string.format(" '%s'", object_name) + end box.error(box.error.PRIV_GRANTED, name, privilege, object_type, object_name) end diff --git a/test/box/access.result b/test/box/access.result index 9554991add79703b955f1a756410d89ea7fe3f87..b454d0eaaf77a27557d5d6cd5b578649d7b8d518 100644 --- a/test/box/access.result +++ b/test/box/access.result @@ -532,7 +532,7 @@ box.space._priv:select{id} ... box.schema.user.grant('user', 'read', 'universe') --- -- error: User 'user' already has read access on universe '' +- error: User 'user' already has read access on universe ... box.space._priv:select{id} --- @@ -738,7 +738,7 @@ box.schema.user.grant('guest', 'read,write,execute', 'universe') ... box.schema.user.grant('guest', 'read,write,execute', 'universe') --- -- error: User 'guest' already has read,write,execute access on universe '' +- error: User 'guest' already has read,write,execute access on universe ... box.schema.user.grant('guest', 'read,write,execute', 'universe', '', { if_not_exists = true }) --- @@ -2108,3 +2108,29 @@ box.space._priv:delete{1, 'universe', 0} --- - error: 'Incorrect grant arguments: can''t revoke universe from the admin user' ... +-- +-- gh-714: box.schema.user.grant error should be versatile, +-- i.e. error on universally granted privileges shouldn't +-- include any redundant details and/or symbols. +-- +box.schema.user.grant('guest', 'read,write,execute', 'universe') +--- +... +box.schema.user.grant('guest', 'read,write,execute', 'universe') +--- +- error: User 'guest' already has read,write,execute access on universe +... +-- Expected behavior of grant() error shouldn't change otherwise. +sp = box.schema.create_space('not_universe') +--- +... +box.schema.user.grant('guest', 'read,write,execute', 'space', 'not_universe') +--- +... +box.schema.user.grant('guest', 'read,write,execute', 'space', 'not_universe') +--- +- error: User 'guest' already has read,write,execute access on space 'not_universe' +... +sp:drop() +--- +... diff --git a/test/box/access.test.lua b/test/box/access.test.lua index 759827721a6daac7abcb6bba4eb7859c32d071de..387c8b06bccfbeaca7c66c1e18bd39c10697e580 100644 --- a/test/box/access.test.lua +++ b/test/box/access.test.lua @@ -806,3 +806,17 @@ box.schema.user.drop("user3") -- instance could not bootstrap nor recovery. -- box.space._priv:delete{1, 'universe', 0} + +-- +-- gh-714: box.schema.user.grant error should be versatile, +-- i.e. error on universally granted privileges shouldn't +-- include any redundant details and/or symbols. +-- +box.schema.user.grant('guest', 'read,write,execute', 'universe') +box.schema.user.grant('guest', 'read,write,execute', 'universe') + +-- Expected behavior of grant() error shouldn't change otherwise. +sp = box.schema.create_space('not_universe') +box.schema.user.grant('guest', 'read,write,execute', 'space', 'not_universe') +box.schema.user.grant('guest', 'read,write,execute', 'space', 'not_universe') +sp:drop()