simple-sso/test/crypto.utest.lua

45 lines
1014 B
Lua

local lu = require("luaunit")
local conf = require("ssso_config")
local crypt = require("ssso_crypto")
local sites = require("ssso_sites")
local here = debug.getinfo(1).source:sub(2, -18)
conf.load_conf(here)
local data = sites.class__profile:build_from_lists("u", nil, nil, "u@h",
{
{
r = {
"regex1",
},
a = {
{"C", "Cn", "Cv"},
{"H", "Hn", "Hv"},
}
},
},
{
"regex2",
}
)
function test_jws_is_well_structured()
local jws, _ = crypt.get_jws_and_tslimit(data)
lu.assertStrMatches(jws, "[^%.]+%.[^%.]+%.[^%.]+")
end
function test_jws_can_be_decoded()
local jws, _ = crypt.get_jws_and_tslimit(data)
local stored, _, _ = crypt.get_profile_and_new_jws(jws)
lu.assertEquals(stored, data)
end
function test_data_must_be_a_profile_with_a_user()
local wrong = sites.class__profile:build_from_conf(nil, "P", "N", "E")
local jws, ts = crypt.get_jws_and_tslimit(wrong)
lu.assertNil(jws)
lu.assertNil(ts)
end
os.exit(lu.LuaUnit.run())