Skip to content

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

fix(prosody): resume the connection after a token check that waits on resume

damencho87ad7dc1f787
diff --git a/resources/prosody-plugins/mod_auth_token.lua b/resources/prosody-plugins/mod_auth_token.lua
index 0b62a75eb3..f6ca0fe3ef 100644
--- a/resources/prosody-plugins/mod_auth_token.lua
+++ b/resources/prosody-plugins/mod_auth_token.lua
@@ -175,6 +175,21 @@ local function anonymous(self, message)
sasl.registerMechanism("ANONYMOUS", {"anonymous"}, anonymous);
+-- The <resume> is processed on the async runner of the resuming connection (from_session),
+-- and the handler below can wait on it (fetching an ASAP public key that is not cached).
+-- While waiting the runner pauses the connection of the session it was created for, and
+-- resumes it once done, but by then update_session() has retired from_session and moved
+-- the connection to the hibernating session, so the connection stays paused and nothing
+-- more is read from it. Point the runner at the session that now owns the connection.
+module:hook_global('c2s-session-updated', function (event)
+ local session, from_session = event.session, event.from_session;
+ local thread = from_session.thread;
+
+ if type(thread) == 'table' and thread.data == from_session then
+ thread.data = session;
+ end
+end, 1000);
+
-- Fired by Prosody's sessionmanager.update_session() during smacks (XEP-0198) session
-- resumption. The naming can be counter-intuitive:
-- event.session (session) – the OLD hibernating session being kept alive.
diff --git a/tests/prosody/mod_muc_wait_for_host_spec.js b/tests/prosody/mod_muc_wait_for_host_spec.js
index a6013d077d..d2689b6e2a 100644
--- a/tests/prosody/mod_muc_wait_for_host_spec.js
+++ b/tests/prosody/mod_muc_wait_for_host_spec.js
@@ -221,6 +221,38 @@ describe('mod_muc_wait_for_host', () => {
await prosodyShell('module:load("auth_token", "hs256.localhost")');
}
});
+
+ it('resuming with a valid token, then joining, is admitted and made owner', async () => {
+ const r = room();
+
+ await focusJoin(r);
+
+ await prosodyShell('module:unload("auth_token", "hs256.localhost")');
+
+ // A fresh module instance has an empty public key cache, so the key is
+ // fetched while the resume is processed and the connection waits on it.
+ await prosodyShell('module:reload("auth_token", "localhost")');
+
+ try {
+ const guest = await connect({ domain: ANON_DOMAIN });
+ const reconnected = guest.waitForReconnect();
+
+ guest.dropConnection({ token: mintAsapToken({ room: r.split('@')[0] }) });
+ await reconnected;
+
+ const presence = await guest.joinRoom(r);
+
+ assert.ok(isAvailablePresence(presence), 'the resumed guest must be admitted as a host');
+
+ const update = await guest.waitForPresence(
+ p => p.getChild('x', MUC_NS)?.getChild('item')?.attrs.affiliation === 'owner'
+ );
+
+ assert.ok(update, 'the resumed guest must be made owner');
+ } finally {
+ await prosodyShell('module:load("auth_token", "hs256.localhost")');
+ }
+ });
});
// -------------------------------------------------------------------------