agmission/Development/server/tests/test_satloc_auth.js

87 lines
2.7 KiB
JavaScript

#!/usr/bin/env node
'use strict';
/**
* Test script to verify SatLoc authentication credentials
*/
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');
async function testSatLocAuth() {
try {
console.log('Testing SatLoc authentication...');
// Connect to database
await mongoose.connection.asPromise();
console.log('Database connected');
// Find SatLoc partner system user
const customerId = '6786d7df571d92737ef69e51'; // From the logs
const partnerSystemUser = await PartnerSystemUser.findOne({
customer: customerId,
kind: UserTypes.PARTNER_SYSTEM_USER
});
if (!partnerSystemUser) {
console.error('No SatLoc partner system user found');
process.exit(1);
}
console.log('Partner System User found:', {
id: partnerSystemUser._id,
customer: partnerSystemUser.customer,
partnerUsername: partnerSystemUser.partnerUsername,
username: partnerSystemUser.username,
hasPassword: !!partnerSystemUser.password,
passwordLength: partnerSystemUser.password?.length,
active: partnerSystemUser.active
});
// Get credentials via partner config
const credentials = partnerConfig.getApiCredentials(partnerSystemUser, 'SATLOC');
console.log('Credentials extracted:', {
username: credentials.username,
hasPassword: !!credentials.password,
passwordLength: credentials.password?.length,
endpoint: credentials.endpoint,
authMethod: credentials.authMethod
});
// Test the working format you provided
const BASE_URL = 'https://www.satloccloudfc.com/api/Satloc';
const AUTH = '/AuthenticateAPIUser';
const username = credentials.username;
const password = credentials.password;
console.log('\nTesting with your working format:');
console.log(`URL: ${BASE_URL}${AUTH}?userLogin=${username}&password=${password.substring(0, 3)}***`);
try {
const response = await axios(`${BASE_URL}${AUTH}?userLogin=${username}&password=${password}`);
console.log('SUCCESS! Authentication worked:', {
status: response.status,
data: response.data
});
} catch (error) {
console.log('FAILED! Authentication error:', {
status: error.response?.status,
statusText: error.response?.statusText,
data: error.response?.data,
message: error.message
});
}
process.exit(0);
} catch (error) {
console.error('Test failed:', error);
process.exit(1);
}
}
testSatLocAuth();