Commit befefe1c authored by Renato Figueiro Maia's avatar Renato Figueiro Maia

[OPENBUS-2441] [Lua] Inclusão de suporte a serialização de cadeias em formato interoperável.

git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/openbus/sdk/lua/branches/02_00_01@157531 ae0415b3-e90b-0410-900d-d0be9363c56b
parent fb19550b
This diff is collapsed.
......@@ -227,7 +227,7 @@ function Interceptor:resetCaches()
}
end
function Interceptor:unmarshalSignedChain(chain)
function Interceptor:unmarshalSignedChain(chain, busid)
local encoded = chain.encoded
if encoded ~= "" then
local context = self.context
......@@ -240,10 +240,12 @@ function Interceptor:unmarshalSignedChain(chain)
chain.originators = originators
chain.caller = decoded.caller
chain.target = decoded.target
chain.busid = busid
return chain
end
end
local unmarshalSignedChain = Interceptor.unmarshalSignedChain
function Interceptor:unmarshalCredential(contexts)
local context = self.context
local types = context.types
......@@ -251,7 +253,7 @@ function Interceptor:unmarshalCredential(contexts)
local data = contexts[CredentialContextId]
if data ~= nil then
local credential = orb:newdecoder(data):get(types.CredentialData)
credential.chain = self:unmarshalSignedChain(credential.chain)
credential.chain = unmarshalSignedChain(self, credential.chain, credential.bus)
return credential
end
if self.legacy ~= nil then
......
......@@ -9,6 +9,7 @@ local parse = luaidl.parse
local idlspec = [[
#include "access_control.idl"
#include "offer_registry.idl"
#include "data_export.idl"
]]
local idlpath = os.getenv("OPENBUS_IDLPATH")
......
......@@ -39,7 +39,8 @@ LIBDEPENDENTIDL= $(OPENBUSLIBIDL)/corba.idl
NEWIDL= \
$(OPENBUSNEWIDL)/access_control.idl \
$(OPENBUSNEWIDL)/offer_registry.idl
$(OPENBUSNEWIDL)/offer_registry.idl \
$(OPENBUSNEWIDL)/data_export.idl
NEWDEPENDENTIDL= \
$(OPENBUSNEWIDL)/core.idl \
......
local _G = require "_G"
local assert = _G.assert
local pcall = _G.pcall
local giop = require "oil.corba.giop"
local openbus = require "openbus"
local libidl = require "openbus.idl"
local idl = require "openbus.core.idl"
local log = require "openbus.util.logger"
local sysex = giop.SystemExceptionIDs
bushost, busport, verbose = ...
require "openbus.test.configs"
syskey = assert(openbus.readKeyFile(syskey))
local connprops = { accesskey = openbus.newKey() }
local orb = openbus.initORB()
local OpenBusContext = orb.OpenBusContext
assert(OpenBusContext.orb == orb)
do log:TEST("Encode illegal argument")
local illegalchains = {
false,
true,
0,
"",
function () end,
coroutine.running(),
io.stdout,
}
for index = 1, 1+#illegalchains do
local illegal = illegalchains[index]
local ok, ex = pcall(OpenBusContext.encodeChain, OpenBusContext, illegal)
assert(not ok)
assert(type(ex) == "string")
assert(ex:find("bad argument", 1, "no regex"))
end
end
do log:TEST("Encode malformed chain")
local malformedchains = {
{ --[[empty]] },
{
busid = "some fake busid",
target = "FakeEntity",
caller = { id = "fake login id", entity = "FakeEntity" },
originators = {},
},
{
busid = "some fake busid",
target = "FakeEntity",
caller = { id = "fake login id", entity = "FakeEntity" },
originators = {},
encoded = "some fake encoded chain",
signature = "some fake encoded chain signature",
},
}
for _, malformed in ipairs(malformedchains) do
local ok, ex = pcall(OpenBusContext.encodeChain, OpenBusContext, malformed)
assert(not ok)
assert(type(ex) == "string")
assert(ex:find("unable to encode chain", 1, "no regex"))
end
end
do log:TEST("Decode illegal argument")
local illegalstreams = {
false,
true,
0,
{ --[[empty]] },
function () --[[empty]] end,
coroutine.running(),
io.stdout,
}
for index = 1, 1+#illegalstreams do
local illegal = illegalstreams[index]
local ok, ex = pcall(OpenBusContext.decodeChain, OpenBusContext, illegal)
assert(not ok)
assert(type(ex) == "string")
assert(ex:find("bad argument", 1, "no regex"))
end
end
do log:TEST("Decode malformed chain")
local malformedstreams = {
"",
"some ramdom rubbish",
"BUS\0 some ramdom short rubbish",
"BUS\1 some ramdom short rubbish",
"BUS\2 some ramdom short rubbish",
}
for _, malformed in ipairs(malformedstreams) do
local ok, ex = pcall(OpenBusContext.decodeChain, OpenBusContext, malformed)
assert(not ok)
assert(ex._repid == libidl.types.InvalidChainStream)
assert(ex.message ~= nil)
end
end
do log:TEST("Encode and decode chains")
local conn1 = OpenBusContext:createConnection(bushost, busport, connprops)
conn1:loginByPassword(user, password)
local conn2 = OpenBusContext:createConnection(bushost, busport, connprops)
conn2:loginByCertificate(system, syskey)
assert(conn1.busid == conn2.busid)
local busid = conn1.busid
local login1 = conn1.login.id
local entity1 = conn1.login.entity
local login2 = conn2.login.id
local entity2 = conn2.login.entity
OpenBusContext:setDefaultConnection(conn1)
local chain1to2 = OpenBusContext:makeChainFor(conn2.login.id)
local stream = assert(OpenBusContext:encodeChain(chain1to2))
assert(type(stream) == "string")
chain1to2 = assert(OpenBusContext:decodeChain(stream))
assert(chain1to2.busid == busid)
assert(chain1to2.target == entity2)
assert(chain1to2.caller.id == login1)
assert(chain1to2.caller.entity == entity1)
assert(#chain1to2.originators == 0)
OpenBusContext:setDefaultConnection(conn2)
OpenBusContext:joinChain(chain1to2)
local chain1to2to1 = OpenBusContext:makeChainFor(conn1.login.id)
OpenBusContext:exitChain()
OpenBusContext:setDefaultConnection(nil)
conn1:logout()
conn2:logout()
local stream = assert(OpenBusContext:encodeChain(chain1to2to1))
assert(type(stream) == "string")
chain1to2to1 = assert(OpenBusContext:decodeChain(stream))
assert(chain1to2to1.busid == busid)
assert(chain1to2to1.target == entity1)
assert(chain1to2to1.caller.id == login2)
assert(chain1to2to1.caller.entity == entity2)
assert(chain1to2to1.originators[1].id == login1)
assert(chain1to2to1.originators[1].entity == entity1)
end
orb:shutdown()
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
......@@ -24,7 +13,6 @@ require "openbus.test.configs"
syskey = assert(openbus.readKeyFile(syskey))
local smalltime = .1
local connprops = { accesskey = openbus.newKey() }
local orb = openbus.initORB()
......@@ -38,12 +26,19 @@ do log:TEST("Make chains for active logins")
conn1:loginByPassword(user, password)
local conn2 = OpenBusContext:createConnection(bushost, busport, connprops)
conn2:loginByCertificate(system, syskey)
assert(conn1.busid == conn2.busid)
local busid = conn1.busid
local login1 = conn1.login.id
local entity1 = conn1.login.entity
local login2 = conn2.login.id
local entity2 = conn2.login.entity
OpenBusContext:setDefaultConnection(conn1)
local chain1to2 = OpenBusContext:makeChainFor(conn2.login.id)
assert(chain1to2.target == conn2.login.entity)
assert(chain1to2.caller.id == conn1.login.id)
assert(chain1to2.caller.entity == conn1.login.entity)
assert(chain1to2.busid == busid)
assert(chain1to2.target == entity2)
assert(chain1to2.caller.id == login1)
assert(chain1to2.caller.entity == entity1)
assert(#chain1to2.originators == 0)
OpenBusContext:joinChain(chain1to2)
......@@ -55,11 +50,12 @@ do log:TEST("Make chains for active logins")
OpenBusContext:setDefaultConnection(conn2)
local chain1to2to1 = OpenBusContext:makeChainFor(conn1.login.id)
assert(chain1to2to1.target == conn1.login.entity)
assert(chain1to2to1.caller.id == conn2.login.id)
assert(chain1to2to1.caller.entity == conn2.login.entity)
assert(chain1to2to1.originators[1].id == conn1.login.id)
assert(chain1to2to1.originators[1].entity == conn1.login.entity)
assert(chain1to2to1.busid == busid)
assert(chain1to2to1.target == entity1)
assert(chain1to2to1.caller.id == login2)
assert(chain1to2to1.caller.entity == entity2)
assert(chain1to2to1.originators[1].id == login1)
assert(chain1to2to1.originators[1].entity == entity1)
OpenBusContext:exitChain()
OpenBusContext:setDefaultConnection(nil)
......
......@@ -16,6 +16,7 @@ openbus/test/LoginLogout \
openbus/test/Concurrency \
openbus/test/NoLoginIceptorCalls \
openbus/test/MakeChainFor \
openbus/test/ChainExport \
openbus/test/assistant/LoginLogout \
openbus/test/assistant/Concurrency \
openbus/test/assistant/NoLoginIceptorCalls \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment