test-spiderfoot-endpoints.js•2.21 kB
// Test script to verify SpiderFoot API endpoints
import axios from 'axios';
const SPIDERFOOT_URL = 'http://localhost:5001';
async function testEndpoint(endpoint, method = 'GET', params = {}) {
try {
console.log(`\n=== Testing ${method} ${endpoint} ===`);
const config = {
method,
url: `${SPIDERFOOT_URL}${endpoint}`,
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
params: method === 'GET' ? params : undefined,
data: method !== 'GET' ? params : undefined
};
const response = await axios(config);
console.log('Status:', response.status);
console.log('Response:', response.data);
return response.data;
} catch (error) {
console.error(`Error testing ${endpoint}:`);
if (error.response) {
console.error('Status:', error.response.status);
console.error('Data:', error.response.data);
} else if (error.request) {
console.error('No response received:', error.request);
} else {
console.error('Error:', error.message);
}
return null;
}
}
async function runTests() {
try {
// 1. Test ping endpoint
await testEndpoint('/ping');
// 2. Test modules endpoint
await testEndpoint('/modules');
// 3. Test event types endpoint
await testEndpoint('/eventtypes');
// 4. Test scan creation
const scanData = {
scantarget: 'example.com',
modulelist: 'sfp_dnsresolve,sfp_dnsbrute',
scantype: 'domain',
usecase: 'all'
};
const scanResult = await testEndpoint('/startscan', 'POST', scanData);
if (scanResult && scanResult.scanId) {
const scanId = scanResult.scanId;
// 5. Test getting scan status
await testEndpoint('/scanstatus', 'GET', { id: scanId });
// 6. Test getting scan results
await testEndpoint('/scanresults', 'GET', { id: scanId, type: 'summary' });
// 7. Test getting scan logs
await testEndpoint('/scanlog', 'GET', { id: scanId });
}
console.log('\n=== All tests completed ===');
} catch (error) {
console.error('Test failed:', error.message);
}
}
runTests();