@@ -33,35 +33,31 @@ export async function testConfig(context) {
3333 } ;
3434
3535 try {
36- //Step 1: Validate configuration values
36+ // Step 1: Validate configuration
3737 if ( ! pluginConfig . serverUrl ) {
3838 newMessage ( 'Server URL is required.' ) ;
39- log . info ( JSON . stringify ( result ) ) ;
4039 return result ;
4140 }
4241 if ( ! pluginConfig . user || ! pluginConfig . pwd || ! pluginConfig . accessID ) {
43- newMessage ( 'Missing required configuration: user, pwd, or accessID.' ) ;
44- log . info ( JSON . stringify ( result ) ) ;
42+ newMessage ( 'Missing required configuration fields.' ) ;
4543 return result ;
4644 }
4745
48- // Validate URL format
46+ // Validate URL
4947 let url ;
5048 try {
5149 url = new URL ( pluginConfig . serverUrl ) ;
5250 } catch {
53- newMessage ( `Invalid server URL: ${ pluginConfig . serverUrl } ` ) ;
54- log . info ( JSON . stringify ( result ) ) ;
51+ newMessage ( 'Invalid server URL format.' ) ;
5552 return result ;
5653 }
5754
5855 if ( url . protocol !== 'https:' ) {
59- newMessage ( 'Server URL must start with https:// for secure communication.' ) ;
60- log . info ( JSON . stringify ( result ) ) ;
56+ newMessage ( 'Server URL must begin with https://' ) ;
6157 return result ;
6258 }
6359
64- // Step 2: Test Login API directly
60+ // Step 2: Test Login API
6561 const agent = new https . Agent ( { rejectUnauthorized : false } ) ;
6662 const uname = pluginConfig . user ;
6763 const upass = Buffer . from ( pluginConfig . pwd ) . toString ( 'base64' ) ;
@@ -70,14 +66,15 @@ export async function testConfig(context) {
7066
7167 const loginUrl = `${ serverUrl } /final/eGMobileService/getLoginSquaredup?uname=${ encodeURIComponent ( uname ) } &user_from=squaredup&upass=${ encodeURIComponent ( upass ) } &accessID=${ encodeURIComponent ( accessID ) } ` ;
7268
73- log . info ( 'Testing login API' , { loginUrl } ) ;
69+ // DO NOT log full URL containing credentials
70+ log . info ( 'Testing login API (URL hidden for security)' ) ;
7471
7572 let response ;
7673 try {
7774 response = await fetch ( loginUrl , { agent, method : 'GET' } ) ;
7875 } catch ( error ) {
79- newMessage ( ` Network error contacting login API: ${ error . message } ` ) ;
80- log . info ( JSON . stringify ( result ) ) ;
76+ newMessage ( ' Network error contacting login API. Please check connectivity.' ) ;
77+ log . error ( `Network error (details hidden): ${ error . message } ` ) ;
8178 return result ;
8279 }
8380
@@ -89,43 +86,44 @@ export async function testConfig(context) {
8986 try {
9087 data = await response . json ( ) ;
9188 } catch {
92- newMessage ( 'Failed to parse JSON response from eG Innovations server.' ) ;
93- log . info ( JSON . stringify ( result ) ) ;
89+ newMessage ( 'Invalid JSON response from eG Enterprise server.' ) ;
9490 return result ;
9591 }
9692 } else {
97- newMessage ( 'Server did not return valid JSON.' ) ;
98- log . info ( JSON . stringify ( result ) ) ;
93+ newMessage ( 'Server did not return JSON.' ) ;
9994 return result ;
10095 }
10196
102- log . info ( 'Login API response' , { status, data } ) ;
97+ // Log without exposing credentials
98+ log . info ( 'Login API response received (content hidden)' ) ;
10399
104- // Step 3: Handle authentication results
100+ // Step 3: Authentication results
105101 if ( status === 200 && data . output ?. toLowerCase ( ) === 'success' ) {
106- newMessage ( 'Authentication successful. Connection to eG Innovations verified. ' , 'success' ) ;
102+ newMessage ( 'Authentication successful.' , 'success' ) ;
107103 } else if ( status === 400 || data . output ?. includes ( 'Invalid AccessID' ) ) {
108- newMessage ( 'Authentication failed: Invalid AccessID. Please provide a valid AccessID. ' ) ;
104+ newMessage ( 'Authentication failed: Invalid AccessID.' ) ;
109105 } else if ( status === 401 || data . output ?. includes ( 'Invalid username or password' ) ) {
110- newMessage ( 'Authentication failed: Invalid username or password. Please check your credentials. ' ) ;
106+ newMessage ( 'Authentication failed: Invalid username or password.' ) ;
111107 } else if ( status === 404 ) {
112- newMessage ( 'Authentication failed: Endpoint not found (404). Please verify the server URL and API path .' ) ;
108+ newMessage ( 'Authentication failed: API endpoint not found (404).' ) ;
113109 } else if ( status === 405 ) {
114- newMessage ( 'Authentication failed: Method not allowed (405). Please contact your administrator. ' ) ;
110+ newMessage ( 'Authentication failed: Method not allowed (405).' ) ;
115111 } else {
116- newMessage ( `Authentication failed: ${ status } ${ response . statusText } .` ) ;
112+ newMessage ( `Authentication failed with status ${ status } .` ) ;
117113 }
114+
118115 } catch ( error ) {
119- log . error ( ' TestConfig error' , { message : error . message , stack : error . stack } ) ;
120- newMessage ( error . message , 'error' ) ;
116+ log . error ( ` TestConfig error (hidden details): ${ error . message } ` ) ;
117+ newMessage ( 'Unexpected internal error occurred.' , 'error' ) ;
121118 }
122119
123- pluginConfig . testResult = result ;
124-
125- log . info ( JSON . stringify ( result ) ) ;
120+ // DO NOT log raw result (it may contain sensitive info)
121+ log . info ( 'TestConfig completed, result sanitized.' ) ;
122+
126123 return result ;
127124}
128125
126+
129127// ============================================================================
130128//
131129// importObjects
0 commit comments