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 jaas tests (#16360)

bgrozevd75de3642ebb
diff --git a/tests/helpers/Participant.ts b/tests/helpers/Participant.ts
index 07b712f766..29e8ced9a8 100644
--- a/tests/helpers/Participant.ts
+++ b/tests/helpers/Participant.ts
@@ -188,7 +188,7 @@ export class Participant {
* @param {IParticipantJoinOptions} options - Options for joining.
* @returns {Promise<void>}
*/
- async joinConference(options: IParticipantJoinOptions): Promise<void> {
+ async joinConference(options: IParticipantJoinOptions): Promise<Participant> {
const config = {
room: options.roomName,
configOverwrite: {
@@ -254,6 +254,8 @@ export class Participant {
}
await this.postLoadProcess();
+
+ return this;
}
/**
diff --git a/tests/helpers/participants.ts b/tests/helpers/participants.ts
index e7273c1ba9..aa9dd7a0de 100644
--- a/tests/helpers/participants.ts
+++ b/tests/helpers/participants.ts
@@ -165,14 +165,16 @@ export async function ensureTwoParticipants(options?: IJoinOptions): Promise<voi
}
/**
- * Creates a participant instance or prepares one for re-joining.
+ * Creates a new participant instance, or returns an existing one if it is already joined.
* @param participantOptions - The participant options, with required name set.
* @param {boolean} options - Join options.
+ * @param reuse whether to reuse an existing participant instance if one is available.
* @returns {Promise<Participant>} - The participant instance.
*/
-export async function joinParticipant( // eslint-disable-line max-params
+async function joinParticipant( // eslint-disable-line max-params
participantOptions: IParticipantOptions,
- options?: IJoinOptions): Promise<Participant> {
+ options?: IJoinOptions
+): Promise<Participant> {
participantOptions.iFrameApi = ctx.testProperties.useIFrameApi;
@@ -195,8 +197,6 @@ export async function joinParticipant( // eslint-disable-line max-params
// Change the page so we can reload same url if we need to, base.html is supposed to be empty or close to empty
await p.driver.url('/base.html');
-
- // we want the participant instance re-recreated so we clear any kept state, like endpoint ID
}
const newParticipant = new Participant(participantOptions);
@@ -211,13 +211,12 @@ export async function joinParticipant( // eslint-disable-line max-params
&& config.iframe.usesJaas && config.iframe.tenant) {
forceTenant = config.iframe.tenant;
}
- await newParticipant.joinConference({
+
+ return await newParticipant.joinConference({
...options,
forceTenant,
roomName: options?.roomName || ctx.roomName,
});
-
- return newParticipant;
}
/**
diff --git a/tests/helpers/types.ts b/tests/helpers/types.ts
index 516b12fcde..dfd6649fe1 100644
--- a/tests/helpers/types.ts
+++ b/tests/helpers/types.ts
@@ -26,7 +26,11 @@ export type IContext = {
**/
testProperties: ITestProperties;
times: any;
- /** A WebhooksProxy instance generated by the framework and available for tests to use, if configured. */
+ /**
+ * A WebhooksProxy instance generated by the framework and available for tests to use, if configured.
+ * Note that this is only configured for roomName, if a test wishes to use a different room name it can set up
+ * a WebhooksProxy instance itself.
+ */
webhooksProxy: WebhookProxy;
};
diff --git a/tests/specs/helpers/jaas.ts b/tests/specs/helpers/jaas.ts
index e4689c21ed..cd87a2fb14 100644
--- a/tests/specs/helpers/jaas.ts
+++ b/tests/specs/helpers/jaas.ts
@@ -1,7 +1,7 @@
-import type { Participant } from '../../helpers/Participant';
+import { Participant } from '../../helpers/Participant';
import { config } from '../../helpers/TestsConfig';
-import { joinParticipant } from '../../helpers/participants';
import { IToken, ITokenOptions, generateToken } from '../../helpers/token';
+import { IParticipantJoinOptions } from '../../helpers/types';
export function generateJaasToken(options: ITokenOptions): IToken {
if (!config.jaas.enabled) {
@@ -17,27 +17,46 @@ export function generateJaasToken(options: ITokenOptions): IToken {
}
/**
- * Creates a new Participant and joins the MUC with the given name. The jaas-specific properties must be set as
- * environment variables (see env.example and TestsConfig.ts).
+ * Creates a new Participant and joins the MUC with the given options. The jaas-specific properties must be set as
+ * environment variables (see env.example and TestsConfig.ts). If no room name is specified, the default room name
+ * from the context is used.
*
* @param instanceId This is the "name" passed to the Participant, I think it's used to match against one of the
* pre-configured browser instances in wdio? It must be one of 'p1', 'p2', 'p3', or 'p4'. TODO: figure out how this
* should be used.
* @param token the token to use, if any.
- * @param roomName the name of the room to join, if any. If not provided, the ctx generated one will be used.
+ * @param joinOptions options to use when joining the MUC.
* @returns {Promise<Participant>} The Participant that has joined the MUC.
*/
-export async function joinMuc(instanceId: 'p1' | 'p2' | 'p3' | 'p4', token?: IToken, roomName?: string):
-Promise<Participant> {
+export async function joinMuc(
+ instanceId: 'p1' | 'p2' | 'p3' | 'p4',
+ token?: IToken,
+ joinOptions?: Partial<IParticipantJoinOptions>): Promise<Participant> {
+
if (!config.jaas.enabled) {
throw new Error('JaaS is not configured.');
}
- return await joinParticipant({
+ // @ts-ignore
+ const p = ctx[instanceId] as Participant;
+
+ if (p) {
+ // Load a blank page to make sure the page is reloaded (in case the new participant uses the same URL). Using
+ // 'about:blank' was causing problems in the past, if we notice any issues we can change to "base.html".
+ await p.driver.url('about:blank');
+ }
+
+ const newParticipant = new Participant({
name: instanceId,
token
- }, {
+ });
+
+ // @ts-ignore
+ ctx[instanceId] = newParticipant;
+
+ return await newParticipant.joinConference({
+ ...joinOptions,
forceTenant: config.jaas.tenant,
- roomName
+ roomName: joinOptions?.roomName || ctx.roomName,
});
}
diff --git a/tests/specs/jaas/joinMuc.spec.ts b/tests/specs/jaas/joinMuc.spec.ts
index 10de75275c..71cfcc963d 100644
--- a/tests/specs/jaas/joinMuc.spec.ts
+++ b/tests/specs/jaas/joinMuc.spec.ts
@@ -13,8 +13,6 @@ describe('XMPP login and MUC join test', () => {
expect(await p.isInMuc()).toBe(true);
expect(await p.isModerator()).toBe(false);
-
- await p.hangup();
});
it('with a valid token (specific room)', async () => {
@@ -23,8 +21,6 @@ describe('XMPP login and MUC join test', () => {
expect(await p.isInMuc()).toBe(true);
expect(await p.isModerator()).toBe(false);
-
- await p.hangup();
});
it('with a token with bad signature', async () => {
@@ -41,8 +37,6 @@ describe('XMPP login and MUC join test', () => {
|| await p.getNotifications().getNotificationText(TOKEN_AUTH_FAILED_TITLE_TEST_ID);
expect(errorText).toContain('not allowed to join');
-
- await p.hangup();
});
it('with an expired token', async () => {
@@ -54,8 +48,6 @@ describe('XMPP login and MUC join test', () => {
const errorText = await p.getNotifications().getNotificationText(TOKEN_AUTH_FAILED_TITLE_TEST_ID);
expect(errorText).toContain('Token is expired');
-
- await p.hangup();
});
it('with a token using the wrong key ID', async () => {
@@ -67,8 +59,6 @@ describe('XMPP login and MUC join test', () => {
const errorText = await p.getNotifications().getNotificationText(TOKEN_AUTH_FAILED_TEST_ID);
expect(errorText).toContain('not allowed to join');
-
- await p.hangup();
});
it('with a token for a different room', async () => {
@@ -80,8 +70,6 @@ describe('XMPP login and MUC join test', () => {
const errorText = await p.getNotifications().getNotificationText(TOKEN_AUTH_FAILED_TEST_ID);
expect(errorText).toContain('not allowed to join');
-
- await p.hangup();
});
it('with a moderator token', async () => {
@@ -90,8 +78,6 @@ describe('XMPP login and MUC join test', () => {
expect(await p.isInMuc()).toBe(true);
expect(await p.isModerator()).toBe(true);
-
- await p.hangup();
});
// This is dependent on jaas account configuration. All tests under jaas/ expect that "unauthenticated access" is
@@ -105,8 +91,6 @@ describe('XMPP login and MUC join test', () => {
const errorText = await p.getNotifications().getNotificationText(TOKEN_AUTH_FAILED_TEST_ID);
expect(errorText).toContain('not allowed to join');
-
- await p.hangup();
});
// it('without sending a conference-request', async () => {
diff --git a/tests/specs/jaas/passcode.spec.ts b/tests/specs/jaas/passcode.spec.ts
index 78b894d926..f1015e2652 100644
--- a/tests/specs/jaas/passcode.spec.ts
+++ b/tests/specs/jaas/passcode.spec.ts
@@ -4,7 +4,8 @@ import { joinMuc, generateJaasToken as t } from '../helpers/jaas';
setTestProperties(__filename, {
useJaas: true,
- useWebhookProxy: true
+ useWebhookProxy: true,
+ usesBrowsers: [ 'p1', 'p2' ]
});
const passcode = '1234';
@@ -16,22 +17,11 @@ describe('Setting passcode through settings provisioning', () => {
visitorsEnabled: true
};
+ // We want to keep the room from getting destroyed, because the visitors queue has a timeout and causes
+ // problems. We could use different rooms instead, but the webhooksProxy is only configured for the default room.
await joinWithPassword('p1', t({ room: ctx.roomName }));
- await joinWithPassword('p1', t({ room: ctx.roomName, moderator: true }));
- await joinWithPassword('p1', t({ room: ctx.roomName, visitor: true }));
- });
- it('With an invalid passcode', async () => {
- ctx.webhooksProxy.defaultMeetingSettings = {
- passcode: 'passcode-must-be-digits-only'
- };
-
- const roomName = ctx.roomName + '-2';
- const p = await joinMuc('p1', t({ room: roomName }), roomName);
-
- // Setting the passcode should fail, resulting in the room being accessible without a password
- await p.waitToJoinMUC();
- expect(await p.isInMuc()).toBe(true);
- expect(await p.getPasswordDialog().isOpen()).toBe(false);
+ await joinWithPassword('p2', t({ room: ctx.roomName, moderator: true }));
+ await joinWithPassword('p2', t({ room: ctx.roomName, visitor: true }));
});
});
@@ -41,7 +31,7 @@ describe('Setting passcode through settings provisioning', () => {
*/
async function joinWithPassword(instanceId: string, token: IToken) {
// @ts-ignore
- const p = await joinMuc(instanceId, token);
+ const p = await joinMuc(instanceId, token, ctx.roomName);
await p.waitForMucJoinedOrError();
expect(await p.isInMuc()).toBe(false);
@@ -57,7 +47,5 @@ async function joinWithPassword(instanceId: string, token: IToken) {
expect(await p.isInMuc()).toBe(true);
expect(await p.getPasswordDialog().isOpen()).toBe(false);
-
- await p.hangup();
}
diff --git a/tests/specs/jaas/passcodeInvalid.spec.ts b/tests/specs/jaas/passcodeInvalid.spec.ts
new file mode 100644
index 0000000000..cac2a9277b
--- /dev/null
+++ b/tests/specs/jaas/passcodeInvalid.spec.ts
@@ -0,0 +1,25 @@
+import { setTestProperties } from '../../helpers/TestProperties';
+import { joinMuc, generateJaasToken as t } from '../helpers/jaas';
+
+setTestProperties(__filename, {
+ useJaas: true,
+ useWebhookProxy: true
+});
+
+// This test is separate from passcode.spec.ts, because it needs to use a different room name, and webhooksProxy is only
+// setup for the default room name.
+describe('Setting passcode through settings provisioning', () => {
+ it('With an invalid passcode', async () => {
+ ctx.webhooksProxy.defaultMeetingSettings = {
+ passcode: 'passcode-must-be-digits-only'
+ };
+
+ const p = await joinMuc('p1', t({ room: ctx.roomName }), ctx.roomName);
+
+ // The settings provisioning contains an invalid passcode, the expected result is that the room is not
+ // configured to require a passcode.
+ await p.waitToJoinMUC();
+ expect(await p.isInMuc()).toBe(true);
+ expect(await p.getPasswordDialog().isOpen()).toBe(false);
+ });
+});
diff --git a/tests/specs/jaas/visitors/visitorTokens.spec.ts b/tests/specs/jaas/visitors/visitorTokens.spec.ts
index e52bd28ea8..926f547cb2 100644
--- a/tests/specs/jaas/visitors/visitorTokens.spec.ts
+++ b/tests/specs/jaas/visitors/visitorTokens.spec.ts
@@ -45,8 +45,6 @@ describe('Visitors triggered by visitor tokens', () => {
expect(await v.isVisitor()).toBe(true);
console.log('Visitor joined');
- await p.hangup();
-
// Joining with a participant token after visitors...:mindblown:
const v2 = await joinMuc(
'p2',