diff --git a/src/box/lua/session.c b/src/box/lua/session.c index a4ddb201ca7f8fb7003ab41326af97622959bdae..c0ac4917b3969435e6dd74e9ebe84e37bf5558c3 100644 --- a/src/box/lua/session.c +++ b/src/box/lua/session.c @@ -214,11 +214,15 @@ lbox_session_su(struct lua_State *L) static int lbox_session_exists(struct lua_State *L) { - if (lua_gettop(L) != 1) + if (lua_gettop(L) > 1) luaL_error(L, "session.exists(sid): bad arguments"); - uint64_t sid = luaL_checkint64(L, -1); - lua_pushboolean(L, session_find(sid) != NULL); + struct session *session; + if (lua_gettop(L) == 1) + session = session_find(luaL_checkint64(L, -1)); + else + session = current_session(); + lua_pushboolean(L, session != NULL); return 1; } @@ -228,11 +232,14 @@ lbox_session_exists(struct lua_State *L) static int lbox_session_fd(struct lua_State *L) { - if (lua_gettop(L) != 1) + if (lua_gettop(L) > 1) luaL_error(L, "session.fd(sid): bad arguments"); - uint64_t sid = luaL_checkint64(L, -1); - struct session *session = session_find(sid); + struct session *session; + if (lua_gettop(L) == 1) + session = session_find(luaL_checkint64(L, -1)); + else + session = current_session(); if (session == NULL) luaL_error(L, "session.fd(): session does not exist"); lua_pushinteger(L, session_fd(session)); diff --git a/test/box-tap/session.test.lua b/test/box-tap/session.test.lua index 857bc643b0861afe50c62dcdd01d443231433d85..5d49655331a8c0c7bffa2177513b15ed704e7c39 100755 --- a/test/box-tap/session.test.lua +++ b/test/box-tap/session.test.lua @@ -15,15 +15,14 @@ session = box.session space = box.schema.space.create('tweedledum') index = space:create_index('primary', { type = 'hash' }) -test:plan(55) +test:plan(56) --- --- Check that Tarantool creates ADMIN session for #! script --- test:ok(session.exists(session.id()), "session is created") test:isnil(session.peer(session.id()), "session.peer") -local ok, err = pcall(session.exists) -test:is(err, "session.exists(sid): bad arguments", "exists bad args #1") +test:ok(session.exists(), "session.exists") ok, err = pcall(session.exists, 1, 2, 3) test:is(err, "session.exists(sid): bad arguments", "exists bad args #2") test:ok(not session.exists(1234567890), "session doesn't exist") @@ -169,6 +168,7 @@ conn = net.box.connect(uri) test:ok(conn:eval("return box.session.exists(box.session.id())"), "remote session exist check") test:isnt(conn:eval("return box.session.peer(box.session.id())"), nil, "remote session peer check") test:ok(conn:eval("return box.session.peer() == box.session.peer(box.session.id())"), "remote session peer check") +test:ok(conn:eval("return box.session.fd() == box.session.fd(box.session.id())"), "remote session fd check") -- gh-2994 session uid vs session effective uid test:is(session.euid(), 1, "session.uid")