test: add validation checks for recording URL responses and refactor related tests

This commit is contained in:
juancarmore 2025-06-10 12:49:19 +02:00
parent 3a28936ca3
commit 082bea9b5e
3 changed files with 36 additions and 15 deletions

View File

@ -441,6 +441,18 @@ export const expectSuccessListRecordingResponse = (
expect(response.body.pagination.maxItems).toBe(maxItems); expect(response.body.pagination.maxItems).toBe(maxItems);
}; };
export const expectValidGetRecordingUrlResponse = (response: any, recordingId: string) => {
expect(response.status).toBe(200);
const recordingUrl = response.body.url;
expect(recordingUrl).toBeDefined();
const parsedUrl = new URL(recordingUrl);
expect(parsedUrl.pathname).toBe(
`${INTERNAL_CONFIG.API_BASE_PATH_V1}/recordings/${recordingId}/media`
);
expect(parsedUrl.searchParams.get('secret')).toBeDefined();
};
export const expectValidRoomRolesAndPermissionsResponse = (response: any, roomId: string) => { export const expectValidRoomRolesAndPermissionsResponse = (response: any, roomId: string) => {
expect(response.status).toBe(200); expect(response.status).toBe(200);
expect(response.body).toEqual( expect(response.body).toEqual(

View File

@ -10,6 +10,7 @@ import {
startTestServer startTestServer
} from '../../../helpers/request-helpers.js'; } from '../../../helpers/request-helpers.js';
import { setupSingleRoomWithRecording } from '../../../helpers/test-scenarios.js'; import { setupSingleRoomWithRecording } from '../../../helpers/test-scenarios.js';
import { expectValidGetRecordingUrlResponse } from '../../../helpers/assertion-helpers.js';
describe('Recording API Tests', () => { describe('Recording API Tests', () => {
let app: Express; let app: Express;
@ -31,12 +32,10 @@ describe('Recording API Tests', () => {
describe('Get Recording URL Tests', () => { describe('Get Recording URL Tests', () => {
it('should get public recording URL', async () => { it('should get public recording URL', async () => {
const response = await getRecordingUrl(recordingId); const response = await getRecordingUrl(recordingId);
expect(response.status).toBe(200); expectValidGetRecordingUrlResponse(response, recordingId);
const recordingUrl = response.body.url;
expect(recordingUrl).toBeDefined();
// Parse the URL to extract the path // Parse the URL to extract the path
const parsedUrl = new URL(recordingUrl); const parsedUrl = new URL(response.body.url);
const recordingPath = parsedUrl.pathname + parsedUrl.search; const recordingPath = parsedUrl.pathname + parsedUrl.search;
// Verify that the URL is publicly accessible // Verify that the URL is publicly accessible
@ -46,12 +45,10 @@ describe('Recording API Tests', () => {
it('should get private recording URL', async () => { it('should get private recording URL', async () => {
const response = await getRecordingUrl(recordingId, true); const response = await getRecordingUrl(recordingId, true);
expect(response.status).toBe(200); expectValidGetRecordingUrlResponse(response, recordingId);
const recordingUrl = response.body.url;
expect(recordingUrl).toBeDefined();
// Parse the URL to extract the path // Parse the URL to extract the path
const parsedUrl = new URL(recordingUrl); const parsedUrl = new URL(response.body.url);
const recordingPath = parsedUrl.pathname + parsedUrl.search; const recordingPath = parsedUrl.pathname + parsedUrl.search;
// Verify that the URL is not publicly accessible // Verify that the URL is not publicly accessible

View File

@ -525,7 +525,11 @@ describe('Recording API Security Tests', () => {
const recordingUrl = recordingUrlResponse.body.url; const recordingUrl = recordingUrlResponse.body.url;
expect(recordingUrl).toBeDefined(); expect(recordingUrl).toBeDefined();
const response = await request(app).get(recordingUrl); // Parse the URL to extract the path
const parsedUrl = new URL(recordingUrl);
const recordingPath = parsedUrl.pathname + parsedUrl.search;
const response = await request(app).get(recordingPath);
expect(response.status).toBe(200); expect(response.status).toBe(200);
}); });
@ -535,7 +539,11 @@ describe('Recording API Security Tests', () => {
const recordingUrl = recordingUrlResponse.body.url; const recordingUrl = recordingUrlResponse.body.url;
expect(recordingUrl).toBeDefined(); expect(recordingUrl).toBeDefined();
const response = await request(app).get(recordingUrl); // Parse the URL to extract the path
const parsedUrl = new URL(recordingUrl);
const recordingPath = parsedUrl.pathname + parsedUrl.search;
const response = await request(app).get(recordingPath);
expect(response.status).toBe(401); expect(response.status).toBe(401);
}); });
@ -545,7 +553,11 @@ describe('Recording API Security Tests', () => {
const recordingUrl = recordingUrlResponse.body.url; const recordingUrl = recordingUrlResponse.body.url;
expect(recordingUrl).toBeDefined(); expect(recordingUrl).toBeDefined();
const response = await request(app).get(recordingUrl).set('Cookie', adminCookie); // Parse the URL to extract the path
const parsedUrl = new URL(recordingUrl);
const recordingPath = parsedUrl.pathname + parsedUrl.search;
const response = await request(app).get(recordingPath).set('Cookie', adminCookie);
expect(response.status).toBe(200); expect(response.status).toBe(200);
}); });