/** * Test Script for Installed Dependencies Scanner * Run with: npx ts-node test-installed-scanner.ts * */ import { InstalledDependenciesScanner, scanInstalledDependencies } from './src/dependencies/installed'; import { generateInstalledDependenciesSection } from './src/reports/installedDepsReportGenerator'; import * as fs from 'fs'; import * as path from 'path'; async function runTest() { console.log('š Testing Installed Dependencies Scanner\n'); console.log('='.repeat(60)); // Test with fake-node_modules folder const testPath = path.join(__dirname, 'test-samples'); console.log(`\nš Scanning test samples at: ${testPath}\n`); const scanner = new InstalledDependenciesScanner({ projectPath: testPath, foldersToScan: [path.join(testPath, 'fake-node_modules')], verbose: true, verifyIntegrity: false, // No lock file for test samples scanPostInstallScripts: true }); const result = await scanner.scan(); // Print results console.log('\n' + '='.repeat(60)); console.log('š SCAN RESULTS'); console.log('='.repeat(60)); console.log(`\nš¦ Packages scanned: ${result.stats.totalPackagesFound}`); console.log(`š Files scanned: ${result.stats.totalFilesScanned}`); console.log(`ā±ļø Duration: ${result.stats.duration}ms`); console.log('\nš¦ MALWARE FINDINGS:'); console.log('-'.repeat(40)); if (result.malwareFindings.length === 0) { console.log(' No malware detected'); } else { for (const finding of result.malwareFindings) { console.log(`\n [${finding.severity.toUpperCase()}] ${finding.title}`); console.log(` Package: ${finding.package.name}@${finding.package.version}`); console.log(` File: ${finding.filePath}`); if (finding.lineNumber) { console.log(` Line: ${finding.lineNumber}`); } console.log(` Indicators: ${finding.indicators.join(', ')}`); console.log(` Confidence: ${finding.confidence}%`); } } console.log('\n\nā ļø SUSPICIOUS POST-INSTALL SCRIPTS:'); console.log('-'.repeat(40)); if (result.suspiciousScripts.length === 0) { console.log(' No suspicious scripts detected'); } else { for (const script of result.suspiciousScripts) { console.log(`\n [${script.severity.toUpperCase()}] ${script.packageName}`); console.log(` Script type: ${script.script.type}`); console.log(` Command: ${script.script.command}`); console.log(` Risk indicators: ${script.riskIndicators.length}`); } } console.log('\n\nš SCANNED FOLDERS:'); console.log('-'.repeat(40)); for (const folder of result.scannedFolders) { console.log(`\n ${folder.path}`); console.log(` Type: ${folder.type}`); console.log(` Ecosystem: ${folder.ecosystem}`); console.log(` Packages: ${folder.packageCount}`); console.log(` Files scanned: ${folder.filesScanned}`); } // Generate HTML report section console.log('\n\nš Generating HTML report section...'); const htmlSection = generateInstalledDependenciesSection(result, 'es'); const reportPath = path.join(testPath, 'installed-deps-report.html'); const fullHtml = `