local lu = require("luaunit") local id = require("ssso_identity") function test_format_replaces_user_placeholders() local identity = id.class__identity:build("U", nil, nil, nil) local template = '{user: "\ru.", foo: "bar", name: "\ru."}' lu.assertEquals(identity:format(template), '{user: "U", foo: "bar", name: "U"}') end function test_format_replaces_password_placeholders() local identity = id.class__identity:build(nil, "P", nil, nil) local template = '{pass: "\rp.", foo: "bar", secret: "\rp."}' lu.assertEquals(identity:format(template), '{pass: "P", foo: "bar", secret: "P"}') end function test_format_replaces_name_placeholders() local identity = id.class__identity:build(nil, nil, "N", nil) local template = '{name: "\rn.", foo: "bar", nickname: "\rn."}' lu.assertEquals(identity:format(template), '{name: "N", foo: "bar", nickname: "N"}') end function test_format_replaces_email_placeholders() local identity = id.class__identity:build(nil, nil, nil, "user@host") local template = '{user: "\re.", foo: "bar", mail: "\re."}' lu.assertEquals(identity:format(template), '{user: "user@host", foo: "bar", mail: "user@host"}') end function test_format_replaces_base64_calls() local identity = id.class__identity:build("👤", "🔒", nil, nil) local template = 'Authorization: Basic \rb64(\ru.:\rp.).' lu.assertEquals(identity:format(template), 'Authorization: Basic 8J+RpDrwn5SS') end function test_format_replaces_base64url_calls() local identity = id.class__identity:build("👤", "🔒", nil, nil) local template = '?authorization=Basic+\ru64(\ru.:\rp.).' lu.assertEquals(identity:format(template), '?authorization=Basic+8J-RpDrwn5SS') end function test_email_returns_the_identity_s_email() local identity = id.class__identity:build(nil, nil, nil, "E") lu.assertEquals(identity:email(), "E") end function test_name_returns_the_identity_s_name() local identity = id.class__identity:build(nil, nil, "N", nil) lu.assertEquals(identity:name(), "N") end function test_user_returns_the_identity_s_user() local identity = id.class__identity:build("U", nil, nil, nil) lu.assertEquals(identity:user(), "U") end function test_build_identity_returns_the_given_information() lu.assertEquals(id.class__identity:build("U", "P", "N", "E"), {u = "U", p = "P", n = "N", e = "E"}) end os.exit(lu.LuaUnit.run())