|
@@ -210,6 +210,62 @@
|
|
|
|
|
|
describe("when recieved", function () {
|
|
describe("when recieved", function () {
|
|
|
|
|
|
|
|
+ it("is discarded if it doesn't come from the right sender",
|
|
|
|
+ mock.initConverse(
|
|
|
|
+ null, ['discoInitialized'], {},
|
|
|
|
+ async function (done, _converse) {
|
|
|
|
+
|
|
|
|
+ await test_utils.waitForRoster(_converse, 'current', 1);
|
|
|
|
+ const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
|
|
|
+ await test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
+ await test_utils.waitUntilDiscoConfirmed(_converse, _converse.bare_jid, null, [Strophe.NS.MAM]);
|
|
|
|
+ const sent_IQs = _converse.connection.IQ_stanzas;
|
|
|
|
+ const stanza = await u.waitUntil(() => sent_IQs.filter(iq => iq.querySelector(`iq[type="set"] query[xmlns="${Strophe.NS.MAM}"]`)).pop());
|
|
|
|
+ const queryid = stanza.querySelector('query').getAttribute('queryid');
|
|
|
|
+ let msg = $msg({'id': _converse.connection.getUniqueId(), 'from': 'impersonator@capulet.lit', 'to': _converse.bare_jid})
|
|
|
|
+ .c('result', {'xmlns': 'urn:xmpp:mam:2', 'queryid':queryid, 'id': _converse.connection.getUniqueId()})
|
|
|
|
+ .c('forwarded', {'xmlns':'urn:xmpp:forward:0'})
|
|
|
|
+ .c('delay', {'xmlns':'urn:xmpp:delay', 'stamp':'2010-07-10T23:08:25Z'}).up()
|
|
|
|
+ .c('message', {
|
|
|
|
+ 'xmlns':'jabber:client',
|
|
|
|
+ 'to': _converse.bare_jid,
|
|
|
|
+ 'id': _converse.connection.getUniqueId(),
|
|
|
|
+ 'from': contact_jid,
|
|
|
|
+ 'type':'chat'
|
|
|
|
+ }).c('body').t("Meet me at the dance");
|
|
|
|
+ spyOn(_converse, 'log');
|
|
|
|
+ _converse.connection._dataRecv(test_utils.createRequest(msg));
|
|
|
|
+ expect(_converse.log).toHaveBeenCalledWith(`Ignoring alleged MAM message from ${msg.nodeTree.getAttribute('from')}`, Strophe.LogLevel.WARN);
|
|
|
|
+
|
|
|
|
+ msg = $msg({'id': _converse.connection.getUniqueId(), 'to': _converse.bare_jid})
|
|
|
|
+ .c('result', {'xmlns': 'urn:xmpp:mam:2', 'queryid':queryid, 'id': _converse.connection.getUniqueId()})
|
|
|
|
+ .c('forwarded', {'xmlns':'urn:xmpp:forward:0'})
|
|
|
|
+ .c('delay', {'xmlns':'urn:xmpp:delay', 'stamp':'2010-07-10T23:08:25Z'}).up()
|
|
|
|
+ .c('message', {
|
|
|
|
+ 'xmlns':'jabber:client',
|
|
|
|
+ 'to': _converse.bare_jid,
|
|
|
|
+ 'id': _converse.connection.getUniqueId(),
|
|
|
|
+ 'from': contact_jid,
|
|
|
|
+ 'type':'chat'
|
|
|
|
+ }).c('body').t("Thrice the brinded cat hath mew'd.");
|
|
|
|
+ _converse.connection._dataRecv(test_utils.createRequest(msg));
|
|
|
|
+
|
|
|
|
+ const iq_result = $iq({'type': 'result', 'id': stanza.getAttribute('id')})
|
|
|
|
+ .c('fin', {'xmlns': 'urn:xmpp:mam:2'})
|
|
|
|
+ .c('set', {'xmlns': 'http://jabber.org/protocol/rsm'})
|
|
|
|
+ .c('first', {'index': '0'}).t('23452-4534-1').up()
|
|
|
|
+ .c('last').t('09af3-cc343-b409f').up()
|
|
|
|
+ .c('count').t('16');
|
|
|
|
+ _converse.connection._dataRecv(test_utils.createRequest(iq_result));
|
|
|
|
+
|
|
|
|
+ const view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
+ await new Promise((resolve, reject) => view.once('messageInserted', resolve));
|
|
|
|
+ expect(view.model.messages.length).toBe(1);
|
|
|
|
+ expect(view.model.messages.at(0).get('message')).toBe("Thrice the brinded cat hath mew'd.");
|
|
|
|
+ done();
|
|
|
|
+ }));
|
|
|
|
+
|
|
|
|
+
|
|
it("updates the is_archived value of an already cached version",
|
|
it("updates the is_archived value of an already cached version",
|
|
mock.initConverse(
|
|
mock.initConverse(
|
|
null, ['discoInitialized'], {},
|
|
null, ['discoInitialized'], {},
|