diff --git a/tests/unit/server.test.ts b/tests/unit/server.test.ts index 87359a8..5191767 100644 --- a/tests/unit/server.test.ts +++ b/tests/unit/server.test.ts @@ -209,6 +209,20 @@ describe('WebhookServer', () => { expect(mockAdd).not.toHaveBeenCalled(); }); + test('should handle requests on configured port', async () => { + const originalPort = process.env.PORT; + process.env.PORT = '3007'; + + try { + const server = await WebhookServer.start(); + const response = await fetch('http://localhost:3007/health'); + expect(response.status).toBe(200); + server.stop(); + } finally { + process.env.PORT = originalPort; + } + }); + test('should handle XSS/SQL injection attempts', async () => { const maliciousMessage = `/tarea nueva '; DROP TABLE tasks; --`; const payload = { diff --git a/tests/unit/services/webhook-manager.test.ts b/tests/unit/services/webhook-manager.test.ts index d3e9f37..ae23d2d 100644 --- a/tests/unit/services/webhook-manager.test.ts +++ b/tests/unit/services/webhook-manager.test.ts @@ -18,6 +18,28 @@ describe('WebhookManager', () => { process.env = envBackup; }); + test('should warn about missing port in internal URLs', () => { + process.env.WEBHOOK_URL = 'http://srv-captain--taskbot/webhook'; + const consoleSpy = mock(() => {}); + console.warn = consoleSpy; + + WebhookManager['validateConfig'](); + + expect(consoleSpy).toHaveBeenCalledWith( + expect.stringContaining('missing port number') + ); + }); + + test('should accept internal URLs with ports', () => { + process.env.WEBHOOK_URL = 'http://srv-captain--taskbot:3007/webhook'; + const consoleSpy = mock(() => {}); + console.warn = consoleSpy; + + WebhookManager['validateConfig'](); + + expect(consoleSpy).not.toHaveBeenCalled(); + }); + test('should create correct config structure', () => { const config = WebhookManager['getConfig'](); expect(config).toEqual({