Commit 84990331 authored by Renato Figueiro Maia's avatar Renato Figueiro Maia
Browse files

[OPENBUS-2184] Adaptação do código para ser compatível também com Lua 5.2

- Passa a utilizar o trunk do LOOP e OiL já devidamente adaptados para Lua 5.2 estrito (sem -DCOMPAT)
- Novos testes da API dos serviços básicos do núcleo do barramento (utiliza classes da LOOP-Lib ao invés do LATT).

git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/openbus/core/branches/02_00_00@148854 ae0415b3-e90b-0410-900d-d0be9363c56b
parent 177b14c4
This diff is collapsed.
......@@ -235,5 +235,4 @@ Options:
-- start ORB
log:uptime(msg.CoreServicesStarted)
orb:run()
end
......@@ -28,7 +28,7 @@ syskey = assert(decodeprvkey(readfrom(syskey)))
-- test initialization ---------------------------------------------------------
local bus = connectToBus(bushost, busport)
local bus, orb = connectToBus(bushost, busport)
local ac = bus.AccessControl
local prvkey = newkey(EncryptedBlockSize)
local pubkey = prvkey:encode("public")
......@@ -264,3 +264,5 @@ do
assert(ex.completed == "COMPLETED_NO")
assert(ex.minor == loginconst.InvalidLoginCode)
end
orb:shutdown()
local _G = require "_G"
local string = _G.string
local os = _G.os
local io = _G.io
local print = _G.print
local tostring = _G.tostring
local assert = _G.assert
-------------------------------------------------------------------------------
-- configurao do teste
bushost, busport = ...
......
local _G = require "_G"
local pcall = _G.pcall
local io = require "io"
local openbus = require "openbus"
local cached = require "loop.cached"
local checks = require "loop.test.checks"
local Fixture = require "loop.test.Fixture"
local Suite = require "loop.test.Suite"
local idl = require "openbus.core.idl"
local UnauthorizedOperation = idl.types.services.UnauthorizedOperation
local MissingCertificate = idl.types.services.access_control.MissingCertificate
......@@ -11,240 +12,196 @@ local admidl = require "openbus.core.admin.idl"
local CertificateRegistry = admidl.types.services.access_control.admin.v1_0.CertificateRegistry
local InvalidCertificate = admidl.types.services.access_control.admin.v1_0.InvalidCertificate
local Check = require "latt.Check"
-- Configuraes --------------------------------------------------------------
bushost, busport = ...
require "openbus.test.configs"
local host = bushost
local port = busport
local admin = admin
local adminPassword = admpsw
local dUser = user
local dPassword = password
local certificate = syscrt
-- Inicializao --------------------------------------------------------------
local orb = openbus.initORB()
local OpenBusContext = orb.OpenBusContext
do
admidl.loadto(orb)
function OpenBusContext:getCertificateRegistry()
local conn = self:getCurrentConnection()
if conn == nil or conn.login == nil then
sysexthrow.NO_PERMISSION{
completed = "COMPLETED_NO",
minor = loginconst.NoLoginCode,
}
end
local facet = conn.bus:getFacetByName("CertificateRegistry")
return self.orb:narrow(facet, CertificateRegistry)
end
end
local connprops = { accesskey = openbus.newKey() }
-- Casos de Teste -------------------------------------------------------------
Suite = {}
Suite.Test1 = {}
Suite.Test2 = {}
Suite.Test3 = {}
-- Aliases
local NoPermissionCase = Suite.Test1
local InvalidParamCase = Suite.Test2
local CRCase = Suite.Test3
-- Testes do CertificateRegistry ----------------------------------------------
-- -- IDL operations
-- function CertificateRegistry:registerCertificate(entity, certificate)
-- function CertificateRegistry:getCertificate(entity)
-- function CertificateRegistry:removeCertificate(entity)
--------------------------------
-- Caso de teste "NO PERMISSION"
--------------------------------
function NoPermissionCase.beforeTestCase(self)
local conn = OpenBusContext:createConnection(host, port, connprops)
OpenBusContext:setDefaultConnection(conn)
conn:loginByPassword(dUser, dPassword)
self.conn = conn
end
function NoPermissionCase.afterTestCase(self)
self.conn:logout()
OpenBusContext:setDefaultConnection(nil)
self.conn = nil
end
function NoPermissionCase.testRegisterCertificateNoPermission(self)
local certificates = OpenBusContext:getCertificateRegistry()
local file = assert(io.open(certificate, "rb"))
local cert = file:read("*a")
file:close()
local ok, err = pcall(certificates.registerCertificate, certificates, "random",
cert)
Check.assertTrue(not ok)
Check.assertEquals(UnauthorizedOperation, err._repid)
end
function NoPermissionCase.testGetCertificateNoPermission(self)
local certificates = OpenBusContext:getCertificateRegistry()
local ok, err = pcall(certificates.getCertificate, certificates, "random")
Check.assertTrue(not ok)
Check.assertEquals(UnauthorizedOperation, err._repid)
end
function NoPermissionCase.testGetEntitiesWithCertificateNoPermission(self)
local certificates = OpenBusContext:getCertificateRegistry()
local ok, err = pcall(certificates.getEntitiesWithCertificate, certificates)
Check.assertTrue(not ok)
Check.assertEquals(UnauthorizedOperation, err._repid)
end
function NoPermissionCase.testRemoveCertificateNoPermission(self)
local certificates = OpenBusContext:getCertificateRegistry()
local ok, err = pcall(certificates.removeCertificate, certificates, "random")
Check.assertTrue(not ok)
Check.assertEquals(UnauthorizedOperation, err._repid)
end
-------------------------------------
-- Caso de teste "INVALID PARAMETERS"
-------------------------------------
function InvalidParamCase.beforeTestCase(self)
local conn = OpenBusContext:createConnection(host, port, connprops)
OpenBusContext:setDefaultConnection(conn)
conn:loginByPassword(admin, adminPassword)
self.conn = conn
self.certs = OpenBusContext:getCertificateRegistry()
end
function InvalidParamCase.afterTestCase(self)
self.conn:logout()
OpenBusContext:setDefaultConnection(nil)
self.conn = nil
self.certs = nil
end
function InvalidParamCase.testRegisterEmptyCertificate(self)
local certs = self.certs
local file = io.tmpfile()
local read = file:read("*a")
local ok, err = pcall(certs.registerCertificate, certs, "unknown", read)
Check.assertTrue(not ok)
Check.assertEquals(InvalidCertificate, err._repid)
file:close()
end
function InvalidParamCase.testRegisterInvalidCertificate(self)
local certs = self.certs
local file = assert(io.open(certificate, "rb"))
local read = file:read("*a")
read = "\n--CORRUPTED!--\n" .. read
local ok, err = pcall(certs.registerCertificate, certs, "unknown", read)
Check.assertTrue(not ok)
Check.assertEquals(InvalidCertificate, err._repid)
file:close()
end
function InvalidParamCase.testInvalidGetCertificate(self)
local certs = self.certs
local ok, err = pcall(certs.getCertificate, certs, "unknown")
Check.assertTrue(not ok)
Check.assertEquals(MissingCertificate, err._repid)
end
function InvalidParamCase.testInvalidRemoveCertificate(self)
local certs = self.certs
local ok, err = pcall(certs.removeCertificate, certs, "unknown")
Check.assertTrue(ok)
Check.assertFalse(err)
end
-------------------------------------
-- Caso de teste "PADRO"
-------------------------------------
function CRCase.beforeTestCase(self)
local conn = OpenBusContext:createConnection(host, port, connprops)
OpenBusContext:setDefaultConnection(conn)
conn:loginByPassword(admin, adminPassword)
self.conn = conn
self.certs = OpenBusContext:getCertificateRegistry()
end
require "openbus.test.core.services.utils"
function CRCase.afterTestCase(self)
self.conn:logout()
OpenBusContext:setDefaultConnection(nil)
self.conn = nil
self.certs = nil
end
local FakeEntityName = "FakeEntityName"
function CRCase.testRegisterRemoveCertificate(self)
local certs = self.certs
local file = assert(io.open(certificate, "rb"))
local read = file:read("*a")
file:close()
certs:registerCertificate("test-1", read)
Check.assertTrue(certs:removeCertificate("test-1"))
end
-- Funes auxiliares ---------------------------------------------------------
function CRCase.testRegisterGetRemoveCertificate(self)
local certs = self.certs
local file = assert(io.open(certificate, "rb"))
local read = file:read("*a")
local SomeCertificate do
local file = assert(io.open(syscrt, "rb"))
SomeCertificate = file:read("*a")
file:close()
certs:registerCertificate("test-2", read)
local result = certs:getCertificate("test-2")
Check.assertTrue(read == result, "certificate file should be the same")
Check.assertTrue(certs:removeCertificate("test-2"))
end
function CRCase.testRegisterCertificateTwice(self)
local certs = self.certs
local file = assert(io.open(certificate, "rb"))
local read = file:read("*a")
file:close()
certs:registerCertificate("test-3", read)
certs:registerCertificate("test-3", read)
local result = certs:removeCertificate("test-3")
Check.assertTrue(result)
local result = certs:removeCertificate("test-3")
Check.assertFalse(result)
end
local CertificatesFixture = cached.class({}, IdentityFixture)
function CRCase.testGetListWithManyEntitiesWithCertificate(self)
local certs = self.certs
-- get entities with previously registered certificates
local previous = {}
local prevcount
for index, entity in ipairs(certs:getEntitiesWithCertificate()) do
previous[entity] = true
prevcount = index
function CertificatesFixture:setup(openbus)
IdentityFixture.setup(self, openbus)
local certificates = self.certificates
if self.certificates == nil then
local conn = openbus.context:getCurrentConnection()
local facet = conn.bus:getFacetByName("CertificateRegistry")
certificates = openbus.orb:narrow(facet, CertificateRegistry)
self.certificates = certificates
end
-- register some new certificates
local file = assert(io.open(certificate, "rb"))
local read = file:read("*a")
file:close()
local count = 3
local expected = {}
for i = 1, count do
local entity = "test-4_"..i
expected[entity] = true
certs:registerCertificate(entity, read)
local unregistered = self.unregistered
if unregistered ~= nil then
local context = openbus.context
if self.identity ~= "admin" then
local admin = self:newConn("admin")
context:setCurrentConnection(admin)
self.admin = admin
end
for _, entity in ipairs(unregistered) do
local ok, err = pcall(certificates.getCertificate, certificates, entity)
checks.assert(ok, checks.equal(false))
checks.assert(err._repid, checks.equal(MissingCertificate))
end
context:setCurrentConnection(nil)
end
-- check the new list inclue the new entities with registered certificates
local list = certs:getEntitiesWithCertificate()
Check.assertEquals(count+prevcount, #list)
for _, entity in ipairs(list) do
if not previous[entity] then
Check.assertTrue(expected[entity])
expected[entity] = nil
certs:removeCertificate(entity)
end
function CertificatesFixture:teardown(openbus)
local unregistered = self.unregistered
if unregistered ~= nil then
if self.identity ~= "admin" then
openbus.context:setCurrentConnection(self.admin)
end
for _, entity in ipairs(unregistered) do
self.certificates:removeCertificate(entity)
end
end
return IdentityFixture.teardown(self, openbus)
end
-- Testes do CertificateRegistry ----------------------------------------------
return OpenBusFixture{
idlloaders = { admidl.loadto },
Suite{
--------------------------------
-- Caso de teste "NO PERMISSION"
--------------------------------
AsUser = CertificatesFixture{
identity = "user",
unregistered = { FakeEntityName },
tests = Suite(makeSimpleTests{
certificates = {
registerCertificate = {
Unauthorized = {
params = { FakeEntityName, SomeCertificate },
except = checks.like{_repid=UnauthorizedOperation},
},
},
getCertificate = {
Unauthorized = {
params = { FakeEntityName },
except = checks.like{_repid=UnauthorizedOperation},
},
},
getEntitiesWithCertificate = {
Unauthorized = {
params = { FakeEntityName },
except = checks.like{_repid=UnauthorizedOperation},
},
},
removeCertificate = {
Unauthorized = {
params = { FakeEntityName },
except = checks.like{_repid=UnauthorizedOperation},
},
},
},
}),
},
AsAdmin = CertificatesFixture{
identity = "admin",
unregistered = {
FakeEntityName,
FakeEntityName.."-1",
FakeEntityName.."-2",
FakeEntityName.."-3",
},
tests = Suite(makeSimpleTests{
-------------------------------------
-- Caso de teste "INVALID PARAMETERS"
-------------------------------------
certificates = {
registerCertificate = {
Empty = {
params = { FakeEntityName, "" },
except = checks.like{_repid=InvalidCertificate},
},
Invalid = {
params = { FakeEntityName, "\n--CORRUPTED!--\n"..SomeCertificate },
except = checks.like{_repid=InvalidCertificate},
},
},
getCertificate = {
Missing = {
params = { FakeEntityName },
except = checks.like{
_repid = MissingCertificate,
entity = FakeEntityName,
},
},
},
removeCertificate = {
Missing = {
params = { FakeEntityName },
result = { checks.equal(false) },
},
},
},
-------------------------
-- Caso de teste "PADRO"
-------------------------
RegisterRemoveCertificate = function (fixture)
local certificates = fixture.certificates
certificates:registerCertificate(FakeEntityName, SomeCertificate)
local removed = certificates:removeCertificate(FakeEntityName)
checks.assert(removed, checks.equal(true))
end,
RegisterGetRemoveCertificate = function (fixture)
local certificates = fixture.certificates
certificates:registerCertificate(FakeEntityName, SomeCertificate)
local certificate = certificates:getCertificate(FakeEntityName)
checks.assert(certificate, checks.equal(SomeCertificate))
local removed = certificates:removeCertificate(FakeEntityName)
checks.assert(removed, checks.equal(true))
end,
RegisterCertificateTwice = function (fixture)
local certificates = fixture.certificates
certificates:registerCertificate(FakeEntityName, SomeCertificate)
certificates:registerCertificate(FakeEntityName, SomeCertificate)
local removed = certificates:removeCertificate(FakeEntityName)
checks.assert(removed, checks.equal(true))
removed = certificates:removeCertificate(FakeEntityName)
checks.assert(removed, checks.equal(false))
end,
GetListWithManyEntitiesWithCertificate = function (fixture)
local certificates = fixture.certificates
-- get entities with previously registered certificates
local previous = {}
local prevcount
for index, entity in ipairs(certificates:getEntitiesWithCertificate()) do
previous[entity] = true
prevcount = index
end
-- register some new certificates
local count = 3
local expected = {}
for i = 1, count do
local entity = FakeEntityName.."-"..i
expected[entity] = true
certificates:registerCertificate(entity, SomeCertificate)
end
-- check the new list inclue the new entities with registered certificates
local list = certificates:getEntitiesWithCertificate()
checks.assert(#list, checks.equal(prevcount+count))
for _, entity in ipairs(list) do
if previous[entity] == nil then
checks.assert(expected[entity], checks.equal(true))
expected[entity] = nil
local removed = certificates:removeCertificate(entity)
checks.assert(removed, checks.equal(true))
end
end
end,
}),
},
},
}
local Suite = require "loop.test.Suite"
return Suite{
CertificateRegistry = require "openbus.test.core.services.CertificateRegistry",
EntityRegistry = require "openbus.test.core.services.EntityRegistry",
LoginRegistry = require "openbus.test.core.services.LoginRegistry",
OfferRegistry = require "openbus.test.core.services.OfferRegistry",
}
This diff is collapsed.
......@@ -9,13 +9,12 @@ elif [ "$1" != "RELEASE" ]; then
exit 1
fi
LATT_LUA=${LATT_LUA:=$OPENBUS_HOME/lib/lua/5.2}
LATT_PRELUDE="package.path=package.path..';$LATT_LUA/?.lua'"
TEST_PRELUDE='package.path=package.path..";"..(os.getenv("OPENBUS_CORE_LUA") or "../lua").."/?.lua"'
LUACASES="\
openbus/test/core/services/LoginDB \
openbus/test/core/Protocol \
openbus/test/core/admin/admin \
"
for case in ${LUACASES}; do
echo -n "Test '${case}' ... "
......@@ -23,15 +22,16 @@ for case in ${LUACASES}; do
echo "OK"
done
LATTCASES="\
openbus/test/core/services/LoginRegistry \
openbus/test/core/services/CertificateRegistry \
openbus/test/core/services/EntityRegistry \
openbus/test/core/services/OfferRegistry \
openbus/test/core/admin/admin \
"
#openbus/test/core/services/LDAPAuthentication
for case in ${LATTCASES}; do
echo "LATT '${case}':"
$CONSOLE -e "$LATT_PRELUDE" $LATT_LUA/latt/ConsoleTestRunner.lua ${case}.lua ${@:2:${#@}} || exit $?
done
TEST_RUNNER="local suite = require('openbus.test.core.services.Suite')
local Runner = require('loop.test.Results')
local path = {}
for name in string.gmatch('$2', '[^.]+') do
path[#path+1] = name
end
local runner = Runner{
reporter = require('loop.test.Reporter'),
path = (#path > 0) and path or nil,
}
runner('OpenBus', suite)"
$CONSOLE -e "$TEST_RUNNER" || exit $?
Supports Markdown
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