From: Jérôme Benoit Date: Thu, 2 Apr 2026 00:27:55 +0000 (+0200) Subject: fix(ocpp): align OCPP 2.x auth adapter version to VERSION_201 X-Git-Tag: ocpp-server@v4.2.0~8 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=bd88bf74971e7f012552ff9c1729170e873e0518;p=e-mobility-charging-stations-simulator.git fix(ocpp): align OCPP 2.x auth adapter version to VERSION_201 OCPP20AuthAdapter was the only 2.x component identifying as VERSION_20 while all services use VERSION_201. Align adapter and CertificateAuthStrategy to match the established convention. --- diff --git a/src/charging-station/ocpp/auth/adapters/OCPP20AuthAdapter.ts b/src/charging-station/ocpp/auth/adapters/OCPP20AuthAdapter.ts index 2e4df2d8..f4b46c22 100644 --- a/src/charging-station/ocpp/auth/adapters/OCPP20AuthAdapter.ts +++ b/src/charging-station/ocpp/auth/adapters/OCPP20AuthAdapter.ts @@ -45,7 +45,7 @@ const moduleName = 'OCPP20AuthAdapter' * between auth types and OCPP 2.0 specific types and protocols. */ export class OCPP20AuthAdapter implements OCPPAuthAdapter { - readonly ocppVersion = OCPPVersion.VERSION_20 + readonly ocppVersion = OCPPVersion.VERSION_201 constructor (private readonly chargingStation: ChargingStation) {} @@ -287,7 +287,7 @@ export class OCPP20AuthAdapter implements OCPPAuthAdapter { context: authContext, identifier, metadata: { - ocppVersion: OCPPVersion.VERSION_20, + ocppVersion: OCPPVersion.VERSION_201, stationId: this.chargingStation.stationInfo?.chargingStationId, }, timestamp: new Date(), diff --git a/src/charging-station/ocpp/auth/strategies/CertificateAuthStrategy.ts b/src/charging-station/ocpp/auth/strategies/CertificateAuthStrategy.ts index 7452a93f..9dad5686 100644 --- a/src/charging-station/ocpp/auth/strategies/CertificateAuthStrategy.ts +++ b/src/charging-station/ocpp/auth/strategies/CertificateAuthStrategy.ts @@ -77,7 +77,7 @@ export class CertificateAuthStrategy implements AuthStrategy { const adapter = this.adapter // For OCPP 2.0, we can use certificate-based validation - if (this.adapter.ocppVersion === OCPPVersion.VERSION_20) { + if (this.adapter.ocppVersion === OCPPVersion.VERSION_201) { const result = await this.validateCertificateWithOCPP20(request, adapter, config) this.updateStatistics(result, startTime) return result diff --git a/tests/charging-station/ocpp/auth/adapters/OCPP20AuthAdapter.test.ts b/tests/charging-station/ocpp/auth/adapters/OCPP20AuthAdapter.test.ts index e42ae662..6d4de7d3 100644 --- a/tests/charging-station/ocpp/auth/adapters/OCPP20AuthAdapter.test.ts +++ b/tests/charging-station/ocpp/auth/adapters/OCPP20AuthAdapter.test.ts @@ -46,7 +46,7 @@ await describe('OCPP20AuthAdapter', async () => { await describe('constructor', async () => { await it('should initialize with correct OCPP version', () => { - assert.strictEqual(adapter.ocppVersion, OCPPVersion.VERSION_20) + assert.strictEqual(adapter.ocppVersion, OCPPVersion.VERSION_201) }) }) @@ -183,7 +183,7 @@ await describe('OCPP20AuthAdapter', async () => { assert.strictEqual(request.connectorId, 1) assert.strictEqual(request.transactionId, 'trans_123') assert.strictEqual(request.context, AuthContext.TRANSACTION_START) - assert.strictEqual(request.metadata?.ocppVersion, OCPPVersion.VERSION_20) + assert.strictEqual(request.metadata?.ocppVersion, OCPPVersion.VERSION_201) }) await it('should map OCPP 2.0 contexts correctly', () => { @@ -316,7 +316,7 @@ await describe('OCPP20AuthAdapter', async () => { await it('should return adapter status information', () => { const status = adapter.getStatus() - assert.strictEqual(status.ocppVersion, OCPPVersion.VERSION_20) + assert.strictEqual(status.ocppVersion, OCPPVersion.VERSION_201) assert.strictEqual(status.isOnline, true) assert.strictEqual(status.stationId, 'TEST-002') assert.notStrictEqual(status.supportsIdTokenTypes, undefined) @@ -412,7 +412,7 @@ await describe('OCPP20AuthAdapter', async () => { await it('should have correct OCPP version for offline tests', () => { // Verify we're testing the correct OCPP version - assert.strictEqual(offlineAdapter.ocppVersion, OCPPVersion.VERSION_20) + assert.strictEqual(offlineAdapter.ocppVersion, OCPPVersion.VERSION_201) }) }) @@ -446,7 +446,7 @@ await describe('OCPP20AuthAdapter', async () => { await it('should initialize with default configuration for offline scenarios', () => { // When: Adapter is created // Then: Should have OCPP 2.0 version - assert.strictEqual(offlineAdapter.ocppVersion, OCPPVersion.VERSION_20) + assert.strictEqual(offlineAdapter.ocppVersion, OCPPVersion.VERSION_201) }) await it('should validate configuration schema for offline auth', () => { @@ -467,7 +467,7 @@ await describe('OCPP20AuthAdapter', async () => { // Then: Status should be defined and include online state assert.notStrictEqual(status, undefined) assert.strictEqual(typeof status.isOnline, 'boolean') - assert.strictEqual(status.ocppVersion, OCPPVersion.VERSION_20) + assert.strictEqual(status.ocppVersion, OCPPVersion.VERSION_201) }) }) }) diff --git a/tests/charging-station/ocpp/auth/factories/AuthComponentFactory.test.ts b/tests/charging-station/ocpp/auth/factories/AuthComponentFactory.test.ts index 07b1a7d5..9f339eff 100644 --- a/tests/charging-station/ocpp/auth/factories/AuthComponentFactory.test.ts +++ b/tests/charging-station/ocpp/auth/factories/AuthComponentFactory.test.ts @@ -37,7 +37,7 @@ await describe('AuthComponentFactory', async () => { const adapter = AuthComponentFactory.createAdapter(chargingStation) assert.notStrictEqual(adapter, undefined) - assert.strictEqual(adapter.ocppVersion, OCPPVersion.VERSION_20) + assert.strictEqual(adapter.ocppVersion, OCPPVersion.VERSION_201) }) await it('should create OCPP 2.0.1 adapter', () => { @@ -47,7 +47,7 @@ await describe('AuthComponentFactory', async () => { const adapter = AuthComponentFactory.createAdapter(chargingStation) assert.notStrictEqual(adapter, undefined) - assert.strictEqual(adapter.ocppVersion, OCPPVersion.VERSION_20) + assert.strictEqual(adapter.ocppVersion, OCPPVersion.VERSION_201) }) await it('should throw error for unsupported version', () => { diff --git a/tests/charging-station/ocpp/auth/strategies/CertificateAuthStrategy.test.ts b/tests/charging-station/ocpp/auth/strategies/CertificateAuthStrategy.test.ts index 19d9a79a..31597349 100644 --- a/tests/charging-station/ocpp/auth/strategies/CertificateAuthStrategy.test.ts +++ b/tests/charging-station/ocpp/auth/strategies/CertificateAuthStrategy.test.ts @@ -34,11 +34,11 @@ await describe('CertificateAuthStrategy', async () => { logPrefix: () => '[TEST-CS-001]', stationInfo: { chargingStationId: 'TEST-CS-001', - ocppVersion: OCPPVersion.VERSION_20, + ocppVersion: OCPPVersion.VERSION_201, }, } as unknown as ChargingStation - mockOCPP20Adapter = createMockOCPPAdapter(OCPPVersion.VERSION_20, { + mockOCPP20Adapter = createMockOCPPAdapter(OCPPVersion.VERSION_201, { authorizeRemote: () => new Promise(resolve => { resolve(