Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

test(mod_muc_allowners): add tests for owner promotion and filtering.

damencho92fa288b7017
diff --git a/tests/prosody/docker/prosody.cfg.lua b/tests/prosody/docker/prosody.cfg.lua
index 0975df41be..358d9a7e2e 100644
--- a/tests/prosody/docker/prosody.cfg.lua
+++ b/tests/prosody/docker/prosody.cfg.lua
@@ -309,3 +309,19 @@ Component "conference-waitforhost.localhost" "muc"
}
muc_mapper_domain_base = "conference.localhost"
muc_mapper_domain_prefix = "conference"
+
+-- Isolated MUC component for mod_muc_allowners tests.
+-- No muc_meeting_id (no jicofo lock) and no token_verification, so anonymous
+-- clients can join freely. In non-moderated rooms every occupant is promoted
+-- to owner on join and muc#admin set stanzas revoking affiliations are
+-- rejected. Room names listed in allowners_moderated_rooms are moderated:
+-- only JWT-authenticated users with a matching room claim are promoted and
+-- the revoke filtering is skipped.
+Component "conference-allowners.localhost" "muc"
+ storage = "memory"
+ modules_enabled = {
+ "muc_allowners";
+ }
+ muc_mapper_domain_base = "localhost"
+ muc_mapper_domain_prefix = "conference"
+ allowners_moderated_rooms = { "moderated-room-1"; "moderated-room-2" }
diff --git a/tests/prosody/helpers/xmpp_client.js b/tests/prosody/helpers/xmpp_client.js
index 3e6e78b875..6d177fdbc3 100644
--- a/tests/prosody/helpers/xmpp_client.js
+++ b/tests/prosody/helpers/xmpp_client.js
@@ -559,6 +559,27 @@ export async function createXmppClient({ host = 'localhost', domain, params, use
);
},
+ /**
+ * Sends a muc#admin set IQ carrying multiple <item> children and
+ * resolves with the server's IQ response. XEP-0045 allows batching
+ * several affiliation/role changes in one stanza; use this to verify
+ * that filtering hooks inspect every item and not just the first one.
+ *
+ * @param {string} roomJid e.g. '[email protected]'
+ * @param {Array<object>} itemsAttrs attribute objects, one per <item>
+ */
+ sendMucAdminItems(roomJid, itemsAttrs) {
+ return sendIq(xmpp, pendingIqs,
+ xml('iq', { type: 'set',
+ to: roomJid,
+ id: `admin-${++_counter}` },
+ xml('query', { xmlns: 'http://jabber.org/protocol/muc#admin' },
+ ...itemsAttrs.map(attrs => xml('item', attrs))
+ )
+ )
+ );
+ },
+
/**
* Destroys a MUC room. The client must be the room owner.
* Resolves when the server acknowledges the destroy IQ.
diff --git a/tests/prosody/mod_muc_allowners_spec.js b/tests/prosody/mod_muc_allowners_spec.js
new file mode 100644
index 0000000000..0d05e97bef
--- /dev/null
+++ b/tests/prosody/mod_muc_allowners_spec.js
@@ -0,0 +1,238 @@
+import assert from 'assert';
+
+import { mintAsapToken } from './helpers/jwt.js';
+import { createXmppClient, joinWithFocus } from './helpers/xmpp_client.js';
+
+// Uses a dedicated MUC component that has muc_allowners loaded and neither
+// muc_meeting_id (no jicofo lock) nor token_verification, so anonymous clients
+// can join freely. Room names listed in allowners_moderated_rooms in
+// docker/prosody.cfg.lua ('moderated-room-1', 'moderated-room-2') are treated
+// as moderated by util.is_moderated().
+const CONFERENCE = 'conference-allowners.localhost';
+const MUC_USER_NS = 'http://jabber.org/protocol/muc#user';
+
+let _roomCounter = 0;
+const room = () => `allowners-${++_roomCounter}@${CONFERENCE}`;
+
+/**
+ * Returns the affiliation carried by a MUC presence stanza, or undefined.
+ * @param {object} presence Presence stanza.
+ * @returns {string|undefined}
+ */
+function affiliationOf(presence) {
+ return presence.getChild('x', MUC_USER_NS)?.getChild('item')?.attrs.affiliation;
+}
+
+/**
+ * Returns true when an IQ response is the auth/forbidden error reply sent by
+ * filter_admin_set_query in mod_muc_allowners.
+ * @param {object} iq IQ response stanza.
+ * @returns {boolean}
+ */
+function isForbidden(iq) {
+ return iq.attrs.type === 'error'
+ && Boolean(iq.getChild('error')?.getChild('forbidden'));
+}
+
+describe('mod_muc_allowners', () => {
+
+ let clients;
+
+ beforeEach(() => {
+ clients = [];
+ });
+
+ afterEach(async () => {
+ await Promise.all(clients.map(c => c.disconnect()));
+ });
+
+ /**
+ * Connects an anonymous client and registers it for cleanup.
+ * @param {object} [opts] Options forwarded to createXmppClient.
+ * @returns {Promise<XmppTestClient>}
+ */
+ async function connect(opts) {
+ const c = await createXmppClient(opts);
+
+ clients.push(c);
+
+ return c;
+ }
+
+ /**
+ * Joins as focus (jicofo admin) and registers the client for cleanup.
+ * Focus is a Prosody admin, so mod_muc_allowners skips it and it creates
+ * and unlocks the room as in production. Rooms must be created by focus:
+ * a regular creator's initial owner self-presence would be filtered by
+ * filter_stanza and the room would never be unlocked.
+ *
+ * @param {string} roomJid Full room JID.
+ * @returns {Promise<XmppTestClient>}
+ */
+ async function focusJoin(roomJid) {
+ const c = await joinWithFocus(roomJid);
+
+ clients.push(c);
+
+ return c;
+ }
+
+ /**
+ * Joins a room and resolves once the occupant holds the owner affiliation.
+ * mod_muc_allowners filters out the initial 'participant' self-presence of
+ * a joining occupant, so joinRoom usually resolves with the promotion
+ * presence directly; handle both event orders to be safe.
+ *
+ * @param {XmppTestClient} c Connected client.
+ * @param {string} roomJid Full room JID.
+ * @returns {Promise<object>} The self-presence carrying the owner affiliation.
+ */
+ async function joinAsOwner(c, roomJid) {
+ const presence = await c.joinRoom(roomJid);
+
+ if (affiliationOf(presence) === 'owner') {
+ return presence;
+ }
+
+ return c.waitForPresence(p =>
+ p.getChild('x', MUC_USER_NS)?.getChildren('status')
+ .some(s => s.attrs.code === '110')
+ && affiliationOf(p) === 'owner');
+ }
+
+ /**
+ * Returns the bare JID of a connected client.
+ * @param {XmppTestClient} c Connected client.
+ * @returns {string}
+ */
+ const bareJid = c => c.jid.split('/')[0];
+
+ // -------------------------------------------------------------------------
+ // Non-moderated rooms
+ // -------------------------------------------------------------------------
+ describe('non-moderated room', () => {
+
+ it('anonymous participants are promoted to owner on join', async () => {
+ const r = room();
+
+ await focusJoin(r);
+
+ const p1 = await connect();
+ const p2 = await connect();
+
+ const presence1 = await joinAsOwner(p1, r);
+ const presence2 = await joinAsOwner(p2, r);
+
+ assert.equal(affiliationOf(presence1), 'owner', 'first participant must be promoted');
+ assert.equal(affiliationOf(presence2), 'owner', 'second participant must be promoted');
+ });
+
+ it('revoking an affiliation is rejected with forbidden', async () => {
+ const r = room();
+
+ await focusJoin(r);
+
+ const p1 = await connect();
+ const p2 = await connect();
+
+ await joinAsOwner(p1, r);
+ await joinAsOwner(p2, r);
+
+ for (const affiliation of [ 'none', 'outcast', 'member' ]) {
+ const response = await p1.sendMucAdmin(r, { jid: bareJid(p2),
+ affiliation });
+
+ assert.ok(isForbidden(response),
+ `affiliation='${affiliation}' must be rejected with forbidden`);
+ }
+ });
+
+ it('a revoke item after a benign first item is also rejected', async () => {
+ const r = room();
+
+ await focusJoin(r);
+
+ const p1 = await connect();
+ const p2 = await connect();
+ const p3 = await connect();
+
+ await joinAsOwner(p1, r);
+ await joinAsOwner(p2, r);
+ await joinAsOwner(p3, r);
+
+ // The first item is an allowed grant; the second revokes p3. The
+ // filter must inspect every item, not just the first one.
+ const response = await p1.sendMucAdminItems(r, [
+ { jid: bareJid(p2),
+ affiliation: 'owner' },
+ { jid: bareJid(p3),
+ affiliation: 'none' }
+ ]);
+
+ assert.ok(isForbidden(response),
+ 'a batched revoke hidden behind a benign first item must be rejected');
+ });
+
+ it('granting owner is allowed', async () => {
+ const r = room();
+
+ await focusJoin(r);
+
+ const p1 = await connect();
+ const p2 = await connect();
+
+ await joinAsOwner(p1, r);
+ await joinAsOwner(p2, r);
+
+ const response = await p1.sendMucAdmin(r, { jid: bareJid(p2),
+ affiliation: 'owner' });
+
+ assert.equal(response.attrs.type, 'result', 'granting owner must not be filtered');
+ });
+ });
+
+ // -------------------------------------------------------------------------
+ // Moderated rooms (listed in allowners_moderated_rooms)
+ // -------------------------------------------------------------------------
+ describe('moderated room', () => {
+
+ it('anonymous participants are not promoted', async () => {
+ const r = `moderated-room-1@${CONFERENCE}`;
+
+ await focusJoin(r);
+
+ const guest = await connect();
+ const presence = await guest.joinRoom(r);
+
+ assert.equal(affiliationOf(presence), 'none',
+ 'anonymous participant must not be promoted in a moderated room');
+ });
+
+ it('JWT host is promoted and may revoke affiliations', async () => {
+ const roomName = 'moderated-room-2';
+ const r = `${roomName}@${CONFERENCE}`;
+
+ await focusJoin(r);
+
+ const token = mintAsapToken({ room: roomName });
+ const host = await connect({ params: { token } });
+
+ const presence = await joinAsOwner(host, r);
+
+ assert.equal(affiliationOf(presence), 'owner',
+ 'JWT host must be promoted in a moderated room');
+
+ const guest = await connect();
+
+ await guest.joinRoom(r);
+
+ // Revoking is filtered only in non-moderated rooms; in a moderated
+ // room the owner may ban an occupant.
+ const response = await host.sendMucAdmin(r, { jid: bareJid(guest),
+ affiliation: 'outcast' });
+
+ assert.equal(response.attrs.type, 'result',
+ 'revoking must be allowed in a moderated room');
+ });
+ });
+});