Fix failing test
This commit is contained in:
parent
b78c19f6f2
commit
ef2c206507
@ -23,7 +23,7 @@ import {
|
|||||||
isHeadline,
|
isHeadline,
|
||||||
isServerMessage,
|
isServerMessage,
|
||||||
isValidReceiptRequest,
|
isValidReceiptRequest,
|
||||||
rejectUnencapsulatedForward,
|
throwErrorIfInvalidForward,
|
||||||
} from '@converse/headless/shared/parsers';
|
} from '@converse/headless/shared/parsers';
|
||||||
|
|
||||||
const { Strophe, sizzle } = converse.env;
|
const { Strophe, sizzle } = converse.env;
|
||||||
@ -37,10 +37,7 @@ const { Strophe, sizzle } = converse.env;
|
|||||||
* @returns { (MessageAttributes|Error) }
|
* @returns { (MessageAttributes|Error) }
|
||||||
*/
|
*/
|
||||||
export async function parseMessage (stanza, _converse) {
|
export async function parseMessage (stanza, _converse) {
|
||||||
const err = rejectUnencapsulatedForward(stanza);
|
throwErrorIfInvalidForward(stanza);
|
||||||
if (err) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
let to_jid = stanza.getAttribute('to');
|
let to_jid = stanza.getAttribute('to');
|
||||||
const to_resource = Strophe.getResourceFromJid(to_jid);
|
const to_resource = Strophe.getResourceFromJid(to_jid);
|
||||||
|
@ -554,13 +554,17 @@ const ChatRoomMixin = {
|
|||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @typedef { Object } MUCMessageData
|
* @typedef { Object } MUCMessageData
|
||||||
* An object containing the original groupchat message stanza,
|
* An object containing the parsed { @link MUCMessageAttributes } and
|
||||||
* as well as the parsed attributes.
|
* current { @link ChatRoom }.
|
||||||
* @property { XMLElement } stanza
|
|
||||||
* @property { MUCMessageAttributes } attrs
|
* @property { MUCMessageAttributes } attrs
|
||||||
* @property { ChatRoom } chatbox
|
* @property { ChatRoom } chatbox
|
||||||
*/
|
*/
|
||||||
const attrs = await parseMUCMessage(stanza, this, _converse);
|
let attrs;
|
||||||
|
try {
|
||||||
|
attrs = await parseMUCMessage(stanza, this, _converse);
|
||||||
|
} catch (e) {
|
||||||
|
return log.error(e.message);
|
||||||
|
}
|
||||||
const data = { stanza, attrs, 'chatbox': this };
|
const data = { stanza, attrs, 'chatbox': this };
|
||||||
/**
|
/**
|
||||||
* Triggered when a groupchat message stanza has been received and parsed.
|
* Triggered when a groupchat message stanza has been received and parsed.
|
||||||
|
@ -18,7 +18,7 @@ import {
|
|||||||
isCarbon,
|
isCarbon,
|
||||||
isHeadline,
|
isHeadline,
|
||||||
isValidReceiptRequest,
|
isValidReceiptRequest,
|
||||||
rejectUnencapsulatedForward,
|
throwErrorIfInvalidForward,
|
||||||
} from '@converse/headless/shared/parsers';
|
} from '@converse/headless/shared/parsers';
|
||||||
import { api, converse } from '@converse/headless/core';
|
import { api, converse } from '@converse/headless/core';
|
||||||
|
|
||||||
@ -103,10 +103,7 @@ function getModerationAttributes (stanza) {
|
|||||||
* @returns { Promise<MUCMessageAttributes|Error> }
|
* @returns { Promise<MUCMessageAttributes|Error> }
|
||||||
*/
|
*/
|
||||||
export async function parseMUCMessage (stanza, chatbox, _converse) {
|
export async function parseMUCMessage (stanza, chatbox, _converse) {
|
||||||
const err = rejectUnencapsulatedForward(stanza);
|
throwErrorIfInvalidForward(stanza);
|
||||||
if (err) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
const selector = `[xmlns="${NS.MAM}"] > forwarded[xmlns="${NS.FORWARD}"] > message`;
|
const selector = `[xmlns="${NS.MAM}"] > forwarded[xmlns="${NS.FORWARD}"] > message`;
|
||||||
const original_stanza = stanza;
|
const original_stanza = stanza;
|
||||||
|
@ -307,12 +307,17 @@ export function isValidReceiptRequest (stanza, attrs) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function rejectUnencapsulatedForward (stanza) {
|
/**
|
||||||
|
* Check whether the passed-in stanza is a forwarded message that is "bare",
|
||||||
|
* i.e. it's not forwarded as part of a larger protocol, like MAM.
|
||||||
|
* @param { XMLElement } stanza
|
||||||
|
*/
|
||||||
|
export function throwErrorIfInvalidForward (stanza) {
|
||||||
const bare_forward = sizzle(`message > forwarded[xmlns="${Strophe.NS.FORWARD}"]`, stanza).length;
|
const bare_forward = sizzle(`message > forwarded[xmlns="${Strophe.NS.FORWARD}"]`, stanza).length;
|
||||||
if (bare_forward) {
|
if (bare_forward) {
|
||||||
rejectMessage(stanza, 'Forwarded messages not part of an encapsulating protocol are not supported');
|
rejectMessage(stanza, 'Forwarded messages not part of an encapsulating protocol are not supported');
|
||||||
const from_jid = stanza.getAttribute('from');
|
const from_jid = stanza.getAttribute('from');
|
||||||
return new StanzaParseError(`Ignoring unencapsulated forwarded message from ${from_jid}`, stanza);
|
throw new StanzaParseError(`Ignoring unencapsulated forwarded message from ${from_jid}`, stanza);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,10 +143,9 @@ describe("A Groupchat Message", function () {
|
|||||||
</message>
|
</message>
|
||||||
`);
|
`);
|
||||||
const view = _converse.chatboxviews.get(muc_jid);
|
const view = _converse.chatboxviews.get(muc_jid);
|
||||||
spyOn(view.model, 'onMessage').and.callThrough();
|
spyOn(converse.env.log, 'error').and.callThrough();
|
||||||
spyOn(converse.env.log, 'error');
|
|
||||||
_converse.connection._dataRecv(mock.createRequest(received_stanza));
|
_converse.connection._dataRecv(mock.createRequest(received_stanza));
|
||||||
await u.waitUntil(() => view.model.onMessage.calls.count() === 1);
|
await u.waitUntil(() => converse.env.log.error.calls.count() === 1);
|
||||||
expect(converse.env.log.error).toHaveBeenCalledWith(
|
expect(converse.env.log.error).toHaveBeenCalledWith(
|
||||||
`Ignoring unencapsulated forwarded message from ${muc_jid}/mallory`
|
`Ignoring unencapsulated forwarded message from ${muc_jid}/mallory`
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user