151 lines
4.8 KiB
JavaScript
151 lines
4.8 KiB
JavaScript
#!/usr/bin/env node
|
|
'use strict';
|
|
|
|
/**
|
|
* Test script to discover actual SatLoc API error responses
|
|
* This will help us understand what errors look like in reality
|
|
*/
|
|
|
|
const axios = require('axios');
|
|
const mongoose = require('mongoose');
|
|
require('./helpers/mongo');
|
|
const { PartnerSystemUser } = require('./model/partner');
|
|
const partnerConfig = require('./helpers/partner_config');
|
|
const { UserTypes } = require('./helpers/constants');
|
|
|
|
const BASE_URL = 'https://www.satloccloudfc.com/api/Satloc';
|
|
|
|
async function testErrorScenarios() {
|
|
try {
|
|
console.log('='.repeat(80));
|
|
console.log('Testing SatLoc API Error Responses');
|
|
console.log('='.repeat(80));
|
|
|
|
// Connect to database to get real credentials
|
|
await mongoose.connection.asPromise();
|
|
console.log('✓ Database connected\n');
|
|
|
|
// Get valid credentials first
|
|
const customerId = '6786d7df571d92737ef69e51';
|
|
const partnerSystemUser = await PartnerSystemUser.findOne({
|
|
customer: customerId,
|
|
kind: UserTypes.PARTNER_SYSTEM_USER
|
|
});
|
|
|
|
let validUsername, validPassword;
|
|
if (partnerSystemUser) {
|
|
const credentials = partnerConfig.getApiCredentials(partnerSystemUser, 'SATLOC');
|
|
validUsername = credentials.username;
|
|
validPassword = credentials.password;
|
|
console.log('✓ Got valid credentials for testing\n');
|
|
} else {
|
|
console.log('⚠ No valid credentials found, using dummy data\n');
|
|
validUsername = 'test@example.com';
|
|
validPassword = 'dummy123';
|
|
}
|
|
|
|
// Test scenarios
|
|
const scenarios = [
|
|
{
|
|
name: 'Valid Credentials',
|
|
username: validUsername,
|
|
password: validPassword
|
|
},
|
|
{
|
|
name: 'Wrong Password',
|
|
username: validUsername,
|
|
password: 'WrongPassword123!@#'
|
|
},
|
|
{
|
|
name: 'Wrong Username',
|
|
username: 'nonexistent@example.com',
|
|
password: validPassword
|
|
},
|
|
{
|
|
name: 'Both Wrong',
|
|
username: 'fake@example.com',
|
|
password: 'FakePass123'
|
|
},
|
|
{
|
|
name: 'Empty Password',
|
|
username: validUsername,
|
|
password: ''
|
|
},
|
|
{
|
|
name: 'Empty Username',
|
|
username: '',
|
|
password: validPassword
|
|
},
|
|
{
|
|
name: 'Special Characters',
|
|
username: 'test<script>alert(1)</script>@test.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(` Status: ${response.status}`);
|
|
console.log(` Status Text: ${response.statusText}`);
|
|
console.log(` Headers:`, JSON.stringify(response.headers, null, 2));
|
|
console.log(` Response Data:`, JSON.stringify(response.data, null, 2));
|
|
|
|
// Check specific fields
|
|
if (response.data) {
|
|
console.log(`\n Has ErrorMessage? ${!!response.data.ErrorMessage}`);
|
|
console.log(` ErrorMessage value: ${response.data.ErrorMessage || '(none)'}`);
|
|
console.log(` Has userId? ${!!response.data.userId}`);
|
|
console.log(` Has companyId? ${!!response.data.companyId}`);
|
|
}
|
|
|
|
} catch (error) {
|
|
console.log('✗ Request threw exception');
|
|
console.log(` Error Name: ${error.name}`);
|
|
console.log(` Error Message: ${error.message}`);
|
|
|
|
if (error.response) {
|
|
console.log(` Response Status: ${error.response.status}`);
|
|
console.log(` Response Status Text: ${error.response.statusText}`);
|
|
console.log(` Response Headers:`, JSON.stringify(error.response.headers, null, 2));
|
|
console.log(` Response Data:`, JSON.stringify(error.response.data, null, 2));
|
|
} else if (error.request) {
|
|
console.log(` No response received`);
|
|
console.log(` Request:`, error.request);
|
|
} else {
|
|
console.log(` Error Details:`, error);
|
|
}
|
|
}
|
|
|
|
console.log('\n');
|
|
}
|
|
|
|
console.log('='.repeat(80));
|
|
console.log('Test Complete!');
|
|
console.log('='.repeat(80));
|
|
|
|
process.exit(0);
|
|
} catch (error) {
|
|
console.error('Test script failed:', error);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
testErrorScenarios();
|