aboutsummaryrefslogtreecommitdiffstats
path: root/test/lua
diff options
context:
space:
mode:
authorIvan Stakhov <50211739+LeftTry@users.noreply.github.com>2024-09-05 13:48:22 +0300
committerGitHub <noreply@github.com>2024-09-05 11:48:22 +0100
commitbb6604f2a6439613fa6546e5e8ec8b61006ec208 (patch)
tree6fcbe4a0f104fe14296d1acc88561ac43e95bc64 /test/lua
parent40a6ddd69be80e6a4ad8a29053bbfa18d24b3bd8 (diff)
downloadrspamd-bb6604f2a6439613fa6546e5e8ec8b61006ec208.tar.gz
rspamd-bb6604f2a6439613fa6546e5e8ec8b61006ec208.zip
[Feature] Add tooling to encrypt strings in Lua
* [Fix] Provide support for OpenSSL 3.0 * [Feature] Provide function to encode header with configured public key * [Feature] Provide function to decode header with configured public key * [Test] Add tests for maybe encode/decode header * [Minor] Fix tests for encode/decode header * [Minor] Small clean up * [Minor] Small clean up * [Minor] Small fix for OpenSSL 3.0 support * [Minor] Provide logging * [Minor] Small fix * [Fix] Fix typo error * [Fix] Another typo * [Minor] Little clean up * [Minor] Little fix * [Minor] Small fix * [Minor] Small fix * [Minor] Rewrite the arguments of secretbox:encrypt/decrypt functions to a more understandable format * [Fix] Fix problem with nonce was not provided * [Test] Add test for nonce * [Minor] Little clean up * [Minor] Little clean up * [Test] Test * [Test] Test * [Test] Test * [Minor] Little fix * [Minor] Small fix * [Minor] Small fix * [Test] Small fix * [Test] Test * [Test] Test * [Test] Test * [Test] Test * [Minor] Small fix for fips provider * [Minor] Change provider apply logic * [Test] Little fix for provider * [Minor] Provide OpenSSL <3.0 support * [Test] Possible provider fix * [Test] Possible provider fix * [Test] Little fix * [Minor] Fix provider issue * [Minor] Small clean up * [Minor] Change logging errors * Update lualib/lua_util.lua --------- Co-authored-by: Vsevolod Stakhov <vsevolod@rspamd.com>
Diffstat (limited to 'test/lua')
-rw-r--r--test/lua/unit/lua_util.maybe_encrypt_decrypt_header.lua57
1 files changed, 57 insertions, 0 deletions
diff --git a/test/lua/unit/lua_util.maybe_encrypt_decrypt_header.lua b/test/lua/unit/lua_util.maybe_encrypt_decrypt_header.lua
new file mode 100644
index 000000000..613101068
--- /dev/null
+++ b/test/lua/unit/lua_util.maybe_encrypt_decrypt_header.lua
@@ -0,0 +1,57 @@
+local util = require 'lua_util'
+
+context("Lua util - maybe encrypt/decrypt header", function()
+ test("Encrypt/Decrypt header with nonce", function()
+ local header = tostring('X-Spamd-Result')
+ local settings = {
+ prefix = 'prefix',
+ prefix_encrypt = true,
+ prefix_key = 'key',
+ prefix_nonce = 'nonce'
+ }
+
+ local encrypted_header = util.maybe_encrypt_header(header, settings, settings.prefix)
+ if encrypted_header == header or encrypted_header == nil then
+ assert_true(false, 'Failed to encrypt header')
+ end
+
+ local decrypted_header = util.maybe_decrypt_header(encrypted_header, settings, settings.prefix)
+ if decrypted_header == encrypted_header or decrypted_header == nil then
+ assert_true(false, 'Failed to decrypt header')
+ end
+
+ if tostring(header) == tostring(decrypted_header) then
+ assert_true(true, 'Succeed to confirm equality of original header and decrypted header')
+ else
+ assert_rspamd_table_eq_sorted({actual = { decrypted_header },
+ expect = { header }})
+ end
+ end)
+
+ test("Encrypt/Decrypt header without nonce", function()
+ local header = tostring('X-Spamd-Result')
+ local settings = {
+ prefix = 'prefix',
+ prefix_encrypt = true,
+ prefix_key = 'key'
+ }
+
+ local encrypted_header, nonce = util.maybe_encrypt_header(header, settings, settings.prefix)
+ if encrypted_header == header or encrypted_header == nil then
+ assert_true(false, 'Failed to encrypt header')
+ end
+
+ local decrypted_header = util.maybe_decrypt_header(encrypted_header, settings,
+ settings.prefix, nonce)
+ if decrypted_header == encrypted_header or decrypted_header == nil then
+ assert_true(false, 'Failed to decrypt header')
+ end
+
+ if tostring(header) == tostring(decrypted_header) then
+ assert_true(true, 'Succeed to confirm equality of original header and decrypted header')
+ else
+ assert_rspamd_table_eq_sorted({actual = { decrypted_header },
+ expect = { header }})
+ end
+ end)
+end) \ No newline at end of file