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

[OPENBUS-1599] Criar suite de testes para o core e sdk-lua do OpenBus 2.0

git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/openbus/sdk/lua/branches/openbus_v2_proto@130301 ae0415b3-e90b-0410-900d-d0be9363c56b
parent de510e14
......@@ -9,29 +9,19 @@ local unpack = _G.unpack
local coroutine = require "coroutine"
local string = require "string"
local io = require "io"
local uuid = require "uuid"
local pubkey = require "lce.pubkey"
local giop = require "oil.corba.giop"
local cothread = require "cothread"
local openbus = require "openbus"
local msg = require "openbus.util.messages"
local idl = require "openbus.core.idl"
local msg = require "openbus.util.messages"
local log = require "openbus.util.logger"
log:level(0)
log:flag("TEST", true)
-- Configuraes --------------------------------------------------------------
local bushost = "localhost"
local busport = 2089
local admin = "admin"
local admpsw = admin
local entity = "TesteBarramento"
local password = entity
local keypath = "TesteBarramento.key"
bushost, busport, verbose = ...
require "openbus.util.testcfg"
local file = assert(io.open(keypath, "rb"))
local privatekey = assert(pubkey.decodeprivate(assert(file:read("*a"))))
file:close()
log:flag("TEST", verbose~=nil)
local thread = coroutine.running()
local userdata = io.stdout
......@@ -39,10 +29,7 @@ local sleep = cothread.delay
local sysex = giop.SystemExceptionIDs
local FourHex = string.rep("%x", 4)
local RamdonUuid = string.format("^%s%%-%s%%-%s%%-%s%%-%s$",
FourHex:rep(2), FourHex, "4%x%x%x", "[89AB]%x%x%x", FourHex:rep(3))
local entity = nil -- defined later
local orb = openbus.initORB()
local manager = orb.OpenBusConnectionManager
assert(manager.orb == orb)
......@@ -74,10 +61,6 @@ local invalidate, shutdown, leasetime do
manager:setDefaultConnection(conn)
leasetime = conn.AccessControl:renew()
function invalidate(loginId)
local validity = logins:getValidity({loginId})[1]
if validity < 1 then
sleep(2) -- wait for the renewer thread to renew the login
end
logins:invalidateLogin(loginId)
end
function shutdown()
......@@ -86,14 +69,14 @@ local invalidate, shutdown, leasetime do
end
local loginways = {
loginByPassword = function() return entity, password end,
loginByCertificate = function() return entity, privatekey end,
loginByPassword = function() return user, password end,
loginByCertificate = function() return system, syskey end,
loginBySingleSignOn = function()
return { -- dummy login process object
login = function()
return {
id = "60D57646-33A4-4108-88DD-AE9B7A9E3C7A",
entity = entity,
entity = system,
}, leasetime
end,
cancel = function () end,
......@@ -108,8 +91,8 @@ local function assertlogged(conn)
assert(conn.orb == orb)
-- check logged in only attributes
assert(conn.login.entity == entity)
assert(conn.login.id:match(RamdonUuid))
assert(conn.busid:match(RamdonUuid))
assert(uuid.isvalid(conn.login.id))
assert(uuid.isvalid(conn.busid))
local loginid = conn.login.id
local busid = conn.busid
-- check the attempt to login again
......@@ -216,7 +199,7 @@ for _, connOp in ipairs({"DefaultConnection", "Requester"}) do
local conn = conns[1]
for _, invalid in ipairs{nil,true,false,123,{},error,thread,userdata} do
local badtype = type(invalid)
local ex = catcherr(conn.loginByPassword, conn, entity, invalid)
local ex = catcherr(conn.loginByPassword, conn, user, invalid)
assert(ex:match("bad argument #2 to 'loginByPassword' %(expected string, got "..badtype.."%)$"))
assertlogoff(conn)
end
......@@ -226,7 +209,7 @@ for _, connOp in ipairs({"DefaultConnection", "Requester"}) do
local conn = conns[1]
for _, invalid in ipairs{nil,true,false,123,"key",{},error,thread} do
local badtype = type(invalid)
local ex = catcherr(conn.loginByCertificate, conn, entity, invalid)
local ex = catcherr(conn.loginByCertificate, conn, system, invalid)
assert(ex:match("bad argument #2 to 'loginByCertificate' %(expected userdata, got "..badtype.."%)$"))
assertlogoff(conn)
end
......@@ -234,14 +217,14 @@ for _, connOp in ipairs({"DefaultConnection", "Requester"}) do
do log:TEST "login with wrong password"
local conn = conns[1]
local ex = catcherr(conn.loginByPassword, conn, entity, "WrongPassword")
local ex = catcherr(conn.loginByPassword, conn, user, "WrongPassword")
assert(ex._repid == idl.types.services.access_control.AccessDenied)
assertlogoff(conn)
end
do log:TEST "login with entity without certificate"
local conn = conns[1]
local ex = catcherr(conn.loginByCertificate, conn, "NoCertif.", privatekey)
local ex = catcherr(conn.loginByCertificate, conn, "NoCertif.", syskey)
assert(ex._repid == idl.types.services.access_control.MissingCertificate)
assert(ex.entity == "NoCertif.")
assertlogoff(conn)
......@@ -249,7 +232,7 @@ for _, connOp in ipairs({"DefaultConnection", "Requester"}) do
do log:TEST "login with wrong private key"
local conn = conns[1]
local ex = catcherr(conn.loginByCertificate, conn, entity,
local ex = catcherr(conn.loginByCertificate, conn, system,
pubkey.create(idl.const.EncryptedBlockSize))
assert(ex:find(msg.WrongPrivateKey, 1, true))
assertlogoff(conn)
......@@ -352,7 +335,7 @@ for _, connOp in ipairs({"DefaultConnection", "Requester"}) do
local ex = callwithin(conn, catcherr, offers.findServices, offers, {})
assert(ex._repid == sysex.NO_PERMISSION)
assert(ex.completed == "COMPLETED_NO")
assert(ex.minor == idl.const.services.access_control.InvalidLoginCode)
assert(ex.minor == idl.const.services.access_control.NoLoginCode)
assert(called); called = nil
assertlogoff(conn)
relogin()
......@@ -362,7 +345,6 @@ for _, connOp in ipairs({"DefaultConnection", "Requester"}) do
function conn:onInvalidLogin(login, busid)
assertCallback(self, login, busid)
relogin()
return true
end
-- during renew
invalidate(conn.login.id)
......@@ -401,8 +383,8 @@ for _, connOp in ipairs({"DefaultConnection", "Requester"}) do
end
testlogin(conns[1], "loginByPassword")
testlogin(conns[1], "loginByCertificate")
entity = user; testlogin(conns[1], "loginByPassword")
entity = system; testlogin(conns[1], "loginByCertificate")
end
log:TEST(false)
......
local _G = require "_G"
local assert = _G.assert
local io = require "io"
local open = io.open
local os = require "os"
local getenv = os.getenv
local verbose = require "oil.verbose"
local log = require "openbus.util.logger"
local server = require "openbus.util.server"
local pkey = server.readprivatekey
local setuplog = server.setuplog
propsfile = getenv("OPENBUS_TESTCFG") or "test.properties"
-- TODO: suggest Cadu to do all this in 'scs.core.utils' -----------------------
local props = {getTagOrDefault=function(self, name, default) return default end}
local file = open(propsfile, "r")
if file ~= nil then
file:close()
require("scs.core.utils")():readProperties(props, propsfile)
end
-- TODO END --------------------------------------------------------------------
testbase = propsfile:match("^(.-)[^/\\]+$")
setuplog(verbose, props:getTagOrDefault("oil.verbose.level" , 0),
props:getTagOrDefault("oil.verbose.file" , ""))
setuplog(log, props:getTagOrDefault("openbus.log.level" , 0),
props:getTagOrDefault("openbus.log.file" , ""))
leasetime = props:getTagOrDefault("login.lease.time" , 1)
expirationgap = props:getTagOrDefault("login.expiration.gap", leasetime/2)
buskey = props:getTagOrDefault("bus.private.key" , testbase.."openbus.key")
busdb = props:getTagOrDefault("bus.database" , testbase.."openbus.db")
bushost = bushost or props:getTagOrDefault("bus.host.name" , "localhost")
busport = busport or props:getTagOrDefault("bus.host.port" , 2089)
admin = props:getTagOrDefault("admin.entity.name" , "admin")
admpsw = props:getTagOrDefault("admin.password" , admin)
user = props:getTagOrDefault("user.entity.name" , "testuser")
password = props:getTagOrDefault("user.password" , user)
system = props:getTagOrDefault("system.entity.name" , "testsyst")
syskey = assert(pkey(props:getTagOrDefault("system.private.key" , testbase.."testsyst.key")))
syscrt = props:getTagOrDefault("system.certificate" , testbase.."testsyst.crt")
category = props:getTagOrDefault("entity.category.name", "testents")
ldapurl = props:getTagOrDefault("ldap.url.tcp" , "ldap://ldap-teste:389")
ldapssl = props:getTagOrDefault("ldap.url.ssl" , "ldaps://ldap-teste:636")
ldappat = props:getTagOrDefault("ldap.pattern" , "cn=%U,ou=usuarios,dc=tecgraf,dc=puc-rio,dc=br")
ldaptimeout = props:getTagOrDefault("ldap.timeout" , 5)
admscript = props:getTagOrDefault("admin.script.test" , "testscript.adm")
admoutput = props:getTagOrDefault("admin.output.file" , "busadmin.txt")
#!/bin/ksh
if [ -z "${OPENBUS_HOME}" ] ;then
echo "[ERRO] Varivel de ambiente OPENBUS_HOME no definida"
exit 1
fi
###############################################################################
. ./test.properties
if [ -z "${host}" ]; then
host="localhost"
fi
if [ -z "${port}" ]; then
port=2089
fi
if [ -z "${adminLogin}" ]; then
adminLogin="admin"
fi
if [ -z "${adminPassword}" ]; then
adminPassword="admin"
fi
if [ -z "${entity}" ]; then
entity="TesteBarramento"
fi
if [ -z "${category}" ]; then
category=${entity}
fi
if [ -z "${certificate}" ]; then
certificate="${entity}.crt"
fi
###############################################################################
if [ ! -e ${certificate} ]; then
echo -e '\n\n\n\n\n\n\n' | openssl-generate.ksh -n ${entity}
CODE=$?
if [ ${CODE} -ne 0 ]; then
echo "[ERRO] Falha na gerao dos certificados"
exit 1
fi
fi
ADMIN_EXTRAARGS="--host=${host} --port=${port} "
ADMIN_EXTRAARGS="${ADMIN_EXTRAARGS} --login=${adminLogin} "
ADMIN_EXTRAARGS="${ADMIN_EXTRAARGS} --password=${adminPassword} "
${OPENBUS_HOME}/bin/busadmin ${ADMIN_EXTRAARGS} --add-category=${category} --name="Teste_do_OpenBus"
CODE=$?
${OPENBUS_HOME}/bin/busadmin ${ADMIN_EXTRAARGS} --add-entity=${entity} --category=${category} --name="Teste_do_Barramento"
CODE=$?
${OPENBUS_HOME}/bin/busadmin ${ADMIN_EXTRAARGS} --add-certificate=${entity} --certificate=${certificate}
CODE=$?
# hoje no possvel recuperar o cdigo de retorno da execuo do busadmin
# essa verificao final precisa ser revista
if [ ${CODE} -ne 0 ]; then
echo "[ERRO] Falha ao configurar o ambiente de teste."
exit 1
fi
#!/bin/ksh
if [ -z "${OPENBUS_HOME}" ] ;then
echo "[ERRO] Varivel de ambiente OPENBUS_HOME no definida"
exit 1
fi
###############################################################################
. ./test.properties
if [ -z "${host}" ]; then
host="localhost"
fi
if [ -z "${port}" ]; then
port=2089
fi
if [ -z "${adminLogin}" ]; then
adminLogin="admin"
fi
if [ -z "${adminPassword}" ]; then
adminPassword="admin"
fi
if [ -z "${entity}" ]; then
entity="TesteBarramento"
fi
if [ -z "${category}" ]; then
category=${entity}
fi
###############################################################################
ADMIN_EXTRAARGS="--host=${host} --port=${port} "
ADMIN_EXTRAARGS="${ADMIN_EXTRAARGS} --login=${adminLogin} "
ADMIN_EXTRAARGS="${ADMIN_EXTRAARGS} --password=${adminPassword} "
${OPENBUS_HOME}/bin/busadmin ${ADMIN_EXTRAARGS} --del-certificate=${entity}
${OPENBUS_HOME}/bin/busadmin ${ADMIN_EXTRAARGS} --del-entity=${entity}
${OPENBUS_HOME}/bin/busadmin ${ADMIN_EXTRAARGS} --del-category=${category}
CODE=$?
# hoje no possvel recuperar o cdigo de retorno da execuo do busadmin
# essa verificao final precisa ser revista
if [ ${CODE} -ne 0 ]; then
echo "[ERRO] Falha ao configurar o ambiente de teste."
exit 1
fi
# removendo certificados
rm *.crt
rm *.key
#!/bin/bash
#OPENBUS_HOME=`pwd`/../../../install
export LD_LIBRARY_PATH="${OPENBUS_HOME}/lib:${LD_LIBRARY_PATH}"
export LUA_PATH=";;${OPENBUS_HOME}/../lib/sdk-lua/lua/?.lua;${OPENBUS_HOME}/../svn/lua/?.lua;${OPENBUS_HOME}/test/?.lua;${OPENBUS_HOME}/lib/lua/5.1/?.lua"
PARAMS=$*
LATT_HOME=${OPENBUS_HOME}/lib/lua/5.1/latt
${OPENBUS_HOME}/bin/busconsole -d ${LATT_HOME}/ConsoleTestRunner.lua ${PARAMS}
host=localhost
port=2089
port2=2090
login=admin
password=admin
adminLogin=admin
adminPassword=admin
entity=TesteBarramento
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