Commit 58ddaf06 authored by Renato Figueiro Maia's avatar Renato Figueiro Maia

Merge from branch 02_00_01 (157500:158001)

git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/openbus/sdk/lua/trunk@158015 ae0415b3-e90b-0410-900d-d0be9363c56b
parent 6a8f6509
local log = require "openbus.util.logger"
local openbus = require "openbus"
require "openbus.test.util"
-- setup the ORB
local orb = openbus.initORB()
-- load interface definition
orb:loadidlfile("idl/proxy.idl")
local iface = orb.types:lookup("tecgraf::openbus::interop::chaining::HelloProxy")
-- customize test configuration for this case
settestcfg(iface, ...)
-- get bus context manager
local OpenBusContext = orb.OpenBusContext
-- connect to the bus
local conn = OpenBusContext:createConnection(bushost, busport)
OpenBusContext:setDefaultConnection(conn)
-- login to the bus
conn:loginByPassword(user, password)
-- define service properties
properties[#properties+1] =
{name="openbus.component.interface",value=iface.repID}
-- find the offered service
log:TEST("retrieve hello service")
local OfferRegistry = OpenBusContext:getOfferRegistry()
for _, offer in ipairs(findoffers(OfferRegistry, properties)) do
local entity = getprop(offer.properties, "openbus.offer.entity")
log:TEST("found service of ",entity,"!")
local hello = offer.service_ref:getFacetByName(iface.name):__narrow(iface)
local login = getprop(offer.properties, "openbus.offer.login")
local chain = OpenBusContext:makeChainFor(login)
local encoded = OpenBusContext:encodeChain(chain)
local result = hello:fetchHello(encoded)
assert(result == "Hello "..user.."!", result)
log:TEST("test successful for service of ",entity)
end
-- logout from the bus
conn:logout()
orb:shutdown()
local log = require "openbus.util.logger"
local openbus = require "openbus"
local sysex = require "openbus.util.sysex"
local ComponentContext = require "scs.core.ComponentContext"
require "openbus.test.util"
-- setup and start the ORB
local orb = openbus.initORB()
-- load interface definition
orb:loadidlfile("idl/proxy.idl")
orb:loadidlfile("helloidl/hello.idl")
local iface = orb.types:lookup("tecgraf::openbus::interop::chaining::HelloProxy")
local serviface = orb.types:lookup("tecgraf::openbus::interop::simple::Hello")
-- customize test configuration for this case
settestcfg(iface, ...)
-- get bus context manager
local OpenBusContext = orb.OpenBusContext
-- create service implementation
local hello = {}
function hello:fetchHello(encodedChain)
if not pcall(function ()
local chain = OpenBusContext:decodeChain(encodedChain)
OpenBusContext:joinChain(chain)
end) then
sysex.BAD_PARAM()
end
local result
if not pcall(function ()
-- define service properties
properties[#properties+1] =
{name="openbus.component.interface",value=serviface.repID}
properties[#properties+1] =
{name="openbus.component.name",value="RestrictedHello"},
-- find the offered service
log:TEST("retrieve hello service")
local OfferRegistry = OpenBusContext:getOfferRegistry()
for _, offer in ipairs(findoffers(OfferRegistry, properties)) do
local entity = getprop(offer.properties, "openbus.offer.entity")
log:TEST("found service of ",entity,"!")
local hello = offer.service_ref:getFacetByName(serviface.name):__narrow(serviface)
result = hello:sayHello()
log:TEST("got result from service of ",entity)
break
end
end) then
sysex.NO_RESOURCES()
end
return result
end
-- create service SCS component
local component = ComponentContext(orb, {
name = "Hello",
major_version = 1,
minor_version = 0,
patch_version = 0,
platform_spec = "Lua",
})
component:addFacet(iface.name, iface.repID, hello)
-- connect to the bus
local conn = OpenBusContext:createConnection(bushost, busport)
OpenBusContext:setDefaultConnection(conn)
-- login to the bus
conn:loginByCertificate(system, assert(openbus.readKeyFile(syskey)))
-- offer service
local OfferRegistry = OpenBusContext:getOfferRegistry()
OfferRegistry:registerService(component.IComponent, properties)
log:TEST("hello service ready!")
local log = require "openbus.util.logger"
local openbus = require "openbus"
local sysex = require "openbus.util.sysex"
local ComponentContext = require "scs.core.ComponentContext"
require "openbus.test.util"
-- setup and start the ORB
local orb = openbus.initORB()
-- load interface definition
orb:loadidlfile("helloidl/hello.idl")
local iface = orb.types:lookup("tecgraf::openbus::interop::simple::Hello")
-- customize test configuration for this case
settestcfg(iface, ...)
-- get bus context manager
local OpenBusContext = orb.OpenBusContext
-- create service implementation
local hello = {}
local expected = {
cpp = true,
java = true,
lua = true,
csharp = true,
}
function hello:sayHello()
local chain = OpenBusContext:getCallerChain()
local entity = chain.caller.entity
if expected[entity:match("^interop_chaining_(.-)_helloproxy$")] ~= nil then
log:TEST("got call from ",chain2str(chain))
return "Hello "..chain.originators[1].entity.."!"
else
sysex.NO_PERMISSION()
end
end
-- create service SCS component
local component = ComponentContext(orb, {
name = "RestrictedHello",
major_version = 1,
minor_version = 0,
patch_version = 0,
platform_spec = "Lua",
})
component:addFacet(iface.name, iface.repID, hello)
-- connect to the bus
local conn = OpenBusContext:createConnection(bushost, busport)
OpenBusContext:setDefaultConnection(conn)
-- login to the bus
conn:loginByCertificate(system, assert(openbus.readKeyFile(syskey)))
-- offer service
local OfferRegistry = OpenBusContext:getOfferRegistry()
OfferRegistry:registerService(component.IComponent, properties)
log:TEST("hello service ready!")
local idl = require "openbus.core.idl"
local log = require "openbus.util.logger"
local except = require "openbus.util.except"
local openbus = require "openbus"
require "openbus.test.util"
-- setup the ORB
local orb = openbus.initORB()
-- load interface definition
orb:loadidlfile("idl/mock.idl")
local iface = orb.types:lookup("tecgraf::openbus::interop::protocol::Server")
-- customize test configuration for this case
settestcfg(iface, ...)
-- get bus context manager
local OpenBusContext = orb.OpenBusContext
-- connect to the bus
local conn = OpenBusContext:createConnection(bushost, busport)
OpenBusContext:setDefaultConnection(conn)
-- login to the bus
conn:loginByPassword(user, password)
-- define service properties
properties[#properties+1] =
{name="openbus.component.interface",value=iface.repID}
-- define test cases
local CredentialResetCases = {
{
target = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
session = 2^32-1,
secret = string.rep("\171", 16),
expected = except.minor.InvalidTarget,
},
{
session = 2^32-1,
challenge = string.rep("\171", idl.const.EncryptedBlockSize),
expected = except.minor.InvalidRemote,
},
}
local NoPermisisonCases = {
{raised=0,expected=0},
{raised=except.minor.InvalidCredential,expected=except.minor.InvalidRemote},
{raised=except.minor.InvalidChain,expected=except.minor.InvalidChain},
{raised=except.minor.UnverifiedLogin,expected=except.minor.UnverifiedLogin},
{raised=except.minor.UnknownBus,expected=except.minor.UnknownBus},
{raised=except.minor.InvalidPublicKey,expected=except.minor.InvalidPublicKey},
{raised=except.minor.NoCredential,expected=except.minor.NoCredential},
{raised=except.minor.NoLogin,expected=except.minor.InvalidRemote},
{raised=except.minor.InvalidRemote,expected=except.minor.InvalidRemote},
{raised=except.minor.UnavailableBus,expected=except.minor.InvalidRemote},
{raised=except.minor.InvalidTarget,expected=except.minor.InvalidRemote},
{raised=except.minor.InvalidLogin,expected=except.minor.InvalidRemote},
}
-- find the offered service
log:TEST("retrieve hello service")
local OfferRegistry = OpenBusContext:getOfferRegistry()
for _, offer in ipairs(findoffers(OfferRegistry, properties)) do
local entity = getprop(offer.properties, "openbus.offer.entity")
log:TEST("found service of ",entity,"!")
local server = offer.service_ref:getFacetByName(iface.name):__narrow(iface)
server:NonBusCall()
for _, case in ipairs(CredentialResetCases) do
local ok, ex
if case.challenge == nil then
ok, ex = pcall(server.ResetCredential, server,
case.target, case.session, case.secret)
else
ok, ex = pcall(server.ResetCredentialWithChallenge, server,
case.session, case.challenge)
end
assert(ok == false)
assert(ex._repid == except.repid.NO_PERMISSION)
assert(ex.minor == case.expected)
assert(ex.completed == "COMPLETED_NO")
end
for _, case in ipairs(NoPermisisonCases) do
local ok, ex = pcall(server.RaiseNoPermission, server, case.raised)
assert(ok == false)
assert(ex._repid == except.repid.NO_PERMISSION)
assert(ex.minor == case.expected)
assert(ex.completed == "COMPLETED_NO")
end
log:TEST("test successful for service of ",entity)
end
-- logout from the bus
conn:logout()
orb:shutdown()
local log = require "openbus.util.logger"
local openbus = require "openbus"
local ComponentContext = require "scs.core.ComponentContext"
-- create service implementation
local impl, servant, iface do
require "openbus.test.lowlevel"
local idl = require "openbus.core.idl"
local sysex = require "openbus.util.sysex"
-- initialize the ORB
local orb = initORB()
idl.loadto(orb)
-- load interface definition
orb:loadidlfile("idl/mock.idl")
iface = orb.types:lookup("tecgraf::openbus::interop::protocol::Server")
impl = { __type = iface }
function impl:NonBusCall(...)
return ...
end
function impl:RaiseNoPermission(minor)
sysex.NO_PERMISSION{ completed = "COMPLETED_NO", minor = minor }
end
function impl:ResetCredential(target, session, secret)
local data = assert(getreqcxt(idl.const.credential.CredentialContextId))
local cred = assert(decodeCredential(data))
local client = self.context:getLoginRegistry():getLoginInfo(cred.login)
putrepcxt(idl.const.credential.CredentialContextId, encodeReset{
target = target,
session = session,
challenge = assert(client.pubkey:encrypt(secret)),
})
sysex.NO_PERMISSION{
completed = "COMPLETED_NO",
minor = idl.const.services.access_control.InvalidCredentialCode,
}
end
function impl:ResetCredentialWithChallenge(session, challenge)
putrepcxt(idl.const.credential.CredentialContextId, encodeReset{
target = self.login,
session = session,
challenge = challenge,
})
sysex.NO_PERMISSION{
completed = "COMPLETED_NO",
minor = idl.const.services.access_control.InvalidCredentialCode,
}
end
servant = orb:newservant(impl)
end
require "openbus.test.util"
-- setup and start the ORB
local orb = openbus.initORB()
-- customize test configuration for this case
settestcfg(iface, ...)
-- get bus context manager
local OpenBusContext = orb.OpenBusContext
impl.context = OpenBusContext
-- create service SCS component
local component = ComponentContext(orb, {
name = "Mock",
major_version = 1,
minor_version = 0,
patch_version = 0,
platform_spec = "Lua",
})
component._facets[iface.name] = {
name = iface.name,
interface_name = iface.repID,
facet_ref = servant,
implementation = impl,
}
component[iface.name] = servant
-- connect to the bus
local conn = OpenBusContext:createConnection(bushost, busport)
OpenBusContext:setDefaultConnection(conn)
-- login to the bus
conn:loginByCertificate(system, assert(openbus.readKeyFile(syskey)))
impl.login = conn.login.id
-- offer service
local OfferRegistry = OpenBusContext:getOfferRegistry()
OfferRegistry:registerService(component.IComponent, properties)
log:TEST("hello service ready!")
#!/bin/bash
/bin/bash runtest.sh $1 protocol server
/bin/bash runtest.sh $1 simple server
/bin/bash runtest.sh $1 multiplexing server
/bin/bash runtest.sh $1 sharedauth server
......
......@@ -11,6 +11,8 @@ for case, services in pairs{
SharedAuth = { "Hello" },
ReloggedJoin = { "Hello" },
Delegation = { "Messenger","Broadcaster","Forwarder" },
Protocol = { "Server" },
Chaining = { "Hello","HelloProxy" },
} do
for _, iface in ipairs(services) do
local module = case:lower()
......
This diff is collapsed.
......@@ -23,14 +23,13 @@ local packargs = vararg.pack
local Wrapper = require "loop.object.Wrapper"
local giop = require "oil.corba.giop"
local sysexid = giop.SystemExceptionIDs
local log = require "openbus.util.logger"
local msg = require "openbus.util.messages"
local oo = require "openbus.util.oo"
local class = oo.class
local sysex = require "openbus.util.sysex"
local NO_PERMISSION = sysex.NO_PERMISSION
local is_OBJECT_NOT_EXIST = sysex.is_OBJECT_NOT_EXIST
local coreidl = require "openbus.core.idl"
local const = coreidl.const.services.access_control
......@@ -254,7 +253,7 @@ function SetPropTask:receive()
local ref = offer.description.ref
local properties = offer.properties
local ok, result = pcall(ref.setProperties, ref, properties)
if ok or result._repid == sysexid.OBJECT_NOT_EXIST then
if ok or is_OBJECT_NOT_EXIST(result) then
offer.description.properties = properties
break
end
......@@ -311,7 +310,7 @@ end
function RegisteredOffer:subscribeObserver(observer, properties)
local assistant = self.assistant
if assistant.loginargs == nil then
sysex.NO_PERMISSION{ minor = const.NoLogin }
NO_PERMISSION{ minor = const.NoLogin }
end
return OfferObserverSubscription{
assistant = assistant,
......@@ -406,7 +405,7 @@ end
function Assistant:registerService(component, properties)
if self.loginargs == nil then
sysex.NO_PERMISSION{ minor = const.NoLogin }
NO_PERMISSION{ minor = const.NoLogin }
end
return RegisteredOffer{
assistant = self,
......@@ -417,7 +416,7 @@ end
function Assistant:subscribeObserver(observer, properties)
if self.loginargs == nil then
sysex.NO_PERMISSION{ minor = const.NoLogin }
NO_PERMISSION{ minor = const.NoLogin }
end
return OfferRegistryObserverSubscription{
assistant = self,
......
......@@ -31,8 +31,6 @@ local memoize = table.memoize
local oil = require "oil"
local neworb = oil.init
local giop = require "oil.corba.giop"
local sysex = giop.SystemExceptionIDs
local CORBAException = require "oil.corba.giop.Exception"
local idl = require "oil.corba.idl"
local OctetSeq = idl.OctetSeq
......@@ -47,6 +45,8 @@ local LRUCache = require "loop.collection.LRUCache"
local log = require "openbus.util.logger"
local oo = require "openbus.util.oo"
local class = oo.class
local sysex = require "openbus.util.sysex"
local is_NO_PERMISSION = sysex.is_NO_PERMISSION
local tickets = require "openbus.util.tickets"
local msg = require "openbus.core.messages"
......@@ -97,6 +97,7 @@ local function newSecret()
end
local function setNoPermSysEx(request, minor)
request.islocal = true
request.success = false
request.results = {CORBAException{"NO_PERMISSION",
completed = "COMPLETED_NO",
......@@ -204,6 +205,25 @@ function Interceptor:resetCaches()
}
end
function Interceptor:unmarshalSignedChain(chain, busid)
local encoded = chain.encoded
if encoded ~= "" then
local context = self.context
local types = context.types
local orb = context.orb
local decoder = orb:newdecoder(chain.encoded)
local decoded = decoder:get(types.CallChain)
local originators = decoded.originators
originators.n = nil -- remove field 'n' created by OiL unmarshal
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
......@@ -211,19 +231,7 @@ function Interceptor:unmarshalCredential(contexts)
local data = contexts[CredentialContextId]
if data ~= nil then
local credential = orb:newdecoder(data):get(types.CredentialData)
local chain = credential.chain
local encoded = chain.encoded
if encoded == "" then
credential.chain = nil
else
local decoder = orb:newdecoder(encoded)
local decoded = decoder:get(types.CallChain)
local originators = decoded.originators
originators.n = nil -- remove field 'n' created by OiL unmarshal
chain.originators = originators
chain.caller = decoded.caller
chain.target = decoded.target
end
credential.chain = unmarshalSignedChain(self, credential.chain, credential.bus)
return credential
end
end
......@@ -236,7 +244,8 @@ function Interceptor:sendrequest(request)
local orb = context.orb
local chain = context.joinedChainOf[running()]
local sessionid, ticket, hash = 0, 0, NullHash
local target = self.profile2login:get(request.profile_data)
local profile2login = self.profile2login
local target = profile2login:get(request.profile_data)
if target ~= nil then -- known IOR profile, so it supports OpenBus 2.0
local ok, result = pcall(self.signChainFor, self, target, chain or NullChain)
if not ok then
......@@ -245,8 +254,13 @@ function Interceptor:sendrequest(request)
target = target,
chain = chain,
})
local minor = loginconst.BusUnavailableCode
local minor = loginconst.UnavailableBusCode
if result._repid == InvalidLoginsException then
for profile_data, profile_target in pairs(profile2login.map) do
if target == profile_target then
profile2login:remove(profile_data)
end
end
minor = loginconst.InvalidTargetCode
end
setNoPermSysEx(request, minor)
......@@ -288,46 +302,59 @@ function Interceptor:sendrequest(request)
request.service_context = contexts
end
local ExclusivelyLocal = {
[loginconst.NoLoginCode] = true,
[loginconst.InvalidRemoteCode] = true,
[loginconst.UnavailableBusCode] = true,
[loginconst.InvalidTargetCode] = true,
}
function Interceptor:receivereply(request)
if not request.success then
local except = request.results[1]
if except._repid == sysex.NO_PERMISSION
and except.completed == "COMPLETED_NO"
and except.minor == loginconst.InvalidCredentialCode then
-- got invalid credential exception
local data = request.reply_service_context[CredentialContextId]
if data ~= nil then
local context = self.context
local decoder = context.orb:newdecoder(data)
local reset = decoder:get(context.types.CredentialReset)
local secret, errmsg = self.prvkey:decrypt(reset.challenge)
if secret ~= nil then
local target = reset.target
log:access(self, msg.GotCredentialReset:tag{
operation = request.operation_name,
remote = target,
})
reset.secret = secret
-- initialize session and set credential session information
self.profile2login:put(request.profile_data, target)
self.outgoingSessions:put(target, {
id = reset.session,
secret = reset.secret,
remote = target,
ticket = -1,
})
request.success = nil -- reissue request to the same reference
if is_NO_PERMISSION(except, nil, "COMPLETED_NO") then
if except.minor == loginconst.InvalidCredentialCode then
-- got invalid credential exception
local data = request.reply_service_context[CredentialContextId]
if data ~= nil then
local context = self.context
local decoder = context.orb:newdecoder(data)
local reset = decoder:get(context.types.CredentialReset)
local secret, errmsg = self.prvkey:decrypt(reset.challenge)
if secret ~= nil then
local target = reset.target
log:access(self, msg.GotCredentialReset:tag{
operation = request.operation_name,
remote = target,
})
reset.secret = secret
-- initialize session and set credential session information
self.profile2login:put(request.profile_data, target)
self.outgoingSessions:put(target, {
id = reset.session,
secret = reset.secret,
remote = target,
ticket = -1,
})
request.success = nil -- reissue request to the same reference
else
log:exception(msg.GotCredentialResetWithBadChallenge:tag{
operation = request.operation_name,
remote = reset.target,
error = errmsg,
})
except.minor = loginconst.InvalidRemoteCode
end
else
log:exception(msg.GotCredentialResetWihtBadChallenge:tag{
log:exception(msg.CredentialResetMissing:tag{
operation = request.operation_name,
remote = reset.target,
error = errmsg,
})
except.minor = loginconst.InvalidRemoteCode
end
else
log:exception(msg.CredentialResetMissing:tag{
elseif not request.islocal and ExclusivelyLocal[except.minor] ~= nil then
log:exception(msg.IllegalUseOfLocalMinorCodeByRemoteSite:tag{
operation = request.operation_name,
codeused = except.minor,
})
except.minor = loginconst.InvalidRemoteCode
end
......
......@@ -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")
......
local _G = require "_G"
local error = _G.error
local string = require "string"
local find = string.find
local substring = string.sub
local table = require "loop.table"
local memoize = table.memoize
local giop = require "oil.corba.giop"
local repids = giop.SystemExceptionIDs
local Exception = require "oil.corba.giop.Exception"
return memoize(function(name)
local repId = "IDL:omg.org/CORBA/"..name..":1.0"
return function(fields)
if fields == nil then fields = {} end
fields._repid = repId
error(Exception(fields))
local checker = find(name, "^is_")
local repid = repids[checker and substring(name, 4) or name]
if checker then
return function(except, minor, completed)
return except._repid == repid
and (minor == nil or except.minor == minor)
and (completed == nil or except.completed == completed)
end
else
return function(fields)
if fields == nil then fields = {} end
fields._repid = repid
error(Exception(fields))
end
end
end)
......@@ -36,7 +36,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)