Skip to content

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

More prosody tests (#17436)

bgrozevcee87644efe9
diff --git a/resources/prosody-plugins/mod_filter_iq_jibri.lua b/resources/prosody-plugins/mod_filter_iq_jibri.lua
index 69a6fe0875..76e9cb79f0 100644
--- a/resources/prosody-plugins/mod_filter_iq_jibri.lua
+++ b/resources/prosody-plugins/mod_filter_iq_jibri.lua
@@ -40,13 +40,15 @@ module:hook("pre-iq/full", function(event)
local token = session.auth_token;
local room = get_room_from_jid(room_jid_match_rewrite(jid_bare(stanza.attr.to)));
local occupant = room:get_occupant_by_real_jid(stanza.attr.from);
- local feature = jibri.attr.recording_mode == 'file' and 'recording' or 'livestreaming';
+ local recording_mode_lower = jibri.attr.recording_mode and jibri.attr.recording_mode:lower();
+ local feature = recording_mode_lower == 'file' and 'recording' or 'livestreaming';
local is_allowed = is_feature_allowed(
feature,
session.jitsi_meet_context_features,
occupant.role == 'moderator');
- if jibri.attr.action == 'start' or jibri.attr.action == 'stop' then
+ local action_lower = jibri.attr.action and jibri.attr.action:lower();
+ if action_lower == 'start' or action_lower == 'stop' then
if not is_allowed then
module:log('info', 'Filtering jibri start recording, stanza:%s', tostring(stanza));
session.send(st.error_reply(stanza, 'auth', 'forbidden'));
diff --git a/resources/prosody-plugins/mod_filter_iq_rayo.lua b/resources/prosody-plugins/mod_filter_iq_rayo.lua
index 740535be22..b2d5afa1ea 100644
--- a/resources/prosody-plugins/mod_filter_iq_rayo.lua
+++ b/resources/prosody-plugins/mod_filter_iq_rayo.lua
@@ -101,7 +101,7 @@ module:hook("pre-iq/full", function(event)
local room_jid = jid.bare(stanza.attr.to);
local room_real_jid = room_jid_match_rewrite(room_jid);
local room = main_muc_service.get_room_from_jid(room_real_jid);
- local feature = dial.attr.to == 'jitsi_meet_transcribe' and 'transcription' or 'outbound-call';
+ local feature = (dial.attr.to and dial.attr.to:lower()) == 'jitsi_meet_transcribe' and 'transcription' or 'outbound-call';
local error_message = nil;
if not room or room:get_occupant_jid(stanza.attr.from) == nil then
diff --git a/resources/prosody-plugins/mod_filter_messages.lua b/resources/prosody-plugins/mod_filter_messages.lua
index 0b9b91dfa5..2c539cdaea 100644
--- a/resources/prosody-plugins/mod_filter_messages.lua
+++ b/resources/prosody-plugins/mod_filter_messages.lua
@@ -1,6 +1,25 @@
--- enable under the main muc module
--- a module that will filter group messages based on features (jitsi_meet_context_features)
--- when requested via metadata (permissions.groupChatRestricted)
+-- Filters MUC group-chat messages when the room operator has restricted chat.
+--
+-- When room.jitsiMetadata.permissions.groupChatRestricted is true, a sender
+-- must have the 'send-groupchat' feature set to true in their JWT context
+-- (session.jitsi_meet_context_features) to send a message. Any message that
+-- fails this check is rejected with a <not-allowed/> error stanza.
+--
+-- Feature evaluation via is_feature_allowed:
+-- send-groupchat = true in token features → allowed
+-- send-groupchat = false in token features → blocked
+-- feature key absent from token features → blocked
+-- no token features at all (anonymous) → blocked
+--
+-- Messages without a <body> (polls, lobby notifications, etc.) are always
+-- passed through regardless of the restriction flag.
+--
+-- Hooks:
+-- message/bare — ordinary MUC group-chat messages
+-- jitsi-visitor-groupchat-pre-route — visitor messages routed via the
+-- visitors component
+--
+-- Load on the MUC component.
local util = module:require 'util';
local get_room_from_jid = util.get_room_from_jid;
local st = require 'util.stanza';
diff --git a/resources/prosody-plugins/mod_jibri_session.lua b/resources/prosody-plugins/mod_jibri_session.lua
index 566bac96ac..741a25be64 100644
--- a/resources/prosody-plugins/mod_jibri_session.lua
+++ b/resources/prosody-plugins/mod_jibri_session.lua
@@ -27,7 +27,7 @@ local stanza = event.stanza;
if stanza.name == "iq" then
local jibri = stanza:get_child('jibri', 'http://jitsi.org/protocol/jibri');
if jibri then
- if jibri.attr.action == 'start' then
+ if jibri.attr.action and jibri.attr.action:lower() == 'start' then
local update_app_data = false;
local app_data = jibri.attr.app_data;
diff --git a/resources/prosody-plugins/mod_muc_displayname.lua b/resources/prosody-plugins/mod_muc_displayname.lua
index cf4b7f9562..d5160b5235 100644
--- a/resources/prosody-plugins/mod_muc_displayname.lua
+++ b/resources/prosody-plugins/mod_muc_displayname.lua
@@ -1,8 +1,32 @@
---- This module removes identity information from presence stanzas when the
---- hideDisplayNameForGuests options are enabled
---- for a room.
-
---- To be enabled under the main muc component
+-- Manages display names and identity visibility in MUC rooms.
+--
+-- Three behaviours:
+--
+-- 1. hideDisplayNameForGuests (outbound filter on stanzas/out, priority -100):
+-- When room._data.hideDisplayNameForGuests is true, strips identity elements
+-- (<nick>, <email>, <stats-id>, and name/email inside <identity>) from
+-- presence stanzas before they are delivered to non-moderator occupants.
+-- Moderator recipients and self-presence are always passed through unchanged.
+-- Uses session.jitsi_web_query_room / jitsi_web_query_prefix to locate the room.
+--
+-- 2. name-readonly (inbound filter on stanzas/in, priority -100):
+-- When session.jitsi_meet_context_features['name-readonly'] is true, enforces
+-- the display name from the JWT token on every outgoing presence from that session:
+-- * Token has context.user.name → replaces the <nick> element with the token name
+-- * Token has no name → removes the <nick> element entirely
+-- This prevents clients from changing their display name when the token marks
+-- it as read-only.
+--
+-- 3. Message display-name handling (MUC hooks):
+-- muc-broadcast-message (priority -1): strips <nick> and <display-name> from
+-- every message before it is broadcast to occupants, so message payloads
+-- never carry identity information to live receivers.
+-- muc-add-history: injects <display-name source="token|guest"> into the
+-- history copy of each message (cloned from the broadcast stanza), sourced
+-- from session.jitsi_meet_context_user.name (token users) or the <nick>
+-- element (guests). Late-joining clients receive this annotated history.
+--
+-- Load on the MUC component.
local filters = require 'util.filters';
local st = require 'util.stanza';
@@ -60,7 +84,7 @@ function filter_stanza_in(stanza, session)
end
if stanza.name ~= 'presence' or stanza.attr.type == 'error'
- or stanza.attr.type == 'unavailable' or is_focus(stanza.attr.from) then
+ or stanza.attr.type == 'unavailable' or is_focus(stanza.attr.from or '') then
return stanza;
end
diff --git a/resources/prosody-plugins/mod_muc_limit_messages.lua b/resources/prosody-plugins/mod_muc_limit_messages.lua
index 89ac6145e3..bd398a9166 100644
--- a/resources/prosody-plugins/mod_muc_limit_messages.lua
+++ b/resources/prosody-plugins/mod_muc_limit_messages.lua
@@ -1,4 +1,10 @@
--- A module to limit the number of messages in a meeting
+-- Enforces a per-room message count cap (muc_limit_messages_count). Once the cap
+-- is reached the triggering message is rejected with <not-allowed/>, a broadcast
+-- is sent to the room, and all further messages are rejected. Messages from
+-- sessions without room context (no jitsi_web_query_room) are passed through.
+-- Body-less non-groupchat messages and answer-poll json-messages are exempt from
+-- counting. With muc_limit_messages_check_token = true an authenticated sender
+-- permanently lifts the cap for that room.
-- Needs to be activated under the muc component where the limit needs to be applied
-- Copyright (C) 2023-present 8x8, Inc.
@@ -44,12 +50,9 @@ function on_message(event)
local session = event.origin;
if not session or not session.jitsi_web_query_room then
- -- if this is a message from visitor, pass it through. Limits are applied in the visitor node.
- if event.origin.type == 's2sin' then
- return;
- end
-
- return false;
+ -- No room context: cannot apply limits, pass through.
+ -- (Visitor messages from s2sin are also passed through — limits enforced at visitor node.)
+ return;
end
-- get room name with tenant and find room
@@ -57,7 +60,7 @@ function on_message(event)
if not room then
module:log('warn', 'No room found for %s/%s',
session.jitsi_web_query_prefix, session.jitsi_web_query_room);
- return false;
+ return;
end
if check_token and session.auth_token then
@@ -97,7 +100,10 @@ end
-- handle messages sent in the component
-- 'message/host' is used for breakout rooms
-module:hook('message/full', on_message); -- private messages
-module:hook('message/bare', on_message); -- room messages
+-- Priority -1 ensures modules at the default priority (0) — notably
+-- filter_messages — run first. Messages they block (return true) never reach
+-- this handler and do not consume cap slots.
+module:hook('message/full', on_message, -1); -- private messages
+module:hook('message/bare', on_message, -1); -- room messages
module:hook_global('config-reloaded', load_config);
diff --git a/resources/prosody-plugins/mod_muc_lobby_rooms.lua b/resources/prosody-plugins/mod_muc_lobby_rooms.lua
index 01f410373c..f25ed786b4 100644
--- a/resources/prosody-plugins/mod_muc_lobby_rooms.lua
+++ b/resources/prosody-plugins/mod_muc_lobby_rooms.lua
@@ -617,7 +617,7 @@ process_host_module(main_muc_component_config, function(host_module, host)
elseif room:get_password() then
local affiliation = room:get_affiliation(invitee);
-- if pre-approved and password is set for the room, add the password to allow joining
- if affiliation == 'member' and not password then
+ if valid_affiliations[affiliation or 'none'] >= valid_affiliations.member and not password then
join:tag('password', { xmlns = MUC_NS }):text(room:get_password());
end
end
diff --git a/resources/prosody-plugins/mod_muc_password_check.lua b/resources/prosody-plugins/mod_muc_password_check.lua
index 7a3c5409e8..70db88a84d 100644
--- a/resources/prosody-plugins/mod_muc_password_check.lua
+++ b/resources/prosody-plugins/mod_muc_password_check.lua
@@ -1,3 +1,36 @@
+-- HTTP module that exposes GET and PUT endpoints at /room-info for querying
+-- and validating MUC room password information.
+--
+-- Endpoints:
+-- GET /room-info?room=<name>[&prefix=<subdomain>]
+-- Returns a JSON object: { conference, passcodeProtected, lobbyEnabled }
+-- where conference is the full room JID, passcodeProtected is true when the
+-- room has a password set, and lobbyEnabled is true when a lobby room is
+-- attached.
+--
+-- PUT /room-info?room=<name>[&prefix=<subdomain>]
+-- Body: application/json { passcode: "<value>" }
+-- Returns: { valid: true|false } indicating whether the submitted passcode
+-- matches the room password.
+--
+-- Authentication:
+-- Both endpoints require a valid ASAP Bearer token (RS256) in the
+-- Authorization header. Token verification is controlled by the
+-- enable_password_token_verification option (default: true).
+--
+-- Error responses:
+-- 400 Missing or invalid parameters (no room param, wrong Content-Type,
+-- empty body, missing passcode key).
+-- 403 Missing or invalid Bearer token.
+-- 404 Room not found.
+--
+-- The HTTP routes are registered on the MUC base domain (muc_mapper_domain_base,
+-- default "localhost") because the HTTP server runs on port 5280 on that host.
+-- The room query parameter is decoded using the muc_mapper_domain_prefix option
+-- (default "conference") to build the full internal MUC JID.
+--
+-- Copyright (C) 2023-present 8x8, Inc.
+
local inspect = require "inspect";
local formdecode = require "util.http".formdecode;
local urlencode = require "util.http".urlencode;
diff --git a/resources/prosody-plugins/mod_polls_component.lua b/resources/prosody-plugins/mod_polls_component.lua
index 6143f701c0..8f757149a4 100644
--- a/resources/prosody-plugins/mod_polls_component.lua
+++ b/resources/prosody-plugins/mod_polls_component.lua
@@ -8,7 +8,6 @@ local array = require 'util.array';
local st = require("util.stanza");
local jid = require "util.jid";
local util = module:require("util");
-local muc = module:depends("muc");
local NS_NICK = 'http://jabber.org/protocol/nick';
local get_room_by_name_and_subdomain = util.get_room_by_name_and_subdomain;
diff --git a/resources/prosody-plugins/mod_test_observer_http.lua b/resources/prosody-plugins/mod_test_observer_http.lua
index 0591996398..fb99eeeee5 100644
--- a/resources/prosody-plugins/mod_test_observer_http.lua
+++ b/resources/prosody-plugins/mod_test_observer_http.lua
@@ -311,6 +311,28 @@ module:provides("http", {
};
end;
+ -- POST /test-observer/rooms/hide-display-name
+ -- Body: { "jid": "[email protected]", "hidden": true|false }
+ -- Sets room._data.hideDisplayNameForGuests for mod_muc_displayname tests.
+ ["POST /rooms/hide-display-name"] = function(event)
+ local data = json.decode(event.request.body or "{}") or {};
+ local room_jid = data.jid;
+ local hidden = data.hidden;
+ if room_jid == nil or hidden == nil then
+ return { status_code = 400; body = '{"error":"missing jid or hidden"}' };
+ end
+ local room = (shared.rooms or {})[room_jid];
+ if not room then
+ return { status_code = 404; body = '{"error":"room not found"}' };
+ end
+ room._data.hideDisplayNameForGuests = hidden;
+ return {
+ status_code = 200;
+ headers = { ["Content-Type"] = "application/json" };
+ body = '{"ok":true}';
+ };
+ end;
+
-- POST /test-observer/rooms/max-occupants
-- Body: { "jid": "[email protected]", "max_occupants": 4 }
-- Sets room._data.max_occupants so per-room limit tests can override the
diff --git a/resources/prosody-plugins/mod_token_affiliation.lua b/resources/prosody-plugins/mod_token_affiliation.lua
index 5c37be2458..df312c879d 100644
--- a/resources/prosody-plugins/mod_token_affiliation.lua
+++ b/resources/prosody-plugins/mod_token_affiliation.lua
@@ -52,6 +52,26 @@ module:hook("muc-occupant-pre-join", function(event)
return
end
+ -- When lobby is active (members-only) and the user has no pre-existing
+ -- affiliation, let the lobby gate handle this join attempt. Once a
+ -- moderator approves them (their affiliation is set to ≥member by the
+ -- lobby module), the next join attempt will have an existing affiliation
+ -- and this hook will upgrade it normally.
+ -- Exception: if the user is bypassing the lobby with the room password,
+ -- apply affiliation immediately so they keep their moderator role.
+ if room:get_members_only() then
+ local existing = room:get_affiliation(occupant.bare_jid)
+ if not existing or existing == 'none' then
+ local join_el = event.stanza:get_child('x', 'http://jabber.org/protocol/muc')
+ local join_pwd = join_el and join_el:get_child_text('password', 'http://jabber.org/protocol/muc')
+ local bypassing_via_password = join_pwd and room:get_password() and join_pwd == room:get_password()
+ if not bypassing_via_password then
+ module:log(LOGLEVEL, "skip, lobby active for %s", occupant.bare_jid)
+ return
+ end
+ end
+ end
+
local affiliation = affiliation_from_token(session)
if not affiliation then
return
diff --git a/tests/prosody/docker/prosody.cfg.lua b/tests/prosody/docker/prosody.cfg.lua
index becc21be4e..8a953ef812 100644
--- a/tests/prosody/docker/prosody.cfg.lua
+++ b/tests/prosody/docker/prosody.cfg.lua
@@ -61,8 +61,6 @@ VirtualHost "localhost"
asap_key_server = "http://localhost:5280/test-observer/asap-keys"
signature_algorithm = "RS256"
allow_empty_token = true
- -- Match production: room claim not required.
- asap_require_room_claim = false
-- Serve test_observer HTTP endpoints here so plain HTTP on port 5280 is
-- reachable. Component HTTP routes end up on HTTPS 5281 due to Prosody's
@@ -89,8 +87,12 @@ VirtualHost "localhost"
-- ([sub][email protected]) for all sessions on all hosts.
"muc_domain_mapper";
"muc_lobby_rooms";
+ "muc_password_check";
}
+ -- mod_muc_password_check: verify Bearer tokens with the login ASAP key server.
+ enable_password_token_verification = true
+
shard_name = "test-shard"
region_name = "test-region"
release_number = "test-release"
@@ -136,7 +138,6 @@ VirtualHost "hs256.localhost"
app_id = "jitsi"
app_secret = "testsecret"
signature_algorithm = "HS256"
- asap_require_room_claim = false
allow_empty_token = false
modules_enabled = { "presence_identity" }
@@ -188,7 +189,13 @@ Component "conference.localhost" "muc"
"token_verification";
"token_affiliation";
"muc_flip";
+ "muc_displayname";
"test_observer";
+ "filter_messages";
+ -- Listed after filter_messages so that messages already blocked by
+ -- filter_messages (return true) never reach this hook; they do not
+ -- count toward the per-room cap.
+ "muc_limit_messages";
}
anonymous_strict = true
@@ -213,6 +220,10 @@ Component "conference.localhost" "muc"
-- token_verification on both muc-room-pre-create and muc-occupant-pre-join,
-- mirroring production where jicofo is a Prosody admin.
+ -- mod_muc_limit_messages: cap per room and honour auth tokens.
+ muc_limit_messages_count = 3
+ muc_limit_messages_check_token = true
+
-- Blocks unauthenticated users from sending room-owner config IQs
-- (muc#owner queries), which is how moderator status is granted to other
-- participants and how room configuration is changed.
diff --git a/tests/prosody/helpers/jwt.js b/tests/prosody/helpers/jwt.js
index 465db7fcec..196bcd15d6 100644
--- a/tests/prosody/helpers/jwt.js
+++ b/tests/prosody/helpers/jwt.js
@@ -61,7 +61,7 @@ function buildPayload(overrides = {}, { expired = false, notYetValid = false } =
* - exp, iss, aud claims
*
* util.lib.lua additionally checks:
- * - requireRoomClaim (false in test config)
+ * - requireRoomClaim (true; callers must include room claim)
* - sets session.jitsi_meet_context_features from claims.context.features
*
* @param {object} [overrides] Fields to merge / override in the payload.
@@ -135,6 +135,7 @@ export function mintSystemToken(overrides = {}, {
} = {}) {
return jwt.sign(
buildPayload({ sub: 'system.localhost',
+ room: '*',
...overrides }, { expired,
notYetValid }),
privateKey,
diff --git a/tests/prosody/helpers/test_observer.js b/tests/prosody/helpers/test_observer.js
index 2f1e185f0d..7ab3229466 100644
--- a/tests/prosody/helpers/test_observer.js
+++ b/tests/prosody/helpers/test_observer.js
@@ -57,6 +57,26 @@ export async function clearEvents() {
}
}
+/**
+ * Sets room._data.hideDisplayNameForGuests for mod_muc_displayname tests.
+ * The room must already exist (at least one occupant).
+ *
+ * @param {string} roomJid e.g. '[email protected]'
+ * @param {boolean} hidden true to enable filtering; false to disable
+ */
+export async function setHideDisplayNameForGuests(roomJid, hidden) {
+ const res = await fetch(`${BASE}/rooms/hide-display-name`, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ jid: roomJid,
+ hidden })
+ });
+
+ if (!res.ok) {
+ throw new Error(`setHideDisplayNameForGuests failed: ${res.status} ${await res.text()}`);
+ }
+}
+
/**
* Sets the per-room max_occupants limit for an existing room.
* The room must already exist (at least one occupant).
diff --git a/tests/prosody/helpers/xmpp_client.js b/tests/prosody/helpers/xmpp_client.js
index ba2efcdea0..84ccfd3f90 100644
--- a/tests/prosody/helpers/xmpp_client.js
+++ b/tests/prosody/helpers/xmpp_client.js
@@ -402,6 +402,29 @@ export async function createXmppClient({ host = 'localhost', domain, params, use
);
},
+ /**
+ * Sends a MUC groupchat message to the room. Resolves with the first
+ * <message> stanza received bearing the same id — either the MUC
+ * reflection (type=groupchat) or an error reply (type=error).
+ *
+ * @param {string} roomJid e.g. '[email protected]'
+ * @param {string} [body] message body text; omit to send body-less
+ * @param {Array} [extensions] extra XML children appended to the stanza
+ */
+ async sendGroupchat(roomJid, body, extensions = []) {
+ const id = `gc-${++_counter}`;
+ const children = body === undefined ? [] : [ xml('body', {}, body) ];
+
+ await xmpp.send(
+ xml('message', { to: roomJid,
+ type: 'groupchat',
+ id },
+ ...children, ...extensions)
+ );
+
+ return this.waitForMessage(s => s.attrs.id === id);
+ },
+
/**
* Grants moderator role to the occupant identified by nick.
* The caller must be the room owner (e.g. the focus client).
diff --git a/tests/prosody/lua/mod_token_affiliation_spec.lua b/tests/prosody/lua/mod_token_affiliation_spec.lua
index 41e5094be7..0dadcd8773 100644
--- a/tests/prosody/lua/mod_token_affiliation_spec.lua
+++ b/tests/prosody/lua/mod_token_affiliation_spec.lua
@@ -66,14 +66,23 @@ local function fresh_jid()
return string.format("user%[email protected]", jid_counter)
end
-local function make_room()
+local function make_room(opts)
+ opts = opts or {}
local room = {
affiliation_log = {},
+ _members_only = opts.members_only or false,
+ _affiliations = opts.affiliations or {},
}
function room:set_affiliation(actor, bare_jid, affiliation)
table.insert(self.affiliation_log, { actor = actor, jid = bare_jid, affiliation = affiliation })
end
+ function room:get_members_only()
+ return self._members_only
+ end
+ function room:get_affiliation(bare_jid)
+ return self._affiliations[bare_jid]
+ end
return room
end
diff --git a/tests/prosody/mod_auth_token_asap_spec.js b/tests/prosody/mod_auth_token_asap_spec.js
index 23683a3bed..bac734a82e 100644
--- a/tests/prosody/mod_auth_token_asap_spec.js
+++ b/tests/prosody/mod_auth_token_asap_spec.js
@@ -55,7 +55,7 @@ describe('mod_auth_token (ASAP / RS256)', () => {
});
it('connects successfully with a valid RS256 token', async () => {
- const token = mintAsapToken();
+ const token = mintAsapToken({ room: '*' });
const c = await asapClient({ token });
clients.push(c);
@@ -105,6 +105,7 @@ describe('mod_auth_token (ASAP / RS256)', () => {
it('sets session.jitsi_meet_context_features from token context', async () => {
const token = mintAsapToken({
+ room: '*',
context: {
features: {
'screen-sharing': true,
@@ -133,6 +134,7 @@ describe('mod_auth_token (ASAP / RS256)', () => {
it('sets session.jitsi_meet_context_user from token context', async () => {
const token = mintAsapToken({
+ room: '*',
context: {
user: { id: 'user-123',
name: 'Alice',
@@ -151,6 +153,7 @@ describe('mod_auth_token (ASAP / RS256)', () => {
it('sets session.jitsi_meet_context_group from token context', async () => {
const token = mintAsapToken({
+ room: '*',
context: { group: 'test-group' }
});
const c = await asapClient({ token });
@@ -162,8 +165,9 @@ describe('mod_auth_token (ASAP / RS256)', () => {
});
it('sets session.jitsi_meet_context_user.id from top-level user_id when context is absent', async () => {
- // eslint-disable-next-line camelcase
- const token = mintAsapToken({ user_id: 'legacy-user-456' });
+ const token = mintAsapToken({ room: '*',
+ // eslint-disable-next-line camelcase
+ user_id: 'legacy-user-456' });
const c = await asapClient({ token });
clients.push(c);
diff --git a/tests/prosody/mod_auth_token_spec.js b/tests/prosody/mod_auth_token_spec.js
index 688b16658b..f1b88d78f8 100644
--- a/tests/prosody/mod_auth_token_spec.js
+++ b/tests/prosody/mod_auth_token_spec.js
@@ -52,7 +52,7 @@ describe('mod_auth_token (HS256 shared secret)', () => {
});
it('connects successfully with a valid token', async () => {
- const token = mintToken();
+ const token = mintToken({ room: '*' });
const c = await hs256Client({ token });
clients.push(c);
@@ -97,6 +97,7 @@ describe('mod_auth_token (HS256 shared secret)', () => {
it('sets session.jitsi_meet_context_features from token context', async () => {
const token = mintToken({
+ room: '*',
context: {
features: {
'screen-sharing': true,
diff --git a/tests/prosody/mod_end_conference_spec.js b/tests/prosody/mod_end_conference_spec.js
index 90de1db709..af0d627f29 100644
--- a/tests/prosody/mod_end_conference_spec.js
+++ b/tests/prosody/mod_end_conference_spec.js
@@ -28,7 +28,8 @@ async function createRoom() {
const focus = await joinWithFocus(roomJid);
- const token = mintAsapToken({ context: { user: { moderator: true } } });
+ const token = mintAsapToken({ room: roomName,
+ context: { user: { moderator: true } } });
const moderator = await createXmppClient({ params: { room: roomName,
token } });
diff --git a/tests/prosody/mod_filter_iq_jibri_spec.js b/tests/prosody/mod_filter_iq_jibri_spec.js
index 78dcea45a9..c57f20f1c0 100644
--- a/tests/prosody/mod_filter_iq_jibri_spec.js
+++ b/tests/prosody/mod_filter_iq_jibri_spec.js
@@ -71,12 +71,17 @@ describe('mod_filter_iq_jibri (feature-based authorization)', () => {
});
/**
- * Creates a test client connected to localhost with the given token,
- * joins a fresh room (focus joins first to unlock the jicofo lock), and
- * returns { client, room }. The client is a non-moderator participant.
+ * Creates a test client with a token scoped to a fresh room, joins that room
+ * (focus joins first to unlock the jicofo lock), and returns { client, room }.
+ *
+ * @param {object} [overrides] JWT payload overrides merged into the token.
+ * @returns {Promise<{client: object, room: string}>}
*/
- async function setup(token) {
+ async function setup(overrides = {}) {
const room = nextRoom();
+ const roomName = room.split('@')[0];
+ const token = mintAsapToken({ room: roomName,
+ ...overrides });
const focus = await joinWithFocus(room);
clients.push(focus);
@@ -97,8 +102,7 @@ describe('mod_filter_iq_jibri (feature-based authorization)', () => {
for (const action of [ 'start', 'stop' ]) {
it(`passes ${action} IQ when features.recording = true`, async () => {
- const token = mintAsapToken({ context: { features: { recording: true } } });
- const { client: c, room } = await setup(token);
+ const { client: c, room } = await setup({ context: { features: { recording: true } } });
const iqs = await sendAndCollect(c, room, action, 'file');
assert.strictEqual(iqs.length, 1, 'IQ should reach the MUC');
@@ -107,8 +111,7 @@ describe('mod_filter_iq_jibri (feature-based authorization)', () => {
});
it(`blocks ${action} IQ when features.recording = false`, async () => {
- const token = mintAsapToken({ context: { features: { recording: false } } });
- const { client: c, room } = await setup(token);
+ const { client: c, room } = await setup({ context: { features: { recording: false } } });
const iqs = await sendAndCollect(c, room, action, 'file');
assert.strictEqual(iqs.length, 0);
@@ -116,8 +119,7 @@ describe('mod_filter_iq_jibri (feature-based authorization)', () => {
it(`blocks ${action} IQ when context.features present but recording key absent`, async () => {
// features object present but no 'recording' key → treated as false
- const token = mintAsapToken({ context: { features: { livestreaming: true } } });
- const { client: c, room } = await setup(token);
+ const { client: c, room } = await setup({ context: { features: { livestreaming: true } } });
const iqs = await sendAndCollect(c, room, action, 'file');
assert.strictEqual(iqs.length, 0);
@@ -126,8 +128,7 @@ describe('mod_filter_iq_jibri (feature-based authorization)', () => {
it(`blocks ${action} IQ when token has no context.features (non-moderator fallback)`, async () => {
// No features in token → is_feature_allowed falls back to is_moderator.
// Client joined after focus so it is a non-moderator participant → blocked.
- const token = mintAsapToken();
- const { client: c, room } = await setup(token);
+ const { client: c, room } = await setup();
const iqs = await sendAndCollect(c, room, action, 'file');
assert.strictEqual(iqs.length, 0);
@@ -135,8 +136,7 @@ describe('mod_filter_iq_jibri (feature-based authorization)', () => {
}
it('passes status IQ regardless of features (only start/stop are gated)', async () => {
- const token = mintAsapToken({ context: { features: { recording: false } } });
- const { client: c, room } = await setup(token);
+ const { client: c, room } = await setup({ context: { features: { recording: false } } });
const iqs = await sendAndCollect(c, room, 'status', 'file');
assert.strictEqual(iqs.length, 1);
@@ -150,8 +150,7 @@ describe('mod_filter_iq_jibri (feature-based authorization)', () => {
for (const action of [ 'start', 'stop' ]) {
it(`passes ${action} IQ when features.livestreaming = true`, async () => {
- const token = mintAsapToken({ context: { features: { livestreaming: true } } });
- const { client: c, room } = await setup(token);
+ const { client: c, room } = await setup({ context: { features: { livestreaming: true } } });
const iqs = await sendAndCollect(c, room, action, 'stream');
assert.strictEqual(iqs.length, 1);
@@ -160,24 +159,21 @@ describe('mod_filter_iq_jibri (feature-based authorization)', () => {
});
it(`blocks ${action} IQ when features.livestreaming = false`, async () => {
- const token = mintAsapToken({ context: { features: { livestreaming: false } } });
- const { client: c, room } = await setup(token);
+ const { client: c, room } = await setup({ context: { features: { livestreaming: false } } });
const iqs = await sendAndCollect(c, room, action, 'stream');
assert.strictEqual(iqs.length, 0);
});
it(`blocks ${action} IQ when context.features present but livestreaming key absent`, async () => {
- const token = mintAsapToken({ context: { features: { recording: true } } });
- const { client: c, room } = await setup(token);
+ const { client: c, room } = await setup({ context: { features: { recording: true } } });
const iqs = await sendAndCollect(c, room, action, 'stream');
assert.strictEqual(iqs.length, 0);
});
it(`blocks ${action} IQ when token has no context.features (non-moderator fallback)`, async () => {
- const token = mintAsapToken();
- const { client: c, room } = await setup(token);
+ const { client: c, room } = await setup();
const iqs = await sendAndCollect(c, room, action, 'stream');
assert.strictEqual(iqs.length, 0);
@@ -185,11 +181,48 @@ describe('mod_filter_iq_jibri (feature-based authorization)', () => {
}
it('passes status IQ regardless of features (only start/stop are gated)', async () => {
- const token = mintAsapToken({ context: { features: { livestreaming: false } } });
- const { client: c, room } = await setup(token);
+ const { client: c, room } = await setup({ context: { features: { livestreaming: false } } });
const iqs = await sendAndCollect(c, room, 'status', 'stream');
assert.strictEqual(iqs.length, 1);
});
});
+
+ // ─── attribute case normalisation ────────────────────────────────────────
+
+ describe('attribute case normalisation', () => {
+
+ for (const action of [ 'START', 'STOP', 'Start', 'Stop' ]) {
+
+ it(`blocks ${action} (recording_mode=file) when features.recording = false`, async () => {
+ const { client: c, room } = await setup({ context: { features: { recording: false } } });
+ const iqs = await sendAndCollect(c, room, action, 'file');
+
+ assert.strictEqual(iqs.length, 0);
+ });
+ }
+
+ it('passes START (recording_mode=file) when features.recording = true', async () => {
+ const { client: c, room } = await setup({ context: { features: { recording: true } } });
+ const iqs = await sendAndCollect(c, room, 'START', 'file');
+
+ assert.strictEqual(iqs.length, 1);
+ });
+
+ it('blocks START (recording_mode=FILE) when features.recording = false', async () => {
+ const { client: c, room } = await setup({ context: { features: { recording: false } } });
+ const iqs = await sendAndCollect(c, room, 'START', 'FILE');
+
+ assert.strictEqual(iqs.length, 0);
+ });
+
+ it('blocks START (recording_mode=FILE) when only features.livestreaming = true (cross-feature)', async () => {
+ // recording_mode='FILE' must still route to the recording gate, not livestreaming
+ const { client: c, room } = await setup({ context: { features: { livestreaming: true,
+ recording: false } } });
+ const iqs = await sendAndCollect(c, room, 'START', 'FILE');
+
+ assert.strictEqual(iqs.length, 0);
+ });
+ });
});
diff --git a/tests/prosody/mod_filter_iq_rayo_spec.js b/tests/prosody/mod_filter_iq_rayo_spec.js
index 4d88a244d1..fdbc051f95 100644
--- a/tests/prosody/mod_filter_iq_rayo_spec.js
+++ b/tests/prosody/mod_filter_iq_rayo_spec.js
@@ -76,12 +76,17 @@ describe('mod_filter_iq_rayo (feature-based authorization)', () => {
});
/**
- * Creates a test client with the given token, joins a fresh room (focus
- * joins first so the jicofo lock is lifted and focus gets owner affiliation),
- * and returns { client, room }.
+ * Creates a test client with a token scoped to a fresh room, joins that room
+ * (focus joins first so the jicofo lock is lifted), and returns { client, room }.
+ *
+ * @param {object} [overrides] JWT payload overrides merged into the token.
+ * @returns {Promise<{client: object, room: string}>}
*/
- async function setup(token) {
+ async function setup(overrides = {}) {
const room = nextRoom();
+ const roomName = room.split('@')[0];
+ const token = mintAsapToken({ room: roomName,
+ ...overrides });
const focus = await joinWithFocus(room);
clients.push(focus);
@@ -100,8 +105,7 @@ describe('mod_filter_iq_rayo (feature-based authorization)', () => {
describe('outbound-call (dial to non-transcribe address)', () => {
it('passes IQ when features.outbound-call = true', async () => {
- const token = mintAsapToken({ context: { features: { 'outbound-call': true } } });
- const { client: c, room } = await setup(token);
+ const { client: c, room } = await setup({ context: { features: { 'outbound-call': true } } });
const iqs = await sendAndCollect(c, room);
assert.strictEqual(iqs.length, 1, 'IQ should reach the MUC');
@@ -109,16 +113,14 @@ describe('mod_filter_iq_rayo (feature-based authorization)', () => {
});
it('blocks IQ when features.outbound-call = false', async () => {
- const token = mintAsapToken({ context: { features: { 'outbound-call': false } } });
- const { client: c, room } = await setup(token);
+ const { client: c, room } = await setup({ context: { features: { 'outbound-call': false } } });
const iqs = await sendAndCollect(c, room);
assert.strictEqual(iqs.length, 0);
});
it('blocks IQ when context.features present but outbound-call key absent', async () => {
- const token = mintAsapToken({ context: { features: { recording: true } } });
- const { client: c, room } = await setup(token);
+ const { client: c, room } = await setup({ context: { features: { recording: true } } });
const iqs = await sendAndCollect(c, room);
assert.strictEqual(iqs.length, 0);
@@ -127,8 +129,7 @@ describe('mod_filter_iq_rayo (feature-based authorization)', () => {
it('blocks IQ when token has no context.features (non-owner fallback)', async () => {
// No features → fallback to is_moderator = affiliation == 'owner'.
// Regular client joined after focus so has 'member' affiliation → blocked.
- const token = mintAsapToken();
- const { client: c, room } = await setup(token);
+ const { client: c, room } = await setup();
const iqs = await sendAndCollect(c, room);
assert.strictEqual(iqs.length, 0);
@@ -140,8 +141,7 @@ describe('mod_filter_iq_rayo (feature-based authorization)', () => {
describe('transcription (dial to jitsi_meet_transcribe)', () => {
it('passes IQ when features.transcription = true', async () => {
- const token = mintAsapToken({ context: { features: { transcription: true } } });
- const { client: c, room } = await setup(token);
+ const { client: c, room } = await setup({ context: { features: { transcription: true } } });
const iqs = await sendAndCollect(c, room, 'jitsi_meet_transcribe');
assert.strictEqual(iqs.length, 1, 'IQ should reach the MUC');
@@ -149,24 +149,21 @@ describe('mod_filter_iq_rayo (feature-based authorization)', () => {
});
it('blocks IQ when features.transcription = false', async () => {
- const token = mintAsapToken({ context: { features: { transcription: false } } });
- const { client: c, room } = await setup(token);
+ const { client: c, room } = await setup({ context: { features: { transcription: false } } });
const iqs = await sendAndCollect(c, room, 'jitsi_meet_transcribe');
assert.strictEqual(iqs.length, 0);
});
it('blocks IQ when context.features present but transcription key absent', async () => {
- const token = mintAsapToken({ context: { features: { 'outbound-call': true } } });
- const { client: c, room } = await setup(token);
+ const { client: c, room } = await setup({ context: { features: { 'outbound-call': true } } });
const iqs = await sendAndCollect(c, room, 'jitsi_meet_transcribe');
assert.strictEqual(iqs.length, 0);
});
it('blocks IQ when token has no context.features (non-owner fallback)', async () => {
- const token = mintAsapToken();
- const { client: c, room } = await setup(token);
+ const { client: c, room } = await setup();
const iqs = await sendAndCollect(c, room, 'jitsi_meet_transcribe');
assert.strictEqual(iqs.length, 0);
@@ -178,8 +175,7 @@ describe('mod_filter_iq_rayo (feature-based authorization)', () => {
describe('JvbRoomName header validation', () => {
it('blocks IQ when JvbRoomName header is missing', async () => {
- const token = mintAsapToken({ context: { features: { 'outbound-call': true } } });
- const { client: c, room } = await setup(token);
+ 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);
@@ -188,8 +184,7 @@ describe('mod_filter_iq_rayo (feature-based authorization)', () => {
});
it('blocks IQ when JvbRoomName header does not match room JID', async () => {
- const token = mintAsapToken({ context: { features: { 'outbound-call': true } } });
- const { client: c, room } = await setup(token);
+ const { client: c, room } = await setup({ context: { features: { 'outbound-call': true } } });
const iqs = await sendAndCollect(c, room, 'sip:[email protected]', '[email protected]');
assert.strictEqual(iqs.length, 0);
diff --git a/tests/prosody/mod_filter_messages_spec.js b/tests/prosody/mod_filter_messages_spec.js
new file mode 100644
index 0000000000..2b866d1318
--- /dev/null
+++ b/tests/prosody/mod_filter_messages_spec.js
@@ -0,0 +1,283 @@
+import assert from 'assert';
+
+import { mintAsapToken } from './helpers/jwt.js';
+import { createXmppClient, joinWithFocus } from './helpers/xmpp_client.js';
+
+const CONFERENCE = 'conference.localhost';
+const METADATA_COMPONENT = 'metadata.localhost';
+const JITMEET_NS = 'http://jitsi.org/jitmeet';
+
+let _counter = 0;
+const nextRoom = () => `filter-msg-${++_counter}@${CONFERENCE}`;
+
+// ─── Helpers ──────────────────────────────────────────────────────────────────
+
+/**
+ * Connects an authenticated client to the main VirtualHost.
+ *
+ * @param {string} roomJid Full room JID — used as the room claim in the token
+ * and as the ?room= WebSocket param.
+ * @param {object} [contextUser] JWT context.user claims; moderator: true → owner.
+ * @param {object} [features] JWT context.features claims.
+ */
+function connect(roomJid, { contextUser, features } = {}) {
+ const roomName = roomJid.split('@')[0];
+ const context = {};
+
+ if (contextUser !== undefined) {
+ context.user = contextUser;
+ }
+ if (features !== undefined) {
+ context.features = features;
+ }
+ const token = mintAsapToken({ room: roomName,
+ context });
+ const params = { room: roomName,
+ token };
+
+ return createXmppClient({ params });
+}
+
+const connectModerator = roomJid => connect(roomJid, { contextUser: { moderator: true } });
+
+/**
+ * Sets groupChatRestricted on the room and waits for the metadata broadcast
+ * to confirm Prosody has processed the update before returning.
+ *
+ * @param {object} mod Moderator XMPP client (occupant of the room).
+ * @param {string} roomJid Full room JID.
+ */
+async function restrictChat(mod, roomJid) {
+ mod.sendMetadataUpdate(METADATA_COMPONENT, roomJid, 'permissions', { groupChatRestricted: true });
+ await mod.waitForMessage(s => {
+ const jsonMsg = s.getChild('json-message', JITMEET_NS);
+
+ if (!jsonMsg) {
+ return false;
+ }
+ try {
+ const parsed = JSON.parse(jsonMsg.getText());
+
+ return parsed?.metadata?.permissions?.groupChatRestricted === true;
+ } catch {
+ return false;
+ }
+ }, 3000);
+}
+
+// ─── Tests ────────────────────────────────────────────────────────────────────
+
+describe('mod_filter_messages', () => {
+
+ const clients = [];
+
+ afterEach(async () => {
+ await Promise.all(clients.map(c => c.disconnect()));
+ clients.length = 0;
+ });
+
+ // ── unrestricted ──────────────────────────────────────────────────────────
+
+ it('message is delivered when groupChatRestricted is not set', async () => {
+ const r = nextRoom();
+
+ const focus = await joinWithFocus(r);
+
+ clients.push(focus);
+
+ const sender = await createXmppClient();
+
+ clients.push(sender);
+ await sender.joinRoom(r);
+
+ const reply = await sender.sendGroupchat(r, 'hello');
+
+ assert.notEqual(reply.attrs.type, 'error', 'message must not be blocked when chat is unrestricted');
+ });
+
+ // ── restricted — blocked ──────────────────────────────────────────────────
+
+ it('anonymous sender is blocked when groupChatRestricted is true', async () => {
+ const r = nextRoom();
+
+ const focus = await joinWithFocus(r);
+ const mod = await connectModerator(r);
+
+ clients.push(focus, mod);
+ await mod.joinRoom(r);
+
+ // Anonymous sender joins.
+ const sender = await createXmppClient();
+
+ clients.push(sender);
+ await sender.joinRoom(r);
+
+ await restrictChat(mod, r);
+
+ const reply = await sender.sendGroupchat(r, 'blocked?');
+
+ assert.strictEqual(reply.attrs.type, 'error',
+ 'anonymous sender must be blocked when groupChatRestricted');
+ assert.ok(
+ reply.getChild('error')?.getChild('not-allowed'),
+ 'expected <not-allowed/> error condition'
+ );
+ });
+
+ it('sender with send-groupchat=false is blocked when groupChatRestricted is true', async () => {
+ const r = nextRoom();
+
+ const focus = await joinWithFocus(r);
+ const mod = await connectModerator(r);
+
+ clients.push(focus, mod);
+ await mod.joinRoom(r);
+
+ const sender = await connect(r, { features: { 'send-groupchat': false } });
+
+ clients.push(sender);
+ await sender.joinRoom(r);
+
+ await restrictChat(mod, r);
+
+ const reply = await sender.sendGroupchat(r, 'blocked?');
+
+ assert.strictEqual(reply.attrs.type, 'error',
+ 'sender with send-groupchat=false must be blocked');
+ assert.ok(
+ reply.getChild('error')?.getChild('not-allowed'),
+ 'expected <not-allowed/> error condition'
+ );
+ });
+
+ it('sender with no send-groupchat key in features is blocked when groupChatRestricted is true', async () => {
+ const r = nextRoom();
+
+ const focus = await joinWithFocus(r);
+ const mod = await connectModerator(r);
+
+ clients.push(focus, mod);
+ await mod.joinRoom(r);
+
+ // Token has a features object but no send-groupchat key.
+ const sender = await connect(r, { features: { 'screen-sharing': true } });
+
+ clients.push(sender);
+ await sender.joinRoom(r);
+
+ await restrictChat(mod, r);
+
+ const reply = await sender.sendGroupchat(r, 'blocked?');
+
+ assert.strictEqual(reply.attrs.type, 'error',
+ 'sender without send-groupchat key must be blocked');
+ assert.ok(
+ reply.getChild('error')?.getChild('not-allowed'),
+ 'expected <not-allowed/> error condition'
+ );
+ });
+
+ it('moderator with no features in token is allowed when groupChatRestricted is true', async () => {
+ // mod_jitsi_permissions (auto-loaded by muc_meeting_id) injects
+ // default_permissions (which includes send-groupchat=true) into
+ // session.jitsi_meet_context_features for moderators whose token
+ // has no explicit context.features.
+ const r = nextRoom();
+
+ const focus = await joinWithFocus(r);
+ const mod = await connectModerator(r);
+
+ clients.push(focus, mod);
+ await mod.joinRoom(r);
+
+ const sender = await connect(r, { contextUser: { moderator: true } });
+
+ clients.push(sender);
+ await sender.joinRoom(r);
+
+ await restrictChat(mod, r);
+
+ const reply = await sender.sendGroupchat(r, 'allowed?');
+
+ assert.notEqual(reply.attrs.type, 'error',
+ 'moderator with no explicit features gets default permissions (send-groupchat=true)');
+ });
+
+ it('moderator with empty features in token is blocked when groupChatRestricted is true', async () => {
+ const r = nextRoom();
+
+ const focus = await joinWithFocus(r);
+ const mod = await connectModerator(r);
+
+ clients.push(focus, mod);
+ await mod.joinRoom(r);
+
+ // Moderator token with an empty features object.
+ const sender = await connect(r, { contextUser: { moderator: true },
+ features: {} });
+
+ clients.push(sender);
+ await sender.joinRoom(r);
+
+ await restrictChat(mod, r);
+
+ const reply = await sender.sendGroupchat(r, 'blocked?');
+
+ assert.strictEqual(reply.attrs.type, 'error',
+ 'moderator with empty features must be blocked');
+ assert.ok(
+ reply.getChild('error')?.getChild('not-allowed'),
+ 'expected <not-allowed/> error condition'
+ );
+ });
+
+ // ── restricted — allowed ──────────────────────────────────────────────────
+
+ it('sender with send-groupchat=true is allowed when groupChatRestricted is true', async () => {
+ const r = nextRoom();
+
+ const focus = await joinWithFocus(r);
+ const mod = await connectModerator(r);
+
+ clients.push(focus, mod);
+ await mod.joinRoom(r);
+
+ const sender = await connect(r, { features: { 'send-groupchat': true } });
+
+ clients.push(sender);
+ await sender.joinRoom(r);
+
+ await restrictChat(mod, r);
+
+ const reply = await sender.sendGroupchat(r, 'allowed!');
+
+ assert.notEqual(reply.attrs.type, 'error',
+ 'sender with send-groupchat=true must be allowed');
+ });
+
+ // ── body-less message ─────────────────────────────────────────────────────
+
+ it('body-less message is always delivered even when groupChatRestricted is true', async () => {
+ const r = nextRoom();
+
+ const focus = await joinWithFocus(r);
+ const mod = await connectModerator(r);
+
+ clients.push(focus, mod);
+ await mod.joinRoom(r);
+
+ // Anonymous sender — would normally be blocked for body messages.
+ const sender = await createXmppClient();
+
+ clients.push(sender);
+ await sender.joinRoom(r);
+
+ await restrictChat(mod, r);
+
+ // Send a groupchat message with no <body> child.
+ const reply = await sender.sendGroupchat(r);
+
+ assert.notEqual(reply.attrs.type, 'error',
+ 'body-less message must pass through even when chat is restricted');
+ });
+});
diff --git a/tests/prosody/mod_jitsi_permissions_spec.js b/tests/prosody/mod_jitsi_permissions_spec.js
index bab41527f0..851a728adf 100644
--- a/tests/prosody/mod_jitsi_permissions_spec.js
+++ b/tests/prosody/mod_jitsi_permissions_spec.js
@@ -77,7 +77,8 @@ describe('mod_jitsi_permissions', () => {
clients.push(await joinWithFocus(r));
- const token = mintAsapToken({ context: { user: { moderator: true } } });
+ const token = mintAsapToken({ room: r.split('@')[0],
+ context: { user: { moderator: true } } });
const c = await connect({ params: { token } });
const presence = await c.joinRoom(r);
@@ -106,6 +107,7 @@ describe('mod_jitsi_permissions', () => {
clients.push(await joinWithFocus(r));
const token = mintAsapToken({
+ room: r.split('@')[0],
context: {
user: { moderator: true },
features: {
@@ -138,7 +140,8 @@ describe('mod_jitsi_permissions', () => {
clients.push(await joinWithFocus(r));
- const token = mintAsapToken({ context: { user: { id: 'user1' } } });
+ const token = mintAsapToken({ room: r.split('@')[0],
+ context: { user: { id: 'user1' } } });
const c = await connect({ params: { token } });
const presence = await c.joinRoom(r);
@@ -155,6 +158,7 @@ describe('mod_jitsi_permissions', () => {
clients.push(await joinWithFocus(r));
const token = mintAsapToken({
+ room: r.split('@')[0],
context: {
user: { moderator: false },
features: { recording: true }
@@ -213,6 +217,7 @@ describe('mod_jitsi_permissions', () => {
clients.push(await joinWithFocus(r));
const token = mintAsapToken({
+ room: r.split('@')[0],
context: {
user: { moderator: true },
features: {
@@ -237,6 +242,7 @@ describe('mod_jitsi_permissions', () => {
clients.push(await joinWithFocus(r));
const token = mintAsapToken({
+ room: r.split('@')[0],
context: {
user: { id: 'user1' },
features: {
@@ -260,7 +266,8 @@ describe('mod_jitsi_permissions', () => {
clients.push(await joinWithFocus(r));
- const token = mintAsapToken({ context: { user: { moderator: true } } });
+ const token = mintAsapToken({ room: r.split('@')[0],
+ context: { user: { moderator: true } } });
const c = await connect({ params: { token } });
await c.joinRoom(r);
@@ -278,7 +285,8 @@ describe('mod_jitsi_permissions', () => {
clients.push(await joinWithFocus(r));
- const token = mintAsapToken({ context: { user: { id: 'user1' } } });
+ const token = mintAsapToken({ room: r.split('@')[0],
+ context: { user: { id: 'user1' } } });
const c = await connect({ params: { token } });
await c.joinRoom(r);
diff --git a/tests/prosody/mod_muc_auth_ban_spec.js b/tests/prosody/mod_muc_auth_ban_spec.js
index e9d71b17f8..291ab6b3d2 100644
--- a/tests/prosody/mod_muc_auth_ban_spec.js
+++ b/tests/prosody/mod_muc_auth_ban_spec.js
@@ -13,7 +13,8 @@ const VPAAS_PREFIX = 'vpaas-magic-cookie-test';
// token string. Use a per-test jti so each test gets a unique token and cannot
// accidentally match a token that was cached as banned by an earlier test.
let _tokenCounter = 0;
-const freshToken = () => mintAsapToken({ jti: `ban-test-${++_tokenCounter}` });
+const freshToken = () => mintAsapToken({ room: '*',
+ jti: `ban-test-${++_tokenCounter}` });
// ─── Helpers ─────────────────────────────────────────────────────────────────
diff --git a/tests/prosody/mod_muc_displayname_spec.js b/tests/prosody/mod_muc_displayname_spec.js
new file mode 100644
index 0000000000..c57e14c9cd
--- /dev/null
+++ b/tests/prosody/mod_muc_displayname_spec.js
@@ -0,0 +1,346 @@
+import assert from 'assert';
+
+import { mintAsapToken } from './helpers/jwt.js';
+import { setHideDisplayNameForGuests, setRoomMaxOccupants } from './helpers/test_observer.js';
+import { createXmppClient, joinWithFocus } from './helpers/xmpp_client.js';
+
+const CONFERENCE = 'conference.localhost';
+const NICK_NS = 'http://jabber.org/protocol/nick';
+const DISPLAY_NAME_NS = 'http://jitsi.org/protocol/display-name';
+
+let _counter = 0;
+const nextRoom = () => `displayname-${++_counter}@${CONFERENCE}`;
+
+// ─── Helpers ──────────────────────────────────────────────────────────────────
+
+/**
+ * Connects a client on the main VirtualHost with a given token context.
+ * Always passes ?room= so that session.jitsi_web_query_room is set —
+ * required by the hideDisplayNameForGuests outbound filter.
+ *
+ * @param {string} roomJid
+ * @param {object} [contextUser] JWT context.user claims (e.g. { name: 'Alice' })
+ * @param {object} [features] JWT context.features claims
+ */
+function connect(roomJid, { contextUser, features } = {}) {
+ const roomName = roomJid.split('@')[0];
+ const context = {};
+
+ if (contextUser !== undefined) {
+ context.user = contextUser;
+ }
+ if (features !== undefined) {
+ context.features = features;
+ }
+ const token = mintAsapToken({ room: roomName,
+ context });
+
+ return createXmppClient({ params: { room: roomName,
+ token } });
+}
+
+const connectModerator = roomJid => connect(roomJid, { contextUser: { moderator: true } });
+
+/**
+ * Waits for a non-error, non-unavailable presence from a specific occupant nick.
+ * Skips any presences already queued from earlier occupants.
+ *
+ * @param {object} client observer client
+ * @param {string} roomJid
+ * @param {string} nick MUC nick of the occupant to wait for
+ */
+function waitForOtherPresence(client, roomJid, nick) {
+ return client.waitForPresence(
+ s => s.attrs.from === `${roomJid}/${nick}` && !s.attrs.type,
+ 5000
+ );
+}
+
+// ─── name-readonly ────────────────────────────────────────────────────────────
+
+describe('mod_muc_displayname — name-readonly', () => {
+
+ const clients = [];
+
+ afterEach(async () => {
+ await Promise.all(clients.map(c => c.disconnect()));
+ clients.length = 0;
+ });
+
+ it('enforces token name: observer sees token name even when sender sent a different nick', async () => {
+ const r = nextRoom();
+
+ const focus = await joinWithFocus(r);
+ const observer = await createXmppClient({ params: { room: r.split('@')[0] } });
+
+ clients.push(focus, observer);
+ await observer.joinRoom(r);
+
+ // Alice connects with name-readonly=true and name="Alice" in the token.
+ const alice = await connect(r, {
+ contextUser: { name: 'Alice' },
+ features: { 'name-readonly': true }
+ });
+
+ clients.push(alice);
+
+ // Alice joins with a different display name — the inbound filter must replace it.
+ await alice.joinRoom(r, undefined, { displayName: 'WrongName' });
+
+ // The observer sees Alice's join presence; nick must be "Alice" (from token).
+ const presence = await waitForOtherPresence(observer, r, alice.nick);
+ const nick = presence.getChild('nick', NICK_NS);
+
+ assert.ok(nick, 'presence must contain a <nick> element');
+ assert.strictEqual(nick.getText(), 'Alice',
+ 'nick must be the token name, not the client-supplied name');
+ });
+
+ it('strips nick when name-readonly=true and token has no name', async () => {
+ const r = nextRoom();
+
+ const focus = await joinWithFocus(r);
+ const observer = await createXmppClient({ params: { room: r.split('@')[0] } });
+
+ clients.push(focus, observer);
+ await observer.joinRoom(r);
+
+ // No context.user.name — name-readonly with no name means nick is stripped.
+ const alice = await connect(r, { features: { 'name-readonly': true } });
+
+ clients.push(alice);
+ await alice.joinRoom(r, undefined, { displayName: 'SomeName' });
+
+ const presence = await waitForOtherPresence(observer, r, alice.nick);
+
+ assert.ok(
+ !presence.getChild('nick', NICK_NS),
+ 'nick element must be absent when name-readonly and token has no name'
+ );
+ });
+
+ it('passes nick unchanged when name-readonly is not set', async () => {
+ const r = nextRoom();
+
+ const focus = await joinWithFocus(r);
+ const observer = await createXmppClient({ params: { room: r.split('@')[0] } });
+
+ clients.push(focus, observer);
+ await observer.joinRoom(r);
+
+ // No name-readonly feature — client's own nick must be preserved.
+ const alice = await connect(r, { contextUser: { name: 'Alice' } });
+
+ clients.push(alice);
+ await alice.joinRoom(r, undefined, { displayName: 'ChosenName' });
+
+ const presence = await waitForOtherPresence(observer, r, alice.nick);
+ const nick = presence.getChild('nick', NICK_NS);
+
+ assert.ok(nick, 'presence must contain a <nick> element');
+ assert.strictEqual(nick.getText(), 'ChosenName',
+ 'nick must be the client-supplied name when name-readonly is not set');
+ });
+});
+
+// ─── hideDisplayNameForGuests ─────────────────────────────────────────────────
+
+describe('mod_muc_displayname — hideDisplayNameForGuests', () => {
+
+ const clients = [];
+
+ afterEach(async () => {
+ await Promise.all(clients.map(c => c.disconnect()));
+ clients.length = 0;
+ });
+
+ it('non-moderator recipient receives identity-stripped presence', async () => {
+ const r = nextRoom();
+ const roomName = r.split('@')[0];
+
+ const focus = await joinWithFocus(r);
+
+ await setRoomMaxOccupants(r, 10);
+
+ // Non-moderator guest — must receive filtered presences.
+ const guest = await createXmppClient({ params: { room: roomName } });
+
+ // Moderator — must receive full presences.
+ const mod = await connectModerator(r);
+
+ clients.push(focus, guest, mod);
+ await guest.joinRoom(r);
+ await mod.joinRoom(r);
+
+ await setHideDisplayNameForGuests(r, true);
+
+ // Alice joins with a display name after the flag is set.
+ const alice = await connect(r, { contextUser: { name: 'Alice' } });
+
+ clients.push(alice);
+ await alice.joinRoom(r, undefined, { displayName: 'Alice' });
+
+ // Guest sees Alice's join presence — identity must be stripped.
+ const guestPresence = await waitForOtherPresence(guest, r, alice.nick);
+
+ assert.ok(
+ !guestPresence.getChild('nick', NICK_NS),
+ 'non-moderator must not see <nick> when hideDisplayNameForGuests is true'
+ );
+ });
+
+ it('moderator recipient receives full presence with identity intact', async () => {
+ const r = nextRoom();
+ const roomName = r.split('@')[0];
+
+ const focus = await joinWithFocus(r);
+
+ await setRoomMaxOccupants(r, 10);
+
+ const guest = await createXmppClient({ params: { room: roomName } });
+ const mod = await connectModerator(r);
+
+ clients.push(focus, guest, mod);
+ await guest.joinRoom(r);
+ await mod.joinRoom(r);
+
+ await setHideDisplayNameForGuests(r, true);
+
+ const alice = await connect(r, { contextUser: { name: 'Alice' } });
+
+ clients.push(alice);
+ await alice.joinRoom(r, undefined, { displayName: 'Alice' });
+
+ // Drain guest's copy; moderator's copy is what we assert on.
+ await waitForOtherPresence(guest, r, alice.nick);
+
+ // Mod sees Alice's join presence — identity must be intact.
+ const modPresence = await waitForOtherPresence(mod, r, alice.nick);
+ const nick = modPresence.getChild('nick', NICK_NS);
+
+ assert.ok(nick, 'moderator must see <nick> when hideDisplayNameForGuests is true');
+ assert.strictEqual(nick.getText(), 'Alice');
+ });
+
+ it('non-moderator receives full presence when hideDisplayNameForGuests is false', async () => {
+ const r = nextRoom();
+ const roomName = r.split('@')[0];
+
+ const focus = await joinWithFocus(r);
+ const guest = await createXmppClient({ params: { room: roomName } });
+
+ clients.push(focus, guest);
+ await guest.joinRoom(r);
+
+ // Flag is not set — guest must receive full presence.
+ const alice = await connect(r, { contextUser: { name: 'Alice' } });
+
+ clients.push(alice);
+ await alice.joinRoom(r, undefined, { displayName: 'Alice' });
+
+ const presence = await waitForOtherPresence(guest, r, alice.nick);
+ const nick = presence.getChild('nick', NICK_NS);
+
+ assert.ok(nick, 'guest must see <nick> when hideDisplayNameForGuests is false');
+ assert.strictEqual(nick.getText(), 'Alice');
+ });
+});
+
+// ─── message display-name handling ───────────────────────────────────────────
+
+describe('mod_muc_displayname — message display-name handling', () => {
+
+ const clients = [];
+
+ afterEach(async () => {
+ await Promise.all(clients.map(c => c.disconnect()));
+ clients.length = 0;
+ });
+
+ it('live broadcast strips <nick> and <display-name> from groupchat messages', async () => {
+ const r = nextRoom();
+ const roomName = r.split('@')[0];
+
+ const focus = await joinWithFocus(r);
+
+ // Alice is the sender; Bob observes live delivery.
+ const alice = await connect(r, { contextUser: { name: 'Alice' } });
+ const bob = await createXmppClient({ params: { room: roomName } });
+
+ clients.push(focus, alice, bob);
+ await alice.joinRoom(r, undefined, { displayName: 'Alice' });
+ await bob.joinRoom(r);
+
+ await alice.sendGroupchat(r, 'hello');
+
+ // Bob receives the live broadcast; it must not contain nick or display-name.
+ const msg = await bob.waitForMessage(
+ s => s.attrs.type === 'groupchat' && s.getChildText('body') === 'hello'
+ );
+
+ assert.ok(!msg.getChild('nick', NICK_NS),
+ 'live message must not contain <nick>');
+ assert.ok(!msg.getChild('display-name', DISPLAY_NAME_NS),
+ 'live message must not contain <display-name>');
+ });
+
+ it('history message contains <display-name> injected from token name', async () => {
+ const r = nextRoom();
+
+ const focus = await joinWithFocus(r);
+
+ // Alice has a token name; her message must be stored in history with display-name.
+ const alice = await connect(r, { contextUser: { name: 'Alice',
+ id: 'alice-id' } });
+
+ clients.push(focus, alice);
+ await alice.joinRoom(r);
+ await alice.sendGroupchat(r, 'history-msg');
+
+ // Bob joins after the message — he receives it as history (with <delay>).
+ const bob = await createXmppClient({ params: { room: r.split('@')[0] } });
+
+ clients.push(bob);
+ await bob.joinRoom(r);
+
+ const historyMsg = await bob.waitForMessage(
+ s => s.attrs.type === 'groupchat'
+ && s.getChildText('body') === 'history-msg'
+ && s.getChild('delay') !== undefined
+ );
+ const displayName = historyMsg.getChild('display-name', DISPLAY_NAME_NS);
+
+ assert.ok(displayName, 'history message must contain <display-name>');
+ assert.strictEqual(displayName.getText(), 'Alice');
+ assert.strictEqual(displayName.attrs.source, 'token');
+ });
+
+ it('history message contains <display-name> from nick for anonymous sender', async () => {
+ const r = nextRoom();
+
+ const focus = await joinWithFocus(r);
+
+ // Anonymous sender — display name comes from their <nick> element, not token.
+ const anon = await createXmppClient({ params: { room: r.split('@')[0] } });
+
+ clients.push(focus, anon);
+ await anon.joinRoom(r, undefined, { displayName: 'GuestUser' });
+ await anon.sendGroupchat(r, 'anon-msg');
+
+ const bob = await createXmppClient({ params: { room: r.split('@')[0] } });
+
+ clients.push(bob);
+ await bob.joinRoom(r);
+
+ const historyMsg = await bob.waitForMessage(
+ s => s.attrs.type === 'groupchat'
+ && s.getChildText('body') === 'anon-msg'
+ && s.getChild('delay') !== undefined
+ );
+ const displayName = historyMsg.getChild('display-name', DISPLAY_NAME_NS);
+
+ assert.ok(displayName, 'history message must contain <display-name>');
+ assert.strictEqual(displayName.getText(), 'GuestUser');
+ assert.strictEqual(displayName.attrs.source, 'guest');
+ });
+});
diff --git a/tests/prosody/mod_muc_end_meeting_spec.js b/tests/prosody/mod_muc_end_meeting_spec.js
index f1248b8203..d7cf89220d 100644
--- a/tests/prosody/mod_muc_end_meeting_spec.js
+++ b/tests/prosody/mod_muc_end_meeting_spec.js
@@ -69,7 +69,7 @@ describe('mod_muc_end_meeting', () => {
const { roomJid, clients } = await createRoom();
try {
- const loginToken = mintAsapToken();
+ const loginToken = mintAsapToken({ room: '*' });
const { status } = await endMeeting(roomJid, loginToken);
assert.strictEqual(status, 401,
diff --git a/tests/prosody/mod_muc_jigasi_invite_spec.js b/tests/prosody/mod_muc_jigasi_invite_spec.js
index 5189c70560..2691e99a2f 100644
--- a/tests/prosody/mod_muc_jigasi_invite_spec.js
+++ b/tests/prosody/mod_muc_jigasi_invite_spec.js
@@ -62,7 +62,7 @@ describe('mod_muc_jigasi_invite', () => {
const { roomJid, focus } = await createRoom();
try {
- const loginToken = mintAsapToken();
+ const loginToken = mintAsapToken({ room: '*' });
const { status } = await inviteJigasi(roomJid, '+15551234567', loginToken);
assert.strictEqual(status, 401,
diff --git a/tests/prosody/mod_muc_kick_participant_spec.js b/tests/prosody/mod_muc_kick_participant_spec.js
index 48970db981..1b4bdac38d 100644
--- a/tests/prosody/mod_muc_kick_participant_spec.js
+++ b/tests/prosody/mod_muc_kick_participant_spec.js
@@ -62,7 +62,7 @@ describe('mod_muc_kick_participant', () => {
const { roomJid, focus } = await createRoom();
try {
- const loginToken = mintAsapToken();
+ const loginToken = mintAsapToken({ room: '*' });
const { status } = await kickParticipant(roomJid, 'focus', loginToken);
assert.strictEqual(status, 403,
diff --git a/tests/prosody/mod_muc_limit_messages_spec.js b/tests/prosody/mod_muc_limit_messages_spec.js
new file mode 100644
index 0000000000..6ed1db5337
--- /dev/null
+++ b/tests/prosody/mod_muc_limit_messages_spec.js
@@ -0,0 +1,380 @@
+import { xml } from '@xmpp/client';
+import assert from 'assert';
+
+import { mintAsapToken } from './helpers/jwt.js';
+import { createXmppClient, joinWithFocus } from './helpers/xmpp_client.js';
+
+const CONFERENCE = 'conference.localhost';
+const METADATA_COMPONENT = 'metadata.localhost';
+const JITMEET_NS = 'http://jitsi.org/jitmeet';
+const LIMIT = 3;
+const ERROR_TEXT = 'The message limit for the room has been reached. Messaging is now disabled.';
+
+let _counter = 0;
+const nextRoom = () => `limit-${++_counter}@${CONFERENCE}`;
+
+// ─── Helpers ──────────────────────────────────────────────────────────────────
+
+/**
+ * Connects an anonymous client to the main VirtualHost with ?room= set so that
+ * session.jitsi_web_query_room is populated — required by mod_muc_limit_messages
+ * to locate the room via get_room_by_name_and_subdomain.
+ *
+ * @param {string} roomJid Full room JID, e.g. '[email protected]'
+ */
+function connectAnon(roomJid) {
+ const roomName = roomJid.split('@')[0];
+
+ return createXmppClient({ params: { room: roomName } });
+}
+
+/**
+ * Connects a token-authenticated client. session.auth_token is set by Prosody's
+ * auth_token module on the VirtualHost, and read by mod_muc_limit_messages when
+ * muc_limit_messages_check_token = true to permanently lift the room cap.
+ *
+ * @param {string} roomJid
+ * @param {object} [contextUser] JWT context.user claims; moderator: true → owner
+ */
+function connectWithToken(roomJid, { contextUser } = {}) {
+ const roomName = roomJid.split('@')[0];
+ const token = mintAsapToken({ room: roomName,
+ context: contextUser ? { user: contextUser } : {} });
+
+ return createXmppClient({ params: { room: roomName,
+ token } });
+}
+
+const connectModerator = roomJid => connectWithToken(roomJid, { contextUser: { moderator: true } });
+
+/**
+ * Sends LIMIT messages (all within the cap) then one more that triggers the
+ * block. Returns the reply stanza for the triggering message.
+ */
+async function exhaustAndTrigger(sender, roomJid) {
+ for (let i = 0; i < LIMIT; i++) {
+ await sender.sendGroupchat(roomJid, `msg ${i + 1}`);
+ }
+
+ return sender.sendGroupchat(roomJid, 'trigger');
+}
+
+/**
+ * Sets groupChatRestricted on the room and waits for the metadata broadcast
+ * to confirm Prosody has processed it before returning.
+ */
+async function restrictChat(mod, roomJid) {
+ mod.sendMetadataUpdate(METADATA_COMPONENT, roomJid, 'permissions', { groupChatRestricted: true });
+ await mod.waitForMessage(s => {
+ const j = s.getChild('json-message', JITMEET_NS);
+
+ if (!j) {
+ return false;
+ }
+ try {
+ return JSON.parse(j.getText())?.metadata?.permissions?.groupChatRestricted === true;
+ } catch {
+ return false;
+ }
+ }, 3000);
+}
+
+/**
+ * Clears groupChatRestricted and waits for the metadata broadcast to confirm.
+ */
+async function unrestrictChat(mod, roomJid) {
+ mod.sendMetadataUpdate(METADATA_COMPONENT, roomJid, 'permissions', { groupChatRestricted: false });
+ await mod.waitForMessage(s => {
+ const j = s.getChild('json-message', JITMEET_NS);
+
+ if (!j) {
+ return false;
+ }
+ try {
+ return JSON.parse(j.getText())?.metadata?.permissions?.groupChatRestricted === false;
+ } catch {
+ return false;
+ }
+ }, 3000);
+}
+
+// ─── Tests ────────────────────────────────────────────────────────────────────
+
+describe('mod_muc_limit_messages', () => {
+
+ const clients = [];
+
+ afterEach(async () => {
+ await Promise.all(clients.map(c => c.disconnect()));
+ clients.length = 0;
+ });
+
+ // ── within limit ──────────────────────────────────────────────────────────
+
+ it('messages within the cap are delivered', async () => {
+ const r = nextRoom();
+ const focus = await joinWithFocus(r);
+ const sender = await connectAnon(r);
+
+ clients.push(focus, sender);
+ await sender.joinRoom(r);
+
+ for (let i = 0; i < LIMIT; i++) {
+ const reply = await sender.sendGroupchat(r, `message ${i + 1}`);
+
+ assert.notEqual(reply.attrs.type, 'error',
+ `message ${i + 1} must not be blocked (within cap)`);
+ }
+ });
+
+ // ── at cap boundary ───────────────────────────────────────────────────────
+
+ it('first message over cap is rejected with <not-allowed/>', async () => {
+ const r = nextRoom();
+ const focus = await joinWithFocus(r);
+ const sender = await connectAnon(r);
+
+ clients.push(focus, sender);
+ await sender.joinRoom(r);
+
+ const reply = await exhaustAndTrigger(sender, r);
+
+ assert.strictEqual(reply.attrs.type, 'error',
+ 'triggering message must be rejected');
+ assert.ok(
+ reply.getChild('error')?.getChild('not-allowed'),
+ 'error condition must be <not-allowed/>'
+ );
+ });
+
+ it('room broadcast is sent when cap is first hit', async () => {
+ const r = nextRoom();
+ const focus = await joinWithFocus(r);
+ const sender = await connectAnon(r);
+
+ // observer must join before the limit fires so it is an occupant
+ // when the broadcast is sent; muc_max_occupants=2 so focus (exempt) +
+ // sender + observer = 2 non-whitelisted users, within the limit.
+ const observer = await connectAnon(r);
+
+ clients.push(focus, sender, observer);
+ await sender.joinRoom(r);
+ await observer.joinRoom(r);
+
+ for (let i = 0; i < LIMIT; i++) {
+ await sender.sendGroupchat(r, `msg ${i + 1}`);
+ }
+
+ const [ senderReply, announcement ] = await Promise.all([
+ sender.sendGroupchat(r, 'trigger'),
+ observer.waitForMessage(
+ s => s.attrs.type === 'groupchat'
+ && s.getChildText('body') === ERROR_TEXT,
+ 5000
+ )
+ ]);
+
+ assert.strictEqual(senderReply.attrs.type, 'error');
+ assert.ok(announcement, 'observer must receive the room announcement');
+ });
+
+ // ── after cap is set ──────────────────────────────────────────────────────
+
+ it('messages after cap remain blocked', async () => {
+ const r = nextRoom();
+ const focus = await joinWithFocus(r);
+ const sender = await connectAnon(r);
+
+ clients.push(focus, sender);
+ await sender.joinRoom(r);
+
+ await exhaustAndTrigger(sender, r);
+
+ for (let i = 0; i < 2; i++) {
+ const reply = await sender.sendGroupchat(r, `post-cap ${i + 1}`);
+
+ assert.strictEqual(reply.attrs.type, 'error',
+ `message ${i + 1} after cap must remain blocked`);
+ }
+ });
+
+ // ── message type exemptions ───────────────────────────────────────────────
+
+ it('body-less groupchat (no json) counts toward the cap and is blocked', async () => {
+ const r = nextRoom();
+ const focus = await joinWithFocus(r);
+ const sender = await connectAnon(r);
+
+ clients.push(focus, sender);
+ await sender.joinRoom(r);
+
+ // Fill LIMIT-1 slots with regular messages.
+ for (let i = 0; i < LIMIT - 1; i++) {
+ await sender.sendGroupchat(r, `msg ${i + 1}`);
+ }
+
+ // Body-less groupchat with no json: not exempt, consumes the last slot.
+ const bodyless = await sender.sendGroupchat(r, undefined);
+
+ assert.notEqual(bodyless.attrs.type, 'error',
+ 'body-less groupchat within cap must pass through');
+
+ // Next message triggers the block.
+ const over = await sender.sendGroupchat(r, 'now blocked');
+
+ assert.strictEqual(over.attrs.type, 'error',
+ 'message after body-less consumed last slot must be blocked');
+ });
+
+ it('answer-poll json-message passes through even after cap is reached', async () => {
+ const r = nextRoom();
+ const focus = await joinWithFocus(r);
+ const sender = await connectAnon(r);
+
+ clients.push(focus, sender);
+ await sender.joinRoom(r);
+
+ await exhaustAndTrigger(sender, r);
+
+ const pollEl = xml('json-message', { xmlns: JITMEET_NS },
+ JSON.stringify({ type: 'answer-poll',
+ pollId: '1',
+ answers: [] }));
+ const reply = await sender.sendGroupchat(r, undefined, [ pollEl ]);
+
+ assert.notEqual(reply.attrs.type, 'error',
+ 'answer-poll body-less message must pass through regardless of cap');
+ });
+
+ // ── check_token × token_verification interaction ──────────────────────────
+ //
+ // muc_limit_messages_check_token = true on conference.localhost.
+ // A sender whose session.auth_token is set (set by mod_auth_token when the
+ // client connects with a valid JWT) permanently disables the cap for that room
+ // by setting room._muc_messages_limit = false, overriding even a cap already
+ // set to true.
+
+ it('authenticated sender lifts the cap permanently', async () => {
+ const r = nextRoom();
+ const focus = await joinWithFocus(r);
+ const anon = await connectAnon(r);
+ const authed = await connectWithToken(r);
+
+ clients.push(focus, anon, authed);
+ await anon.joinRoom(r);
+ await authed.joinRoom(r);
+
+ // Anonymous sender exhausts and triggers the cap.
+ await exhaustAndTrigger(anon, r);
+
+ // Authenticated sender (session.auth_token set by token_verification)
+ // sets room._muc_messages_limit = false.
+ const authedReply = await authed.sendGroupchat(r, 'auth unlocks');
+
+ assert.notEqual(authedReply.attrs.type, 'error',
+ 'authenticated sender must pass through');
+
+ // Cap is now lifted: anonymous sender can send freely again.
+ const anonReply = await anon.sendGroupchat(r, 'now unlimited');
+
+ assert.notEqual(anonReply.attrs.type, 'error',
+ 'cap must be permanently lifted after authenticated sender');
+ });
+
+ it('unauthenticated sender is still capped when check_token is enabled', async () => {
+ const r = nextRoom();
+ const focus = await joinWithFocus(r);
+ const anon = await connectAnon(r);
+
+ clients.push(focus, anon);
+ await anon.joinRoom(r);
+
+ const reply = await exhaustAndTrigger(anon, r);
+
+ assert.strictEqual(reply.attrs.type, 'error',
+ 'anonymous sender must still hit the cap with check_token=true');
+ });
+
+ // ── priority-race regression detector ─────────────────────────────────────
+ //
+ // mod_filter_messages and mod_muc_limit_messages both hook message/bare at
+ // the default priority (0). Lua's table.sort is not stable for equal keys,
+ // so the firing order is non-deterministic across Prosody restarts (but
+ // fixed for the lifetime of a single Prosody process).
+ //
+ // When muc_limit_messages fires first it increments the room counter before
+ // filter_messages swallows the message, so the LIMIT blocked messages
+ // silently exhaust the cap. The very next real message then trips it.
+
+ it('[race] muc_limit_messages must not count messages already blocked by filter_messages', async () => {
+ const r = nextRoom();
+ const focus = await joinWithFocus(r);
+ const mod = await connectModerator(r);
+ const anon = await connectAnon(r);
+
+ clients.push(focus, mod, anon);
+ await mod.joinRoom(r);
+ await anon.joinRoom(r);
+
+ // Restrict chat; filter_messages should swallow every anon message.
+ await restrictChat(mod, r);
+
+ // Send exactly LIMIT messages. If muc_limit_messages runs first on all
+ // of them the counter hits the cap without any real message delivered.
+ for (let i = 0; i < LIMIT; i++) {
+ await anon.sendGroupchat(r, `blocked ${i + 1}`);
+ }
+
+ await unrestrictChat(mod, r);
+
+ // With correct ordering the counter is still 0 and this passes.
+ // With the race the counter is already LIMIT, this triggers the cap
+ // and is rejected with <not-allowed/>.
+ const reply = await anon.sendGroupchat(r, 'should pass');
+
+ assert.notEqual(reply.attrs.type, 'error',
+ 'race: muc_limit_messages counted filter_messages-blocked messages');
+ });
+
+ // ── filter_messages × muc_limit_messages hook-ordering interaction ────────
+ //
+ // filter_messages is listed before muc_limit_messages in modules_enabled so
+ // its message/bare hook fires first. When filter_messages blocks a message it
+ // returns true, ending the hook chain — muc_limit_messages never runs and the
+ // room counter is not incremented. Verifies correct ordering.
+
+ it('messages blocked by filter_messages do not count toward the cap', async () => {
+ const r = nextRoom();
+ const focus = await joinWithFocus(r);
+ const mod = await connectModerator(r);
+ const anon = await connectAnon(r);
+
+ clients.push(focus, mod, anon);
+ await mod.joinRoom(r);
+ await anon.joinRoom(r);
+
+ // Restrict chat so that filter_messages blocks anon messages.
+ await restrictChat(mod, r);
+
+ // Send more than LIMIT messages — all blocked by filter_messages before
+ // muc_limit_messages runs, so the room counter stays at zero.
+ for (let i = 0; i < LIMIT + 1; i++) {
+ const reply = await anon.sendGroupchat(r, `restricted ${i + 1}`);
+
+ assert.strictEqual(reply.attrs.type, 'error',
+ `restricted message ${i + 1} must be blocked`);
+ }
+
+ // Lift the restriction.
+ await unrestrictChat(mod, r);
+
+ // Counter is still 0, so the next LIMIT messages must all pass.
+ for (let i = 0; i < LIMIT; i++) {
+ const reply = await anon.sendGroupchat(r, `after unrestrict ${i + 1}`);
+
+ assert.notEqual(reply.attrs.type, 'error',
+ `message ${i + 1} after unrestrict must pass (cap not consumed by blocked messages)`);
+ }
+ });
+
+});
diff --git a/tests/prosody/mod_muc_lobby_rooms_spec.js b/tests/prosody/mod_muc_lobby_rooms_spec.js
index 3fc0d9c000..025c5a8e89 100644
--- a/tests/prosody/mod_muc_lobby_rooms_spec.js
+++ b/tests/prosody/mod_muc_lobby_rooms_spec.js
@@ -1,11 +1,27 @@
import assert from 'assert';
+import { mintAsapToken } from './helpers/jwt.js';
import { disableLobby, enableLobby, setAffiliation } from './helpers/test_observer.js';
import { createXmppClient, joinWithFocus } from './helpers/xmpp_client.js';
const CONFERENCE = 'conference.localhost';
const LOBBY = 'lobby.conference.localhost';
const LOBBY_NS = 'http://jitsi.org/jitmeet';
+const MUC_NS = 'http://jabber.org/protocol/muc#user';
+
+/**
+ * Extracts role and affiliation from a self-presence stanza.
+ * @param {object} presence
+ * @returns {{ role: string|null, affiliation: string|null }}
+ */
+function getRoleAndAffiliation(presence) {
+ const item = presence.getChild('x', MUC_NS)?.getChild('item');
+
+ return {
+ role: item?.attrs.role ?? null,
+ affiliation: item?.attrs.affiliation ?? null
+ };
+}
let _roomCounter = 0;
const room = () => `lobby-${++_roomCounter}@${CONFERENCE}`;
@@ -142,12 +158,11 @@ describe('mod_muc_lobby_rooms', () => {
const r = room();
await focusJoin(r);
-
await enableLobby(r);
+ // Connect first to learn the server-assigned JID, then pre-approve the
+ // user by setting member affiliation before they attempt to join.
const c = await connect();
-
- // Grant member affiliation before the client attempts to join.
const bareJid = c.jid.split('/')[0];
await setAffiliation(r, bareJid, 'member');
@@ -235,4 +250,131 @@ describe('mod_muc_lobby_rooms', () => {
'non-member must be allowed after lobby is disabled');
});
});
+
+ // -------------------------------------------------------------------------
+ // token_affiliation interaction
+ // -------------------------------------------------------------------------
+ describe('token_affiliation interaction', () => {
+
+ it('moderator token holder is blocked by lobby, not bypassed by affiliation grant', async () => {
+ const r = room();
+ const roomName = r.split('@')[0];
+
+ await focusJoin(r);
+ await enableLobby(r);
+
+ const token = mintAsapToken({ room: roomName,
+ context: { user: { moderator: true } } });
+ const c = await connect({ params: { token } });
+ const presence = await c.joinRoom(r, undefined, { displayName: 'TokenMod' });
+
+ assert.equal(presence.attrs.type, 'error',
+ 'moderator token user must be blocked by lobby');
+
+ const error = presence.getChild('error');
+
+ assert.ok(error, 'error element must be present');
+ assert.ok(
+ error.getChild('registration-required'),
+ 'error condition must be registration-required'
+ );
+ });
+
+ it('non-moderator token holder is blocked by lobby', async () => {
+ const r = room();
+ const roomName = r.split('@')[0];
+
+ await focusJoin(r);
+ await enableLobby(r);
+
+ const token = mintAsapToken({ room: roomName,
+ context: { user: { id: 'user1' } } });
+ const c = await connect({ params: { token } });
+ const presence = await c.joinRoom(r, undefined, { displayName: 'TokenUser' });
+
+ assert.equal(presence.attrs.type, 'error',
+ 'non-moderator token user must be blocked by lobby');
+
+ const error = presence.getChild('error');
+
+ assert.ok(error, 'error element must be present');
+ assert.ok(
+ error.getChild('registration-required'),
+ 'error condition must be registration-required'
+ );
+ });
+
+ // ---------------------------------------------------------------------
+ // lobby + room password
+ // ---------------------------------------------------------------------
+
+ it('moderator token user admitted from lobby joins directly without password prompt', async () => {
+ const r = room();
+ const roomName = r.split('@')[0];
+ const focus = await focusJoin(r);
+
+ await focus.setRoomPassword(r, 'testpass');
+ await enableLobby(r);
+
+ const token = mintAsapToken({ room: roomName,
+ context: { user: { moderator: true } } });
+ const c = await connect({ params: { token } });
+
+ // First attempt — blocked by lobby
+ const blocked = await c.joinRoom(r, undefined, { displayName: 'TokenMod' });
+
+ assert.equal(blocked.attrs.type, 'error', 'first join must be blocked by lobby');
+ assert.ok(
+ blocked.getChild('error')?.getChild('registration-required'),
+ 'must be blocked with registration-required'
+ );
+
+ // Simulate moderator approval
+ const userBareJid = c.jid.split('/')[0];
+
+ await setAffiliation(r, userBareJid, 'member');
+
+ // Second attempt — admitted user must join directly as moderator, no password required
+ const presence = await c.joinRoom(r, undefined, { displayName: 'TokenMod' });
+
+ assert.notEqual(presence.attrs.type, 'error',
+ 'admitted user must not be asked for password');
+
+ const { role, affiliation } = getRoleAndAffiliation(presence);
+
+ assert.equal(affiliation, 'owner',
+ 'admitted moderator token user must get owner affiliation');
+ assert.equal(role, 'moderator',
+ 'admitted moderator token user must get moderator role');
+ });
+
+ it('moderator token user who bypasses lobby with room password gets moderator role', async () => {
+ const r = room();
+ const roomName = r.split('@')[0];
+ const focus = await focusJoin(r);
+
+ await focus.setRoomPassword(r, 'testpass');
+ await enableLobby(r);
+
+ const token = mintAsapToken({ room: roomName,
+ context: { user: { moderator: true } } });
+ const c = await connect({ params: { token } });
+
+ // Join with password — must bypass lobby and get moderator role
+ const presence = await c.joinRoom(r, undefined, {
+ password: 'testpass',
+ displayName: 'TokenMod'
+ });
+
+ assert.notEqual(presence.attrs.type, 'error',
+ 'password-bypass join must succeed');
+
+ const { role, affiliation } = getRoleAndAffiliation(presence);
+
+ assert.equal(affiliation, 'owner',
+ 'moderator token user who bypassed lobby via password must get owner affiliation');
+ assert.equal(role, 'moderator',
+ 'moderator token user who bypassed lobby via password must get moderator role');
+ });
+ });
});
diff --git a/tests/prosody/mod_muc_password_check_spec.js b/tests/prosody/mod_muc_password_check_spec.js
new file mode 100644
index 0000000000..ad11dcc91b
--- /dev/null
+++ b/tests/prosody/mod_muc_password_check_spec.js
@@ -0,0 +1,318 @@
+import assert from 'assert';
+
+import { mintAsapToken } from './helpers/jwt.js';
+import { enableLobby } from './helpers/test_observer.js';
+import { joinWithFocus } from './helpers/xmpp_client.js';
+
+const CONFERENCE = 'conference.localhost';
+const BASE_URL = 'http://localhost:5280/room-info';
+
+let _roomCounter = 0;
+const room = () => `password-check-${++_roomCounter}@${CONFERENCE}`;
+
+describe('mod_muc_password_check', () => {
+
+ let clients;
+
+ beforeEach(() => {
+ clients = [];
+ });
+
+ afterEach(async () => {
+ await Promise.all(clients.map(c => c.disconnect()));
+ });
+
+ /**
+ * Joins a room as focus and registers the client for cleanup.
+ *
+ * @param {string} roomJid Full room JID.
+ * @returns {Promise<object>} The focus client.
+ */
+ async function focusJoin(roomJid) {
+ const c = await joinWithFocus(roomJid);
+
+ clients.push(c);
+
+ return c;
+ }
+
+ /**
+ * Calls GET /room-info?room=<roomName> and returns the parsed response.
+ *
+ * @param {string} roomName The room query param value (bare or full JID).
+ * @param {string|null} token Bearer token to include, or null to omit.
+ * @param {object} [opts]
+ * @param {boolean} [opts.omitAuth=false] When true, omit the Authorization header entirely.
+ * @returns {Promise<{status: number, body: object|string}>}
+ */
+ async function getRoomInfo(roomName, token, { omitAuth = false } = {}) {
+ const headers = { 'Content-Type': 'application/json' };
+
+ if (!omitAuth && token !== null) {
+ headers.Authorization = `Bearer ${token}`;
+ }
+
+ const res = await fetch(`${BASE_URL}?room=${encodeURIComponent(roomName)}`, { headers });
+ const text = await res.text();
+ let body;
+
+ try {
+ body = JSON.parse(text);
+ } catch {
+ body = text;
+ }
+
+ return { status: res.status,
+ body };
+ }
+
+ /**
+ * Calls PUT /room-info?room=<roomName> with the given passcode and returns
+ * the parsed response.
+ *
+ * @param {string} roomName The room query param value.
+ * @param {string} passcode The passcode to submit.
+ * @param {string|null} token Bearer token, or null to send without value.
+ * @param {object} [opts]
+ * @param {boolean} [opts.omitAuth=false] When true, omit the Authorization header entirely.
+ * @returns {Promise<{status: number, body: object|string}>}
+ */
+ async function validatePasscode(roomName, passcode, token, { omitAuth = false } = {}) {
+ const headers = { 'Content-Type': 'application/json' };
+
+ if (!omitAuth && token !== null) {
+ headers.Authorization = `Bearer ${token}`;
+ }
+
+ const res = await fetch(`${BASE_URL}?room=${encodeURIComponent(roomName)}`, {
+ method: 'PUT',
+ headers,
+ body: JSON.stringify({ passcode })
+ });
+ const text = await res.text();
+ let body;
+
+ try {
+ body = JSON.parse(text);
+ } catch {
+ body = text;
+ }
+
+ return { status: res.status,
+ body };
+ }
+
+ // -------------------------------------------------------------------------
+ // authentication
+ // -------------------------------------------------------------------------
+ describe('authentication', () => {
+
+ it('GET returns 403 when Authorization header is absent', async () => {
+ const r = room();
+
+ await focusJoin(r);
+
+ const { status } = await getRoomInfo(r.split('@')[0], null, { omitAuth: true });
+
+ assert.strictEqual(status, 403);
+ });
+
+ it('GET returns 403 when token is invalid', async () => {
+ const r = room();
+
+ await focusJoin(r);
+
+ const { status } = await getRoomInfo(r.split('@')[0], 'invalid.token.here');
+
+ assert.strictEqual(status, 403);
+ });
+
+ it('PUT returns 403 when Authorization header is absent', async () => {
+ const r = room();
+
+ await focusJoin(r);
+
+ const { status } = await validatePasscode(r.split('@')[0], 'somepasscode', null, { omitAuth: true });
+
+ assert.strictEqual(status, 403);
+ });
+
+ });
+
+ // -------------------------------------------------------------------------
+ // parameter validation
+ // -------------------------------------------------------------------------
+ describe('parameter validation', () => {
+
+ it('GET returns 400 when room query param is missing', async () => {
+ const token = mintAsapToken({ room: '*' });
+ const res = await fetch(BASE_URL, {
+ headers: { Authorization: `Bearer ${token}` }
+ });
+
+ assert.strictEqual(res.status, 400);
+ });
+
+ it('PUT returns 400 when Content-Type is not application/json', async () => {
+ const token = mintAsapToken({ room: '*' });
+ const res = await fetch(`${BASE_URL}?room=someroom`, {
+ method: 'PUT',
+ headers: {
+ 'Content-Type': 'text/plain',
+ Authorization: `Bearer ${token}`
+ },
+ body: '{"passcode":"test"}'
+ });
+
+ assert.strictEqual(res.status, 400);
+ });
+
+ it('PUT returns 400 when body is empty', async () => {
+ const token = mintAsapToken({ room: '*' });
+ const res = await fetch(`${BASE_URL}?room=someroom`, {
+ method: 'PUT',
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: `Bearer ${token}`
+ },
+ body: ''
+ });
+
+ assert.strictEqual(res.status, 400);
+ });
+
+ it('PUT returns 400 when body is valid JSON but passcode key is missing', async () => {
+ const token = mintAsapToken({ room: '*' });
+ const res = await fetch(`${BASE_URL}?room=someroom`, {
+ method: 'PUT',
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: `Bearer ${token}`
+ },
+ body: '{}'
+ });
+
+ assert.strictEqual(res.status, 400);
+ });
+
+ });
+
+ // -------------------------------------------------------------------------
+ // room lookup
+ // -------------------------------------------------------------------------
+ describe('room lookup', () => {
+
+ it('GET returns 404 when room does not exist', async () => {
+ const token = mintAsapToken({ room: '*' });
+ const { status } = await getRoomInfo('nonexistent-room', token);
+
+ assert.strictEqual(status, 404);
+ });
+
+ it('PUT returns 404 when room does not exist', async () => {
+ const token = mintAsapToken({ room: '*' });
+ const { status } = await validatePasscode('nonexistent-room', 'secret', token);
+
+ assert.strictEqual(status, 404);
+ });
+
+ });
+
+ // -------------------------------------------------------------------------
+ // GET room info
+ // -------------------------------------------------------------------------
+ describe('GET room info', () => {
+
+ it('returns passcodeProtected: false and lobbyEnabled: false for a plain room', async () => {
+ const r = room();
+ const roomName = r.split('@')[0];
+
+ await focusJoin(r);
+
+ const token = mintAsapToken({ room: '*' });
+ const { status, body } = await getRoomInfo(roomName, token);
+
+ assert.strictEqual(status, 200);
+ assert.strictEqual(body.passcodeProtected, false);
+ assert.strictEqual(body.lobbyEnabled, false);
+ });
+
+ it('returns passcodeProtected: true when room has a password set', async () => {
+ const r = room();
+ const roomName = r.split('@')[0];
+ const focus = await focusJoin(r);
+
+ await focus.setRoomPassword(r, 'secret123');
+
+ const token = mintAsapToken({ room: '*' });
+ const { status, body } = await getRoomInfo(roomName, token);
+
+ assert.strictEqual(status, 200);
+ assert.strictEqual(body.passcodeProtected, true);
+ });
+
+ it('returns lobbyEnabled: true when lobby is enabled', async () => {
+ const r = room();
+ const roomName = r.split('@')[0];
+
+ await focusJoin(r);
+ await enableLobby(r);
+
+ const token = mintAsapToken({ room: '*' });
+ const { status, body } = await getRoomInfo(roomName, token);
+
+ assert.strictEqual(status, 200);
+ assert.strictEqual(body.lobbyEnabled, true);
+ });
+
+ it('conference field equals the full room JID', async () => {
+ const r = room();
+ const roomName = r.split('@')[0];
+
+ await focusJoin(r);
+
+ const token = mintAsapToken({ room: '*' });
+ const { status, body } = await getRoomInfo(roomName, token);
+
+ assert.strictEqual(status, 200);
+ assert.strictEqual(body.conference, `${roomName}@${CONFERENCE}`);
+ });
+
+ });
+
+ // -------------------------------------------------------------------------
+ // PUT passcode validation
+ // -------------------------------------------------------------------------
+ describe('PUT passcode validation', () => {
+
+ it('returns { valid: true } when submitted passcode matches', async () => {
+ const r = room();
+ const roomName = r.split('@')[0];
+ const focus = await focusJoin(r);
+
+ await focus.setRoomPassword(r, 'correct-pass');
+
+ const token = mintAsapToken({ room: '*' });
+ const { status, body } = await validatePasscode(roomName, 'correct-pass', token);
+
+ assert.strictEqual(status, 200);
+ assert.strictEqual(body.valid, true);
+ });
+
+ it('returns { valid: false } when submitted passcode does not match', async () => {
+ const r = room();
+ const roomName = r.split('@')[0];
+ const focus = await focusJoin(r);
+
+ await focus.setRoomPassword(r, 'correct-pass');
+
+ const token = mintAsapToken({ room: '*' });
+ const { status, body } = await validatePasscode(roomName, 'wrong-pass', token);
+
+ assert.strictEqual(status, 200);
+ assert.strictEqual(body.valid, false);
+ });
+
+ });
+
+});
diff --git a/tests/prosody/mod_presence_identity_spec.js b/tests/prosody/mod_presence_identity_spec.js
index d18b288fa7..f624509351 100644
--- a/tests/prosody/mod_presence_identity_spec.js
+++ b/tests/prosody/mod_presence_identity_spec.js
@@ -13,11 +13,14 @@ const room = () => `presence-identity-${++_roomCounter}@${CONFERENCE}`;
* Connects to the hs256.localhost VirtualHost with a signed token.
* mod_presence_identity is loaded on this VirtualHost.
*
- * @param {object} [tokenPayload] JWT payload overrides (e.g. { context: { user: ... } }).
+ * @param {string} roomJid full room JID, e.g. '[email protected]'
+ * @param {object} [tokenPayload] JWT payload overrides (e.g. { context: { user: ... } }).
* @returns {Promise<XmppTestClient>}
*/
-function hs256Client(tokenPayload = {}) {
- const token = mintToken(tokenPayload);
+function hs256Client(roomJid, tokenPayload = {}) {
+ const roomName = roomJid.split('@')[0];
+ const token = mintToken({ room: roomName,
+ ...tokenPayload });
return createXmppClient({ domain: 'hs256.localhost',
params: { token } });
@@ -55,7 +58,7 @@ describe('mod_presence_identity', () => {
it('injects <identity><user> from JWT context.user into MUC presence', async () => {
const r = room();
- const identity = await hs256Client({
+ const identity = await hs256Client(r, {
context: { user: { id: 'u1',
name: 'Alice' } }
});
@@ -83,7 +86,7 @@ describe('mod_presence_identity', () => {
it('adds <group> inside <identity> when context.group is set', async () => {
const r = room();
- const identity = await hs256Client({
+ const identity = await hs256Client(r, {
context: {
user: { id: 'u2' },
group: 'mygroup'
@@ -110,7 +113,7 @@ describe('mod_presence_identity', () => {
const r = room();
// Valid token but no context field → no jitsi_meet_context_user on session.
- const noContext = await hs256Client();
+ const noContext = await hs256Client(r);
clients.push(noContext);
await noContext.joinRoom(r);
@@ -134,7 +137,7 @@ describe('mod_presence_identity', () => {
clients.push(observer);
await observer.joinRoom(r);
- const identity = await hs256Client({
+ const identity = await hs256Client(r, {
context: { user: { id: 'u3',
name: 'Bob' } }
});
@@ -173,7 +176,7 @@ describe('mod_presence_identity', () => {
// Token with no context → no jitsi_meet_context_user on session.
// The client manually crafts an <identity> element in the join presence.
- const intruder = await hs256Client();
+ const intruder = await hs256Client(r);
clients.push(intruder);
@@ -204,7 +207,7 @@ describe('mod_presence_identity', () => {
// Token with real context.user but also a crafted <identity> in the stanza.
// The module must strip the crafted one and inject the real one from the session.
- const identity = await hs256Client({
+ const identity = await hs256Client(r, {
context: { user: { id: 'real-id',
name: 'Real User' } }
});
diff --git a/tests/prosody/mod_room_metadata_component_spec.js b/tests/prosody/mod_room_metadata_component_spec.js
index af63d7a802..e52f2fa6dd 100644
--- a/tests/prosody/mod_room_metadata_component_spec.js
+++ b/tests/prosody/mod_room_metadata_component_spec.js
@@ -28,7 +28,8 @@ function connect(roomJid, contextUser) {
const params = { room: roomName };
if (contextUser !== undefined) {
- params.token = mintAsapToken({ context: { user: contextUser } });
+ params.token = mintAsapToken({ room: roomName,
+ context: { user: contextUser } });
}
return createXmppClient({ params });
diff --git a/tests/prosody/mod_system_chat_message_spec.js b/tests/prosody/mod_system_chat_message_spec.js
index 4a0b787d30..17826daf57 100644
--- a/tests/prosody/mod_system_chat_message_spec.js
+++ b/tests/prosody/mod_system_chat_message_spec.js
@@ -63,7 +63,7 @@ describe('mod_system_chat_message', () => {
const { roomJid, focus } = await createRoom();
try {
- const loginToken = mintAsapToken();
+ const loginToken = mintAsapToken({ room: '*' });
const { status } = await sendSystemChatMessage(
roomJid, [ focus.jid ], 'hello', loginToken);
diff --git a/tests/prosody/mod_token_affiliation_spec.js b/tests/prosody/mod_token_affiliation_spec.js
index 1d36df8d7c..9f308bd100 100644
--- a/tests/prosody/mod_token_affiliation_spec.js
+++ b/tests/prosody/mod_token_affiliation_spec.js
@@ -26,13 +26,16 @@ function getRoleAndAffiliation(presence) {
/**
* Connects a client on the main VirtualHost with the given context.user claims
- * embedded in a RS256 token.
+ * embedded in a RS256 token scoped to the given room.
*
+ * @param {string} roomJid full room JID, e.g. '[email protected]'
* @param {object} contextUser JWT context.user payload.
* @returns {Promise<XmppTestClient>}
*/
-function connectWithToken(contextUser) {
- const token = mintAsapToken({ context: { user: contextUser } });
+function connectWithToken(roomJid, contextUser) {
+ const roomName = roomJid.split('@')[0];
+ const token = mintAsapToken({ room: roomName,
+ context: { user: contextUser } });
return createXmppClient({ params: { token } });
}
@@ -61,7 +64,7 @@ describe('mod_token_affiliation', () => {
clients.push(await joinWithFocus(r));
- const c = await connectWithToken(contextUser);
+ const c = await connectWithToken(r, contextUser);
clients.push(c);
@@ -89,7 +92,7 @@ describe('mod_token_affiliation', () => {
clients.push(await joinWithFocus(r));
- const c = await connectWithToken({ id: 'user1' });
+ const c = await connectWithToken(r, { id: 'user1' });
clients.push(c);
@@ -105,7 +108,7 @@ describe('mod_token_affiliation', () => {
clients.push(await joinWithFocus(r));
- const c = await connectWithToken({ moderator: false });
+ const c = await connectWithToken(r, { moderator: false });
clients.push(c);
@@ -144,8 +147,8 @@ describe('mod_token_affiliation', () => {
clients.push(await joinWithFocus(r));
- const mod = await connectWithToken({ moderator: true });
- const member = await connectWithToken({ id: 'plain' });
+ const mod = await connectWithToken(r, { moderator: true });
+ const member = await connectWithToken(r, { id: 'plain' });
clients.push(mod, member);
diff --git a/tests/prosody/mod_token_verification_spec.js b/tests/prosody/mod_token_verification_spec.js
index bf5431e388..b831a3d2fe 100644
--- a/tests/prosody/mod_token_verification_spec.js
+++ b/tests/prosody/mod_token_verification_spec.js
@@ -76,19 +76,15 @@ describe('mod_token_verification', () => {
);
});
- it('allows join with token that has no room claim', async () => {
- const room = await setupRoom();
-
- // No 'room' field in payload → session.jitsi_meet_room = nil → passes.
- const token = mintAsapToken();
- const c = await createXmppClient({ params: { token } });
-
- clients.push(c);
+ it('rejects connection when token has no room claim', async () => {
+ // asap_require_room_claim = true: a token without a room claim is
+ // rejected at SASL / connection time, before the client can join a room.
+ const token = mintAsapToken({ room: undefined });
- const presence = await c.joinRoom(room);
-
- assert.ok(isAvailablePresence(presence),
- 'token without a room claim must be allowed (treated as anonymous)');
+ await assert.rejects(
+ createXmppClient({ params: { token } }),
+ 'connection must be rejected when the room claim is absent'
+ );
});
it('allows join with token whose room claim matches the room', async () => {
@@ -123,6 +119,45 @@ describe('mod_token_verification', () => {
'expected <not-allowed/> error condition');
});
+ it('blocks join for moderator token scoped to a different room', async () => {
+ const room = await setupRoom();
+
+ // Moderator token scoped to 'other-room' — mod_token_verification
+ // checks the room claim at priority 99, before mod_token_affiliation
+ // (priority 0) can grant owner status, so being a moderator is no bypass.
+ const token = mintAsapToken({ room: 'other-room',
+ context: { user: { moderator: true } } });
+ const c = await createXmppClient({ params: { token } });
+
+ clients.push(c);
+
+ const presence = await c.joinRoom(room);
+
+ assert.strictEqual(presence.attrs.type, 'error',
+ 'moderator token for wrong room must be rejected');
+ assert.ok(
+ presence.getChild('error')?.getChild('not-allowed'),
+ 'expected <not-allowed/> error condition');
+ });
+
+ it('blocks join for member token scoped to a different room', async () => {
+ const room = await setupRoom();
+
+ const token = mintAsapToken({ room: 'other-room',
+ context: { user: { id: 'user1' } } });
+ const c = await createXmppClient({ params: { token } });
+
+ clients.push(c);
+
+ const presence = await c.joinRoom(room);
+
+ assert.strictEqual(presence.attrs.type, 'error',
+ 'member token for wrong room must be rejected');
+ assert.ok(
+ presence.getChild('error')?.getChild('not-allowed'),
+ 'expected <not-allowed/> error condition');
+ });
+
it('allows join with wildcard (*) room claim', async () => {
const room = await setupRoom();
const token = mintAsapToken({ room: '*' });
diff --git a/tests/prosody/package-lock.json b/tests/prosody/package-lock.json
index b40af3dbe7..080267cc88 100644
--- a/tests/prosody/package-lock.json
+++ b/tests/prosody/package-lock.json
@@ -76,6 +76,7 @@
"resolved": "https://registry.npmjs.org/@babel/core/-/core-7.29.0.tgz",
"integrity": "sha512-CGOfOJqWjg2qW/Mb6zNsDm+u5vFQ8DxXfbM09z69p5Z6+mE1ikP2jUXw+j42Pf1XTYED2Rni5f95npYeuwMDQA==",
"license": "MIT",
+ "peer": true,
"dependencies": {
"@babel/code-frame": "^7.29.0",
"@babel/generator": "^7.29.0",
@@ -1729,6 +1730,7 @@
}
],
"license": "MIT",
+ "peer": true,
"dependencies": {
"baseline-browser-mapping": "^2.10.12",
"caniuse-lite": "^1.0.30001782",
@@ -2754,6 +2756,7 @@
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
"integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==",
+ "dev": true,
"hasInstallScript": true,
"license": "MIT",
"optional": true,
@@ -3951,6 +3954,7 @@
"integrity": "sha512-VZlYo/WE8t1tstuRmqgeyBgCbJc/lEdopaa+axcKzTBJ+UIdlAB9XnmvTCAH4pwR4ElNInaedhEBmZD8iCSVEg==",
"dev": true,
"license": "MIT",
+ "peer": true,
"dependencies": {
"ansi-colors": "^4.1.3",
"browser-stdout": "^1.3.1",