aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2020-05-15 20:55:22 +0200
committerKim Alvefur <zash@zash.se>2020-05-15 20:55:22 +0200
commitd916ce38f6b434552a5ebd2a1751286da9cf2d69 (patch)
tree59de3908c95b1c65ede2ac695a19ee43eeaa2a0d
parentd689f6c9a103215f7ce2b23aca163c21a63a4ce3 (diff)
downloadprosody-d916ce38f6b434552a5ebd2a1751286da9cf2d69.tar.gz
prosody-d916ce38f6b434552a5ebd2a1751286da9cf2d69.zip
mod_storage_internal: Fix keeping old timestamp in archive map API
This led to a missing 'when' field on changed items, which would cause a traceack.
-rw-r--r--plugins/mod_storage_internal.lua2
-rw-r--r--spec/core_storagemanager_spec.lua17
2 files changed, 15 insertions, 4 deletions
diff --git a/plugins/mod_storage_internal.lua b/plugins/mod_storage_internal.lua
index 586ea10f..472ec642 100644
--- a/plugins/mod_storage_internal.lua
+++ b/plugins/mod_storage_internal.lua
@@ -234,7 +234,7 @@ function archive:set(username, key, new_value, new_when, new_with)
if old_item.key == key then
local item = st.preserialize(st.clone(new_value));
- local when = new_when or item.when or datetime.parse(item.attr.stamp);
+ local when = new_when or old_item.when or datetime.parse(old_item.attr.stamp);
item.key = key;
item.when = when;
item.with = new_with or old_item.with;
diff --git a/spec/core_storagemanager_spec.lua b/spec/core_storagemanager_spec.lua
index 96ccceb6..a19edbab 100644
--- a/spec/core_storagemanager_spec.lua
+++ b/spec/core_storagemanager_spec.lua
@@ -445,13 +445,24 @@ describe("storagemanager", function ()
assert.falsy(archive:set("mapuser", "no-such-id", test_stanza));
local id = archive:append("mapuser", nil, test_stanza, test_time, "contact@example.com");
- assert.same(test_stanza, archive:get("mapuser", id));
+ do
+ local stanza_roundtrip, when, with = archive:get("mapuser", id);
+ assert.same(test_stanza, stanza_roundtrip, "same stanza is returned");
+ assert.equal(test_time, when, "same 'when' is returned");
+ assert.equal("contact@example.com", with, "same 'with' is returned");
+ end
local replacement_stanza = st.stanza("test", { xmlns = "urn:example:foo" })
:tag("bar"):up()
:reset();
- assert(archive:set("mapuser", id, replacement_stanza));
- assert.same(replacement_stanza, archive:get("mapuser", id));
+ assert(archive:set("mapuser", id, replacement_stanza, test_time+1));
+
+ do
+ local replaced, when, with = archive:get("mapuser", id);
+ assert.same(replacement_stanza, replaced, "replaced stanza is returned");
+ assert.equal(test_time+1, when, "modified 'when' is returned");
+ assert.equal("contact@example.com", with, "original 'with' is returned");
+ end
end);
end);