import { describe, it, expect } from 'vitest'; import { phishingDetector } from '../src/lib/phishing-detector'; import { UrlVerdict, ThreatType } from '../src/types'; describe('PhishingDetector (cache test)', () => { describe('analyzeUrl', () => { it('should return SAFE for legitimate URLs', () => { const result = phishingDetector.analyzeUrl('https://www.google.com/search?q=test'); expect(result.verdict).toBe(UrlVerdict.SAFE); }); it('should detect suspicious TLD', () => { const result = phishingDetector.analyzeUrl('https://free-prize.tk/claim'); expect(result.threats.some((t) => t.type === ThreatType.DOMAIN_AGE)).toBe(true); }); it('should detect typosquatting', () => { const result = phishingDetector.analyzeUrl('https://goggle.com/login'); expect(result.threats.some((t) => t.type === ThreatType.TYPOSQUAT)).toBe(true); }); it('should detect IP address hostname', () => { const result = phishingDetector.analyzeUrl('http://192.168.1.100/admin'); expect(result.threats.some((t) => t.type === ThreatType.PHISHING_HEURISTIC)).toBe(true); }); it('should detect phishing pattern in hostname', () => { const result = phishingDetector.analyzeUrl('https://login-secure-portal.xyz/account'); expect(result.threats.some((t) => t.type === ThreatType.PHISHING_HEURISTIC)).toBe(true); }); it('should detect HTTP protocol', () => { const result = phishingDetector.analyzeUrl('http://example.com/login'); expect(result.threats.some((t) => t.type === ThreatType.MIXED_CONTENT)).toBe(true); }); it('should return UNKNOWN for malformed URLs', () => { const result = phishingDetector.analyzeUrl('not-a-real-url'); expect(result.verdict).toBe(UrlVerdict.UNKNOWN); }); }); });