From 9036462dcbb26ca029ee4d7709f4d8d2a377734c Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 20 Apr 2020 18:17:57 +0200 Subject: mod_version: Add scansion test Why was this module enabled in the config for tests if it wasn't tested? --- spec/scansion/prosody.cfg.lua | 2 ++ spec/scansion/version.scs | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 spec/scansion/version.scs diff --git a/spec/scansion/prosody.cfg.lua b/spec/scansion/prosody.cfg.lua index 6a72584d..d7444e7a 100644 --- a/spec/scansion/prosody.cfg.lua +++ b/spec/scansion/prosody.cfg.lua @@ -84,6 +84,8 @@ pidfile = "prosody.pid" VirtualHost "localhost" +hide_os_type = true -- absense tested for in version.scs + Component "conference.localhost" "muc" storage = "memory" diff --git a/spec/scansion/version.scs b/spec/scansion/version.scs new file mode 100644 index 00000000..6c841dd9 --- /dev/null +++ b/spec/scansion/version.scs @@ -0,0 +1,27 @@ +# XEP-0092: Software Version / mod_version + +[Client] Romeo + password: password + jid: romeo@localhost/dfaZpuxV + +----- + +Romeo connects + +Romeo sends: + + + + +# Version string would vary so we can't do an exact match atm +# Inclusion of is disabled in the config, it should be absent +Romeo receives: + + + Prosody + + + + + +Romeo disconnects -- cgit v1.2.3 From 5955cc392426300b07c9cbfdb80371a14de6b729 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 20 Apr 2020 18:20:24 +0200 Subject: scansion: Mock time libraries during tests The passage of time does not need test coverage, just look in a mirror. --- spec/scansion/prosody.cfg.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/scansion/prosody.cfg.lua b/spec/scansion/prosody.cfg.lua index d7444e7a..88a5e0c9 100644 --- a/spec/scansion/prosody.cfg.lua +++ b/spec/scansion/prosody.cfg.lua @@ -1,5 +1,16 @@ --luacheck: ignore +-- Mock time functions to simplify tests +function _G.os.time() + return 1219439344; +end +package.preload["util.time"] = function () + return { + now = function () return 1219439344.1; end; + monotonic = function () return 0.1; end; + } +end + admins = { "admin@localhost" } use_libevent = true -- cgit v1.2.3 From 85b09097dc5367e4223595c7debbb92a401cfd12 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 20 Apr 2020 19:22:54 +0200 Subject: mod_uptime: Add scansion test coverage Once the Prosody is up, who cares when it comes down? That's not my department, says scanison. --- spec/scansion/uptime.scs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 spec/scansion/uptime.scs diff --git a/spec/scansion/uptime.scs b/spec/scansion/uptime.scs new file mode 100644 index 00000000..188b9eb5 --- /dev/null +++ b/spec/scansion/uptime.scs @@ -0,0 +1,21 @@ +# XEP-0012: Last Activity / mod_uptime + +[Client] Romeo + jid: romeo@localhost + password: password + +----- + +Romeo connects + +Romeo sends: + + + + +Romeo receives: + + + + +Romeo disconnects -- cgit v1.2.3 From 8be4a3edd7de37c5c06beb3479ec6c84b510f95a Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 20 Apr 2020 18:33:05 +0200 Subject: mod_lastactivity: Add basic scansion test coverage When run on Lua 5.3 produces an issue similar to #1536 --- spec/scansion/lastactivity.scs | 45 ++++++++++++++++++++++++++++++++++++++++++ spec/scansion/prosody.cfg.lua | 1 + 2 files changed, 46 insertions(+) create mode 100644 spec/scansion/lastactivity.scs diff --git a/spec/scansion/lastactivity.scs b/spec/scansion/lastactivity.scs new file mode 100644 index 00000000..44f4e516 --- /dev/null +++ b/spec/scansion/lastactivity.scs @@ -0,0 +1,45 @@ +# XEP-0012: Last Activity / mod_lastactivity + +[Client] Romeo + jid: romeo@localhost + password: password + +----- + +Romeo connects + +Romeo sends: + + Hello + + +Romeo receives: + + Hello + + +Romeo sends: + + Goodbye + + +Romeo receives: + + Goodbye + + +# mod_lastlog saves time + status message from the last unavailable presence + +Romeo sends: + + + + +Romeo receives: + + Goodbye + + +Romeo disconnects + +# recording ended on 2020-04-20T14:39:47Z diff --git a/spec/scansion/prosody.cfg.lua b/spec/scansion/prosody.cfg.lua index 88a5e0c9..b7d6ccd5 100644 --- a/spec/scansion/prosody.cfg.lua +++ b/spec/scansion/prosody.cfg.lua @@ -59,6 +59,7 @@ modules_enabled = { --"motd"; -- Send a message to users when they log in --"legacyauth"; -- Legacy authentication. Only used by some old clients and bots. --"proxy65"; -- Enables a file transfer proxy service which clients behind NAT can use + "lastactivity"; -- Useful for testing --"scansion_record"; -- Records things that happen in scansion test case format -- cgit v1.2.3 From 8f77033238b4cf72377ae0b45d5951c32324892d Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 18 Apr 2020 19:36:26 +0200 Subject: mod_csi_simple: Consider MUC invites important Both mediated invites defined by XEP-0045: Multi-User Chat and direct invites defined by XEP-0249: Direct MUC Invitations --- doc/doap.xml | 8 ++++++++ plugins/mod_csi_simple.lua | 3 +++ 2 files changed, 11 insertions(+) diff --git a/doc/doap.xml b/doc/doap.xml index c23334ae..540cbe51 100644 --- a/doc/doap.xml +++ b/doc/doap.xml @@ -429,6 +429,14 @@ implied by rfc6121 + + + + 1.2 + 0.12 + mod_csi_simple + + diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index e439bf38..cc15f033 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -48,6 +48,9 @@ module:hook("csi-is-stanza-important", function (event) if stanza:get_child("encryption", "urn:xmpp:eme:0") then return true; end + if stanza:get_child("x", "jabber:x:conference") or stanza:find("{http://jabber.org/protocol/muc#user}x/invite") then + return true; + end for important in important_payloads do if stanza:find(important) then return true; -- cgit v1.2.3 From 5817e5f02d048aa6c17d5430d55f11c4a7a40a96 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 21 Apr 2020 00:53:21 +0200 Subject: mod_mam: Factor out "should we store this" into a function Meant to improve readability and ease further improvements to this algorithm. --- plugins/mod_mam/mod_mam.lua | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index 8229eb4e..27b4796d 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -263,11 +263,28 @@ local function strip_stanza_id(stanza, user) return stanza; end +local function should_store(stanza) --> boolean, reason: string + local orig_type = stanza.attr.type or "normal"; + -- We store chat messages or normal messages that have a body + if not(orig_type == "chat" or (orig_type == "normal" and stanza:get_child("body")) ) then + return false, "type"; + end + + -- or if hints suggest we shouldn't + if not stanza:get_child("store", "urn:xmpp:hints") then -- No hint telling us we should store + if stanza:get_child("no-permanent-store", "urn:xmpp:hints") + or stanza:get_child("no-store", "urn:xmpp:hints") then -- Hint telling us we should NOT store + return false, "hint"; + end + end + + return true, "default"; +end + -- Handle messages local function message_handler(event, c2s) local origin, stanza = event.origin, event.stanza; local log = c2s and origin.log or module._log; - local orig_type = stanza.attr.type or "normal"; local orig_from = stanza.attr.from; local orig_to = stanza.attr.to or orig_from; -- Stanza without 'to' are treated as if it was to their own bare jid @@ -280,21 +297,12 @@ local function message_handler(event, c2s) -- Filter out that claim to be from us event.stanza = strip_stanza_id(stanza, store_user); - -- We store chat messages or normal messages that have a body - if not(orig_type == "chat" or (orig_type == "normal" and stanza:get_child("body")) ) then - log("debug", "Not archiving stanza: %s (type)", stanza:top_tag()); + local should, why = should_store(stanza); + if not should then + log("debug", "Not archiving stanza: %s (%s)", stanza:top_tag(), why); return; end - -- or if hints suggest we shouldn't - if not stanza:get_child("store", "urn:xmpp:hints") then -- No hint telling us we should store - if stanza:get_child("no-permanent-store", "urn:xmpp:hints") - or stanza:get_child("no-store", "urn:xmpp:hints") then -- Hint telling us we should NOT store - log("debug", "Not archiving stanza: %s (hint)", stanza:top_tag()); - return; - end - end - local clone_for_storage; if not strip_tags:empty() then clone_for_storage = st.clone(stanza); -- cgit v1.2.3 From 962d36d401a1a55346a92fe3b30c6b215583fada Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 21 Apr 2020 00:53:23 +0200 Subject: mod_mam: Log 'why' a stanza is archived Logging of 'why not' is already done. Why not both? Will make more sense when the rules evolve a bit. --- plugins/mod_mam/mod_mam.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index 27b4796d..9c00cc99 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -323,7 +323,7 @@ local function message_handler(event, c2s) -- Check with the users preferences if shall_store(store_user, with) then - log("debug", "Archiving stanza: %s", stanza:top_tag()); + log("debug", "Archiving stanza: %s (%s)", stanza:top_tag(), why); -- And stash it local time = time_now(); -- cgit v1.2.3 From e5d6376c58d026003fbcee2dff60a7b244debbdb Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 21 Apr 2020 00:56:56 +0200 Subject: mod_mam: Invert check for type This is based on code in mod_csi_simple and aiming towards being more flexible and maintainable than a couple of tests for when not to store. --- plugins/mod_mam/mod_mam.lua | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index 9c00cc99..028c3b8f 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -264,11 +264,8 @@ local function strip_stanza_id(stanza, user) end local function should_store(stanza) --> boolean, reason: string - local orig_type = stanza.attr.type or "normal"; - -- We store chat messages or normal messages that have a body - if not(orig_type == "chat" or (orig_type == "normal" and stanza:get_child("body")) ) then - return false, "type"; - end + local st_type = stanza.attr.type or "normal"; + local st_to_full = (stanza.attr.to or ""):find("/"); -- or if hints suggest we shouldn't if not stanza:get_child("store", "urn:xmpp:hints") then -- No hint telling us we should store @@ -277,6 +274,17 @@ local function should_store(stanza) --> boolean, reason: string return false, "hint"; end end + if st_type == "headline" then + -- Headline messages are ephemeral by definition + return false, "headline"; + end + if st_type == "groupchat" and st_to_full then + -- MUC messages always go to the full JID, usually archived by the MUC + return false, "groupchat"; + end + if stanza:get_child("body") then + return true, "body"; + end return true, "default"; end -- cgit v1.2.3 From 0613c5b47f429e34ca3cbe4eec671e2f281321a8 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 21 Apr 2020 01:01:25 +0200 Subject: mod_mam: Rework hints handling Improved readability and early returns definite yes/no answer. --- plugins/mod_mam/mod_mam.lua | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index 028c3b8f..57f399ae 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -267,13 +267,6 @@ local function should_store(stanza) --> boolean, reason: string local st_type = stanza.attr.type or "normal"; local st_to_full = (stanza.attr.to or ""):find("/"); - -- or if hints suggest we shouldn't - if not stanza:get_child("store", "urn:xmpp:hints") then -- No hint telling us we should store - if stanza:get_child("no-permanent-store", "urn:xmpp:hints") - or stanza:get_child("no-store", "urn:xmpp:hints") then -- Hint telling us we should NOT store - return false, "hint"; - end - end if st_type == "headline" then -- Headline messages are ephemeral by definition return false, "headline"; @@ -282,6 +275,12 @@ local function should_store(stanza) --> boolean, reason: string -- MUC messages always go to the full JID, usually archived by the MUC return false, "groupchat"; end + if stanza:get_child("no-permanent-store", "urn:xmpp:hints") then + return false, "hint"; + end + if stanza:get_child("store", "urn:xmpp:hints") then + return true, "hint"; + end if stanza:get_child("body") then return true, "body"; end -- cgit v1.2.3 From e84179de9814eded7c4543848d871fd163ac31d2 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 21 Apr 2020 01:17:55 +0200 Subject: mod_mam: Add more positive hints for storage Mostly just lifted from mod_csi_simple --- plugins/mod_mam/mod_mam.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index 57f399ae..385a0ad2 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -284,6 +284,18 @@ local function should_store(stanza) --> boolean, reason: string if stanza:get_child("body") then return true, "body"; end + if stanza:get_child("subject") then + -- XXX Who would send a message with a subject but with a body? + return true, "subject"; + end + if stanza:get_child("encryption", "urn:xmpp:eme:0") then + -- Since we can't know what an encrypted message contains, we assume it's important + return true, "encrypted"; + end + if stanza:get_child("x", "jabber:x:conference") + or stanza:find("{http://jabber.org/protocol/muc#user}x/invite") then + return true, "invite"; + end return true, "default"; end -- cgit v1.2.3 From c8db26be662085caef941923286bdcce9f600950 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 21 Apr 2020 01:18:54 +0200 Subject: mod_mam: Store XEP-0184 receipts and requests Happy now Ge0rG? --- plugins/mod_mam/mod_mam.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index 385a0ad2..6e522d73 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -292,6 +292,11 @@ local function should_store(stanza) --> boolean, reason: string -- Since we can't know what an encrypted message contains, we assume it's important return true, "encrypted"; end + if stanza:get_child(nil, "urn:xmpp:receipts") then + -- If it's important enough to ask for a receipt then it's important enough to archive + -- and the same applies to the receipt + return true, "receipt"; + end if stanza:get_child("x", "jabber:x:conference") or stanza:find("{http://jabber.org/protocol/muc#user}x/invite") then return true, "invite"; -- cgit v1.2.3 From 78668f1be3eb2e0c8301995a65fd7aa87e67aefa Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 21 Apr 2020 01:29:58 +0200 Subject: mod_mam: Check sender of error instead of receiver The intent is to capture errors to stanzas sent by the local user, so that they can see why a message failed to be delivered even if the error came after they went offline. --- plugins/mod_mam/mod_mam.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index 6e522d73..db0e7f8d 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -266,6 +266,9 @@ end local function should_store(stanza) --> boolean, reason: string local st_type = stanza.attr.type or "normal"; local st_to_full = (stanza.attr.to or ""):find("/"); + if st_type == "error" then + st_to_full = (stanza.attr.from or ""):find("/"); + end if st_type == "headline" then -- Headline messages are ephemeral by definition -- cgit v1.2.3 From 617ac066385fea7bc1841252c87ea786bc84eafc Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 21 Apr 2020 19:41:43 +0200 Subject: mod_mam: Prefer not archiving if no interesting payloads are found --- plugins/mod_mam/mod_mam.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index db0e7f8d..69282857 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -305,7 +305,9 @@ local function should_store(stanza) --> boolean, reason: string return true, "invite"; end - return true, "default"; + -- The IM-NG thing to do here would be to return `not st_to_full` + -- One day ... + return false, "default"; end -- Handle messages -- cgit v1.2.3 From b0dbacb69cac71c39088328f740b7e4b59831b81 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 21 Apr 2020 23:06:55 +0200 Subject: mod_mam: Fix typo in comment If it is with a body then it execution does not get this far --- plugins/mod_mam/mod_mam.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index 69282857..6d493131 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -288,7 +288,7 @@ local function should_store(stanza) --> boolean, reason: string return true, "body"; end if stanza:get_child("subject") then - -- XXX Who would send a message with a subject but with a body? + -- XXX Who would send a message with a subject but without a body? return true, "subject"; end if stanza:get_child("encryption", "urn:xmpp:eme:0") then -- cgit v1.2.3 From 8c1161cf773fa9eb5371e2bffdb054b97a71dad1 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 22 Apr 2020 18:47:06 +0200 Subject: mod_mam: Respect no-store hint (thanks Ge0rG) no-store is used in an example in XEP-0313, so obviously this is the preferred hint --- plugins/mod_mam/mod_mam.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index 6d493131..7ac2a512 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -278,7 +278,8 @@ local function should_store(stanza) --> boolean, reason: string -- MUC messages always go to the full JID, usually archived by the MUC return false, "groupchat"; end - if stanza:get_child("no-permanent-store", "urn:xmpp:hints") then + if stanza:get_child("no-store", "urn:xmpp:hints") + or stanza:get_child("no-permanent-store", "urn:xmpp:hints") then return false, "hint"; end if stanza:get_child("store", "urn:xmpp:hints") then -- cgit v1.2.3 From 9bb75c85c478a5da62e697aa6006c570db15eae2 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 22 Apr 2020 18:48:27 +0200 Subject: mod_mam: Keep chat markers (thanks Ge0rG) --- plugins/mod_mam/mod_mam.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index 7ac2a512..06a20f4d 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -301,6 +301,9 @@ local function should_store(stanza) --> boolean, reason: string -- and the same applies to the receipt return true, "receipt"; end + if stanza:get_child(nil, "urn:xmpp:chat-markers:0") then + return true, "marker"; + end if stanza:get_child("x", "jabber:x:conference") or stanza:find("{http://jabber.org/protocol/muc#user}x/invite") then return true, "invite"; -- cgit v1.2.3 From 92150bd359689a2b3401ae9dcdc8ba51fbaf8e1f Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 22 Apr 2020 18:50:30 +0200 Subject: mod_mam: Save delivery failures (thanks Ge0rG) Makes it possible to learn of delivery failure even if it came bouncing back while you were offline. --- plugins/mod_mam/mod_mam.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index 06a20f4d..b74a92ea 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -274,6 +274,9 @@ local function should_store(stanza) --> boolean, reason: string -- Headline messages are ephemeral by definition return false, "headline"; end + if st_type == "error" then + return true, "bounce"; + end if st_type == "groupchat" and st_to_full then -- MUC messages always go to the full JID, usually archived by the MUC return false, "groupchat"; -- cgit v1.2.3 From 966c3c56043bb8903acbbd5c8f9ee36bc23d5388 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 22 Apr 2020 18:53:50 +0200 Subject: mod_mam: Make note of Experimental (or Deferred) XEPs Since these XEPs are subject to change we may need come back and double check these in the future. --- plugins/mod_mam/mod_mam.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index b74a92ea..a9d389f5 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -283,6 +283,7 @@ local function should_store(stanza) --> boolean, reason: string end if stanza:get_child("no-store", "urn:xmpp:hints") or stanza:get_child("no-permanent-store", "urn:xmpp:hints") then + -- XXX Experimental XEP return false, "hint"; end if stanza:get_child("store", "urn:xmpp:hints") then @@ -297,6 +298,7 @@ local function should_store(stanza) --> boolean, reason: string end if stanza:get_child("encryption", "urn:xmpp:eme:0") then -- Since we can't know what an encrypted message contains, we assume it's important + -- XXX Experimental XEP return true, "encrypted"; end if stanza:get_child(nil, "urn:xmpp:receipts") then @@ -305,6 +307,7 @@ local function should_store(stanza) --> boolean, reason: string return true, "receipt"; end if stanza:get_child(nil, "urn:xmpp:chat-markers:0") then + -- XXX Experimental XEP return true, "marker"; end if stanza:get_child("x", "jabber:x:conference") -- cgit v1.2.3 From 16c54b170580328dd57bb35a68281d5e385b82dc Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 22 Apr 2020 21:35:33 +0200 Subject: util.hashes: Use generic name of PBKDF2-HMAC-SHA1 function in tests --- spec/util_hashes_spec.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/util_hashes_spec.lua b/spec/util_hashes_spec.lua index 1e6187bb..5c616a8d 100644 --- a/spec/util_hashes_spec.lua +++ b/spec/util_hashes_spec.lua @@ -4,34 +4,34 @@ local hex = require "util.hex"; -- Also see spec for util.hmac where HMAC test cases reside -describe("PBKDF2-SHA1", function () +describe("PBKDF2-HMAC-SHA1", function () it("test vector 1", function () local P = "password" local S = "salt" local c = 1 local DK = "0c60c80f961f0e71f3a9b524af6012062fe037a6"; - assert.equal(DK, hex.to(hashes.scram_Hi_sha1(P, S, c))); + assert.equal(DK, hex.to(hashes.pbkdf2_hmac_sha1(P, S, c))); end); it("test vector 2", function () local P = "password" local S = "salt" local c = 2 local DK = "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957"; - assert.equal(DK, hex.to(hashes.scram_Hi_sha1(P, S, c))); + assert.equal(DK, hex.to(hashes.pbkdf2_hmac_sha1(P, S, c))); end); it("test vector 3", function () local P = "password" local S = "salt" local c = 4096 local DK = "4b007901b765489abead49d926f721d065a429c1"; - assert.equal(DK, hex.to(hashes.scram_Hi_sha1(P, S, c))); + assert.equal(DK, hex.to(hashes.pbkdf2_hmac_sha1(P, S, c))); end); it("test vector 4 #SLOW", function () local P = "password" local S = "salt" local c = 16777216 local DK = "eefe3d61cd4da4e4e9945b3d6ba2158c2634e984"; - assert.equal(DK, hex.to(hashes.scram_Hi_sha1(P, S, c))); + assert.equal(DK, hex.to(hashes.pbkdf2_hmac_sha1(P, S, c))); end); end); -- cgit v1.2.3 From 701c5f48110cb004925ba659b7221b18713ad2c7 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 22 Apr 2020 21:38:36 +0200 Subject: util.hashes: Fix output length of PBKDF2-HMAC-SHA256 Somehow it got SHA1's 20 byte output instead of the proper 32 = 256/8 --- spec/util_hashes_spec.lua | 18 ++++++++++++++++++ util-src/hashes.c | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/spec/util_hashes_spec.lua b/spec/util_hashes_spec.lua index 5c616a8d..3639dd4e 100644 --- a/spec/util_hashes_spec.lua +++ b/spec/util_hashes_spec.lua @@ -35,3 +35,21 @@ describe("PBKDF2-HMAC-SHA1", function () end); end); +describe("PBKDF2-HMAC-SHA256", function () + it("test vector 1", function () + local P = "password"; + local S = "salt"; + local c = 1 + local DK = "120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b"; + assert.equal(DK, hex.to(hashes.pbkdf2_hmac_sha256(P, S, c))); + end); + it("test vector 2", function () + local P = "password"; + local S = "salt"; + local c = 2 + local DK = "ae4d0c95af6b46d32d0adff928f06dd02a303f8ef3c251dfd6e2d85a95474c43"; + assert.equal(DK, hex.to(hashes.pbkdf2_hmac_sha256(P, S, c))); + end); +end); + + diff --git a/util-src/hashes.c b/util-src/hashes.c index 51c7611c..84a604ef 100644 --- a/util-src/hashes.c +++ b/util-src/hashes.c @@ -129,7 +129,7 @@ static int Lpbkdf2_sha256(lua_State *L) { return luaL_error(L, "PKCS5_PBKDF2_HMAC() failed"); } - lua_pushlstring(L, (char *)out, SHA_DIGEST_LENGTH); + lua_pushlstring(L, (char *)out, SHA256_DIGEST_LENGTH); return 1; } -- cgit v1.2.3 From bc0e389d47b0a40e1ea871fe4ff583746af928be Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 22 Apr 2020 21:46:56 +0200 Subject: mod_uptime: Encode uptime as decimal, fix #1536 (thanks Martin) --- plugins/mod_uptime.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_uptime.lua b/plugins/mod_uptime.lua index 035f7e9b..8a01fb17 100644 --- a/plugins/mod_uptime.lua +++ b/plugins/mod_uptime.lua @@ -16,7 +16,7 @@ module:add_feature("jabber:iq:last"); module:hook("iq-get/host/jabber:iq:last:query", function(event) local origin, stanza = event.origin, event.stanza; - origin.send(st.reply(stanza):tag("query", {xmlns = "jabber:iq:last", seconds = tostring(os.difftime(os.time(), start_time))})); + origin.send(st.reply(stanza):tag("query", {xmlns = "jabber:iq:last", seconds = tostring(("%d"):format(os.difftime(os.time(), start_time)))})); return true; end); -- cgit v1.2.3 From d649e78d6d7e2977e6e60e26262eac1161631857 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 22 Apr 2020 23:36:25 +0200 Subject: mod_lastactivity: Encode seconds as decimal, not float In Lua 5.3 difftime() takes integers as argument but returns a float, and then tostring() serializes it with a decimal point. This violates XEP-0012. Like #1536 --- plugins/mod_lastactivity.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_lastactivity.lua b/plugins/mod_lastactivity.lua index 575e66be..91d11bd2 100644 --- a/plugins/mod_lastactivity.lua +++ b/plugins/mod_lastactivity.lua @@ -30,7 +30,7 @@ module:hook("iq-get/bare/jabber:iq:last:query", function(event) if not stanza.attr.to or is_contact_subscribed(username, module.host, jid_bare(stanza.attr.from)) then local seconds, text = "0", ""; if map[username] then - seconds = tostring(os.difftime(os.time(), map[username].t)); + seconds = string.format("%d", os.difftime(os.time(), map[username].t)); text = map[username].s; end origin.send(st.reply(stanza):tag('query', {xmlns='jabber:iq:last', seconds=seconds}):text(text)); -- cgit v1.2.3 From ba452d69231d6cbf4c2efb4f5e99df40d9a11ede Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 23 Apr 2020 00:55:34 +0200 Subject: mod_mam: Don't store any groupchat messages The intent was to not store MUC groupchat messages, which are sent from the MUC to local full JIDs, while allowing for potential future account based group chat. However, since this function handles messages in both directions and outgoing MUC messages are sent to the bare room JID, those were stored. --- plugins/mod_mam/mod_mam.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index a9d389f5..65859afd 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -269,6 +269,8 @@ local function should_store(stanza) --> boolean, reason: string if st_type == "error" then st_to_full = (stanza.attr.from or ""):find("/"); end + -- FIXME pass direction of stanza and use that along with bare/full JID addressing + -- for more accurate MUC / type=groupchat check if st_type == "headline" then -- Headline messages are ephemeral by definition @@ -277,7 +279,7 @@ local function should_store(stanza) --> boolean, reason: string if st_type == "error" then return true, "bounce"; end - if st_type == "groupchat" and st_to_full then + if st_type == "groupchat" then -- MUC messages always go to the full JID, usually archived by the MUC return false, "groupchat"; end -- cgit v1.2.3 From 80aaa484c38af613e61ad2f1af0ca186933ab3b8 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 23 Apr 2020 01:05:34 +0200 Subject: mod_mam: Remove unused variables [luacheck] Logic using full vs bare JID addressing may return in the future. --- plugins/mod_mam/mod_mam.lua | 4 ---- 1 file changed, 4 deletions(-) diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index 65859afd..d61d4883 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -265,10 +265,6 @@ end local function should_store(stanza) --> boolean, reason: string local st_type = stanza.attr.type or "normal"; - local st_to_full = (stanza.attr.to or ""):find("/"); - if st_type == "error" then - st_to_full = (stanza.attr.from or ""):find("/"); - end -- FIXME pass direction of stanza and use that along with bare/full JID addressing -- for more accurate MUC / type=groupchat check -- cgit v1.2.3