Software /
code /
prosody
Changeset
10842:5a6ba2f38e2b
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.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 15 May 2020 20:55:22 +0200 |
parents | 10841:22f783d80eec |
children | 10844:05f4386c846e |
files | plugins/mod_storage_internal.lua spec/core_storagemanager_spec.lua |
diffstat | 2 files changed, 15 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/mod_storage_internal.lua Thu May 14 16:55:01 2020 +0200 +++ b/plugins/mod_storage_internal.lua Fri May 15 20:55:22 2020 +0200 @@ -234,7 +234,7 @@ 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;
--- a/spec/core_storagemanager_spec.lua Thu May 14 16:55:01 2020 +0200 +++ b/spec/core_storagemanager_spec.lua Fri May 15 20:55:22 2020 +0200 @@ -445,13 +445,24 @@ 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);