/**
* Get strategy-specific statistics
*/
- getStats(): JsonObject | Promise<JsonObject>
+ getStats(): JsonObject
/**
* Initialize the strategy with configuration
/**
* Check if remote authorization is available
*/
- isRemoteAvailable(): boolean | Promise<boolean>
+ isRemoteAvailable(): boolean
/**
* The OCPP version this adapter handles
/**
* Get authentication statistics
*/
- getStats(): Promise<AuthStats>
+ getStats(): AuthStats
/**
* Invalidate cached authorization for an identifier
* Get authentication statistics
* @returns Authentication statistics including cache and rate limiting metrics
*/
- public async getStats (): Promise<AuthStats> {
+ public getStats (): AuthStats {
const avgResponseTime =
this.metrics.totalRequests > 0
? this.metrics.totalResponseTime / this.metrics.totalRequests
| { blockedRequests: number; rateLimitedIdentifiers: number; totalChecks: number }
const remoteStrategy = this.strategies.get('remote')
if (remoteStrategy?.getStats) {
- const strategyStatistics = await remoteStrategy.getStats()
+ const strategyStatistics = remoteStrategy.getStats()
if ('cache' in strategyStatistics) {
const cacheStatistics = strategyStatistics.cache as {
rateLimit?: {
}
// Check if remote service is available
- const isAvailable = await this.checkRemoteAvailability(adapter, config)
+ const isAvailable = this.checkRemoteAvailability(adapter, config)
if (!isAvailable) {
logger.debug(`${moduleName}: Remote service unavailable`)
return undefined
* Get strategy statistics
* @returns Strategy statistics including success rates, response times, and error counts
*/
- public async getStats (): Promise<JsonObject> {
+ public getStats (): JsonObject {
const cacheStatistics = this.authCache ? this.authCache.getStats() : null
let adapterAvailable = false
if (this.adapter) {
try {
- adapterAvailable = await this.adapter.isRemoteAvailable()
+ adapterAvailable = this.adapter.isRemoteAvailable()
} catch {
adapterAvailable = false
}
* Test connectivity to remote authorization service
* @returns True if the OCPP adapter can reach its remote service
*/
- public async testConnectivity (): Promise<boolean> {
+ public testConnectivity (): boolean {
if (!this.isInitialized || this.adapter == null) {
return false
}
try {
- return await this.adapter.isRemoteAvailable()
+ return this.adapter.isRemoteAvailable()
} catch {
return false
}
/**
* Check if remote authorization service is available
* @param adapter - OCPP adapter to check for remote service availability
- * @param config - Authentication configuration with timeout settings
- * @returns True if the remote service responds within timeout
+ * @param _config - Authentication configuration (unused)
+ * @returns True if the remote service responds
*/
- private async checkRemoteAvailability (
- adapter: OCPPAuthAdapter,
- config: AuthConfiguration
- ): Promise<boolean> {
+ private checkRemoteAvailability (adapter: OCPPAuthAdapter, _config: AuthConfiguration): boolean {
try {
- const timeout = (config.authorizationTimeout * 1000) / 2
- return await promiseWithTimeout(
- Promise.resolve(adapter.isRemoteAvailable()),
- timeout,
- new AuthenticationError('Availability check timeout', AuthErrorCode.TIMEOUT)
- )
+ return adapter.isRemoteAvailable()
} catch (error) {
const errorMessage = getErrorMessage(error)
logger.debug(`${moduleName}: Remote availability check failed: ${errorMessage}`)
/* empty */
},
getConfiguration: () => ({}) as AuthConfiguration,
- getStats: () =>
- new Promise<Record<string, unknown>>(resolve => {
- resolve({
- avgResponseTime: 0,
- cacheHitRate: 0,
- failedAuth: 0,
- lastUpdatedDate: new Date(),
- localUsageRate: 1,
- remoteSuccessRate: 0,
- successfulAuth: 0,
- totalRequests: 0,
- })
- }),
+ getStats: () => ({
+ avgResponseTime: 0,
+ cacheHitRate: 0,
+ failedAuth: 0,
+ lastUpdatedDate: new Date(),
+ localUsageRate: 1,
+ remoteSuccessRate: 0,
+ successfulAuth: 0,
+ totalRequests: 0,
+ }),
invalidateCache: () => {
/* empty */
},
mockStation = createMockAuthServiceTestStation('getStats')
})
- await it('should return authentication statistics', async () => {
+ await it('should return authentication statistics', () => {
const authService = new OCPPAuthServiceImpl(mockStation)
- const stats = await authService.getStats()
+ const stats = authService.getStats()
assert.notStrictEqual(stats, undefined)
assert.notStrictEqual(stats.totalRequests, undefined)
})
await describe('testConnectivity', async () => {
- await it('should test connectivity successfully', async () => {
+ await it('should test connectivity successfully', () => {
strategy.initialize(createTestAuthConfig())
- const result = await strategy.testConnectivity()
+ const result = strategy.testConnectivity()
assert.strictEqual(result, true)
})
- await it('should return false when not initialized', async () => {
+ await it('should return false when not initialized', () => {
const newStrategy = new RemoteAuthStrategy()
- const result = await newStrategy.testConnectivity()
+ const result = newStrategy.testConnectivity()
assert.strictEqual(result, false)
})
- await it('should return false when adapter unavailable', async () => {
+ await it('should return false when adapter unavailable', () => {
mockOCPP16Adapter.isRemoteAvailable = () => false
strategy.initialize(createTestAuthConfig())
- const result = await strategy.testConnectivity()
+ const result = strategy.testConnectivity()
assert.strictEqual(result, false)
})
})
await describe('getStats', async () => {
- await it('should return strategy statistics', async () => {
- const stats = await strategy.getStats()
+ await it('should return strategy statistics', () => {
+ const stats = strategy.getStats()
assert.strictEqual(stats.hasAdapter, true)
assert.strictEqual(stats.failedRemoteAuth, 0)
assert.strictEqual(stats.hasAuthCache, true)
assert.strictEqual(stats.totalRequests, 0)
})
- await it('should include adapter statistics', async () => {
+ await it('should include adapter statistics', () => {
strategy.initialize(createTestAuthConfig())
- const stats = await strategy.getStats()
+ const stats = strategy.getStats()
assert.strictEqual(typeof stats.adapterAvailable, 'boolean')
})
})
await strategy.authenticate(successRequest, createTestAuthConfig())
- const statsAfterSuccess = await strategy.getStats()
+ const statsAfterSuccess = strategy.getStats()
assert.strictEqual(statsAfterSuccess.totalRequests, 1)
assert.strictEqual(statsAfterSuccess.successfulRemoteAuth, 1)
assert.strictEqual(statsAfterSuccess.failedRemoteAuth, 0)
})
await strategy.authenticate(failRequest, createTestAuthConfig())
- const statsAfterFailure = await strategy.getStats()
+ const statsAfterFailure = strategy.getStats()
assert.strictEqual(statsAfterFailure.totalRequests, 2)
assert.strictEqual(statsAfterFailure.successfulRemoteAuth, 1)
assert.strictEqual(statsAfterFailure.failedRemoteAuth, 1)
})
await describe('cleanup', async () => {
- await it('should reset strategy state', async () => {
+ await it('should reset strategy state', () => {
strategy.cleanup()
- const stats = await strategy.getStats()
+ const stats = strategy.getStats()
assert.strictEqual(stats.isInitialized, false)
assert.strictEqual(stats.totalRequests, 0)
})
throw new Error('Invalid connectivity test result')
}
- const stats = await this.authService.getStats()
+ const stats = this.authService.getStats()
if (typeof stats.totalRequests !== 'number') {
throw new Error('Invalid statistics object')
}