From 7bffed69f021f32bca545cc4bfbe6b2c1ad6b6c6 Mon Sep 17 00:00:00 2001 From: juancarmore Date: Thu, 14 Aug 2025 13:51:55 +0200 Subject: [PATCH] tests: update participant token tests to include participantIdentity parameter --- backend/tests/helpers/assertion-helpers.ts | 17 +++++++- .../api/participants/generate-token.test.ts | 1 + .../api/participants/refresh-token.test.ts | 41 +++++++++++++++---- .../api/security/participant-security.test.ts | 27 ++++++++---- 4 files changed, 66 insertions(+), 20 deletions(-) diff --git a/backend/tests/helpers/assertion-helpers.ts b/backend/tests/helpers/assertion-helpers.ts index c8856fa..1e8c46f 100644 --- a/backend/tests/helpers/assertion-helpers.ts +++ b/backend/tests/helpers/assertion-helpers.ts @@ -492,7 +492,11 @@ export const expectValidRoomRoleAndPermissionsResponse = ( }); }; -export const getPermissions = (roomId: string, role: ParticipantRole, addJoinPermission = true): ParticipantPermissions => { +export const getPermissions = ( + roomId: string, + role: ParticipantRole, + addJoinPermission = true +): ParticipantPermissions => { switch (role) { case ParticipantRole.MODERATOR: return { @@ -536,6 +540,7 @@ export const expectValidParticipantTokenResponse = ( roomId: string, participantRole: ParticipantRole, participantName?: string, + participantIdentity?: string, otherRoles: ParticipantRole[] = [] ) => { expect(response.status).toBe(200); @@ -558,8 +563,16 @@ export const expectValidParticipantTokenResponse = ( } if (participantName) { - expect(decodedToken).toHaveProperty('sub', participantName); + expect(decodedToken).toHaveProperty('name', participantName); + expect(decodedToken).toHaveProperty('sub'); + + if (participantIdentity) { + expect(decodedToken.sub).toBe(participantIdentity); + } else { + expect(decodedToken.sub).toContain(participantName.replace(/\s+/g, '')); // Ensure sub contains the name without spaces + } } else { + expect(decodedToken).not.toHaveProperty('name'); expect(decodedToken).not.toHaveProperty('sub'); } diff --git a/backend/tests/integration/api/participants/generate-token.test.ts b/backend/tests/integration/api/participants/generate-token.test.ts index 34f051c..541608e 100644 --- a/backend/tests/integration/api/participants/generate-token.test.ts +++ b/backend/tests/integration/api/participants/generate-token.test.ts @@ -82,6 +82,7 @@ describe('Participant API Tests', () => { roomData.room.roomId, ParticipantRole.SPEAKER, `${participantName}_SPEAKER`, + undefined, [ParticipantRole.MODERATOR] ); }); diff --git a/backend/tests/integration/api/participants/refresh-token.test.ts b/backend/tests/integration/api/participants/refresh-token.test.ts index d5f54d4..9e65b4a 100644 --- a/backend/tests/integration/api/participants/refresh-token.test.ts +++ b/backend/tests/integration/api/participants/refresh-token.test.ts @@ -41,7 +41,8 @@ describe('Participant API Tests', () => { { roomId: roomData.room.roomId, secret: roomData.moderatorSecret, - participantName + participantName, + participantIdentity: participantName }, roomData.moderatorCookie ); @@ -49,6 +50,7 @@ describe('Participant API Tests', () => { response, roomData.room.roomId, ParticipantRole.MODERATOR, + participantName, participantName ); }); @@ -58,7 +60,8 @@ describe('Participant API Tests', () => { { roomId: roomData.room.roomId, secret: roomData.speakerSecret, - participantName + participantName, + participantIdentity: participantName }, roomData.speakerCookie ); @@ -66,6 +69,7 @@ describe('Participant API Tests', () => { response, roomData.room.roomId, ParticipantRole.SPEAKER, + participantName, participantName ); }); @@ -75,7 +79,8 @@ describe('Participant API Tests', () => { { roomId: roomData.room.roomId, secret: 'invalid_secret', - participantName + participantName, + participantIdentity: participantName }, roomData.moderatorCookie ); @@ -87,7 +92,8 @@ describe('Participant API Tests', () => { { roomId: roomData.room.roomId, secret: roomData.moderatorSecret, - participantName + participantName, + participantIdentity: participantName }, '' ); @@ -95,13 +101,26 @@ describe('Participant API Tests', () => { expect(response.body.message).toBe('No participant token provided'); }); + it('should fail with 400 when participantIdentity is not provided', async () => { + const response = await refreshParticipantToken( + { + roomId: roomData.room.roomId, + secret: 'invalid_secret', + participantName + }, + roomData.moderatorCookie + ); + expect(response.status).toBe(400); + }); + it('should fail with 404 when participant does not exist in the room', async () => { const newRoomData = await setupSingleRoom(); const response = await refreshParticipantToken( { roomId: newRoomData.room.roomId, secret: newRoomData.moderatorSecret, - participantName + participantName, + participantIdentity: participantName }, roomData.moderatorCookie ); @@ -113,7 +132,8 @@ describe('Participant API Tests', () => { { roomId: 'non_existent_room', secret: roomData.moderatorSecret, - participantName + participantName, + participantIdentity: participantName }, roomData.moderatorCookie ); @@ -126,7 +146,8 @@ describe('Participant API Tests', () => { const response = await refreshParticipantToken( { secret: roomData.moderatorSecret, - participantName + participantName, + participantIdentity: participantName }, roomData.moderatorCookie ); @@ -137,7 +158,8 @@ describe('Participant API Tests', () => { const response = await refreshParticipantToken( { roomId: roomData.room.roomId, - participantName + participantName, + participantIdentity: participantName }, roomData.moderatorCookie ); @@ -149,7 +171,8 @@ describe('Participant API Tests', () => { { roomId: roomData.room.roomId, secret: '', - participantName + participantName, + participantIdentity: participantName }, roomData.moderatorCookie ); diff --git a/backend/tests/integration/api/security/participant-security.test.ts b/backend/tests/integration/api/security/participant-security.test.ts index a884f2d..e08fc61 100644 --- a/backend/tests/integration/api/security/participant-security.test.ts +++ b/backend/tests/integration/api/security/participant-security.test.ts @@ -162,7 +162,8 @@ describe('Participant API Security Tests', () => { .send({ roomId: roomData.room.roomId, secret: roomData.speakerSecret, - participantName: PARTICIPANT_NAME + participantName: PARTICIPANT_NAME, + participantIdentity: PARTICIPANT_NAME }); expect(response.status).toBe(200); }); @@ -176,7 +177,8 @@ describe('Participant API Security Tests', () => { .send({ roomId: roomData.room.roomId, secret: roomData.moderatorSecret, - participantName: PARTICIPANT_NAME + participantName: PARTICIPANT_NAME, + participantIdentity: PARTICIPANT_NAME }); expect(response.status).toBe(200); }); @@ -190,7 +192,8 @@ describe('Participant API Security Tests', () => { .send({ roomId: roomData.room.roomId, secret: roomData.speakerSecret, - participantName: PARTICIPANT_NAME + participantName: PARTICIPANT_NAME, + participantIdentity: PARTICIPANT_NAME }); expect(response.status).toBe(200); }); @@ -204,7 +207,8 @@ describe('Participant API Security Tests', () => { .send({ roomId: roomData.room.roomId, secret: roomData.moderatorSecret, - participantName: PARTICIPANT_NAME + participantName: PARTICIPANT_NAME, + participantIdentity: PARTICIPANT_NAME }); expect(response.status).toBe(200); }); @@ -218,7 +222,8 @@ describe('Participant API Security Tests', () => { .send({ roomId: roomData.room.roomId, secret: roomData.moderatorSecret, - participantName: PARTICIPANT_NAME + participantName: PARTICIPANT_NAME, + participantIdentity: PARTICIPANT_NAME }); expect(response.status).toBe(401); }); @@ -232,7 +237,8 @@ describe('Participant API Security Tests', () => { .send({ roomId: roomData.room.roomId, secret: roomData.speakerSecret, - participantName: PARTICIPANT_NAME + participantName: PARTICIPANT_NAME, + participantIdentity: PARTICIPANT_NAME }); expect(response.status).toBe(200); }); @@ -246,7 +252,8 @@ describe('Participant API Security Tests', () => { .send({ roomId: roomData.room.roomId, secret: roomData.speakerSecret, - participantName: PARTICIPANT_NAME + participantName: PARTICIPANT_NAME, + participantIdentity: PARTICIPANT_NAME }); expect(response.status).toBe(401); }); @@ -260,7 +267,8 @@ describe('Participant API Security Tests', () => { .send({ roomId: roomData.room.roomId, secret: roomData.moderatorSecret, - participantName: PARTICIPANT_NAME + participantName: PARTICIPANT_NAME, + participantIdentity: PARTICIPANT_NAME }); expect(response.status).toBe(200); }); @@ -274,7 +282,8 @@ describe('Participant API Security Tests', () => { .send({ roomId: roomData.room.roomId, secret: roomData.moderatorSecret, - participantName: PARTICIPANT_NAME + participantName: PARTICIPANT_NAME, + participantIdentity: PARTICIPANT_NAME }); expect(response.status).toBe(401); });