From e039e48e0694753255d23b719281ca4013e71eaa Mon Sep 17 00:00:00 2001 From: juancarmore Date: Tue, 10 Jun 2025 16:27:03 +0200 Subject: [PATCH] test: update getRecordingUrl tests to use new URL format --- backend/tests/helpers/assertion-helpers.ts | 2 +- .../api/recordings/get-recording-url.test.ts | 23 ++++++++++++------- .../api/security/recording-security.test.ts | 20 ++++++++-------- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/backend/tests/helpers/assertion-helpers.ts b/backend/tests/helpers/assertion-helpers.ts index 31b6c70..7f16199 100644 --- a/backend/tests/helpers/assertion-helpers.ts +++ b/backend/tests/helpers/assertion-helpers.ts @@ -448,7 +448,7 @@ export const expectValidGetRecordingUrlResponse = (response: any, recordingId: s const parsedUrl = new URL(recordingUrl); expect(parsedUrl.pathname).toBe( - `${INTERNAL_CONFIG.API_BASE_PATH_V1}/recordings/${recordingId}/media` + `/recording/${recordingId}` ); expect(parsedUrl.searchParams.get('secret')).toBeDefined(); }; diff --git a/backend/tests/integration/api/recordings/get-recording-url.test.ts b/backend/tests/integration/api/recordings/get-recording-url.test.ts index 757ff76..f798a8c 100644 --- a/backend/tests/integration/api/recordings/get-recording-url.test.ts +++ b/backend/tests/integration/api/recordings/get-recording-url.test.ts @@ -11,6 +11,7 @@ import { } from '../../../helpers/request-helpers.js'; import { setupSingleRoomWithRecording } from '../../../helpers/test-scenarios.js'; import { expectValidGetRecordingUrlResponse } from '../../../helpers/assertion-helpers.js'; +import INTERNAL_CONFIG from '../../../../src/config/internal-config.js'; describe('Recording API Tests', () => { let app: Express; @@ -30,30 +31,36 @@ describe('Recording API Tests', () => { }); describe('Get Recording URL Tests', () => { + const RECORDINGS_PATH = `${INTERNAL_CONFIG.API_BASE_PATH_V1}/recordings`; + it('should get public recording URL', async () => { const response = await getRecordingUrl(recordingId); expectValidGetRecordingUrlResponse(response, recordingId); - // Parse the URL to extract the path + // Parse the URL to extract the secret from the query parameters const parsedUrl = new URL(response.body.url); - const recordingPath = parsedUrl.pathname + parsedUrl.search; + const secret = parsedUrl.searchParams.get('secret'); // Verify that the URL is publicly accessible - const publicResponse = await request(app).get(recordingPath); - expect(publicResponse.status).toBe(200); + const recordingResponse = await request(app).get( + `${RECORDINGS_PATH}/${recordingId}/media?secret=${secret}` + ); + expect(recordingResponse.status).toBe(200); }); it('should get private recording URL', async () => { const response = await getRecordingUrl(recordingId, true); expectValidGetRecordingUrlResponse(response, recordingId); - // Parse the URL to extract the path + // Parse the URL to extract the secret from the query parameters const parsedUrl = new URL(response.body.url); - const recordingPath = parsedUrl.pathname + parsedUrl.search; + const secret = parsedUrl.searchParams.get('secret'); // Verify that the URL is not publicly accessible - const publicResponse = await request(app).get(recordingPath); - expect(publicResponse.status).toBe(401); + const recordingResponse = await request(app).get( + `${RECORDINGS_PATH}/${recordingId}/media?secret=${secret}` + ); + expect(recordingResponse.status).toBe(401); }); it('should fail with a 404 error when the recording does not exist', async () => { diff --git a/backend/tests/integration/api/security/recording-security.test.ts b/backend/tests/integration/api/security/recording-security.test.ts index babcc79..8d1ed74 100644 --- a/backend/tests/integration/api/security/recording-security.test.ts +++ b/backend/tests/integration/api/security/recording-security.test.ts @@ -525,11 +525,11 @@ describe('Recording API Security Tests', () => { const recordingUrl = recordingUrlResponse.body.url; expect(recordingUrl).toBeDefined(); - // Parse the URL to extract the path + // Parse the URL to extract the secret from the query parameters const parsedUrl = new URL(recordingUrl); - const recordingPath = parsedUrl.pathname + parsedUrl.search; + const secret = parsedUrl.searchParams.get('secret'); - const response = await request(app).get(recordingPath); + const response = await request(app).get(`${RECORDINGS_PATH}/${recordingId}/media?secret=${secret}`); expect(response.status).toBe(200); }); @@ -539,11 +539,11 @@ describe('Recording API Security Tests', () => { const recordingUrl = recordingUrlResponse.body.url; expect(recordingUrl).toBeDefined(); - // Parse the URL to extract the path + // Parse the URL to extract the secret from the query parameters const parsedUrl = new URL(recordingUrl); - const recordingPath = parsedUrl.pathname + parsedUrl.search; + const secret = parsedUrl.searchParams.get('secret'); - const response = await request(app).get(recordingPath); + const response = await request(app).get(`${RECORDINGS_PATH}/${recordingId}/media?secret=${secret}`); expect(response.status).toBe(401); }); @@ -553,11 +553,13 @@ describe('Recording API Security Tests', () => { const recordingUrl = recordingUrlResponse.body.url; expect(recordingUrl).toBeDefined(); - // Parse the URL to extract the path + // Parse the URL to extract the secret from the query parameters const parsedUrl = new URL(recordingUrl); - const recordingPath = parsedUrl.pathname + parsedUrl.search; + const secret = parsedUrl.searchParams.get('secret'); - const response = await request(app).get(recordingPath).set('Cookie', adminCookie); + const response = await request(app) + .get(`${RECORDINGS_PATH}/${recordingId}/media?secret=${secret}`) + .set('Cookie', adminCookie); expect(response.status).toBe(200); });