simple-sso/test/portal1.ctest.lua

35 lines
1.2 KiB
Lua

local lu = require("luaunit")
local ngx = require("ngx")
local crypto = require("ssso_crypto")
local sites = require("ssso_sites")
require("do_init")
function test_portal_url_returns_html_with_authorized_links_and_identity()
-- given
local profile = sites.class__profile:build_from_lists("guest", "", "Guest", "guest@example.org")
local jws, _ = crypto.get_jws_and_tslimit(profile)
ngx.reset_resp_body()
ngx.reset_var()
ngx.var.cookie_SSSO_TOKEN = jws
ngx.var.request_method = "GET"
ngx.var.request_uri = "/ssso/portal"
local expected = [[<html><head>
<link href="portal.css">
<script src="portal.js"></script>
</head><body>
guest Guest guest@example.org
<nav id="sites"><ul><li><a href="/mixed/guest/webmail"><span>My e-mail</span></a></li><li><a href="/mixed/guest/files"><span>My files</span></a></li><li><a href="/public/git/guest"><span>My projects</span></a></li></ul></nav>
</body></html>
]]
-- when
local resp = require("do_access")
-- then
lu.assertEquals(resp, 200)
lu.assertEquals(ngx.say(), expected)
lu.assertEquals(ngx.header["Content-Type"], "text/html; charset=UTF-8")
lu.assertEquals(ngx.header["Content-Length"], tostring(#expected))
end
os.exit(lu.LuaUnit.run())