tests: Added tests for util.sasl.scram.Hi().
authorWaqas Hussain <waqas20@gmail.com>
Sun, 25 Jul 2010 20:12:52 +0000 (01:12 +0500)
committerWaqas Hussain <waqas20@gmail.com>
Sun, 25 Jul 2010 20:12:52 +0000 (01:12 +0500)
tests/test.lua
tests/test_util_sasl_scram.lua [new file with mode: 0644]

index 38ef6191ad4191a2ae49a88fd24a6513e9478f19..bb9bc876b517bbdab195b880b5d5aecba9defa11 100644 (file)
@@ -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
diff --git a/tests/test_util_sasl_scram.lua b/tests/test_util_sasl_scram.lua
new file mode 100644 (file)
index 0000000..aeae874
--- /dev/null
@@ -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