82 lines
2.1 KiB
Lua
82 lines
2.1 KiB
Lua
local lu = require("luaunit")
|
|
local prf = require("ssso_profile")
|
|
|
|
function test_format_replaces_user_placeholders()
|
|
local profile = {
|
|
u = "U",
|
|
}
|
|
local template = '{user: "\ru.", foo: "bar", name: "\ru."}'
|
|
lu.assertEquals(prf.format(template, profile), '{user: "U", foo: "bar", name: "U"}')
|
|
end
|
|
|
|
function test_format_replaces_password_placeholders()
|
|
local profile = {
|
|
p = "P",
|
|
}
|
|
local template = '{pass: "\rp.", foo: "bar", secret: "\rp."}'
|
|
lu.assertEquals(prf.format(template, profile), '{pass: "P", foo: "bar", secret: "P"}')
|
|
end
|
|
|
|
function test_format_replaces_name_placeholders()
|
|
local profile = {
|
|
n = "N",
|
|
}
|
|
local template = '{name: "\rn.", foo: "bar", nickname: "\rn."}'
|
|
lu.assertEquals(prf.format(template, profile), '{name: "N", foo: "bar", nickname: "N"}')
|
|
end
|
|
|
|
function test_format_replaces_email_placeholders()
|
|
local profile = {
|
|
e = "user@host",
|
|
}
|
|
local template = '{user: "\re.", foo: "bar", mail: "\re."}'
|
|
lu.assertEquals(prf.format(template, profile), '{user: "user@host", foo: "bar", mail: "user@host"}')
|
|
end
|
|
|
|
function test_format_replaces_base64_calls()
|
|
local profile = {
|
|
u = "👤",
|
|
p = "🔒",
|
|
}
|
|
local template = 'Authorization: Basic \rb64(\ru.:\rp.).'
|
|
lu.assertEquals(prf.format(template, profile), 'Authorization: Basic 8J+RpDrwn5SS')
|
|
end
|
|
|
|
function test_format_replaces_base64url_calls()
|
|
local profile = {
|
|
u = "👤",
|
|
p = "🔒",
|
|
}
|
|
local template = '?authorization=Basic+\ru64(\ru.:\rp.).'
|
|
lu.assertEquals(prf.format(template, profile), '?authorization=Basic+8J-RpDrwn5SS')
|
|
end
|
|
|
|
function test_email_returns_the_profile_s_email()
|
|
local profile = {
|
|
e = "E",
|
|
}
|
|
lu.assertEquals(prf.email(profile), "E")
|
|
end
|
|
|
|
|
|
function test_name_returns_the_profile_s_name()
|
|
local profile = {
|
|
n = "N",
|
|
}
|
|
lu.assertEquals(prf.name(profile), "N")
|
|
end
|
|
|
|
|
|
function test_user_returns_the_profile_s_user()
|
|
local profile = {
|
|
u = "U",
|
|
}
|
|
lu.assertEquals(prf.user(profile), "U")
|
|
end
|
|
|
|
function test_build_profile_returns_the_given_information()
|
|
lu.assertEquals(prf.build_profile("U", "P", "N", "E"), {u = "U", p = "P", n = "N", e = "E"})
|
|
end
|
|
|
|
os.exit(lu.LuaUnit.run())
|