test: enhance security middleware and token management tests

- Added comprehensive test coverage for TokenManager encryption and validation methods
- Implemented detailed test scenarios for security middleware functions
- Updated test cases to handle edge cases and improve input validation
- Refactored test mocks to provide more robust and realistic testing environment
- Improved error handling and input validation in security-related components
This commit is contained in:
jango-blockchained
2025-02-03 18:44:38 +01:00
parent 4e89e5458c
commit d17d881e7b
12 changed files with 658 additions and 428 deletions

View File

@@ -3,15 +3,15 @@ import express from 'express';
import request from 'supertest';
import { config } from 'dotenv';
import { resolve } from 'path';
import type { Entity } from '../../src/types/hass';
import { TokenManager } from '../../src/security/index';
import { MCP_SCHEMA } from '../../src/mcp/schema';
import type { Entity } from '../../src/types/hass.js';
import { TokenManager } from '../../src/security/index.js';
import { MCP_SCHEMA } from '../../src/mcp/schema.js';
// Load test environment variables
config({ path: resolve(process.cwd(), '.env.test') });
// Mock dependencies
jest.mock('../../src/security/index', () => ({
jest.mock('../../src/security/index.js', () => ({
TokenManager: {
validateToken: jest.fn().mockImplementation((token) => token === 'valid-test-token'),
},
@@ -39,7 +39,7 @@ const mockEntity: Entity = {
};
// Mock Home Assistant module
jest.mock('../../src/hass/index');
jest.mock('../../src/hass/index.js');
// Mock LiteMCP
jest.mock('litemcp', () => ({