#!/usr/bin/env node 'use strict'; /** * Test script to discover actual SatLoc API error responses * Tests with dummy credentials to see what errors look like */ const axios = require('axios'); const BASE_URL = 'https://www.satloccloudfc.com/api/Satloc'; async function testErrorScenarios() { console.log('='.repeat(80)); console.log('Testing SatLoc API Error Responses'); console.log('='.repeat(80)); console.log('This will test various error scenarios to see actual API responses\n'); // Test scenarios with intentionally wrong credentials const scenarios = [ { name: 'Wrong Username and Password', username: 'fake@example.com', password: 'FakePassword123' }, { name: 'Empty Password', username: 'test@example.com', password: '' }, { name: 'Empty Username', username: '', password: 'somePassword' }, { name: 'SQL Injection Attempt', username: "admin' OR '1'='1", password: "anything" }, { name: 'Special Characters', username: 'test@example.com', password: 'Pass"\'<>&123' } ]; for (const scenario of scenarios) { console.log('-'.repeat(80)); console.log(`Scenario: ${scenario.name}`); console.log('-'.repeat(80)); console.log(`Username: ${scenario.username}`); console.log(`Password: ${scenario.password ? scenario.password.substring(0, 3) + '***' : '(empty)'}\n`); try { // Test with axios like the actual code does const response = await axios.get(`${BASE_URL}/AuthenticateAPIUser`, { params: { userLogin: scenario.username, password: scenario.password }, timeout: 30000, validateStatus: (status) => status < 500 // Accept all responses except server errors }); console.log('✓ Request succeeded (no exception thrown)'); console.log(` HTTP Status: ${response.status}`); console.log(` Status Text: ${response.statusText}`); console.log(` Content-Type: ${response.headers['content-type']}`); // Show response data structure console.log(`\n Response Data Type: ${typeof response.data}`); console.log(` Response Data:`, JSON.stringify(response.data, null, 2)); // Check specific fields that authenticate() looks for if (response.data && typeof response.data === 'object') { console.log(`\n Analysis:`); console.log(` - Has ErrorMessage? ${!!response.data.ErrorMessage}`); console.log(` - ErrorMessage: "${response.data.ErrorMessage || '(none)'}"`); console.log(` - Has userId? ${!!response.data.userId}`); console.log(` - Has companyId? ${!!response.data.companyId}`); console.log(` - Has email? ${!!response.data.email}`); // Show what authenticate() would do if (!response.data || response.data.ErrorMessage) { console.log(`\n ⚠ authenticate() would REJECT this (has ErrorMessage or no data)`); } else if (response.data.userId && response.data.companyId) { console.log(`\n ✓ authenticate() would ACCEPT this (has userId and companyId)`); } } } catch (error) { console.log('✗ Request threw exception'); console.log(` Error Name: ${error.name}`); console.log(` Error Message: ${error.message}`); console.log(` Error Code: ${error.code || '(none)'}`); if (error.response) { console.log(`\n Response received:`); console.log(` Status: ${error.response.status}`); console.log(` Status Text: ${error.response.statusText}`); console.log(` Content-Type: ${error.response.headers['content-type']}`); console.log(` Data Type: ${typeof error.response.data}`); console.log(` Data:`, JSON.stringify(error.response.data, null, 2)); } else if (error.request) { console.log(`\n No response received (network/timeout error)`); } } console.log('\n'); // Small delay between requests to be nice to their server await new Promise(resolve => setTimeout(resolve, 1000)); } console.log('='.repeat(80)); console.log('Test Complete!'); console.log('='.repeat(80)); console.log('\nSummary:'); console.log('- Check which scenarios returned ErrorMessage field'); console.log('- Check HTTP status codes for auth failures'); console.log('- Check response structure for errors vs success'); } testErrorScenarios() .then(() => process.exit(0)) .catch(error => { console.error('Test failed:', error); process.exit(1); });