Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
test(mod_filter_iq_rayo): add tests for header stripping and JvbRoomPassword
Boris Grozev825ea720f163
diff --git a/resources/prosody-plugins/mod_test_observer.lua b/resources/prosody-plugins/mod_test_observer.luaindex dc5b014381..44d39af28e 100644--- a/resources/prosody-plugins/mod_test_observer.lua+++ b/resources/prosody-plugins/mod_test_observer.lua@@ -68,18 +68,19 @@ module:hook("iq/full", function(event)endlocal dial = stanza:get_child('dial', 'urn:xmpp:rayo:1');if dial then- -- Extract JvbRoomName header value for assertion.- local room_name_header;+ local headers = {};for _, child in ipairs(dial.tags) do- if child.name == "header" and child.attr.name == "JvbRoomName" then- room_name_header = child.attr.value;+ if child.name == "header" and child.attr.name then+ headers[child.attr.name] = child.attr.value;endendtable.insert(shared.dial_iqs, {from = stanza.attr.from;to = stanza.attr.to;dial_to = dial.attr.to;- room_name_header = room_name_header;+ room_name_header = headers["JvbRoomName"];+ room_pass_header = headers["JvbRoomPassword"];+ headers = headers;});endend, 500);diff --git a/tests/prosody/helpers/xmpp_client.js b/tests/prosody/helpers/xmpp_client.jsindex 661908acf7..a0c6a3e013 100644--- a/tests/prosody/helpers/xmpp_client.js+++ b/tests/prosody/helpers/xmpp_client.js@@ -315,16 +315,20 @@ export async function createXmppClient({ host = 'localhost', domain, params, use* mod_filter_iq_rayo may block it, and the test asserts via the* /dial-iqs HTTP endpoint instead.*- * @param {string} roomJid e.g. '[email protected]'- * @param {string} [dialTo='sip:[email protected]'] value for dial's `to` attribute.- * Pass 'jitsi_meet_transcribe' to trigger- * the transcription feature gate.- * @param {string|null} [roomNameHeader] value for the JvbRoomName header.- * Defaults to `roomJid` (correct value).- * Pass null to omit the header entirely.- * Pass any other string for a mismatch test.+ * @param {string} roomJid e.g. '[email protected]'+ * @param {object} [opts]+ * @param {string} [opts.dialTo='sip:[email protected]'] dial `to` attribute.+ * @param {string|null} [opts.roomNameHeader] JvbRoomName value; defaults to roomJid.+ * Pass null to omit, any other string for a mismatch test.+ * @param {string|null} [opts.roomPassHeader] JvbRoomPassword value; omitted by default.+ * @param {object} [opts.extraHeaders] extra name→value header pairs (spoof/strip tests).*/- sendRayoIq(roomJid, dialTo = 'sip:[email protected]', roomNameHeader = roomJid) {+ sendRayoIq(roomJid, {+ dialTo = 'sip:[email protected]',+ roomNameHeader = roomJid,+ roomPassHeader = null,+ extraHeaders = {}+ } = {}) {const headers = [];if (roomNameHeader !== null) {@@ -335,6 +339,22 @@ export async function createXmppClient({ host = 'localhost', domain, params, use}));}+ if (roomPassHeader !== null) {+ headers.push(xml('header', {+ xmlns: 'urn:xmpp:rayo:1',+ name: 'JvbRoomPassword',+ value: roomPassHeader+ }));+ }++ for (const [ name, value ] of Object.entries(extraHeaders)) {+ headers.push(xml('header', {+ xmlns: 'urn:xmpp:rayo:1',+ name,+ value+ }));+ }+return xmpp.send(xml('iq', { type: 'set',to: `${roomJid}/focus`,diff --git a/tests/prosody/mod_filter_iq_rayo_spec.js b/tests/prosody/mod_filter_iq_rayo_spec.jsindex fdbc051f95..14cf01a7c5 100644--- a/tests/prosody/mod_filter_iq_rayo_spec.js+++ b/tests/prosody/mod_filter_iq_rayo_spec.js@@ -51,12 +51,11 @@ function clearDialIqs() {** @param {object} client XmppTestClient with sendRayoIq* @param {string} roomJid full room JID- * @param {string} [dialTo] dial `to` attribute (default: 'sip:[email protected]')- * @param {string|null} [roomNameHeader] JvbRoomName header value (default: roomJid)+ * @param {object} [opts] options forwarded to sendRayoIq*/-async function sendAndCollect(client, roomJid, dialTo, roomNameHeader) {+async function sendAndCollect(client, roomJid, opts) {await clearDialIqs();- await client.sendRayoIq(roomJid, dialTo, roomNameHeader);+ await client.sendRayoIq(roomJid, opts);// Give Prosody time to route (or block) the IQ before we poll.await new Promise(r => setTimeout(r, 300));@@ -142,7 +141,7 @@ describe('mod_filter_iq_rayo (feature-based authorization)', () => {it('passes IQ when features.transcription = true', async () => {const { client: c, room } = await setup({ context: { features: { transcription: true } } });- const iqs = await sendAndCollect(c, room, 'jitsi_meet_transcribe');+ const iqs = await sendAndCollect(c, room, { dialTo: 'jitsi_meet_transcribe' });assert.strictEqual(iqs.length, 1, 'IQ should reach the MUC');assert.strictEqual(iqs[0].dial_to, 'jitsi_meet_transcribe');@@ -150,21 +149,21 @@ describe('mod_filter_iq_rayo (feature-based authorization)', () => {it('blocks IQ when features.transcription = false', async () => {const { client: c, room } = await setup({ context: { features: { transcription: false } } });- const iqs = await sendAndCollect(c, room, 'jitsi_meet_transcribe');+ const iqs = await sendAndCollect(c, room, { dialTo: 'jitsi_meet_transcribe' });assert.strictEqual(iqs.length, 0);});it('blocks IQ when context.features present but transcription key absent', async () => {const { client: c, room } = await setup({ context: { features: { 'outbound-call': true } } });- const iqs = await sendAndCollect(c, room, 'jitsi_meet_transcribe');+ const iqs = await sendAndCollect(c, room, { dialTo: 'jitsi_meet_transcribe' });assert.strictEqual(iqs.length, 0);});it('blocks IQ when token has no context.features (non-owner fallback)', async () => {const { client: c, room } = await setup();- const iqs = await sendAndCollect(c, room, 'jitsi_meet_transcribe');+ const iqs = await sendAndCollect(c, room, { dialTo: 'jitsi_meet_transcribe' });assert.strictEqual(iqs.length, 0);});@@ -178,16 +177,51 @@ describe('mod_filter_iq_rayo (feature-based authorization)', () => {const { client: c, room } = await setup({ context: { features: { 'outbound-call': true } } });// null → header omitted entirely- const iqs = await sendAndCollect(c, room, 'sip:[email protected]', null);+ const iqs = await sendAndCollect(c, room, { roomNameHeader: null });assert.strictEqual(iqs.length, 0);});it('blocks IQ when JvbRoomName header does not match room JID', async () => {const { client: c, room } = await setup({ context: { features: { 'outbound-call': true } } });- const iqs = await sendAndCollect(c, room, 'sip:[email protected]', '[email protected]');+ const iqs = await sendAndCollect(c, room, { roomNameHeader: '[email protected]' });assert.strictEqual(iqs.length, 0);});});++ // ─── Header stripping ───────────────────────────────────────────────────++ describe('header stripping', () => {++ it('strips arbitrary client-supplied headers', async () => {+ const { client: c, room } = await setup({ context: { features: { 'outbound-call': true } } });+ const iqs = await sendAndCollect(c, room, { extraHeaders: { SomeHeader: 'spoofed-value' } });++ assert.strictEqual(iqs.length, 1, 'IQ should reach the MUC');+ assert.strictEqual(iqs[0].headers?.SomeHeader, undefined, 'custom header must be stripped');+ });+ });++ // ─── JvbRoomPassword header ──────────────────────────────────────────────++ describe('JvbRoomPassword header', () => {++ it('passes JvbRoomPassword through when provided', async () => {+ const { client: c, room } = await setup({ context: { features: { 'outbound-call': true } } });+ const iqs = await sendAndCollect(c, room, { roomPassHeader: 'secret123' });++ assert.strictEqual(iqs.length, 1);+ assert.strictEqual(iqs[0].room_pass_header, 'secret123');+ });++ it('omits JvbRoomPassword in forwarded IQ when not provided by client', async () => {+ const { client: c, room } = await setup({ context: { features: { 'outbound-call': true } } });+ const iqs = await sendAndCollect(c, room);++ assert.strictEqual(iqs.length, 1);+ assert.strictEqual(iqs[0].room_pass_header, undefined);+ });++ });});