test: add port validation tests for internal docker URLs

main
borja (aider) 3 months ago
parent 58200854bc
commit 48a238139e

@ -209,6 +209,20 @@ describe('WebhookServer', () => {
expect(mockAdd).not.toHaveBeenCalled(); 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 () => { test('should handle XSS/SQL injection attempts', async () => {
const maliciousMessage = `/tarea nueva <script>alert('xss')</script>'; DROP TABLE tasks; --`; const maliciousMessage = `/tarea nueva <script>alert('xss')</script>'; DROP TABLE tasks; --`;
const payload = { const payload = {

@ -18,6 +18,28 @@ describe('WebhookManager', () => {
process.env = envBackup; 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', () => { test('should create correct config structure', () => {
const config = WebhookManager['getConfig'](); const config = WebhookManager['getConfig']();
expect(config).toEqual({ expect(config).toEqual({

Loading…
Cancel
Save