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);
};
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) => {
expect(response.status).toBe(200);
expect(response.body).toEqual(

View File

@ -10,6 +10,7 @@ import {
startTestServer
} from '../../../helpers/request-helpers.js';
import { setupSingleRoomWithRecording } from '../../../helpers/test-scenarios.js';
import { expectValidGetRecordingUrlResponse } from '../../../helpers/assertion-helpers.js';
describe('Recording API Tests', () => {
let app: Express;
@ -31,14 +32,12 @@ describe('Recording API Tests', () => {
describe('Get Recording URL Tests', () => {
it('should get public recording URL', async () => {
const response = await getRecordingUrl(recordingId);
expect(response.status).toBe(200);
const recordingUrl = response.body.url;
expect(recordingUrl).toBeDefined();
expectValidGetRecordingUrlResponse(response, recordingId);
// 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;
// Verify that the URL is publicly accessible
const publicResponse = await request(app).get(recordingPath);
expect(publicResponse.status).toBe(200);
@ -46,17 +45,15 @@ describe('Recording API Tests', () => {
it('should get private recording URL', async () => {
const response = await getRecordingUrl(recordingId, true);
expect(response.status).toBe(200);
const recordingUrl = response.body.url;
expect(recordingUrl).toBeDefined();
expectValidGetRecordingUrlResponse(response, recordingId);
// 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;
// Verify that the URL is not publicly accessible
const publicResponse = await request(app).get(recordingPath);
expect(publicResponse.status).toBe(401);
// Verify that the URL is not publicly accessible
const publicResponse = await request(app).get(recordingPath);
expect(publicResponse.status).toBe(401);
});
it('should fail with a 404 error when the recording does not exist', async () => {

View File

@ -525,7 +525,11 @@ describe('Recording API Security Tests', () => {
const recordingUrl = recordingUrlResponse.body.url;
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);
});
@ -535,7 +539,11 @@ describe('Recording API Security Tests', () => {
const recordingUrl = recordingUrlResponse.body.url;
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);
});
@ -545,7 +553,11 @@ describe('Recording API Security Tests', () => {
const recordingUrl = recordingUrlResponse.body.url;
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);
});