OnCallDispatch.lua 6.3 KB
Newer Older
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
local _G = require "_G"
local assert = _G.assert
local error = _G.error
local ipairs = _G.ipairs
local pairs = _G.pairs
local pcall = _G.pcall
local type = _G.type
local coroutine = require "coroutine"
local string = require "string"
local io = require "io"
local uuid = require "uuid"
local giop = require "oil.corba.giop"
local cothread = require "cothread"
local openbus = require "openbus"
local libidl = require "openbus.idl"
local idl = require "openbus.core.idl"
local msg = require "openbus.util.messages"
local log = require "openbus.util.logger"

local sysex = giop.SystemExceptionIDs
local LoginObserverRepId = idl.types.services.access_control.LoginObserver

bushost, busport, verbose = ...
require "openbus.test.configs"

local smalltime = .1
local connprops = { accesskey = openbus.newKey() }

-- login as admin and provide additional functionality for the test
local invalidate, shutdown, busid, caller do
  local orb = openbus.initORB()
  local OpenBusContext = orb.OpenBusContext
  local conn = OpenBusContext:createConnection(bushost, busport)
  conn:loginByPassword(admin, admpsw)
  busid = conn.busid
  caller = conn.login
  OpenBusContext:setDefaultConnection(conn)
  function invalidate(loginId)
    OpenBusContext:getLoginRegistry():invalidateLogin(loginId)
  end
  function newproxy(...)
    return orb:newproxy(...)
  end
  function servant(func)
    if func == nil then func = function() end end
    return tostring(orb:newservant({entityLogout=func}, nil,
                                   LoginObserverRepId)),
           nil,
           LoginObserverRepId
  end
  function shutdown()
    conn:logout()
    orb:shutdown()
  end
end

local orb = openbus.initORB()
local OpenBusContext = orb.OpenBusContext
assert(OpenBusContext.orb == orb)



do log:TEST("Return no connections")
  function OpenBusContext:onCallDispatch(bus, login, objkey, opname, ...)
    assert(bus == busid)
    assert(login == caller.id)
    assert(objkey == "DummyObject")
    assert(opname == "_non_existent")
    assert(select("#", ...) == 0)
  end

  local srv = orb:newservant({}, "DummyObject", "CORBA::InterfaceDef")
  local ior = tostring(srv)
  local pxy = newproxy(ior, nil, "CORBA::InterfaceDef")

  local ok, ex = pcall(pxy._non_existent, pxy)
  assert(not ok)
  assert(ex._repid == sysex.NO_PERMISSION)
  assert(ex.completed == "COMPLETED_NO")
  assert(ex.minor == idl.const.services.access_control.UnknownBusCode)

  srv:__deactivate()
end

do log:TEST("Return disconnected connection")
  local conn = OpenBusContext:createConnection(bushost, busport, connprops)

  function OpenBusContext:onCallDispatch(bus, login, objkey, opname, ...)
    assert(bus == busid)
    assert(login == caller.id)
    assert(objkey == "DummyObject")
    assert(opname == "_non_existent")
    assert(select("#", ...) == 0)
    return conn
  end

  local srv = orb:newservant({}, "DummyObject", "CORBA::InterfaceDef")
  local ior = tostring(srv)
  local pxy = newproxy(ior, nil, "CORBA::InterfaceDef")

  local ok, ex = pcall(pxy._non_existent, pxy)
  assert(not ok)
  assert(ex._repid == sysex.NO_PERMISSION)
  assert(ex.completed == "COMPLETED_NO")
  assert(ex.minor == idl.const.services.access_control.UnknownBusCode)

  srv:__deactivate()
end

do log:TEST("Default connection fallback")
  local conn = OpenBusContext:createConnection(bushost, busport, connprops)
  conn:loginByPassword(user, password)
  OpenBusContext:setDefaultConnection(conn)

  function OpenBusContext:onCallDispatch(bus, login, objkey, opname, ...)
    assert(bus == busid)
    assert(login == caller.id)
    assert(objkey == "DummyObject")
    assert(opname == "_non_existent")
    assert(select("#", ...) == 0)
  end

  local srv = orb:newservant({}, "DummyObject", "CORBA::InterfaceDef")
  local ior = tostring(srv)
  local pxy = newproxy(ior, nil, "CORBA::InterfaceDef")
  
  assert(pxy:_non_existent() == false)
  
  srv:__deactivate()

  assert(conn:logout())
  OpenBusContext:setDefaultConnection(nil)
end

do log:TEST("Return connection to another bus")
  local conn = OpenBusContext:createConnection(bushost, busport, connprops)
  conn:loginByPassword(user, password)
  OpenBusContext:setDefaultConnection(conn)

  local conn2 = OpenBusContext:createConnection(bus2host, bus2port, connprops)
  conn2:loginByPassword(user, password)
  function OpenBusContext:onCallDispatch(bus, login, objkey, opname, ...)
    assert(bus == busid)
    assert(login == caller.id)
    assert(objkey == "DummyObject")
    assert(opname == "_non_existent")
    assert(select("#", ...) == 0)
    return conn2
  end

  local srv = orb:newservant({}, "DummyObject", "CORBA::InterfaceDef")
  local ior = tostring(srv)
  local pxy = newproxy(ior, nil, "CORBA::InterfaceDef")
  
  local ok, ex = pcall(pxy._non_existent, pxy)
  assert(not ok)
  assert(ex._repid == sysex.NO_PERMISSION)
  assert(ex.completed == "COMPLETED_NO")
  assert(ex.minor == idl.const.services.access_control.UnknownBusCode)
  
  srv:__deactivate()

  assert(conn2:logout())
  assert(conn:logout())
  OpenBusContext:setDefaultConnection(nil)
end

do log:TEST("Raise error")
  function OpenBusContext:onCallDispatch(bus, login, objkey, opname, ...)
    assert(bus == busid)
    assert(login == caller.id)
    assert(objkey == "DummyObject")
    assert(opname == "_non_existent")
    assert(select("#", ...) == 0)
    error("INTENTIONAL ERROR")
  end

  local srv = orb:newservant({}, "DummyObject", "CORBA::InterfaceDef")
  local ior = tostring(srv)
  local pxy = newproxy(ior, nil, "CORBA::InterfaceDef")
  
  local ok, ex = pcall(pxy._non_existent, pxy)
  assert(not ok)
  assert(ex._repid == sysex.UNKNOWN)
  
  srv:__deactivate()

end

do log:TEST("Raise CORBA system exception")
  function OpenBusContext:onCallDispatch(bus, login, objkey, opname, ...)
    assert(bus == busid)
    assert(login == caller.id)
    assert(objkey == "DummyObject")
    assert(opname == "_non_existent")
    assert(select("#", ...) == 0)
    error{
      _repid = sysex.NO_PERMISSION,
      completed = "COMPLETED_YES",
      minor = 1234,
    }
  end

  local srv = orb:newservant({}, "DummyObject", "CORBA::InterfaceDef")
  local ior = tostring(srv)
  local pxy = newproxy(ior, nil, "CORBA::InterfaceDef")
  
  local ok, ex = pcall(pxy._non_existent, pxy)
  assert(not ok)
  assert(ex._repid == sysex.NO_PERMISSION)
  assert(ex.completed == "COMPLETED_YES")
  assert(ex.minor == 1234)
  
  srv:__deactivate()

end



orb:shutdown()
shutdown()