From: Jérôme Benoit Date: Tue, 31 Mar 2026 22:34:20 +0000 (+0200) Subject: refactor(log): quote and truncate all auth identifiers in log messages X-Git-Tag: ocpp-server@v4.1.1~1 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=854457bd4283388d5f5f2f1713c7e1e3a01c4a9b;p=e-mobility-charging-stations-simulator.git refactor(log): quote and truncate all auth identifiers in log messages Wrap all idTag/idToken/identifier values in single quotes and apply truncateId() consistently across OCPP 1.6, 2.0, and auth module log messages. Removes eslint-disable comments for restrict-template-expressions where ?? '' fallback eliminates the type issue. --- diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 02a33d53..eeb7655c 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -291,7 +291,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { // eslint-disable-next-line @typescript-eslint/restrict-template-expressions chargingStation.stationInfo?.chargingStationId // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - }#${connectorId?.toString()} for idTag '${idTag}'` + }#${connectorId?.toString()} for idTag '${truncateId(idTag)}'` ) } else { logger.debug( @@ -299,7 +299,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { // eslint-disable-next-line @typescript-eslint/restrict-template-expressions chargingStation.stationInfo?.chargingStationId // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - }#${connectorId?.toString()} for idTag '${idTag}'` + }#${connectorId?.toString()} for idTag '${truncateId(idTag)}'` ) } return undefined @@ -1297,7 +1297,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { `${chargingStation.logPrefix()} ${moduleName}.handleRequestRemoteStartTransaction: Remote start transaction ACCEPTED on ${ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions chargingStation.stationInfo?.chargingStationId - }#${transactionConnectorId.toString()}, idTag '${idTag}'` + }#${transactionConnectorId.toString()}, idTag '${truncateId(idTag)}'` ) return OCPP16Constants.OCPP_RESPONSE_ACCEPTED } @@ -1617,7 +1617,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { `${chargingStation.logPrefix()} ${moduleName}.notifyRemoteStartTransactionRejected: Remote start transaction REJECTED on ${ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions chargingStation.stationInfo?.chargingStationId - }#${connectorId.toString()}, idTag '${idTag}', availability '${ + }#${connectorId.toString()}, idTag '${truncateId(idTag)}', availability '${ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions connectorStatus?.availability // eslint-disable-next-line @typescript-eslint/restrict-template-expressions diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index 50f37e87..9ecc9d29 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -172,9 +172,9 @@ export class OCPP16ResponseService extends OCPPResponseService { if (payload.idTagInfo.status === OCPP16AuthorizationStatus.ACCEPTED) { authorizeConnectorStatus.idTagAuthorized = true logger.debug( - `${chargingStation.logPrefix()} ${moduleName}.handleResponseAuthorize: idTag '${ + `${chargingStation.logPrefix()} ${moduleName}.handleResponseAuthorize: idTag '${truncateId( requestPayload.idTag - }' accepted on connector id ${authorizeConnectorId.toString()}` + )}' accepted on connector id ${authorizeConnectorId.toString()}` ) } else { authorizeConnectorStatus.idTagAuthorized = false @@ -188,9 +188,9 @@ export class OCPP16ResponseService extends OCPPResponseService { } } else { logger.warn( - `${chargingStation.logPrefix()} ${moduleName}.handleResponseAuthorize: idTag '${ + `${chargingStation.logPrefix()} ${moduleName}.handleResponseAuthorize: idTag '${truncateId( requestPayload.idTag - }' has no authorize request pending` + )}' has no authorize request pending` ) } OCPP16ServiceUtils.updateAuthorizationCache( @@ -278,10 +278,9 @@ export class OCPP16ResponseService extends OCPPResponseService { connectorStatus.idTagLocalAuthorized === false ) { logger.warn( - `${chargingStation.logPrefix()} ${moduleName}.handleResponseStartTransaction: Trying to start a transaction with a not local authorized idTag ${ - // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - connectorStatus.localAuthorizeIdTag - } on connector id ${connectorId.toString()}` + `${chargingStation.logPrefix()} ${moduleName}.handleResponseStartTransaction: Trying to start a transaction with a not local authorized idTag '${truncateId( + connectorStatus.localAuthorizeIdTag ?? '' + )}' on connector id ${connectorId.toString()}` ) await this.resetConnectorOnStartTransactionError(chargingStation, connectorId) return @@ -294,10 +293,9 @@ export class OCPP16ResponseService extends OCPPResponseService { connectorStatus.idTagAuthorized === false ) { logger.warn( - `${chargingStation.logPrefix()} ${moduleName}.handleResponseStartTransaction: Trying to start a transaction with a not authorized idTag ${ - // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - connectorStatus.authorizeIdTag - } on connector id ${connectorId.toString()}` + `${chargingStation.logPrefix()} ${moduleName}.handleResponseStartTransaction: Trying to start a transaction with a not authorized idTag '${truncateId( + connectorStatus.authorizeIdTag ?? '' + )}' on connector id ${connectorId.toString()}` ) await this.resetConnectorOnStartTransactionError(chargingStation, connectorId) return @@ -308,11 +306,11 @@ export class OCPP16ResponseService extends OCPPResponseService { connectorStatus.authorizeIdTag !== requestPayload.idTag ) { logger.warn( - `${chargingStation.logPrefix()} ${moduleName}.handleResponseStartTransaction: Trying to start a transaction with an idTag ${ + `${chargingStation.logPrefix()} ${moduleName}.handleResponseStartTransaction: Trying to start a transaction with an idTag '${truncateId( requestPayload.idTag - } different from the authorize request one ${ - connectorStatus.authorizeIdTag - } on connector id ${connectorId.toString()}` + )}' different from the authorize request one '${truncateId( + connectorStatus.authorizeIdTag ?? '' + )}' on connector id ${connectorId.toString()}` ) await this.resetConnectorOnStartTransactionError(chargingStation, connectorId) return @@ -323,21 +321,20 @@ export class OCPP16ResponseService extends OCPPResponseService { connectorStatus.localAuthorizeIdTag !== requestPayload.idTag ) { logger.warn( - `${chargingStation.logPrefix()} ${moduleName}.handleResponseStartTransaction: Trying to start a transaction with an idTag ${ + `${chargingStation.logPrefix()} ${moduleName}.handleResponseStartTransaction: Trying to start a transaction with an idTag '${truncateId( requestPayload.idTag - } different from the local authorized one ${ - connectorStatus.localAuthorizeIdTag - } on connector id ${connectorId.toString()}` + )}' different from the local authorized one '${truncateId( + connectorStatus.localAuthorizeIdTag ?? '' + )}' on connector id ${connectorId.toString()}` ) await this.resetConnectorOnStartTransactionError(chargingStation, connectorId) return } if (connectorStatus?.transactionStarted === true) { logger.warn( - `${chargingStation.logPrefix()} ${moduleName}.handleResponseStartTransaction: Trying to start a transaction on an already used connector id ${connectorId.toString()} by idTag ${ - // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - connectorStatus.transactionIdTag - }` + `${chargingStation.logPrefix()} ${moduleName}.handleResponseStartTransaction: Trying to start a transaction on an already used connector id ${connectorId.toString()} by idTag '${truncateId( + connectorStatus.transactionIdTag ?? '' + )}'` ) return } @@ -347,10 +344,9 @@ export class OCPP16ResponseService extends OCPPResponseService { for (const [id, status] of evseStatus.connectors) { if (id !== connectorId && status.transactionStarted === true) { logger.warn( - `${chargingStation.logPrefix()} ${moduleName}.handleResponseStartTransaction: Trying to start a transaction on an already used evse id ${evseId.toString()} by connector id ${id.toString()} with idTag ${ - // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - status.transactionIdTag - }` + `${chargingStation.logPrefix()} ${moduleName}.handleResponseStartTransaction: Trying to start a transaction on an already used evse id ${evseId.toString()} by connector id ${id.toString()} with idTag '${truncateId( + status.transactionIdTag ?? '' + )}'` ) await this.resetConnectorOnStartTransactionError(chargingStation, connectorId) return @@ -399,9 +395,9 @@ export class OCPP16ResponseService extends OCPPResponseService { if (reservation != null) { if (reservation.idTag !== requestPayload.idTag) { logger.warn( - `${chargingStation.logPrefix()} ${moduleName}.handleResponseStartTransaction: Reserved transaction ${payload.transactionId.toString()} started with a different idTag ${truncateId( + `${chargingStation.logPrefix()} ${moduleName}.handleResponseStartTransaction: Reserved transaction ${payload.transactionId.toString()} started with a different idTag '${truncateId( requestPayload.idTag - )} than the reservation one ${truncateId(reservation.idTag)}` + )}' than the reservation one '${truncateId(reservation.idTag)}'` ) } if (hasReservationExpired(reservation)) { diff --git a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts index 718e2460..b7840fdb 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts @@ -620,7 +620,7 @@ export class OCPP16ServiceUtils { chargingStationReservation.idTag === idTag) ) { logger.debug( - `${chargingStation.logPrefix()} ${moduleName}.hasReservation: Connector id ${connectorId.toString()} has a valid reservation for idTag ${idTag}: %j`, + `${chargingStation.logPrefix()} ${moduleName}.hasReservation: Connector id ${connectorId.toString()} has a valid reservation for idTag '${truncateId(idTag)}': %j`, connectorReservation ?? chargingStationReservation ) return true diff --git a/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts b/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts index 9b0df3f6..58056fa7 100644 --- a/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts @@ -834,7 +834,7 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { if (authResult.status !== AuthorizationStatus.ACCEPTED) { logger.warn( - `${chargingStation.logPrefix()} ${moduleName}.authorizeToken: ${tokenLabel} ${truncateId(tokenValue)} is not authorized` + `${chargingStation.logPrefix()} ${moduleName}.authorizeToken: ${tokenLabel} '${truncateId(tokenValue)}' is not authorized` ) } @@ -2294,7 +2294,7 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { ): Promise { const { chargingProfile, evseId, groupIdToken, idToken, remoteStartId } = commandPayload logger.info( - `${chargingStation.logPrefix()} ${moduleName}.handleRequestStartTransaction: Remote start transaction request received on EVSE ${evseId?.toString() ?? 'undefined'} with idToken ${truncateId(idToken.idToken)} and remoteStartId ${remoteStartId.toString()}` + `${chargingStation.logPrefix()} ${moduleName}.handleRequestStartTransaction: Remote start transaction request received on EVSE ${evseId?.toString() ?? 'undefined'} with idToken '${truncateId(idToken.idToken)}' and remoteStartId ${remoteStartId.toString()}` ) let resolvedEvseId = evseId @@ -2415,7 +2415,7 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { ) } catch (error) { logger.error( - `${chargingStation.logPrefix()} ${moduleName}.handleRequestStartTransaction: Authorization error for ${truncateId(idToken.idToken)}:`, + `${chargingStation.logPrefix()} ${moduleName}.handleRequestStartTransaction: Authorization error for '${truncateId(idToken.idToken)}':`, error ) return { @@ -2437,7 +2437,7 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { return { status: RequestStartStopStatusEnumType.Rejected, statusInfo: { - additionalInfo: `IdToken ${truncateId(idToken.idToken)} is not authorized`, + additionalInfo: `IdToken '${truncateId(idToken.idToken)}' is not authorized`, reasonCode: ReasonCodeEnumType.InvalidIdToken, }, transactionId: generateUUID(), @@ -2456,7 +2456,7 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { ) } catch (error) { logger.error( - `${chargingStation.logPrefix()} ${moduleName}.handleRequestStartTransaction: Group authorization error for ${truncateId(groupIdToken.idToken)}:`, + `${chargingStation.logPrefix()} ${moduleName}.handleRequestStartTransaction: Group authorization error for '${truncateId(groupIdToken.idToken)}':`, error ) return { @@ -2472,7 +2472,7 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { return { status: RequestStartStopStatusEnumType.Rejected, statusInfo: { - additionalInfo: `GroupIdToken ${truncateId(groupIdToken.idToken)} is not authorized`, + additionalInfo: `GroupIdToken '${truncateId(groupIdToken.idToken)}' is not authorized`, reasonCode: ReasonCodeEnumType.InvalidIdToken, }, transactionId: generateUUID(), @@ -2977,7 +2977,7 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { } logger.debug( - `${chargingStation.logPrefix()} ${moduleName}.isAuthorizedToStopTransaction: IdToken ${truncateId(presentedIdToken.idToken)} not authorized to stop transaction on connector ${connectorId.toString()}` + `${chargingStation.logPrefix()} ${moduleName}.isAuthorizedToStopTransaction: IdToken '${truncateId(presentedIdToken.idToken)}' not authorized to stop transaction on connector ${connectorId.toString()}` ) return false } diff --git a/src/charging-station/ocpp/IdTagAuthorization.ts b/src/charging-station/ocpp/IdTagAuthorization.ts index 0412fdd4..8520c458 100644 --- a/src/charging-station/ocpp/IdTagAuthorization.ts +++ b/src/charging-station/ocpp/IdTagAuthorization.ts @@ -1,6 +1,6 @@ import type { ChargingStation } from '../../charging-station/index.js' -import { logger } from '../../utils/index.js' +import { logger, truncateId } from '../../utils/index.js' import { AuthContext, AuthenticationMethod, @@ -17,7 +17,7 @@ export const isIdTagAuthorized = async ( ): Promise => { try { logger.debug( - `${chargingStation.logPrefix()} Authorizing idTag '${idTag}' on connector ${connectorId.toString()}` + `${chargingStation.logPrefix()} Authorizing idTag '${truncateId(idTag)}' on connector ${connectorId.toString()}` ) const authService = OCPPAuthServiceFactory.getInstance(chargingStation) @@ -34,7 +34,7 @@ export const isIdTagAuthorized = async ( }) logger.debug( - `${chargingStation.logPrefix()} Authorization result for idTag '${idTag}': ${authResult.status} using ${authResult.method} method` + `${chargingStation.logPrefix()} Authorization result for idTag '${truncateId(idTag)}': ${authResult.status} using ${authResult.method} method` ) if (authResult.status === AuthorizationStatus.ACCEPTED) { diff --git a/src/charging-station/ocpp/auth/adapters/OCPP16AuthAdapter.ts b/src/charging-station/ocpp/auth/adapters/OCPP16AuthAdapter.ts index 9ed202d6..fb90d924 100644 --- a/src/charging-station/ocpp/auth/adapters/OCPP16AuthAdapter.ts +++ b/src/charging-station/ocpp/auth/adapters/OCPP16AuthAdapter.ts @@ -56,7 +56,7 @@ export class OCPP16AuthAdapter implements OCPPAuthAdapter { try { logger.debug( - `${this.chargingStation.logPrefix()} ${moduleName}.${methodName}: Authorizing identifier ${truncateId(identifier.value)} via OCPP 1.6` + `${this.chargingStation.logPrefix()} ${moduleName}.${methodName}: Authorizing identifier '${truncateId(identifier.value)}' via OCPP 1.6` ) // Mark connector as authorizing if provided diff --git a/src/charging-station/ocpp/auth/adapters/OCPP20AuthAdapter.ts b/src/charging-station/ocpp/auth/adapters/OCPP20AuthAdapter.ts index ef4ffabc..2e4df2d8 100644 --- a/src/charging-station/ocpp/auth/adapters/OCPP20AuthAdapter.ts +++ b/src/charging-station/ocpp/auth/adapters/OCPP20AuthAdapter.ts @@ -65,7 +65,7 @@ export class OCPP20AuthAdapter implements OCPPAuthAdapter { try { logger.debug( - `${this.chargingStation.logPrefix()} ${moduleName}.${methodName}: Authorizing identifier ${truncateId(identifier.value)} via OCPP 2.0 Authorize` + `${this.chargingStation.logPrefix()} ${moduleName}.${methodName}: Authorizing identifier '${truncateId(identifier.value)}' via OCPP 2.0 Authorize` ) const isRemoteAuth = this.isRemoteAvailable() diff --git a/src/charging-station/ocpp/auth/cache/InMemoryAuthCache.ts b/src/charging-station/ocpp/auth/cache/InMemoryAuthCache.ts index aa6bbf4b..5698c03d 100644 --- a/src/charging-station/ocpp/auth/cache/InMemoryAuthCache.ts +++ b/src/charging-station/ocpp/auth/cache/InMemoryAuthCache.ts @@ -171,7 +171,7 @@ export class InMemoryAuthCache implements AuthCache { // Check rate limiting first if (!this.checkRateLimit(identifier)) { this.stats.rateLimitBlocked++ - logger.warn(`${moduleName}: Rate limit exceeded for identifier: ${truncateId(identifier)}`) + logger.warn(`${moduleName}: Rate limit exceeded for identifier: '${truncateId(identifier)}'`) return undefined } @@ -198,7 +198,7 @@ export class InMemoryAuthCache implements AuthCache { } this.lruOrder.set(identifier, now) logger.debug( - `${moduleName}: Expired entry transitioned to EXPIRED for identifier: ${truncateId(identifier)}` + `${moduleName}: Expired entry transitioned to EXPIRED for identifier: '${truncateId(identifier)}'` ) return authCacheEntry.result } @@ -216,7 +216,7 @@ export class InMemoryAuthCache implements AuthCache { authCacheEntry.expiresAt = now + this.defaultTtl * 1000 } - logger.debug(`${moduleName}: Cache hit for identifier: ${truncateId(identifier)}`) + logger.debug(`${moduleName}: Cache hit for identifier: '${truncateId(identifier)}'`) return authCacheEntry.result } @@ -264,7 +264,7 @@ export class InMemoryAuthCache implements AuthCache { this.lruOrder.delete(identifier) if (deleted) { - logger.debug(`${moduleName}: Removed entry for identifier: ${truncateId(identifier)}`) + logger.debug(`${moduleName}: Removed entry for identifier: '${truncateId(identifier)}'`) } } @@ -318,7 +318,7 @@ export class InMemoryAuthCache implements AuthCache { if (!this.checkRateLimit(identifier)) { this.stats.rateLimitBlocked++ logger.warn( - `${moduleName}: Rate limit exceeded, not caching identifier: ${truncateId(identifier)}` + `${moduleName}: Rate limit exceeded, not caching identifier: '${truncateId(identifier)}'` ) return } @@ -344,7 +344,7 @@ export class InMemoryAuthCache implements AuthCache { this.stats.sets++ logger.debug( - `${moduleName}: Cached result for identifier: ${truncateId(identifier)}, ttl=${String(clampedTtl)}s, entries=${String(this.cache.size)}/${String(this.maxEntries)}` + `${moduleName}: Cached result for identifier: '${truncateId(identifier)}', ttl=${String(clampedTtl)}s, entries=${String(this.cache.size)}/${String(this.maxEntries)}` ) } @@ -452,7 +452,7 @@ export class InMemoryAuthCache implements AuthCache { this.cache.delete(candidateIdentifier) this.lruOrder.delete(candidateIdentifier) this.stats.evictions++ - logger.debug(`${moduleName}: Evicted LRU entry: ${truncateId(candidateIdentifier)}`) + logger.debug(`${moduleName}: Evicted LRU entry: '${truncateId(candidateIdentifier)}'`) } } } diff --git a/src/charging-station/ocpp/auth/services/OCPPAuthServiceImpl.ts b/src/charging-station/ocpp/auth/services/OCPPAuthServiceImpl.ts index ca6ac217..bbd3e23c 100644 --- a/src/charging-station/ocpp/auth/services/OCPPAuthServiceImpl.ts +++ b/src/charging-station/ocpp/auth/services/OCPPAuthServiceImpl.ts @@ -88,7 +88,7 @@ export class OCPPAuthServiceImpl implements OCPPAuthService { this.metrics.totalRequests++ logger.debug( - `${this.chargingStation.logPrefix()} ${moduleName}.authenticate: Starting authentication for identifier: ${truncateId(request.identifier.value)}` + `${this.chargingStation.logPrefix()} ${moduleName}.authenticate: Starting authentication for identifier: '${truncateId(request.identifier.value)}'` ) // Try each strategy in priority order @@ -372,7 +372,7 @@ export class OCPPAuthServiceImpl implements OCPPAuthService { } this.authCache.remove(identifier.value) logger.info( - `${this.chargingStation.logPrefix()} ${moduleName}.invalidateCache: Cache invalidated for identifier: ${truncateId(identifier.value)}` + `${this.chargingStation.logPrefix()} ${moduleName}.invalidateCache: Cache invalidated for identifier: '${truncateId(identifier.value)}'` ) } @@ -492,7 +492,7 @@ export class OCPPAuthServiceImpl implements OCPPAuthService { const ttlSeconds = Math.floor((expiry.getTime() - Date.now()) / 1000) if (ttlSeconds <= 0) { logger.debug( - `${this.chargingStation.logPrefix()} ${moduleName}.updateCacheEntry: Skipping expired entry for ${truncateId(identifier)}` + `${this.chargingStation.logPrefix()} ${moduleName}.updateCacheEntry: Skipping expired entry for '${truncateId(identifier)}'` ) return } @@ -511,7 +511,7 @@ export class OCPPAuthServiceImpl implements OCPPAuthService { this.authCache.set(identifier, result, effectiveTtl) logger.debug( - `${this.chargingStation.logPrefix()} ${moduleName}.updateCacheEntry: Updated cache for ${truncateId(identifier)} status=${status}${effectiveTtl != null ? `, ttl=${effectiveTtl.toString()}s` : ''}` + `${this.chargingStation.logPrefix()} ${moduleName}.updateCacheEntry: Updated cache for '${truncateId(identifier)}' status=${status}${effectiveTtl != null ? `, ttl=${effectiveTtl.toString()}s` : ''}` ) } diff --git a/src/charging-station/ocpp/auth/strategies/LocalAuthStrategy.ts b/src/charging-station/ocpp/auth/strategies/LocalAuthStrategy.ts index b6f97b87..3b955099 100644 --- a/src/charging-station/ocpp/auth/strategies/LocalAuthStrategy.ts +++ b/src/charging-station/ocpp/auth/strategies/LocalAuthStrategy.ts @@ -72,7 +72,7 @@ export class LocalAuthStrategy implements AuthStrategy { try { logger.debug( - `${moduleName}: Authenticating ${truncateId(request.identifier.value)} for ${request.context}` + `${moduleName}: Authenticating '${truncateId(request.identifier.value)}' for ${request.context}` ) // 1. Try local authorization list first (highest priority) @@ -130,7 +130,7 @@ export class LocalAuthStrategy implements AuthStrategy { } logger.debug( - `${moduleName}: No local authorization found for ${truncateId(request.identifier.value)}` + `${moduleName}: No local authorization found for '${truncateId(request.identifier.value)}'` ) return undefined } catch (error) { @@ -163,7 +163,7 @@ export class LocalAuthStrategy implements AuthStrategy { try { this.authCache.set(identifier, result, ttl) - logger.debug(`${moduleName}: Cached result for ${truncateId(identifier)}`) + logger.debug(`${moduleName}: Cached result for '${truncateId(identifier)}'`) } catch (error) { const errorMessage = getErrorMessage(error) logger.error(`${moduleName}: Failed to cache result: ${errorMessage}`) @@ -288,7 +288,7 @@ export class LocalAuthStrategy implements AuthStrategy { try { this.authCache.remove(identifier) - logger.debug(`${moduleName}: Invalidated cache for ${truncateId(identifier)}`) + logger.debug(`${moduleName}: Invalidated cache for '${truncateId(identifier)}'`) } catch (error) { const errorMessage = getErrorMessage(error) logger.error(`${moduleName}: Failed to invalidate cache: ${errorMessage}`) @@ -352,7 +352,7 @@ export class LocalAuthStrategy implements AuthStrategy { return undefined } - logger.debug(`${moduleName}: Cache hit for ${truncateId(request.identifier.value)}`) + logger.debug(`${moduleName}: Cache hit for '${truncateId(request.identifier.value)}'`) return cachedResult } catch (error) { const errorMessage = getErrorMessage(error) @@ -390,7 +390,7 @@ export class LocalAuthStrategy implements AuthStrategy { // Check if entry is expired if (entry.expiryDate && entry.expiryDate < new Date()) { - logger.debug(`${moduleName}: Entry ${truncateId(request.identifier.value)} expired`) + logger.debug(`${moduleName}: Entry '${truncateId(request.identifier.value)}' expired`) return { expiryDate: entry.expiryDate, isOffline: false, @@ -437,7 +437,7 @@ export class LocalAuthStrategy implements AuthStrategy { config: AuthConfiguration ): AuthorizationResult | undefined { logger.debug( - `${moduleName}: Applying offline fallback for ${truncateId(request.identifier.value)}` + `${moduleName}: Applying offline fallback for '${truncateId(request.identifier.value)}'` ) // For transaction stops, always allow (safety requirement) diff --git a/src/charging-station/ocpp/auth/strategies/RemoteAuthStrategy.ts b/src/charging-station/ocpp/auth/strategies/RemoteAuthStrategy.ts index acf185a6..7cf28b9b 100644 --- a/src/charging-station/ocpp/auth/strategies/RemoteAuthStrategy.ts +++ b/src/charging-station/ocpp/auth/strategies/RemoteAuthStrategy.ts @@ -88,7 +88,7 @@ export class RemoteAuthStrategy implements AuthStrategy { try { logger.debug( - `${moduleName}: Authenticating ${truncateId(request.identifier.value)} via CSMS for ${request.context}` + `${moduleName}: Authenticating '${truncateId(request.identifier.value)}' via CSMS for ${request.context}` ) // Get adapter @@ -119,7 +119,7 @@ export class RemoteAuthStrategy implements AuthStrategy { const isInLocalList = await this.localAuthListManager.getEntry(request.identifier.value) if (isInLocalList) { logger.debug( - `${moduleName}: Skipping cache for local list identifier: ${truncateId(request.identifier.value)}` + `${moduleName}: Skipping cache for local list identifier: '${truncateId(request.identifier.value)}'` ) } else { this.cacheResult( @@ -147,7 +147,7 @@ export class RemoteAuthStrategy implements AuthStrategy { } logger.debug( - `${moduleName}: No remote authorization result for ${truncateId(request.identifier.value)}` + `${moduleName}: No remote authorization result for '${truncateId(request.identifier.value)}'` ) return undefined } catch (error) { @@ -379,7 +379,7 @@ export class RemoteAuthStrategy implements AuthStrategy { const cacheTtl = ttl ?? result.cacheTtl ?? 300 // Default 5 minutes this.authCache.set(identifier, result, cacheTtl) logger.debug( - `${moduleName}: Cached result for ${truncateId(identifier)} (TTL: ${String(cacheTtl)}s)` + `${moduleName}: Cached result for '${truncateId(identifier)}' (TTL: ${String(cacheTtl)}s)` ) } catch (error) { const errorMessage = getErrorMessage(error) diff --git a/src/charging-station/ocpp/auth/utils/AuthHelpers.ts b/src/charging-station/ocpp/auth/utils/AuthHelpers.ts index de0a5435..61cede25 100644 --- a/src/charging-station/ocpp/auth/utils/AuthHelpers.ts +++ b/src/charging-station/ocpp/auth/utils/AuthHelpers.ts @@ -80,7 +80,7 @@ function createRejectedResult ( * @returns Formatted error string with truncated identifier */ function formatAuthError (error: Error, identifier: Identifier): string { - return `Authentication failed for identifier ${truncateId(identifier.value)} (${identifier.type}): ${error.message}` + return `Authentication failed for identifier '${truncateId(identifier.value)}' (${identifier.type}): ${error.message}` } /**