import { describe, it, expect, beforeEach, afterEach } from 'vitest'; import request from 'supertest'; import { initDb, closeDb, setActiveTenant } from '../../src/db.js'; import path from 'path'; import os from 'os'; import fs from 'fs'; let dbPath: string; let app: any; beforeEach(async () => { dbPath = path.join(os.tmpdir(), `excalidraw-security-test-${Date.now()}-${Math.random().toString(36).slice(2)}.db`); initDb(dbPath); setActiveTenant('default'); const mod = await import('../../src/server.js'); app = mod.default; }); afterEach(() => { closeDb(); for (const suffix of ['', '-wal', '-shm']) { try { fs.unlinkSync(dbPath + suffix); } catch {} } }); // ─── Input Validation ─────────────────────────────────────── describe('Input validation - element creation', () => { it('rejects element with missing type', async () => { const res = await request(app) .post('/api/elements') .send({ x: 0, y: 0, width: 100, height: 50 }); expect(res.status).toBe(400); }); it('rejects element with invalid type', async () => { const res = await request(app) .post('/api/elements') .send({ type: 'malicious