aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test.lua3
-rw-r--r--tests/test_core_configmanager.lua2
-rw-r--r--tests/test_core_stanza_router.lua12
-rw-r--r--tests/test_sasl.lua43
-rw-r--r--tests/test_util_jid.lua31
-rw-r--r--tests/test_util_multitable.lua2
-rw-r--r--tests/test_util_sasl_scram.lua23
-rw-r--r--tests/test_util_stanza.lua1
-rw-r--r--tests/util/logger.lua2
9 files changed, 76 insertions, 43 deletions
diff --git a/tests/test.lua b/tests/test.lua
index 38ef6191..ae5b24f0 100644
--- a/tests/test.lua
+++ b/tests/test.lua
@@ -16,6 +16,7 @@ function run_all_tests()
dotest "core.s2smanager"
dotest "core.configmanager"
dotest "util.stanza"
+ dotest "util.sasl.scram"
dosingletest("test_sasl.lua", "latin1toutf8");
end
@@ -216,7 +217,7 @@ function new_line_coverage_monitor(file)
for line, active in pairs(lines_hit) do
if active ~= nil then total_active_lines = total_active_lines + 1; end
if coverage_file then
- if active == false then coverage_file:write(fn, "|", line, "|", name or "", "|miss\n");
+ if active == false then coverage_file:write(fn, "|", line, "|", name or "", "|miss\n");
else coverage_file:write(fn, "|", line, "|", name or "", "|", tostring(success), "\n"); end
end
end
diff --git a/tests/test_core_configmanager.lua b/tests/test_core_configmanager.lua
index c4ed746f..132dfc74 100644
--- a/tests/test_core_configmanager.lua
+++ b/tests/test_core_configmanager.lua
@@ -29,7 +29,7 @@ end
function set(set, u)
assert_equal(set("*"), false, "Set with no section/key");
- assert_equal(set("*", "set_test"), false, "Set with no key");
+ assert_equal(set("*", "set_test"), false, "Set with no key");
assert_equal(set("*", "set_test", "testkey"), true, "Setting a nil global value");
assert_equal(set("*", "set_test", "testkey", 123), true, "Setting a global value");
diff --git a/tests/test_core_stanza_router.lua b/tests/test_core_stanza_router.lua
index 97dc2e19..0a93694f 100644
--- a/tests/test_core_stanza_router.lua
+++ b/tests/test_core_stanza_router.lua
@@ -66,7 +66,7 @@ function core_process_stanza(core_process_stanza, u)
function env.core_post_stanza(p_origin, p_stanza)
assert_equal(p_origin, local_user_session, "origin of handled stanza is not correct");
assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print());
- target_handled = true;
+ target_handled = true;
end
env.hosts = hosts;
@@ -84,7 +84,7 @@ function core_process_stanza(core_process_stanza, u)
function env.core_route_stanza(p_origin, p_stanza)
assert_equal(p_origin, local_user_session, "origin of handled stanza is not correct");
assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print());
- target_routed = true;
+ target_routed = true;
end
function env.core_post_stanza(...) env.core_route_stanza(...); end
@@ -104,7 +104,7 @@ function core_process_stanza(core_process_stanza, u)
function env.core_route_stanza(p_origin, p_stanza)
assert_equal(p_origin, local_user_session, "origin of handled stanza is not correct");
assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print());
- target_routed = true;
+ target_routed = true;
end
function env.core_post_stanza(...)
@@ -129,7 +129,7 @@ function core_process_stanza(core_process_stanza, u)
function env.core_route_stanza(p_origin, p_stanza)
assert_equal(p_origin, local_user_session, "origin of handled stanza is not correct");
assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print());
- target_routed = true;
+ target_routed = true;
end
function env.core_post_stanza(...)
@@ -151,7 +151,7 @@ function core_process_stanza(core_process_stanza, u)
function env.core_route_stanza(p_origin, p_stanza)
assert_equal(p_origin, s2sin_session, "origin of handled stanza is not correct");
assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print());
- target_routed = true;
+ target_routed = true;
end
function env.core_post_stanza(...)
@@ -173,7 +173,7 @@ function core_process_stanza(core_process_stanza, u)
function env.core_post_stanza(p_origin, p_stanza)
assert_equal(p_origin, local_user_session, "origin of handled stanza is not correct");
assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print());
- target_handled = true;
+ target_handled = true;
end
env.hosts = hosts;
diff --git a/tests/test_sasl.lua b/tests/test_sasl.lua
index 7c0b02f8..271fa69a 100644
--- a/tests/test_sasl.lua
+++ b/tests/test_sasl.lua
@@ -6,32 +6,25 @@
-- COPYING file in the source package for more information.
--
-
---- WARNING! ---
--- This file contains a mix of encodings below.
--- Many editors will unquestioningly convert these for you.
--- Please be careful :( (I recommend Scite)
----------------------------------
-
-local gmatch = string.gmatch;
-local t_concat, t_insert = table.concat, table.insert;
-local to_byte, to_char = string.byte, string.char;
+local gmatch = string.gmatch;
+local t_concat, t_insert = table.concat, table.insert;
+local to_byte, to_char = string.byte, string.char;
local function _latin1toutf8(str)
- if not str then return str; end
- local p = {};
- for ch in gmatch(str, ".") do
- ch = to_byte(ch);
- if (ch < 0x80) then
- t_insert(p, to_char(ch));
- elseif (ch < 0xC0) then
- t_insert(p, to_char(0xC2, ch));
- else
- t_insert(p, to_char(0xC3, ch - 64));
- end
- end
- return t_concat(p);
- end
+ if not str then return str; end
+ local p = {};
+ for ch in gmatch(str, ".") do
+ ch = to_byte(ch);
+ if (ch < 0x80) then
+ t_insert(p, to_char(ch));
+ elseif (ch < 0xC0) then
+ t_insert(p, to_char(0xC2, ch));
+ else
+ t_insert(p, to_char(0xC3, ch - 64));
+ end
+ end
+ return t_concat(p);
+end
function latin1toutf8()
local function assert_utf8(latin, utf8)
@@ -41,5 +34,5 @@ function latin1toutf8()
assert_utf8("", "")
assert_utf8("test", "test")
assert_utf8(nil, nil)
- assert_utf8("foobar.råkat.se", "foobar.rÃ¥kat.se")
+ assert_utf8("foobar.r\229kat.se", "foobar.r\195\165kat.se")
end
diff --git a/tests/test_util_jid.lua b/tests/test_util_jid.lua
index 5cc1390b..a817e644 100644
--- a/tests/test_util_jid.lua
+++ b/tests/test_util_jid.lua
@@ -25,15 +25,21 @@ function split(split)
assert_equal(expected_server, rserver, "split("..tostring(input_jid)..") failed");
assert_equal(expected_resource, rresource, "split("..tostring(input_jid)..") failed");
end
+
+ -- Valid JIDs
test("node@server", "node", "server", nil );
- test("node@server/resource", "node", "server", "resource" );
- test("server", nil, "server", nil );
- test("server/resource", nil, "server", "resource" );
- test(nil, nil, nil , nil );
+ test("node@server/resource", "node", "server", "resource" );
+ test("server", nil, "server", nil );
+ test("server/resource", nil, "server", "resource" );
+ test("server/resource@foo", nil, "server", "resource@foo" );
+ test("server/resource@foo/bar", nil, "server", "resource@foo/bar");
- test("node@/server", nil, nil, nil , nil );
- test("@server", nil, nil, nil , nil );
- test("@server/resource",nil,nil,nil, nil );
+ -- Always invalid JIDs
+ test(nil, nil, nil, nil);
+ test("node@/server", nil, nil, nil);
+ test("@server", nil, nil, nil);
+ test("@server/resource", nil, nil, nil);
+ test("@/resource", nil, nil, nil);
end
function bare(bare)
@@ -54,3 +60,14 @@ function bare(bare)
assert_equal(bare("user@host/"), nil, "invalid JID is nil");
end
+function compare(compare)
+ assert_equal(compare("host", "host"), true, "host should match");
+ assert_equal(compare("host", "other-host"), false, "host should not match");
+ assert_equal(compare("other-user@host/resource", "host"), true, "host should match");
+ assert_equal(compare("other-user@host", "user@host"), false, "user should not match");
+ assert_equal(compare("user@host", "host"), true, "host should match");
+ assert_equal(compare("user@host/resource", "host"), true, "host should match");
+ assert_equal(compare("user@host/resource", "user@host"), true, "user and host should match");
+ assert_equal(compare("user@other-host", "host"), false, "host should not match");
+ assert_equal(compare("user@other-host", "user@host"), false, "host should not match");
+end
diff --git a/tests/test_util_multitable.lua b/tests/test_util_multitable.lua
index 4b7e4fcc..ed10b128 100644
--- a/tests/test_util_multitable.lua
+++ b/tests/test_util_multitable.lua
@@ -32,7 +32,7 @@ function get(get, multitable)
should_have[item] = nil;
end
if next(should_have) then
- return false, "not-enough";
+ return false, "not-enough";
end
return true, "has-all";
end
diff --git a/tests/test_util_sasl_scram.lua b/tests/test_util_sasl_scram.lua
new file mode 100644
index 00000000..aeae8748
--- /dev/null
+++ b/tests/test_util_sasl_scram.lua
@@ -0,0 +1,23 @@
+
+
+local hmac_sha1 = require "util.hmac".sha1;
+local function toHex(s)
+ return s and (s:gsub(".", function (c) return ("%02x"):format(c:byte()); end));
+end
+
+function Hi(Hi)
+ assert( toHex(Hi(hmac_sha1, "password", "salt", 1)) == "0c60c80f961f0e71f3a9b524af6012062fe037a6",
+ [[FAIL: toHex(Hi(hmac_sha1, "password", "salt", 1)) == "0c60c80f961f0e71f3a9b524af6012062fe037a6"]])
+ assert( toHex(Hi(hmac_sha1, "password", "salt", 2)) == "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957",
+ [[FAIL: toHex(Hi(hmac_sha1, "password", "salt", 2)) == "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957"]])
+ assert( toHex(Hi(hmac_sha1, "password", "salt", 64)) == "a7bc9b6efea2cbd717da72d83bfcc4e17d0b6280",
+ [[FAIL: toHex(Hi(hmac_sha1, "password", "salt", 64)) == "a7bc9b6efea2cbd717da72d83bfcc4e17d0b6280"]])
+ assert( toHex(Hi(hmac_sha1, "password", "salt", 4096)) == "4b007901b765489abead49d926f721d065a429c1",
+ [[FAIL: toHex(Hi(hmac_sha1, "password", "salt", 4096)) == "4b007901b765489abead49d926f721d065a429c1"]])
+ -- assert( toHex(Hi(hmac_sha1, "password", "salt", 16777216)) == "eefe3d61cd4da4e4e9945b3d6ba2158c2634e984",
+ -- [[FAIL: toHex(Hi(hmac_sha1, "password", "salt", 16777216)) == "eefe3d61cd4da4e4e9945b3d6ba2158c2634e984"]])
+end
+
+function init(init)
+ -- no tests
+end
diff --git a/tests/test_util_stanza.lua b/tests/test_util_stanza.lua
index 7916a0c1..fce26f3a 100644
--- a/tests/test_util_stanza.lua
+++ b/tests/test_util_stanza.lua
@@ -21,7 +21,6 @@ function deserialize(deserialize, st)
local stanza2 = deserialize(st.preserialize(stanza));
assert_is(stanza2 and stanza.name, "deserialize returns a stanza");
- assert_is(stanza2.last_add, "Deserialized stanza is missing last_add for adding child tags");
assert_table(stanza2.attr, "Deserialized stanza has attributes");
assert_equal(stanza2.attr.a, "a", "Deserialized stanza retains attributes");
assert_table(getmetatable(stanza2), "Deserialized stanza has metatable");
diff --git a/tests/util/logger.lua b/tests/util/logger.lua
index e62a1aa8..35facd4e 100644
--- a/tests/util/logger.lua
+++ b/tests/util/logger.lua
@@ -33,7 +33,7 @@ function init(name)
local inf = debug.getinfo(3, 'Snl');
level = level .. ","..tostring(inf.short_src):match("[^/]*$")..":"..inf.currentline;
end
- if ... then
+ if ... then
print(name, getstring(logstyles[level], level), format(message, ...));
else
print(name, getstring(logstyles[level], level), message);