From c0cb4e65ad38198b8112238995b224b64e83c901 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 28 Feb 2015 00:24:13 +0000 Subject: Adopt RSA test for telescope. --- test/lua/tests.lua | 9 +++++++++ test/lua/unit/rsa.lua | 55 ++++++++++++++++++++------------------------------- 2 files changed, 30 insertions(+), 34 deletions(-) (limited to 'test') diff --git a/test/lua/tests.lua b/test/lua/tests.lua index 0f6b06b4b..8f64bba4e 100644 --- a/test/lua/tests.lua +++ b/test/lua/tests.lua @@ -10,7 +10,16 @@ end local buffer = {} local results = telescope.run(contexts, callbacks, test_pattern) local summary, data = telescope.summary_report(contexts, results) + table.insert(buffer, telescope.test_report(contexts, results)) +table.insert(buffer, summary) + +local report = telescope.error_report(contexts, results) + +if report then + table.insert(buffer, "") + table.insert(buffer, report) +end if #buffer > 0 then print(table.concat(buffer, "\n")) end diff --git a/test/lua/unit/rsa.lua b/test/lua/unit/rsa.lua index 75d07fd30..caf017118 100644 --- a/test/lua/unit/rsa.lua +++ b/test/lua/unit/rsa.lua @@ -1,6 +1,6 @@ -- Test rsa signing -describe("rsa signarture test", function() +context("RSA signature verification test", function() local rsa_privkey = require "rspamd_rsa_privkey" local rsa_pubkey = require "rspamd_rsa_pubkey" local rsa_signature = require "rspamd_rsa_signature" @@ -9,37 +9,24 @@ describe("rsa signarture test", function() local privkey = 'testkey' local data = 'test.data' local signature = 'test.sig' - - -- Signing test - local rsa_key = rsa_privkey.load(string.format('%s/%s', test_dir, privkey)) - - if not rsa_key then - return -1 - end - - local rsa_sig = rsa.sign_file(rsa_key, string.format('%s/%s', test_dir, data)) - - if not rsa_sig then - return -1 - end - - rsa_sig:save(string.format('%s/%s', test_dir, signature), true) - - -- Verifying test - rsa_key = rsa_pubkey.load(string.format('%s/%s', test_dir, pubkey)) - - if not rsa_key then - return -1 - end - - rsa_sig = rsa_signature.load(string.format('%s/%s', test_dir, signature)) - - if not rsa_sig then - return -1 - end - - if not rsa.verify_file(rsa_key, rsa_sig, string.format('%s/%s', test_dir, data)) then - return -1 - end - + local test_dir = string.gsub(debug.getinfo(1).source, "^@(.+/)[^/]+$", "%1") + local rsa_key, rsa_sig + + test("RSA sign", function() + -- Signing test + local rsa_key = rsa_privkey.load(string.format('%s/%s', test_dir, privkey)) + assert_not_nil(rsa_key) + local rsa_sig = rsa.sign_file(rsa_key, string.format('%s/%s', test_dir, data)) + assert_not_nil(rsa_sig) + rsa_sig:save(string.format('%s/%s', test_dir, signature), true) + end) + + test("RSA verify", function() + -- Verifying test + rsa_key = rsa_pubkey.load(string.format('%s/%s', test_dir, pubkey)) + assert_not_nil(rsa_key) + rsa_sig = rsa_signature.load(string.format('%s/%s', test_dir, signature)) + assert_not_nil(rsa_sig) + assert_true(rsa.verify_file(rsa_key, rsa_sig, string.format('%s/%s', test_dir, data))) + end) end) -- cgit v1.2.3