admin.lua 3.67 KB
Newer Older
1
2
-------------------------------------------------------------------------------
-- configurao do teste
3
bushost, busport = ...
4
require "openbus.test.configs"
5
6
7
8
9
10
11
local host = bushost
local port = busport
local admin = admin
local adminPassword = admpsw
local certfile = syscrt
local script = admscript
local outputfile = admoutput
12

13
local bin = "busadmin "
14
15
local login = "--login="..admin.." "
local password = "--password="..adminPassword.." "
16
local certificate = "--certificate="..certfile
17
18
19
20
21

local OPENBUS_HOME = os.getenv("OPENBUS_HOME")
if OPENBUS_HOME then
  bin = OPENBUS_HOME.."/bin/"..bin
end
22
-------------------------------------------------------------------------------
23
24

local function finalize()
25
  os.execute("rm -f " ..outputfile)
26
27
end

28
local function readOutput()
29
30
31
32
33
34
  local f = io.open(outputfile)
  local err = f:read("*a")
  f:close()
  return err
end

35
local function execute(...)
36
  local command = bin..login..password
37
  local params = table.concat({...}, " ")
38
  local tofile = " > "..outputfile
39
40
41
42
43
44
45
46
47
  os.execute(command..params..tofile)
  local output = readOutput()
  local failed = output:find("[ERRO]",1,true)
  if not failed then
    return true
  else
    finalize()
    return false, output
  end
48
49
50
end

-- help
51
assert(execute("--help"))
52
53

-- categoria
54
55
56
57
58
59
assert(execute("--add-category=CTG01","--name='categoria numero 01'"))
assert(execute("--add-category=CTG02","--name='categoria numero 02'"))
assert(execute("--list-category"))
assert(execute("--list-category=CTG01"))
assert(execute("--set-category=CTG01","--name='novo nome da categoria 01'"))
assert(execute("--del-category=CTG01"))
60
61

-- entidade
62
assert(execute("--add-entity=ENT01","--category=CTG02","--name='entidade 01'"))
63
64
assert(execute("--add-entity=ENT02","--category=CTG02", "--name='entidade 02'"))
assert(execute("--add-certificate=ENT02", certificate))
65
66
67
68
69
70
71
assert(execute("--add-entity=ENT03","--category=CTG02","--name='entidade 03'"))
assert(execute("--add-entity=ENT04","--category=CTG02","--name='entidade 04'"))
assert(execute("--list-entity"))
assert(execute("--list-entity=ENT02"))
assert(execute("--list-entity","--category=CTG02"))
assert(execute("--set-entity=ENT01","--name='novo nome da entidade 01'"))
assert(execute("--del-entity=ENT01"))
72
73

-- certificado
74
75
76
assert(execute("--add-certificate=NoReg",certificate))
assert(execute("--del-certificate=NoReg"))
assert(execute("--del-certificate=ENT02"))
77
assert(execute("--list-certificate"))
78
79

-- interface
80
81
82
83
assert(execute("--add-interface=IDL:script/test:1.0"))
assert(execute("--add-interface=IDL:script/test2:1.0"))
assert(execute("--list-interface"))
assert(execute("--del-interface=IDL:script/test2:1.0"))
84
85

-- autorizao
86
87
88
89
90
91
assert(execute("--set-authorization=ENT02","--grant=IDL:script/test:1.0"))
assert(execute("--set-authorization=ENT03","--grant=IDL:script/test:1.0"))
assert(execute("--set-authorization=ENT04","--grant=IDL:script/test:1.0"))
assert(execute("--set-authorization=ENT04","--revoke=IDL:script/test:1.0"))
assert(execute("--list-authorization"))
assert(execute("--list-authorization=ENT03"))
92
assert(execute("--list-authorization","--interface=IDL:script/test:1.0"))
93
94

-- oferta
95
assert(execute("--list-offer"))
96
97

-- login
98
assert(execute("--list-login"))
99
100

-- script
101
102
assert(execute("--script="..script))
assert(execute("--undo-script="..script))
103
104

-- removendo tudo o que foi criado
105
106
107
108
109
110
111
assert(execute("--set-authorization=ENT02","--revoke=IDL:script/test:1.0"))
assert(execute("--set-authorization=ENT03","--revoke=IDL:script/test:1.0"))
assert(execute("--del-interface=IDL:script/test:1.0"))
assert(execute("--del-entity=ENT02"))
assert(execute("--del-entity=ENT03"))
assert(execute("--del-entity=ENT04"))
assert(execute("--del-category=CTG02"))
112
113
114

finalize()
print("[OK] Script de testes executado por completo!")
115
116

os.exit()