chore: migrate project to pnpm and update workspace configuration - Added pnpm workspace configuration in pnpm-workspace.yaml to manage packages. - Updated prepare.sh script to use pnpm for installing and building packages. - Modified testapp/package.json scripts to use pnpm instead of npm. - Enhanced tsconfig.client.json and tsconfig.json with additional options and exclusions. - Updated typings README.md to reflect the use of pnpm for installation and building. streamline build process in prepare script and update dependency installation Refactor code structure for improved readability and maintainability refactor: optimize Dockerfile for better layer caching and dependency installation refactor: migrate typings from '@lib/typings/ce' to '@openvidu-meet/typings' - Updated imports across multiple components and services to use the new '@openvidu-meet/typings' package. - Removed legacy typings references and adjusted paths in the frontend and webcomponent projects. - Cleaned up the typings package structure and added build scripts for TypeScript. - Removed the sync-types.sh script as it is no longer needed with the new structure. - Updated README and package.json files to reflect the new package name and structure. feat: add nodemon configuration for API documentation updates and enhance development scripts feat: implement type checking in watch mode and update development scripts feat: enhance development scripts with wait-for-typings and watch-typings utilities fix: remove obsolete sync:backend script and enhance dev script with preserveWatchOutput option feat: enhance development scripts with typings guard and improve watch behavior Refactors build and dev scripts Simplifies and consolidates build and development-related scripts for improved maintainability. - Updates the build process to be more streamlined. - Improves the development workflow by consolidating common tasks. - Removes redundant scripts. Replaces prepare script with meet script Replaces the old `prepare.sh` script with a new `meet.sh` script to provide a more user-friendly and comprehensive interface for building and managing the project. - Integrates command-line arguments for different build targets. - Includes documentation generation for web components and REST APIs. - Provides improved error handling and user feedback. - Simplifies the build process with `pnpm`. chore: update typescript version to 5.9.2 across multiple package.json files refactor: replace constructor injection with inject function for AppDataService feat: add commands to build webcomponent and run unit tests meet.sh: add end-to-end testing support for webcomponent with optional Playwright browser installation chore: update pnpm version to 10 and streamline test commands in workflows meet.sh: rename build_webcomponent_only to build_webcomponent and streamline dependency installation gitignore: add test-results directory to ignore list meet.sh: rename build_webcomponent_only to build_webcomponent for consistency Updated pnpm-lock.yml refactor: streamline build scripts and enhance service start options in meet.sh ci: update OpenVidu Meet actions to use meet-pnpm-migration version refactor: update import paths for WebComponentCommand and WebComponentEvent to use shared typings fix: add moduleNameMapper for typings path in jest configuration fix: correct action version syntax for OpenVidu Meet setup in workflow fix: update typings imports to use shared @openvidu-meet/typings package fix: add skip-install and skip-typings options to meet.sh and update workflows meet.sh: add development mode command and update start services options fix: format code in meeting.component.ts and remove unused export in public-api.ts added openvidu-components-angular to the local workspace and watch for changes in dev mode fix: update Node.js action to v5 and streamline build steps in wc-unit-test.yaml fix: remove pnpm install from build scripts in package.json fix: update backend unit test workflow and add test unit command in meet.sh fix: update unit test command in package.json to use pnpm exec Updates import path for LiveKit permissions Updates the import path for LiveKit permissions to align with the new typings package location, ensuring the test suite remains functional after the project's dependencies are migrated. fix: remove redundant dependency installation and build steps in start_services function fix: update Node.js setup action version and adjust OpenVidu actions for pnpm migration fix: update tsconfig.json to exclude specific type declaration paths fix: remove deprecated dependencies and update openapi-generate-html version fix: update build messages and streamline start commands for production and CI modes fix: update OpenVidu Meet and Testapp actions to use main branch and streamline pre-startup commands Refactors type import for auth mode Updates the import path for the authentication transport mode type. This change ensures consistency across the application by using a centralized type definition. Refactors backend integration tests Streamlines the backend integration test workflow. Consolidates test jobs for better organization and efficiency. Leverages matrix testing for recordings API with different storage providers. Improves AWS runner management for recording tests. Adds artifact cleanup to prevent storage bloat. Sets up Node.js and pnpm Adds Node.js and pnpm setup steps to the integration test workflow. This enables the use of pnpm for managing dependencies during integration tests. Refactors test commands to use pnpm exec Updates the test commands in package.json to use `pnpm exec` for running Jest. This ensures that the Jest CLI is executed within the pnpm managed environment, resolving potential path and dependency issues. Refactors imports to use the new typings package Updates imports to use the new `@openvidu-meet/typings` package. Removes now-unnecessary module name mappings. This change is part of the pnpm migration, ensuring correct resolution of shared types. Enhances backend integration tests and updates Node.js setup Simplifies integration tests execution Updates integration test scripts to streamline execution. - Uses a single, parameterized script to run all backend integration tests. - Removes redundant prefixes from test script names. Refactors jest configuration to include moduleNameMapper for improved module resolution Updates Jest integration test commands to use experimental VM modules and adjusts TypeScript root directory settings for better output structure Ensures OpenVidu Meet logs are uploaded Guarantees OpenVidu Meet logs are uploaded as artifacts, regardless of test outcome. Moves log upload to ensure consistent capture, and does so for all test scenarios. Commented backend integration tests Fix build script to specify TypeScript configuration file Refactor integration test command to use pnpm bin for jest execution Update integration test commands to use relative paths for Jest execution Revert "Commented backend integration tests" This reverts commit 1da8cddb55e29036c2a816244f4bc8b665ede581. Change log upload condition to trigger on failure for OpenVidu Meet logs Add caching step for OpenVidu local deployment images in backend integration tests Revert "Add caching step for OpenVidu local deployment images in backend integration tests" This reverts commit bf4692d168c671100a88c09853a460ec5417979d. Enhance AWS runner setup with storage provider matrix and update job names for clarity Refactor AWS runner setup to separate jobs for S3, ABS, and GCS, enhancing clarity and maintainability Update README.md to enhance structure and clarity, including detailed sections on prerequisites, getting started, development, and documentation. Refactor Dockerfile and entrypoint script, remove deprecated image creation scripts, and enhance meet.sh with Docker build functionality and base href support Update README.md to reflect changes in Docker image build commands using meet.sh Update package.json to correct versioning and remove redundant entries Added browser sync for live reloading chore: update @typescript-eslint packages to version 8.46.1 in frontend and pnpm-lock.yaml fix: correct argument skipping logic and ensure typings are built in install_dependencies function Adapt project structure backend: add TypeScript type annotations for Router instances in route files fix: update path for nodemon configuration in dev:rest-api-docs script fix: update paths in webcomponent documentation generation scripts fix: update Dockerfile and entrypoint script for correct directory structure and improve error handling fix: update .dockerignore and Dockerfile for improved directory handling and permissions; add backend type checker script Added all tests files Updates OpenVidu Meet action refs to main Updates the OpenVidu Meet GitHub Action references in the CI workflows to point to the `main` branch. This ensures that the workflows use the latest version of the action.
330 lines
11 KiB
TypeScript
330 lines
11 KiB
TypeScript
import { afterAll, beforeAll, describe, expect, it } from '@jest/globals';
|
|
import { Express } from 'express';
|
|
import request from 'supertest';
|
|
import { container } from '../../../../src/config/dependency-injector.config.js';
|
|
import INTERNAL_CONFIG from '../../../../src/config/internal-config.js';
|
|
import { MeetStorageService } from '../../../../src/services/index.js';
|
|
import { expectValidationError } from '../../../helpers/assertion-helpers.js';
|
|
import {
|
|
changeAuthTransportMode,
|
|
extractCookieFromHeaders,
|
|
generateApiKey,
|
|
getApiKeys,
|
|
loginUser,
|
|
startTestServer
|
|
} from '../../../helpers/request-helpers.js';
|
|
import { AuthTransportMode } from '@openvidu-meet/typings';
|
|
|
|
const AUTH_PATH = `${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/auth`;
|
|
|
|
describe('Authentication API Tests', () => {
|
|
let app: Express;
|
|
|
|
beforeAll(() => {
|
|
app = startTestServer();
|
|
});
|
|
|
|
describe('Login Tests', () => {
|
|
it('should successfully login with valid credentials', async () => {
|
|
const response = await request(app)
|
|
.post(`${AUTH_PATH}/login`)
|
|
.send({
|
|
username: 'admin',
|
|
password: 'admin'
|
|
})
|
|
.expect(200);
|
|
|
|
expect(response.body).toHaveProperty('message');
|
|
|
|
// Check for access and refresh tokens
|
|
expect(response.body).toHaveProperty('accessToken');
|
|
expect(response.body).toHaveProperty('refreshToken');
|
|
});
|
|
|
|
it('should successfully login and set cookies in cookie mode', async () => {
|
|
// Set auth transport mode to cookie
|
|
await changeAuthTransportMode(AuthTransportMode.COOKIE);
|
|
|
|
const response = await request(app)
|
|
.post(`${AUTH_PATH}/login`)
|
|
.send({
|
|
username: 'admin',
|
|
password: 'admin'
|
|
})
|
|
.expect(200);
|
|
|
|
// Check for access and refresh token cookies
|
|
const accessTokenCookie = extractCookieFromHeaders(response, INTERNAL_CONFIG.ACCESS_TOKEN_COOKIE_NAME);
|
|
const refreshTokenCookie = extractCookieFromHeaders(response, INTERNAL_CONFIG.REFRESH_TOKEN_COOKIE_NAME);
|
|
expect(accessTokenCookie).toBeDefined();
|
|
expect(refreshTokenCookie).toBeDefined();
|
|
|
|
// Revert auth transport mode to header
|
|
await changeAuthTransportMode(AuthTransportMode.HEADER);
|
|
});
|
|
|
|
it('should return 404 for invalid credentials', async () => {
|
|
const response = await request(app)
|
|
.post(`${AUTH_PATH}/login`)
|
|
.send({
|
|
username: 'admin',
|
|
password: 'invalidpassword'
|
|
})
|
|
.expect(404);
|
|
|
|
expect(response.body).toHaveProperty('message');
|
|
expect(response.body.message).toContain('Invalid username or password');
|
|
});
|
|
|
|
it('should return 422 when username is missing', async () => {
|
|
const response = await request(app)
|
|
.post(`${AUTH_PATH}/login`)
|
|
.send({
|
|
password: 'user'
|
|
})
|
|
.expect(422);
|
|
|
|
expectValidationError(response, 'username', 'Required');
|
|
});
|
|
|
|
it('should return 422 when password is missing', async () => {
|
|
const response = await request(app)
|
|
.post(`${AUTH_PATH}/login`)
|
|
.send({
|
|
username: 'user'
|
|
})
|
|
.expect(422);
|
|
|
|
expectValidationError(response, 'password', 'Required');
|
|
});
|
|
|
|
it('should return 422 when username is too short', async () => {
|
|
const response = await request(app)
|
|
.post(`${AUTH_PATH}/login`)
|
|
.send({
|
|
username: 'usr',
|
|
password: 'user'
|
|
})
|
|
.expect(422);
|
|
|
|
expectValidationError(response, 'username', 'Username must be at least 4 characters long');
|
|
});
|
|
|
|
it('should return 422 when password is too short', async () => {
|
|
const response = await request(app)
|
|
.post(`${AUTH_PATH}/login`)
|
|
.send({
|
|
username: 'user',
|
|
password: 'usr'
|
|
})
|
|
.expect(422);
|
|
|
|
expectValidationError(response, 'password', 'Password must be at least 4 characters long');
|
|
});
|
|
});
|
|
|
|
describe('Logout Tests', () => {
|
|
it('should successfully logout', async () => {
|
|
const response = await request(app).post(`${AUTH_PATH}/logout`).expect(200);
|
|
|
|
expect(response.body).toHaveProperty('message');
|
|
expect(response.body.message).toBe('Logout successful');
|
|
});
|
|
|
|
it('should successfully logout and clear cookies in cookie mode', async () => {
|
|
// Set auth transport mode to cookie
|
|
await changeAuthTransportMode(AuthTransportMode.COOKIE);
|
|
|
|
const response = await request(app).post(`${AUTH_PATH}/logout`).expect(200);
|
|
|
|
// Check that the access and refresh token cookies are cleared
|
|
const accessTokenCookie = extractCookieFromHeaders(response, INTERNAL_CONFIG.ACCESS_TOKEN_COOKIE_NAME);
|
|
const refreshTokenCookie = extractCookieFromHeaders(response, INTERNAL_CONFIG.REFRESH_TOKEN_COOKIE_NAME);
|
|
expect(accessTokenCookie).toBeDefined();
|
|
expect(accessTokenCookie).toContain('Expires=Thu, 01 Jan 1970 00:00:00 GMT');
|
|
expect(refreshTokenCookie).toBeDefined();
|
|
expect(refreshTokenCookie).toContain('Expires=Thu, 01 Jan 1970 00:00:00 GMT');
|
|
|
|
// Revert auth transport mode to header
|
|
await changeAuthTransportMode(AuthTransportMode.HEADER);
|
|
});
|
|
});
|
|
|
|
describe('Refresh Token Tests', () => {
|
|
it('should successfully refresh token with valid refresh token', async () => {
|
|
// First, login to get a valid refresh token
|
|
const loginResponse = await request(app)
|
|
.post(`${AUTH_PATH}/login`)
|
|
.send({
|
|
username: 'admin',
|
|
password: 'admin'
|
|
})
|
|
.expect(200);
|
|
|
|
expect(loginResponse.body).toHaveProperty('refreshToken');
|
|
const refreshToken = loginResponse.body.refreshToken;
|
|
|
|
const response = await request(app)
|
|
.post(`${AUTH_PATH}/refresh`)
|
|
.set(INTERNAL_CONFIG.REFRESH_TOKEN_HEADER, `Bearer ${refreshToken}`)
|
|
.expect(200);
|
|
|
|
expect(response.body).toHaveProperty('message');
|
|
expect(response.body).toHaveProperty('accessToken');
|
|
});
|
|
|
|
it('should successfully refresh token and set new access token cookie in cookie mode', async () => {
|
|
// Set auth transport mode to cookie
|
|
await changeAuthTransportMode(AuthTransportMode.COOKIE);
|
|
|
|
// First, login to get a valid refresh token cookie
|
|
const loginResponse = await request(app)
|
|
.post(`${AUTH_PATH}/login`)
|
|
.send({
|
|
username: 'admin',
|
|
password: 'admin'
|
|
})
|
|
.expect(200);
|
|
|
|
const refreshTokenCookie = extractCookieFromHeaders(
|
|
loginResponse,
|
|
INTERNAL_CONFIG.REFRESH_TOKEN_COOKIE_NAME
|
|
);
|
|
expect(refreshTokenCookie).toBeDefined();
|
|
|
|
const response = await request(app)
|
|
.post(`${AUTH_PATH}/refresh`)
|
|
.set('Cookie', refreshTokenCookie!)
|
|
.expect(200);
|
|
|
|
// Check that a new access token cookie is set
|
|
const newAccessTokenCookie = extractCookieFromHeaders(response, INTERNAL_CONFIG.ACCESS_TOKEN_COOKIE_NAME);
|
|
expect(newAccessTokenCookie).toBeDefined();
|
|
|
|
// Revert auth transport mode to header
|
|
await changeAuthTransportMode(AuthTransportMode.HEADER);
|
|
});
|
|
|
|
it('should return 400 when no refresh token is provided', async () => {
|
|
const response = await request(app).post(`${AUTH_PATH}/refresh`).expect(400);
|
|
|
|
expect(response.body).toHaveProperty('message');
|
|
expect(response.body.message).toContain('No refresh token provided');
|
|
});
|
|
|
|
it('should return 400 when refresh token is invalid', async () => {
|
|
const response = await request(app)
|
|
.post(`${AUTH_PATH}/refresh`)
|
|
.set(INTERNAL_CONFIG.REFRESH_TOKEN_HEADER, 'Bearer invalidtoken')
|
|
.expect(400);
|
|
|
|
expect(response.body).toHaveProperty('message');
|
|
expect(response.body.message).toContain('Invalid refresh token');
|
|
});
|
|
});
|
|
|
|
describe('API Keys Management', () => {
|
|
let adminAccessToken: string;
|
|
|
|
beforeAll(async () => {
|
|
adminAccessToken = await loginUser();
|
|
});
|
|
|
|
afterAll(async () => {
|
|
// Restore API key
|
|
const storageService = container.get(MeetStorageService);
|
|
await storageService['initializeApiKey']();
|
|
});
|
|
|
|
const getRoomsWithApiKey = async (apiKey: string) => {
|
|
return request(app)
|
|
.get(`${INTERNAL_CONFIG.API_BASE_PATH_V1}/rooms`)
|
|
.set(INTERNAL_CONFIG.API_KEY_HEADER, apiKey);
|
|
};
|
|
|
|
it('should create a new API key', async () => {
|
|
const response = await request(app)
|
|
.post(`${AUTH_PATH}/api-keys`)
|
|
.set(INTERNAL_CONFIG.ACCESS_TOKEN_HEADER, adminAccessToken)
|
|
.expect(201);
|
|
|
|
expect(response.body).toHaveProperty('key');
|
|
expect(response.body).toHaveProperty('creationDate');
|
|
expect(response.body.key).toMatch(/^ovmeet-/);
|
|
|
|
// Verify the API key works by making a request to the get rooms endpoint
|
|
// using the newly created API key
|
|
const apiResponse = await getRoomsWithApiKey(response.body.key);
|
|
expect(apiResponse.status).toBe(200);
|
|
});
|
|
|
|
it('should get the list of API keys', async () => {
|
|
await generateApiKey();
|
|
const response = await getApiKeys();
|
|
|
|
expect(Array.isArray(response.body)).toBe(true);
|
|
|
|
if (response.body.length > 0) {
|
|
expect(response.body[0]).toHaveProperty('key');
|
|
expect(response.body[0]).toHaveProperty('creationDate');
|
|
}
|
|
});
|
|
|
|
it('should only exist one API key at a time', async () => {
|
|
const apiKey1 = await generateApiKey();
|
|
const apiKey2 = await generateApiKey();
|
|
const response = await getApiKeys();
|
|
|
|
expect(response.body.length).toBe(1);
|
|
expect(response.body[0].key).toBe(apiKey2); // The second key should replace the first
|
|
|
|
// Verify the first API key no longer works
|
|
let apiResponse = await getRoomsWithApiKey(apiKey1);
|
|
expect(apiResponse.status).toBe(401);
|
|
|
|
// Verify the second API key works
|
|
apiResponse = await getRoomsWithApiKey(apiKey2);
|
|
expect(apiResponse.status).toBe(200);
|
|
});
|
|
|
|
it('should delete all API keys', async () => {
|
|
const apiKey = await generateApiKey();
|
|
await request(app)
|
|
.delete(`${AUTH_PATH}/api-keys`)
|
|
.set(INTERNAL_CONFIG.ACCESS_TOKEN_HEADER, adminAccessToken)
|
|
.expect(200);
|
|
|
|
// Confirm deletion
|
|
const getResponse = await getApiKeys();
|
|
expect(getResponse.status).toBe(200);
|
|
expect(Array.isArray(getResponse.body)).toBe(true);
|
|
expect(getResponse.body.length).toBe(0);
|
|
|
|
// Verify the deleted API key no longer works
|
|
const apiResponse = await getRoomsWithApiKey(apiKey);
|
|
expect(apiResponse.status).toBe(401);
|
|
});
|
|
|
|
it('should succeed API key endpoints for authenticated admin user in cookie mode', async () => {
|
|
// Set auth transport mode to cookie
|
|
await changeAuthTransportMode(AuthTransportMode.COOKIE);
|
|
|
|
// Login as admin to get access token cookie
|
|
const adminCookie = await loginUser();
|
|
|
|
await request(app).post(`${AUTH_PATH}/api-keys`).set('Cookie', adminCookie).expect(201);
|
|
await request(app).get(`${AUTH_PATH}/api-keys`).set('Cookie', adminCookie).expect(200);
|
|
await request(app).delete(`${AUTH_PATH}/api-keys`).set('Cookie', adminCookie).expect(200);
|
|
|
|
// Revert auth transport mode to header
|
|
await changeAuthTransportMode(AuthTransportMode.HEADER);
|
|
});
|
|
|
|
it('should reject API key endpoints for unauthenticated users', async () => {
|
|
await request(app).post(`${AUTH_PATH}/api-keys`).expect(401);
|
|
await request(app).get(`${AUTH_PATH}/api-keys`).expect(401);
|
|
await request(app).delete(`${AUTH_PATH}/api-keys`).expect(401);
|
|
});
|
|
});
|
|
});
|