diff --git a/CHANGELOG.md b/CHANGELOG.md index bcdebe4..bb89619 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed +- Grant method was added for `*_ready_buffer` spaces (#237). + ## [1.4.2] - 2024-08-10 The release re-publish packages. diff --git a/queue/abstract.lua b/queue/abstract.lua index 3e441d5..9c2d434 100644 --- a/queue/abstract.lua +++ b/queue/abstract.lua @@ -346,7 +346,7 @@ function tube.grant(self, user, args) tube_grant_space(user, '_queue', 'read') tube_grant_space(user, '_queue_consumers') tube_grant_space(user, '_queue_taken_2') - tube_grant_space(user, self.name) + self.raw:grant(user, {if_not_exists = true}) session.grant(user) if args.call then diff --git a/queue/abstract/driver/fifo.lua b/queue/abstract/driver/fifo.lua index bc723e6..1cb65f9 100644 --- a/queue/abstract/driver/fifo.lua +++ b/queue/abstract/driver/fifo.lua @@ -61,6 +61,11 @@ function tube.new(space, on_task_change) return self end +-- method.grant grants provided user to all spaces of driver. +function method.grant(self, user, opts) + box.schema.user.grant(user, 'read,write', 'space', self.space.name, opts) +end + -- normalize task: cleanup all internal fields function method.normalize_task(self, task) return task diff --git a/queue/abstract/driver/fifottl.lua b/queue/abstract/driver/fifottl.lua index 7467132..e44a476 100644 --- a/queue/abstract/driver/fifottl.lua +++ b/queue/abstract/driver/fifottl.lua @@ -202,6 +202,11 @@ function tube.new(space, on_task_change, opts) return self end +-- method.grant grants provided user to all spaces of driver. +function method.grant(self, user, opts) + box.schema.user.grant(user, 'read,write', 'space', self.space.name, opts) +end + -- cleanup internal fields in task function method.normalize_task(self, task) return task and task:transform(3, 5) diff --git a/queue/abstract/driver/utube.lua b/queue/abstract/driver/utube.lua index b93a8db..0a7faf9 100644 --- a/queue/abstract/driver/utube.lua +++ b/queue/abstract/driver/utube.lua @@ -126,6 +126,14 @@ function tube.new(space, on_task_change, opts) return self end +-- method.grant grants provided user to all spaces of driver. +function method.grant(self, user, opts) + box.schema.user.grant(user, 'read,write', 'space', self.space.name, opts) + if self.space_ready_buffer ~= nil then + box.schema.user.grant(user, 'read,write', 'space', self.space_ready_buffer.name, opts) + end +end + -- normalize task: cleanup all internal fields function method.normalize_task(self, task) return task and task:transform(3, 1) diff --git a/queue/abstract/driver/utubettl.lua b/queue/abstract/driver/utubettl.lua index 36c481f..619b759 100644 --- a/queue/abstract/driver/utubettl.lua +++ b/queue/abstract/driver/utubettl.lua @@ -386,6 +386,14 @@ function tube.new(space, on_task_change, opts) return self end +-- method.grant grants provided user to all spaces of driver. +function method.grant(self, user, opts) + box.schema.user.grant(user, 'read,write', 'space', self.space.name, opts) + if self.space_ready_buffer ~= nil then + box.schema.user.grant(user, 'read,write', 'space', self.space_ready_buffer.name, opts) + end +end + -- cleanup internal fields in task function method.normalize_task(self, task) return task and task:transform(i_next_event, i_data - i_next_event) diff --git a/t/090-grant-check.t b/t/090-grant-check.t index ad26bcc..03dde41 100755 --- a/t/090-grant-check.t +++ b/t/090-grant-check.t @@ -1,6 +1,6 @@ #!/usr/bin/env tarantool local test = require('tap').test() -test:plan(3) +test:plan(9) local test_user = 'test' local test_pass = '1234' @@ -21,6 +21,68 @@ local engine = os.getenv('ENGINE') or 'memtx' local qc = require('queue.compat') +local test_drivers_grant_cases = { + { + name = 'fifo', + queue_type = 'fifo', + }, + { + name = 'fifottl', + queue_type = 'fifottl', + }, + { + name = 'utube_default', + queue_type = 'utube', + storage_mode = 'default', + }, + { + name = 'utube_ready_buffer', + queue_type = 'utube', + storage_mode = 'ready_buffer', + }, + { + name = 'utubettl_default', + queue_type = 'utubettl', + storage_mode = 'default', + }, + { + name = 'utubettl_ready_buffer', + queue_type = 'utubettl', + storage_mode = 'ready_buffer', + }, +} + +for _, tc in pairs(test_drivers_grant_cases) do + test:test('test dirvers grant ' .. tc.name, function(test) + local queue = require('queue') + box.schema.user.create(test_user, { password = test_pass }) + + test:plan(2) + + local tube_opts = { engine = engine } + if tc.storage_mode ~= nil and tc.storage_mode ~= 'default' then + tube_opts.storage_mode = tc.storage_mode + tube_opts.engine = 'memtx' + end + local tube = queue.create_tube('test', tc.queue_type, tube_opts) + tube:put('help') + + tube:grant(test_user) + + box.session.su(test_user) + local a = tube:take() + test:is(a[1], 0, 'we aren\'t getting any error') + + local c = tube:ack(a[1]) + test:is(c[1], 0, 'we aren\'t getting any error') + + box.session.su('admin') + + box.schema.user.drop(test_user) + tube:drop() + end) +end + test:test('check for space grants', function(test) -- prepare for tests local queue = require('queue')