File: gh-4077-iproto-execute-no-bind.test.lua

package info (click to toggle)
tarantool 2.6.0-1.4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 85,412 kB
  • sloc: ansic: 513,775; cpp: 69,493; sh: 25,650; python: 19,190; perl: 14,973; makefile: 4,178; yacc: 1,329; sql: 1,074; pascal: 620; ruby: 190; awk: 18; lisp: 7
file content (72 lines) | stat: -rwxr-xr-x 2,129 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env tarantool

local tap = require('tap')
local net_box = require('net.box')
local urilib = require('uri')
local msgpack = require('msgpack')

local IPROTO_REQUEST_TYPE       = 0x00
local IPROTO_EXECUTE            = 0x0b
local IPROTO_SYNC               = 0x01
local IPROTO_SQL_TEXT           = 0x40
local IPROTO_SQL_INFO           = 0x42
local IPROTO_SQL_INFO_ROW_COUNT = 0x00
local IPROTO_OK                 = 0x00
local IPROTO_SCHEMA_VERSION     = 0x05
local IPROTO_STATUS_KEY         = 0x00

box.cfg({
    listen = os.getenv('LISTEN') or 'localhost:3301',
})

box.schema.user.grant('guest', 'read,write,execute', 'universe')
box.execute('create table T(ID int primary key)')

local test = tap.test('gh-4077-iproto-execute-no-bind')
test:plan(3)

local uri = urilib.parse(box.cfg.listen)
local sock = net_box.establish_connection(uri.host, uri.service)

-- Send request w/o SQL_BIND field in body.
local next_request_id = 16
local header = msgpack.encode({
    [IPROTO_REQUEST_TYPE] = IPROTO_EXECUTE,
    [IPROTO_SYNC] = next_request_id,
})
local body = msgpack.encode({
    [IPROTO_SQL_TEXT] = 'insert into T values (1)',
})
local size = msgpack.encode(header:len() + body:len())
sock:write(size .. header .. body)

-- Read response.
local size = msgpack.decode(sock:read(5))
local header_body = sock:read(size)
local header, header_len = msgpack.decode(header_body)
local body = msgpack.decode(header_body:sub(header_len))
sock:close()

-- Verify response.
header[IPROTO_SCHEMA_VERSION] = nil -- expect any
local exp_header = {
    [IPROTO_STATUS_KEY] = IPROTO_OK,
    [IPROTO_SYNC] = next_request_id,
}
local exp_body = {
    [IPROTO_SQL_INFO] = {
        [IPROTO_SQL_INFO_ROW_COUNT] = 1,
    }
}
test:is_deeply(exp_header, header, 'verify response header')
test:is_deeply(exp_body, body, 'verify response body')

-- Verify space data.
local exp_res = {{1}}
local res = box.space.T:pairs():map(box.tuple.totable):totable()
test:is_deeply(res, exp_res, 'verify inserted data')

box.execute('drop table T')
box.schema.user.revoke('guest', 'read,write,execute', 'universe')

os.exit(test:check() == true and 0 or 1)