Commit 639f4f77 authored by Renato Figueiro Maia's avatar Renato Figueiro Maia

[OPENBUS-2601] (Lua) Implementação dos testes de interoperabilidade de exceções do protocolo

git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/openbus/sdk/lua/branches/02_00_00@157634 ae0415b3-e90b-0410-900d-d0be9363c56b
parent 3ed1e651
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.NoLogin},
}
-- 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,7 @@ for case, services in pairs{
SharedAuth = { "Hello" },
ReloggedJoin = { "Hello" },
Delegation = { "Messenger","Broadcaster","Forwarder" },
Protocol = { "Server" },
} do
for _, iface in ipairs(services) do
local module = case:lower()
......
......@@ -108,15 +108,29 @@ do -- CORBA GIOP message context manipuation functions
end
do -- protocol data encoding functions
function calculateHash(secret, ticket, opname)
return sha256("\002\000"..encode(
"<c0I4c0", -- '<' flag to set to little endian
secret, -- 'c0' sequence of all chars of a string
ticket, -- 'I4' unsigned integer with 4 bytes
opname)) -- 'c0' sequence of all chars of a string
end
function encodeCredential(data)
data.hash = sha256("\002\000"..encode(
"<c0I4c0", -- '<' flag to set to little endian
data.secret, -- 'c0' sequence of all chars of a string
data.ticket, -- 'I4' unsigned integer with 4 bytes
data.opname)) -- 'c0' sequence of all chars of a string
if data.hash == nil then
data.hash = calcHash(data.secret, data.ticket, data.opname)
end
return encodeCDR(data, credtypes.CredentialData)
end
function decodeCredential(stream)
return decodeCDR(stream, credtypes.CredentialData)
end
function encodeReset(data)
return encodeCDR(data, credtypes.CredentialReset)
end
function decodeReset(stream, prvkey)
local reset = decodeCDR(stream, credtypes.CredentialReset)
reset.secret = assert(prvkey:decrypt(reset.challenge))
......
......@@ -35,8 +35,8 @@ function findoffers(offers, props, count, tries, interval)
if count == nil then count = 1 end
if tries == nil then tries = 10 end
if interval == nil then interval = 1 end
local found = {}
for i = 1, tries do
local found = {}
local offers = offers:findServices(props)
for _, offer in ipairs(offers) do
local service = offer.service_ref
......@@ -46,6 +46,7 @@ function findoffers(offers, props, count, tries, interval)
end
end
if #found >= count then return found end
found = {}
openbus.sleep(interval)
end
error(msg.UnableToFindOffers:tag{
......
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