|
| 1 | +#!/usr/bin/env tarantool |
| 2 | +local test = require('tap').test() |
| 3 | +test:plan(2) |
| 4 | + |
| 5 | +local test_user = 'test' |
| 6 | +local test_pass = '1234' |
| 7 | +local test_host = 'localhost' |
| 8 | +local test_port = '3388' |
| 9 | + |
| 10 | +local uri = require('uri') |
| 11 | +local netbox = require('net.box') |
| 12 | + |
| 13 | +local tnt = require('t.tnt') |
| 14 | + |
| 15 | +tnt.cfg{ |
| 16 | + listen = uri.format({ host = test_host, service = test_port }) |
| 17 | +} |
| 18 | + |
| 19 | +local qc = require('queue.compat') |
| 20 | + |
| 21 | +test:test('check for space grants', function(test) |
| 22 | + -- prepare for tests |
| 23 | + local queue = require('queue') |
| 24 | + box.schema.user.create(test_user, { password = test_pass }) |
| 25 | + |
| 26 | + test:plan(5) |
| 27 | + |
| 28 | + local tube = queue.create_tube('test', 'fifo') |
| 29 | + tube:put('help'); |
| 30 | + local task = tube:take(); |
| 31 | + test:is(task[1], 0, 'we can get record') |
| 32 | + tube:release(task[1]) |
| 33 | + |
| 34 | + -- checking without grants |
| 35 | + box.session.su('test') |
| 36 | + local stat, er = pcall(tube.take, tube) |
| 37 | + test:is(stat, false, 'we\'re getting error') |
| 38 | + box.session.su('admin') |
| 39 | + |
| 40 | + -- checking with grants |
| 41 | + tube:grant('test') |
| 42 | + box.session.su('test') |
| 43 | + local a = tube:take() |
| 44 | + test:is(a[1], 0, 'we aren\'t getting any error') |
| 45 | + local b = tube:take(0.1) |
| 46 | + test:isnil(b, 'we aren\'t getting any error') |
| 47 | + local c = tube:ack(a[1]) |
| 48 | + test:is(a[1], 0, 'we aren\'t getting any error') |
| 49 | + box.session.su('admin') |
| 50 | + |
| 51 | + -- checking double grants |
| 52 | + tube:grant('test') |
| 53 | + |
| 54 | + box.schema.user.drop(test_user) |
| 55 | + tube:drop() |
| 56 | +end) |
| 57 | + |
| 58 | +test:test('check for call grants', function(test) |
| 59 | + -- prepare for tests |
| 60 | + _G.queue = require('queue') |
| 61 | + box.schema.user.create(test_user, { password = test_pass }) |
| 62 | + |
| 63 | + test:plan(9) |
| 64 | + |
| 65 | + local tube = queue.create_tube('test', 'fifo') |
| 66 | + tube:put('help'); |
| 67 | + local task = tube:take(); |
| 68 | + test:is(task[1], 0, 'we can get record') |
| 69 | + tube:release(task[1]) |
| 70 | + |
| 71 | + -- checking without grants |
| 72 | + box.session.su('test') |
| 73 | + local stat, er = pcall(tube.take, tube) |
| 74 | + test:is(stat, false, 'we\'re getting error') |
| 75 | + box.session.su('admin') |
| 76 | + |
| 77 | + -- checking with grants |
| 78 | + tube:grant('test') |
| 79 | + |
| 80 | + box.session.su('test') |
| 81 | + local a = tube:take() |
| 82 | + test:is(a[1], 0, 'we aren\'t getting any error') |
| 83 | + local b = tube:take(0.1) |
| 84 | + test:isnil(b, 'we aren\'t getting any error') |
| 85 | + local c = tube:release(a[1]) |
| 86 | + test:is(a[1], 0, 'we aren\'t getting any error') |
| 87 | + box.session.su('admin') |
| 88 | + |
| 89 | + local con = netbox.connect(uri.format({ |
| 90 | + login = test_user, password = test_pass, |
| 91 | + host = test_host, service = test_port, |
| 92 | + }, true)) |
| 93 | + |
| 94 | + local stat, er = pcall(con.call, con, tube, 'queue.tube.test:take') |
| 95 | + test:is(stat, false, 'we\'re getting error') |
| 96 | + |
| 97 | + -- granting call |
| 98 | + tube:grant('test', { call = true }) |
| 99 | + |
| 100 | + local a = con:call('queue.tube.test:take') |
| 101 | + test:is(a[1], 0, 'we aren\'t getting any error') |
| 102 | + local b = con:call('queue.tube.test:take', qc.pack_args(0.1)) |
| 103 | + test:isnil(b, 'we aren\'t getting any error') |
| 104 | + local c = con:call('queue.tube.test:ack', qc.pack_args(a[1])) |
| 105 | + test:is(a[1], 0, 'we aren\'t getting any error') |
| 106 | + |
| 107 | + -- check grants again |
| 108 | + tube:grant('test', { call = true }) |
| 109 | + |
| 110 | + _G.queue = nil |
| 111 | + tube:drop() |
| 112 | +end) |
| 113 | + |
| 114 | +tnt.finish() |
| 115 | + |
| 116 | +os.exit(test:check() == true and 0 or -1) |
| 117 | +-- vim: set ft=lua : |
0 commit comments