JC Brand 5 luni în urmă
părinte
comite
4fc23a632d

+ 1 - 1
src/headless/shared/model-with-messages.js

@@ -911,7 +911,7 @@ export default function ModelWithMessages(BaseModel) {
 
             const stanza = stx`
                 <message xmlns="jabber:client"
-                        from="${message.get('from') || api.connection.get().jid}"
+                        from="${message.get('type') === 'groupchat' ? api.connection.get().jid : message.get('from')}"
                         to="${message.get('to') || this.get('jid')}"
                         type="${this.get('message_type')}"
                         id="${(edited && u.getUniqueId()) || msgid}">

+ 13 - 9
src/plugins/muc-views/tests/corrections.js

@@ -4,6 +4,8 @@ const { Strophe, u, stx } = converse.env;
 
 describe("A Groupchat Message", function () {
 
+    beforeAll(() => jasmine.addMatchers({ toEqualStanza: jasmine.toEqualStanza }));
+
     it("can be replaced with a correction",
             mock.initConverse([], {}, async function (_converse) {
 
@@ -173,6 +175,8 @@ describe("A Groupchat Message", function () {
     it("can be sent as a correction by using the up arrow",
             mock.initConverse([], {}, async function (_converse) {
 
+        const { api } = _converse;
+        const { jid: own_jid } = api.connection.get();
         const nick = 'romeo'
         const muc_jid = 'lounge@montague.lit';
         await mock.openAndEnterChatRoom(_converse, muc_jid, nick);
@@ -220,15 +224,15 @@ describe("A Groupchat Message", function () {
 
         expect(_converse.api.connection.get().send).toHaveBeenCalled();
         const msg = _converse.api.connection.get().send.calls.all()[0].args[0];
-        expect(Strophe.serialize(msg)).toBe(
-            `<message from="${muc_jid}/${nick}" id="${msg.getAttribute("id")}" `+
-                `to="lounge@montague.lit" type="groupchat" `+
-                `xmlns="jabber:client">`+
-                    `<body>But soft, what light through yonder window breaks?</body>`+
-                    `<active xmlns="http://jabber.org/protocol/chatstates"/>`+
-                    `<replace id="${first_msg.get("msgid")}" xmlns="urn:xmpp:message-correct:0"/>`+
-                    `<origin-id id="${msg.querySelector('origin-id').getAttribute("id")}" xmlns="urn:xmpp:sid:0"/>`+
-            `</message>`);
+        expect(msg).toEqualStanza(stx`
+            <message from="${own_jid}" id="${msg.getAttribute("id")}"
+                to="lounge@montague.lit" type="groupchat"
+                xmlns="jabber:client">
+                    <body>But soft, what light through yonder window breaks?</body>
+                    <active xmlns="http://jabber.org/protocol/chatstates"/>
+                    <replace id="${first_msg.get("msgid")}" xmlns="urn:xmpp:message-correct:0"/>
+                    <origin-id id="${msg.querySelector('origin-id').getAttribute("id")}" xmlns="urn:xmpp:sid:0"/>
+            </message>`);
 
         expect(view.model.messages.models.length).toBe(1);
         const corrected_message = view.model.messages.at(0);

+ 16 - 14
src/plugins/muc-views/tests/http-file-upload.js

@@ -5,6 +5,8 @@ const { Strophe, sizzle, u, stx } = converse.env;
 
 describe("XEP-0363: HTTP File Upload", function () {
 
+    beforeAll(() => jasmine.addMatchers({ toEqualStanza: jasmine.toEqualStanza }));
+
     describe("When not supported", function () {
         describe("A file upload toolbar button", function () {
 
@@ -124,20 +126,20 @@ describe("XEP-0363: HTTP File Upload", function () {
                     _converse.api.connection.get()._dataRecv(mock.createRequest(stanza));
 
                     await u.waitUntil(() => sent_stanza, 1000);
-                    expect(Strophe.serialize(sent_stanza)).toBe(
-                        `<message `+
-                            `from="${muc_jid}/${nick}" `+
-                            `id="${sent_stanza.getAttribute("id")}" `+
-                            `to="lounge@montague.lit" `+
-                            `type="groupchat" `+
-                            `xmlns="jabber:client">`+
-                                `<body>${message}</body>`+
-                                `<active xmlns="http://jabber.org/protocol/chatstates"/>`+
-                                `<x xmlns="jabber:x:oob">`+
-                                    `<url>${message}</url>`+
-                                `</x>`+
-                                `<origin-id id="${sent_stanza.querySelector('origin-id').getAttribute("id")}" xmlns="urn:xmpp:sid:0"/>`+
-                        `</message>`);
+                    expect(sent_stanza).toEqualStanza(stx`
+                        <message
+                            from="romeo@montague.lit/orchard"
+                            id="${sent_stanza.getAttribute("id")}"
+                            to="lounge@montague.lit"
+                            type="groupchat"
+                            xmlns="jabber:client">
+                                <body>${message}</body>
+                                <active xmlns="http://jabber.org/protocol/chatstates"/>
+                                <x xmlns="jabber:x:oob">
+                                    <url>${message}</url>
+                                </x>
+                                <origin-id id="${sent_stanza.querySelector('origin-id').getAttribute("id")}" xmlns="urn:xmpp:sid:0"/>
+                        </message>`);
                     const img_link_el = await u.waitUntil(() => view.querySelector('converse-chat-message-body .chat-image__link'), 1000);
                     // Check that the image renders
                     expect(img_link_el.outerHTML.replace(/<!-.*?->/g, '').trim()).toEqual(

+ 43 - 35
src/plugins/muc-views/tests/mentions.js

@@ -84,11 +84,13 @@ describe("An incoming groupchat message", function () {
     it("properly renders mentions that contain the pipe character",
             mock.initConverse([], {}, async function (_converse) {
 
+        const { api } = _converse;
+        const { jid: own_jid } = api.connection.get();
         const muc_jid = 'lounge@montague.lit';
         const nick = 'romeo';
         const muc = await mock.openAndEnterChatRoom(_converse, muc_jid, nick);
         const view = _converse.chatboxviews.get(muc_jid);
-        _converse.api.connection.get()._dataRecv(mock.createRequest(
+        api.connection.get()._dataRecv(mock.createRequest(
             stx`<presence
                     to="romeo@montague.lit/resource"
                     from="lounge@montague.lit/ThUnD3r|Gr33n"
@@ -116,7 +118,7 @@ describe("An incoming groupchat message", function () {
         const sent_stanzas = _converse.api.connection.get().sent_stanzas;
         const msg = await u.waitUntil(() => sent_stanzas.filter(s => s.nodeName.toLowerCase() === 'message').pop());
         expect(msg).toEqualStanza(
-            stx`<message from="${muc_jid}/${nick}"
+            stx`<message from="${own_jid}"
                         id="${msg.getAttribute("id")}"
                         to="lounge@montague.lit" type="groupchat"
                         xmlns="jabber:client">
@@ -336,6 +338,8 @@ describe("A sent groupchat message", function () {
         it("properly encodes the URIs in sent out references",
                 mock.initConverse([], {}, async function (_converse) {
 
+            const { api } = _converse;
+            const { jid: own_jid } = api.connection.get();
             const nick = 'tom';
             const muc_jid = 'lounge@montague.lit';
             await mock.openAndEnterChatRoom(_converse, muc_jid, nick);
@@ -364,15 +368,15 @@ describe("A sent groupchat message", function () {
             await u.waitUntil(() => view.querySelectorAll('.chat-msg__text').length);
             const sent_stanzas = _converse.api.connection.get().sent_stanzas;
             const msg = await u.waitUntil(() => sent_stanzas.filter(s => s.nodeName.toLowerCase() === 'message').pop());
-            expect(Strophe.serialize(msg))
-                    .toBe(`<message from="${muc_jid}/${nick}" id="${msg.getAttribute("id")}" `+
-                        `to="lounge@montague.lit" type="groupchat" `+
-                        `xmlns="jabber:client">`+
-                            `<body>hello Link Mauve</body>`+
-                            `<active xmlns="http://jabber.org/protocol/chatstates"/>`+
-                            `<reference begin="6" end="16" type="mention" uri="xmpp:lounge@montague.lit/Link%20Mauve" xmlns="urn:xmpp:reference:0"/>`+
-                            `<origin-id id="${msg.querySelector('origin-id').getAttribute("id")}" xmlns="urn:xmpp:sid:0"/>`+
-                        `</message>`);
+            expect(msg).toEqualStanza(stx`
+                <message from="${own_jid}" id="${msg.getAttribute("id")}"
+                    to="lounge@montague.lit" type="groupchat"
+                    xmlns="jabber:client">
+                        <body>hello Link Mauve</body>
+                        <active xmlns="http://jabber.org/protocol/chatstates"/>
+                        <reference begin="6" end="16" type="mention" uri="xmpp:lounge@montague.lit/Link%20Mauve" xmlns="urn:xmpp:reference:0"/>
+                        <origin-id id="${msg.querySelector('origin-id').getAttribute("id")}" xmlns="urn:xmpp:sid:0"/>
+                    </message>`);
         }));
 
         it("can get corrected and given new references",
@@ -380,6 +384,8 @@ describe("A sent groupchat message", function () {
 
             const nick = 'tom';
             const muc_jid = 'lounge@montague.lit';
+            const { api } = _converse;
+            const { jid: own_jid } = api.connection.get();
 
             // Making the MUC non-anonymous so that real JIDs are included
             const features = [
@@ -432,17 +438,17 @@ describe("A sent groupchat message", function () {
 
             const sent_stanzas = _converse.api.connection.get().sent_stanzas;
             const msg = await u.waitUntil(() => sent_stanzas.filter(s => s.nodeName.toLowerCase() === 'message').pop());
-            expect(Strophe.serialize(msg))
-                .toBe(`<message from="${muc_jid}/${nick}" id="${msg.getAttribute("id")}" `+
-                    `to="lounge@montague.lit" type="groupchat" `+
-                    `xmlns="jabber:client">`+
-                        `<body>hello z3r0 gibson mr.robot, how are you?</body>`+
-                        `<active xmlns="http://jabber.org/protocol/chatstates"/>`+
-                        `<reference begin="6" end="10" type="mention" uri="xmpp:z3r0@montague.lit" xmlns="urn:xmpp:reference:0"/>`+
-                        `<reference begin="11" end="17" type="mention" uri="xmpp:gibson@montague.lit" xmlns="urn:xmpp:reference:0"/>`+
-                        `<reference begin="18" end="26" type="mention" uri="xmpp:mr.robot@montague.lit" xmlns="urn:xmpp:reference:0"/>`+
-                        `<origin-id id="${msg.querySelector('origin-id').getAttribute("id")}" xmlns="urn:xmpp:sid:0"/>`+
-                    `</message>`);
+            expect(msg).toEqualStanza(stx`
+                <message from="${own_jid}" id="${msg.getAttribute("id")}"
+                            to="lounge@montague.lit" type="groupchat"
+                            xmlns="jabber:client">
+                    <body>hello z3r0 gibson mr.robot, how are you?</body>
+                    <active xmlns="http://jabber.org/protocol/chatstates"/>
+                    <reference begin="6" end="10" type="mention" uri="xmpp:z3r0@montague.lit" xmlns="urn:xmpp:reference:0"/>
+                    <reference begin="11" end="17" type="mention" uri="xmpp:gibson@montague.lit" xmlns="urn:xmpp:reference:0"/>
+                    <reference begin="18" end="26" type="mention" uri="xmpp:mr.robot@montague.lit" xmlns="urn:xmpp:reference:0"/>
+                    <origin-id id="${msg.querySelector('origin-id').getAttribute("id")}" xmlns="urn:xmpp:sid:0"/>
+                </message>`);
 
             const action = await u.waitUntil(() => view.querySelector('.chat-msg .chat-msg__action'));
             action.style.opacity = 1;
@@ -459,23 +465,25 @@ describe("A sent groupchat message", function () {
                 'hello z3r0 gibson sw0rdf1sh, how are you?', 500);
 
             const correction = sent_stanzas.filter(s => s.nodeName.toLowerCase() === 'message').pop();
-            expect(Strophe.serialize(correction))
-                .toBe(`<message from="${muc_jid}/${nick}" id="${correction.getAttribute("id")}" `+
-                    `to="lounge@montague.lit" type="groupchat" `+
-                    `xmlns="jabber:client">`+
-                        `<body>hello z3r0 gibson sw0rdf1sh, how are you?</body>`+
-                        `<active xmlns="http://jabber.org/protocol/chatstates"/>`+
-                        `<reference begin="6" end="10" type="mention" uri="xmpp:z3r0@montague.lit" xmlns="urn:xmpp:reference:0"/>`+
-                        `<reference begin="11" end="17" type="mention" uri="xmpp:gibson@montague.lit" xmlns="urn:xmpp:reference:0"/>`+
-                        `<reference begin="18" end="27" type="mention" uri="xmpp:sw0rdf1sh@montague.lit" xmlns="urn:xmpp:reference:0"/>`+
-                        `<replace id="${msg.getAttribute("id")}" xmlns="urn:xmpp:message-correct:0"/>`+
-                        `<origin-id id="${correction.querySelector('origin-id').getAttribute("id")}" xmlns="urn:xmpp:sid:0"/>`+
-                    `</message>`);
+            expect(correction).toEqualStanza(stx`
+                <message from="${own_jid}" id="${correction.getAttribute("id")}"
+                    to="lounge@montague.lit" type="groupchat"
+                    xmlns="jabber:client">
+                        <body>hello z3r0 gibson sw0rdf1sh, how are you?</body>
+                        <active xmlns="http://jabber.org/protocol/chatstates"/>
+                        <reference begin="6" end="10" type="mention" uri="xmpp:z3r0@montague.lit" xmlns="urn:xmpp:reference:0"/>
+                        <reference begin="11" end="17" type="mention" uri="xmpp:gibson@montague.lit" xmlns="urn:xmpp:reference:0"/>
+                        <reference begin="18" end="27" type="mention" uri="xmpp:sw0rdf1sh@montague.lit" xmlns="urn:xmpp:reference:0"/>
+                        <replace id="${msg.getAttribute("id")}" xmlns="urn:xmpp:message-correct:0"/>
+                        <origin-id id="${correction.querySelector('origin-id').getAttribute("id")}" xmlns="urn:xmpp:sid:0"/>
+                    </message>`);
         }));
 
         it("includes a XEP-0372 references to that person",
                 mock.initConverse([], { auto_register_muc_nickname: false }, async function (_converse) {
 
+            const { api } = _converse;
+            const { jid: own_jid } = api.connection.get();
             const nick = 'romeo';
             const muc_jid = 'lounge@montague.lit';
             const muc = await mock.openAndEnterChatRoom(_converse, muc_jid, nick);
@@ -509,7 +517,7 @@ describe("A sent groupchat message", function () {
 
             const msg = _converse.api.connection.get().send.calls.all()[0].args[0];
             expect(msg).toEqualStanza(
-                stx`<message from="${muc_jid}/${nick}"
+                stx`<message from="${own_jid}"
                             id="${msg.getAttribute("id")}"
                             to="lounge@montague.lit"
                             type="groupchat"

+ 19 - 17
src/plugins/muc-views/tests/unfurls.js

@@ -4,6 +4,8 @@ const { Strophe, u, stx } = converse.env;
 
 describe("A Groupchat Message", function () {
 
+    beforeAll(() => jasmine.addMatchers({ toEqualStanza: jasmine.toEqualStanza }));
+
     it("will render an unfurl based on OGP data", mock.initConverse(['chatBoxesFetched'], {}, async function (_converse) {
         const nick = 'romeo';
         const muc_jid = 'lounge@montague.lit';
@@ -404,6 +406,9 @@ describe("A Groupchat Message", function () {
 
     it("will not render an unfurl that has been removed in a subsequent correction",
             mock.initConverse(['chatBoxesFetched'], { auto_register_muc_nickname: false }, async function (_converse) {
+
+        const { api } = _converse;
+        const { jid: own_jid } = api.connection.get();
         const nick = 'romeo';
         const muc_jid = 'lounge@muc.montague.lit';
         await mock.openAndEnterChatRoom(_converse, muc_jid, nick);
@@ -426,17 +431,15 @@ describe("A Groupchat Message", function () {
         message_form.onKeyDown(enter_event);
 
         await u.waitUntil(() => view.querySelectorAll('.chat-msg').length === 1);
-        expect(view.querySelector('.chat-msg__text').textContent)
-            .toBe(unfurl_url);
+        expect(view.querySelector('.chat-msg__text').textContent).toBe(unfurl_url);
 
         let msg = _converse.api.connection.get().send.calls.all()[1].args[0];
-        expect(Strophe.serialize(msg))
-        .toBe(
-            `<message from="${muc_jid}/${nick}" id="${msg.getAttribute('id')}" to="${muc_jid}" type="groupchat" xmlns="jabber:client">`+
-                `<body>${unfurl_url}</body>`+
-                `<active xmlns="http://jabber.org/protocol/chatstates"/>`+
-                `<origin-id id="${msg.querySelector('origin-id')?.getAttribute('id')}" xmlns="urn:xmpp:sid:0"/>`+
-            `</message>`);
+        expect(msg).toEqualStanza(stx`
+            <message from="${own_jid}" id="${msg.getAttribute('id')}" to="${muc_jid}" type="groupchat" xmlns="jabber:client">
+                <body>${unfurl_url}</body>
+                <active xmlns="http://jabber.org/protocol/chatstates"/>
+                <origin-id id="${msg.querySelector('origin-id')?.getAttribute('id')}" xmlns="urn:xmpp:sid:0"/>
+            </message>`);
 
         const el = await u.waitUntil(() => view.querySelector('.chat-msg__text'));
         expect(el.textContent).toBe(unfurl_url);
@@ -478,13 +481,12 @@ describe("A Groupchat Message", function () {
         const getSentMessages = () => _converse.api.connection.get().send.calls.all().map(c => c.args[0]).filter(s => s.nodeName === 'message');
         await u.waitUntil(() => getSentMessages().length == 2);
         msg = getSentMessages().pop();
-        expect(Strophe.serialize(msg))
-        .toBe(
-            `<message from="${muc_jid}/${nick}" id="${msg.getAttribute('id')}" to="${muc_jid}" type="groupchat" xmlns="jabber:client">`+
-                `<body>never mind</body>`+
-                `<active xmlns="http://jabber.org/protocol/chatstates"/>`+
-                `<replace id="${msg.querySelector('replace')?.getAttribute('id')}" xmlns="urn:xmpp:message-correct:0"/>`+
-                `<origin-id id="${msg.querySelector('origin-id')?.getAttribute('id')}" xmlns="urn:xmpp:sid:0"/>`+
-            `</message>`);
+        expect(msg).toEqualStanza(stx`
+            <message from="${own_jid}" id="${msg.getAttribute('id')}" to="${muc_jid}" type="groupchat" xmlns="jabber:client">
+                <body>never mind</body>
+                <active xmlns="http://jabber.org/protocol/chatstates"/>
+                <replace id="${msg.querySelector('replace')?.getAttribute('id')}" xmlns="urn:xmpp:message-correct:0"/>
+                <origin-id id="${msg.querySelector('origin-id')?.getAttribute('id')}" xmlns="urn:xmpp:sid:0"/>
+            </message>`);
     }));
 });

+ 43 - 37
src/plugins/omemo/tests/corrections.js

@@ -4,6 +4,8 @@ const { Strophe, $iq, $msg, $pres, u, omemo } = converse.env;
 
 describe("An OMEMO encrypted message", function() {
 
+    beforeAll(() => jasmine.addMatchers({ toEqualStanza: jasmine.toEqualStanza }));
+
     it("can be edited", mock.initConverse(['chatBoxesFetched'], {}, async function (_converse) {
 
         await mock.waitForRoster(_converse, 'current', 1);
@@ -211,6 +213,8 @@ describe("An OMEMO encrypted message", function() {
 
 describe("An OMEMO encrypted MUC message", function() {
 
+    beforeAll(() => jasmine.addMatchers({ toEqualStanza: jasmine.toEqualStanza }));
+
     it("can be edited", mock.initConverse(['chatBoxesFetched'], {}, async function (_converse) {
 
         // MEMO encryption works only in members only conferences
@@ -225,6 +229,8 @@ describe("An OMEMO encrypted MUC message", function() {
             'muc_unmoderated',
             'muc_nonanonymous'
         ];
+        const { api } = _converse;
+        const { jid: own_jid } = api.connection.get();
         const nick = 'romeo';
         const muc_jid = 'lounge@montague.lit';
         await mock.openAndEnterChatRoom(_converse, muc_jid, nick, features);
@@ -334,26 +340,26 @@ describe("An OMEMO encrypted MUC message", function() {
         await u.waitUntil(() => _converse.api.connection.get().send.calls.count(), 1000);
         const sent_stanza = _converse.api.connection.get().send.calls.all()[0].args[0];
 
-        expect(Strophe.serialize(sent_stanza)).toBe(
-            `<message from="${muc_jid}/${nick}" `+
-                     `id="${sent_stanza.getAttribute("id")}" `+
-                     `to="lounge@montague.lit" `+
-                     `type="groupchat" `+
-                     `xmlns="jabber:client">`+
-                `<body>This is an OMEMO encrypted message which your client doesn’t seem to support. Find more information on https://conversations.im/omemo</body>`+
-                `<active xmlns="http://jabber.org/protocol/chatstates"/>`+
-                `<origin-id id="${sent_stanza.getAttribute('id')}" xmlns="urn:xmpp:sid:0"/>`+
-                `<encrypted xmlns="eu.siacs.conversations.axolotl">`+
-                    `<header sid="123456789">`+
-                        `<key rid="482886413b977930064a5888b92134fe">YzFwaDNSNzNYNw==</key>`+
-                        `<key rid="4e30f35051b7b8b42abe083742187228">YzFwaDNSNzNYNw==</key>`+
-                        `<iv>${sent_stanza.querySelector("iv").textContent}</iv>`+
-                    `</header>`+
-                    `<payload>${sent_stanza.querySelector("payload").textContent}</payload>`+
-                `</encrypted>`+
-                `<store xmlns="urn:xmpp:hints"/>`+
-                `<encryption namespace="eu.siacs.conversations.axolotl" xmlns="urn:xmpp:eme:0"/>`+
-            `</message>`);
+        expect(sent_stanza).toEqualStanza(stx`
+            <message from="${own_jid}"
+                     id="${sent_stanza.getAttribute("id")}"
+                     to="lounge@montague.lit"
+                     type="groupchat"
+                     xmlns="jabber:client">
+                <body>This is an OMEMO encrypted message which your client doesn’t seem to support. Find more information on https://conversations.im/omemo</body>
+                <active xmlns="http://jabber.org/protocol/chatstates"/>
+                <origin-id id="${sent_stanza.getAttribute('id')}" xmlns="urn:xmpp:sid:0"/>
+                <encrypted xmlns="eu.siacs.conversations.axolotl">
+                    <header sid="123456789">
+                        <key rid="482886413b977930064a5888b92134fe">YzFwaDNSNzNYNw==</key>
+                        <key rid="4e30f35051b7b8b42abe083742187228">YzFwaDNSNzNYNw==</key>
+                        <iv>${sent_stanza.querySelector("iv").textContent}</iv>
+                    </header>
+                    <payload>${sent_stanza.querySelector("payload").textContent}</payload>
+                </encrypted>
+                <store xmlns="urn:xmpp:hints"/>
+                <encryption namespace="eu.siacs.conversations.axolotl" xmlns="urn:xmpp:eme:0"/>
+            </message>`);
 
         await u.waitUntil(() => textarea.value === '');
 
@@ -388,23 +394,23 @@ describe("An OMEMO encrypted MUC message", function() {
         await u.waitUntil(() => _converse.api.connection.get().sent_stanzas.filter(s => s.nodeName === 'message').length === 2);
         const msg = _converse.api.connection.get().sent_stanzas.pop();
 
-        expect(Strophe.serialize(msg))
-            .toBe(`<message from="${muc_jid}/${nick}" id="${msg.getAttribute("id")}" to="${muc_jid}" type="groupchat" xmlns="jabber:client">`+
-                    `<body>${fallback_text}</body>`+
-                    `<active xmlns="http://jabber.org/protocol/chatstates"/>`+
-                    `<replace id="${first_msg.get("msgid")}" xmlns="urn:xmpp:message-correct:0"/>`+
-                    `<origin-id id="${msg.querySelector('origin-id').getAttribute("id")}" xmlns="urn:xmpp:sid:0"/>`+
-                    `<encrypted xmlns="eu.siacs.conversations.axolotl">`+
-                        `<header sid="123456789">`+
-                            `<key rid="482886413b977930064a5888b92134fe">YzFwaDNSNzNYNw==</key>`+
-                            `<key rid="4e30f35051b7b8b42abe083742187228">YzFwaDNSNzNYNw==</key>`+
-                            `<iv>${msg.querySelector("iv").textContent}</iv>`+
-                        `</header>`+
-                        `<payload>${msg.querySelector("payload").textContent}</payload>`+
-                    `</encrypted>`+
-                    `<store xmlns="urn:xmpp:hints"/>`+
-                    `<encryption namespace="eu.siacs.conversations.axolotl" xmlns="urn:xmpp:eme:0"/>`+
-                `</message>`);
+        expect(msg).toEqualStanza(stx`
+            <message from="${own_jid}" id="${msg.getAttribute("id")}" to="${muc_jid}" type="groupchat" xmlns="jabber:client">
+                <body>${fallback_text}</body>
+                <active xmlns="http://jabber.org/protocol/chatstates"/>
+                <replace id="${first_msg.get("msgid")}" xmlns="urn:xmpp:message-correct:0"/>
+                <origin-id id="${msg.querySelector('origin-id').getAttribute("id")}" xmlns="urn:xmpp:sid:0"/>
+                <encrypted xmlns="eu.siacs.conversations.axolotl">
+                    <header sid="123456789">
+                        <key rid="482886413b977930064a5888b92134fe">YzFwaDNSNzNYNw==</key>
+                        <key rid="4e30f35051b7b8b42abe083742187228">YzFwaDNSNzNYNw==</key>
+                        <iv>${msg.querySelector("iv").textContent}</iv>
+                    </header>
+                    <payload>${msg.querySelector("payload").textContent}</payload>
+                </encrypted>
+                <store xmlns="urn:xmpp:hints"/>
+                <encryption namespace="eu.siacs.conversations.axolotl" xmlns="urn:xmpp:eme:0"/>
+            </message>`);
 
 
         // Test reception of an encrypted message

+ 24 - 20
src/plugins/omemo/tests/muc.js

@@ -5,6 +5,8 @@ const u = converse.env.utils;
 
 describe("The OMEMO module", function() {
 
+    beforeAll(() => jasmine.addMatchers({ toEqualStanza: jasmine.toEqualStanza }));
+
     it("enables encrypted groupchat messages to be sent and received",
             mock.initConverse(['chatBoxesFetched'], {}, async function (_converse) {
 
@@ -20,6 +22,8 @@ describe("The OMEMO module", function() {
             'muc_unmoderated',
             'muc_nonanonymous'
         ];
+        const { api } = _converse;
+        const { jid: own_jid } = api.connection.get();
         const nick = 'romeo';
         const muc_jid = 'lounge@montague.lit';
         await mock.openAndEnterChatRoom(_converse, muc_jid, nick, features);
@@ -131,26 +135,26 @@ describe("The OMEMO module", function() {
         await u.waitUntil(() => _converse.api.connection.get().send.calls.count(), 1000);
         const sent_stanza = _converse.api.connection.get().send.calls.all()[0].args[0];
 
-        expect(Strophe.serialize(sent_stanza)).toBe(
-            `<message from="${muc_jid}/${nick}" `+
-                     `id="${sent_stanza.getAttribute("id")}" `+
-                     `to="lounge@montague.lit" `+
-                     `type="groupchat" `+
-                     `xmlns="jabber:client">`+
-                `<body>This is an OMEMO encrypted message which your client doesn’t seem to support. Find more information on https://conversations.im/omemo</body>`+
-                `<active xmlns="http://jabber.org/protocol/chatstates"/>`+
-                `<origin-id id="${sent_stanza.getAttribute('id')}" xmlns="urn:xmpp:sid:0"/>`+
-                `<encrypted xmlns="eu.siacs.conversations.axolotl">`+
-                    `<header sid="123456789">`+
-                        `<key rid="482886413b977930064a5888b92134fe">YzFwaDNSNzNYNw==</key>`+
-                        `<key rid="4e30f35051b7b8b42abe083742187228">YzFwaDNSNzNYNw==</key>`+
-                        `<iv>${sent_stanza.querySelector("iv").textContent}</iv>`+
-                    `</header>`+
-                    `<payload>${sent_stanza.querySelector("payload").textContent}</payload>`+
-                `</encrypted>`+
-                `<store xmlns="urn:xmpp:hints"/>`+
-                `<encryption namespace="eu.siacs.conversations.axolotl" xmlns="urn:xmpp:eme:0"/>`+
-            `</message>`);
+        expect(sent_stanza).toEqualStanza(stx`
+            <message from="${own_jid}"
+                     id="${sent_stanza.getAttribute("id")}"
+                     to="lounge@montague.lit"
+                     type="groupchat"
+                     xmlns="jabber:client">
+                <body>This is an OMEMO encrypted message which your client doesn’t seem to support. Find more information on https://conversations.im/omemo</body>
+                <active xmlns="http://jabber.org/protocol/chatstates"/>
+                <origin-id id="${sent_stanza.getAttribute('id')}" xmlns="urn:xmpp:sid:0"/>
+                <encrypted xmlns="eu.siacs.conversations.axolotl">
+                    <header sid="123456789">
+                        <key rid="482886413b977930064a5888b92134fe">YzFwaDNSNzNYNw==</key>
+                        <key rid="4e30f35051b7b8b42abe083742187228">YzFwaDNSNzNYNw==</key>
+                        <iv>${sent_stanza.querySelector("iv").textContent}</iv>
+                    </header>
+                    <payload>${sent_stanza.querySelector("payload").textContent}</payload>
+                </encrypted>
+                <store xmlns="urn:xmpp:hints"/>
+                <encryption namespace="eu.siacs.conversations.axolotl" xmlns="urn:xmpp:eme:0"/>
+            </message>`);
 
         // Test reception of an encrypted message
         const obj = await omemo.encryptMessage('This is an encrypted message from the contact')