From 13e651cf8dfe3de4721d7bf570eda68325faf6cb Mon Sep 17 00:00:00 2001 From: juancarmore Date: Thu, 19 Jun 2025 12:20:49 +0200 Subject: [PATCH] test: streamline password reset logic in user security tests and update change password method to use MEET_ADMIN_SECRET --- backend/tests/helpers/assertion-helpers.ts | 8 ++------ .../integration/api/security/user-security.test.ts | 14 +++++++++----- .../integration/api/users/change-password.test.ts | 3 ++- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/backend/tests/helpers/assertion-helpers.ts b/backend/tests/helpers/assertion-helpers.ts index 7f16199..3b62083 100644 --- a/backend/tests/helpers/assertion-helpers.ts +++ b/backend/tests/helpers/assertion-helpers.ts @@ -9,8 +9,6 @@ import { ParticipantRole } from '../../src/typings/ce'; -const RECORDINGS_PATH = `${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/recordings`; - export const expectErrorResponse = ( response: any, status = 422, @@ -445,11 +443,9 @@ export const expectValidGetRecordingUrlResponse = (response: any, recordingId: s expect(response.status).toBe(200); const recordingUrl = response.body.url; expect(recordingUrl).toBeDefined(); - + const parsedUrl = new URL(recordingUrl); - expect(parsedUrl.pathname).toBe( - `/recording/${recordingId}` - ); + expect(parsedUrl.pathname).toBe(`/recording/${recordingId}`); expect(parsedUrl.searchParams.get('secret')).toBeDefined(); }; diff --git a/backend/tests/integration/api/security/user-security.test.ts b/backend/tests/integration/api/security/user-security.test.ts index 87ef8fa..c4c93e3 100644 --- a/backend/tests/integration/api/security/user-security.test.ts +++ b/backend/tests/integration/api/security/user-security.test.ts @@ -1,8 +1,9 @@ -import { beforeAll, describe, expect, it } from '@jest/globals'; +import { afterEach, beforeAll, describe, expect, it } from '@jest/globals'; import { Express } from 'express'; import request from 'supertest'; import INTERNAL_CONFIG from '../../../../src/config/internal-config.js'; -import { loginUser, startTestServer } from '../../../helpers/request-helpers.js'; +import { MEET_ADMIN_SECRET } from '../../../../src/environment.js'; +import { changePassword, loginUser, startTestServer } from '../../../helpers/request-helpers.js'; const USERS_PATH = `${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/users`; @@ -42,6 +43,11 @@ describe('User API Security Tests', () => { adminCookie = await loginUser(); }); + afterEach(async () => { + // Reset password + await changePassword(MEET_ADMIN_SECRET, adminCookie); + }); + it('should succeed when user is authenticated as admin', async () => { const response = await request(app) .post(`${USERS_PATH}/change-password`) @@ -51,9 +57,7 @@ describe('User API Security Tests', () => { }); it('should fail when user is not authenticated', async () => { - const response = await request(app) - .post(`${USERS_PATH}/change-password`) - .send(changePasswordRequest); + const response = await request(app).post(`${USERS_PATH}/change-password`).send(changePasswordRequest); expect(response.status).toBe(401); }); }); diff --git a/backend/tests/integration/api/users/change-password.test.ts b/backend/tests/integration/api/users/change-password.test.ts index 82a8bd7..a3a9dc6 100644 --- a/backend/tests/integration/api/users/change-password.test.ts +++ b/backend/tests/integration/api/users/change-password.test.ts @@ -1,4 +1,5 @@ import { afterEach, beforeAll, describe, expect, it } from '@jest/globals'; +import { MEET_ADMIN_SECRET } from '../../../../src/environment.js'; import { expectValidationError } from '../../../helpers/assertion-helpers.js'; import { changePassword, loginUser, startTestServer } from '../../../helpers/request-helpers.js'; @@ -12,7 +13,7 @@ describe('Users API Tests', () => { afterEach(async () => { // Reset password - await changePassword('admin', adminCookie); + await changePassword(MEET_ADMIN_SECRET, adminCookie); }); describe('Change Password Tests', () => {