test-scan-flow.js•2.77 kB
// Test script for SpiderFoot scan flow
import SpiderFootClient from './spiderfoot-direct-client.js';
async function testScanFlow() {
const client = new SpiderFootClient();
try {
console.log('=== Testing SpiderFoot Scan Flow ===');
// 1. Ping the server
console.log('\n1. Pinging server...');
const ping = await client.ping();
console.log('Server response:', ping);
// 2. List available modules
console.log('\n2. Fetching available modules...');
const modules = await client.listModules();
console.log(`Found ${Object.keys(modules).length} modules`);
// 3. Start a new scan
console.log('\n3. Starting a new scan...');
const target = 'example.com'; // Test with a safe target
const modulesToUse = 'sfp_dnsresolve,sfp_dnsbrute';
const scanName = `test-scan-${Date.now()}`;
console.log(`Starting scan on ${target} with modules: ${modulesToUse}`);
const scanResult = await client.startScan(target, modulesToUse, scanName, 'domain');
console.log('Scan started:', scanResult);
if (scanResult.status === 'ERROR') {
throw new Error(`Failed to start scan: ${scanResult.error}`);
}
const scanId = scanResult.scanId;
console.log(`Scan ID: ${scanId}`);
// 4. Monitor scan status
console.log('\n4. Monitoring scan status (press Ctrl+C to stop)...');
const checkStatus = async () => {
const status = await client.getScanStatus(scanId);
console.log('Scan status:', status);
return status.status === 'FINISHED' || status.status === 'ERROR';
};
// Check status every 5 seconds
const interval = setInterval(async () => {
try {
const isDone = await checkStatus();
if (isDone) {
clearInterval(interval);
// 5. Get scan results
console.log('\n5. Fetching scan results...');
const results = await client.getScanResults(scanId, 'summary');
console.log('Scan results:', results);
// 6. Get scan logs
console.log('\n6. Fetching scan logs...');
const logs = await client.getScanLogs(scanId);
console.log('Scan logs:', logs);
console.log('\n✅ Scan flow test completed successfully!');
}
} catch (error) {
console.error('Error monitoring scan:', error.message);
clearInterval(interval);
}
}, 5000);
// Stop monitoring after 5 minutes
setTimeout(() => {
clearInterval(interval);
console.log('\n⏱️ Monitoring stopped after 5 minutes');
}, 5 * 60 * 1000);
} catch (error) {
console.error('\n❌ Test failed:', error.message);
process.exit(1);
}
}
testScanFlow();