]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commit
refactor(ocpp): integrate unified auth as sole authorization mechanism (#1764)
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Mon, 30 Mar 2026 20:02:25 +0000 (22:02 +0200)
committerGitHub <noreply@github.com>
Mon, 30 Mar 2026 20:02:25 +0000 (22:02 +0200)
commitcebc17583b0d5ec09c5e3d41a6c204a84afe134e
treee85ecb11afb30e40c8b8dd9383da1a1bfb8f8338
parentf9634f6865caa1e574330c6f2144221c31935f13
refactor(ocpp): integrate unified auth as sole authorization mechanism (#1764)

* refactor(ocpp): route v1.6 auth through unified system, remove legacy functions

* refactor(ocpp): replace OCPP 2.0 inline auth with unified auth service

* test(ocpp): update OCPP 1.6 authorization tests for unified auth path

* test(ocpp): add OCPP 2.0 unified auth integration tests

* chore: pass all quality gates

* [autofix.ci] apply automated fixes

* refactor(ocpp): pass correct AuthContext to isIdTagAuthorized callers

REMOTE_START for RemoteStartTransaction, RESERVATION for ReserveNow.
ATG keeps the default TRANSACTION_START.

* refactor(ocpp): use auth barrel index instead of deep imports

* refactor(ocpp): use auth barrel for all external imports

* refactor(ocpp): remove redundant 'unified' naming from auth system

* refactor(ocpp): extract authorizeToken helper and fix rejection test assertions

* test(ocpp): add coverage for auth error and context parameter paths

* test(ocpp): remove redundant tests and unnecessary JSDoc from authorization tests

* refactor(ocpp): address review feedback — explicit switch cases, parameterize context, merge imports

* fix(ocpp): preserve OCPP 2.0 token type in authorizeToken per C01.FR.25

authorizeToken was hardcoding IdentifierType.ID_TAG, causing all
Authorize.req to carry type 'Local' regardless of the actual token
type (ISO14443, eMAID, etc.). Pass the OCPP 2.0 token type through
and use mapOCPP20TokenType for proper mapping.

Also fix log message attribution and deduplicate OCPPAuthServiceFactory
from the dynamic import (already available via static import).

* refactor(ocpp): eliminate unnecessary dynamic imports and synchronize auth factory

Extract isIdTagAuthorized to IdTagAuthorization.ts to break the
OCPPServiceUtils ESM evaluation cycle, enabling static imports from
the auth barrel. Convert AuthComponentFactory, OCPPAuthServiceFactory,
and OCPPAuthServiceImpl to fully synchronous APIs. Remove the
globalThis Symbol hack that was needed for cross-module-instance
sharing. Move getMessageTypeString to utils/Utils.ts where it belongs.

- 9 dynamic imports eliminated (20 → 11, remaining are inheritance cycles)
- Auth factory chain fully sync (getInstance, createAdapter, initialize)
- IdTagAuthorization.ts imports auth/index.js barrel statically
- Tests relocated to follow moved code
- All barrel exports consolidated between components

* build: add skott for type-aware circular dependency detection

Add skott as devDependency with a circular-deps script that scans
the entire src/ directory using --no-trackTypeOnlyDependencies to
ignore import type (unlike madge which reports false positives).
Exit code 0 for now since known cycles exist — switch to 1 when
integrated in CI.

* build: override effect>=3.20.0 to fix CVE-2026-32887 (skott transitive dep)

* refactor: break UI server circular dependency via IBootstrap DIP

Introduce IBootstrap interface to decouple AbstractUIService from the
Bootstrap singleton import. Bootstrap implements IBootstrap and is
injected through the UIServerFactory → AbstractUIServer → UIService
chain. This structurally eliminates the cycle:
AbstractUIServer → UIServiceFactory → AbstractUIService → Bootstrap →
UIServerFactory → UIHttpServer → extends AbstractUIServer.

Also removes the cross-component re-export workaround in
charging-station/index.ts (getMessageTypeString from utils/) that
was only needed to preserve ESM evaluation order around this cycle.

- Circular dependency paths: 177 → 39 (type-aware, skott)
- Short cycles (depth ≤ 4): 7 → 4
- ErrorUtils now imports getMessageTypeString from its own component

* test: fix mock isolation and type safety in UI server tests

Move mockBootstrap to beforeEach for per-test isolation.
Remove as-never cast by providing all SimulatorState fields.
Remove unnecessary JSDoc on self-documenting mock factory.

* fix: align auth barrel section headers with exports, use barrel for CertificateAuthStrategy import

* refactor(auth): eliminate code duplication, dead code, and type casts

- DRY: Replace duplicated mappers in OCPP20AuthAdapter with shared
  mapToOCPP20TokenType/mapOCPP20TokenType from AuthTypes
- DRY: Extract duplicated enhanceResult from Local/Remote strategies
  into shared enhanceAuthResult in AuthTypes
- Dead code: Remove unused parseIntegerVariable from OCPP20AuthAdapter
- YAGNI: Remove unused AuthHelpers from barrel export
- Type safety: Add getAuthCache() to AuthStrategy interface, eliminating
  3 concrete as-LocalAuthStrategy casts in OCPPAuthServiceImpl

* fix(auth): preserve OCPP 2.0 Central/Local token type in adapter mapping

Remove post-processing that collapsed Central/Local to ID_TAG in
OCPP20AuthAdapter.convertToIdentifier. The shared mapOCPP20TokenType
correctly returns CENTRAL/LOCAL, which downstream code uses for spec
compliance (C03.FR.01 skip Authorize.req for Central tokens, C11
cache exclusion for Central identifiers).

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
70 files changed:
package.json
pnpm-lock.yaml
pnpm-workspace.yaml
src/charging-station/Bootstrap.ts
src/charging-station/ChargingStation.ts
src/charging-station/Helpers.ts
src/charging-station/IBootstrap.ts [new file with mode: 0644]
src/charging-station/index.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts
src/charging-station/ocpp/2.0/OCPP20ResponseService.ts
src/charging-station/ocpp/2.0/OCPP20VariableRegistry.ts
src/charging-station/ocpp/IdTagAuthorization.ts [new file with mode: 0644]
src/charging-station/ocpp/OCPPRequestService.ts
src/charging-station/ocpp/OCPPServiceUtils.ts
src/charging-station/ocpp/auth/adapters/OCPP16AuthAdapter.ts
src/charging-station/ocpp/auth/adapters/OCPP20AuthAdapter.ts
src/charging-station/ocpp/auth/factories/AuthComponentFactory.ts
src/charging-station/ocpp/auth/index.ts
src/charging-station/ocpp/auth/interfaces/OCPPAuthService.ts
src/charging-station/ocpp/auth/services/OCPPAuthServiceFactory.ts
src/charging-station/ocpp/auth/services/OCPPAuthServiceImpl.ts
src/charging-station/ocpp/auth/strategies/CertificateAuthStrategy.ts
src/charging-station/ocpp/auth/strategies/LocalAuthStrategy.ts
src/charging-station/ocpp/auth/strategies/RemoteAuthStrategy.ts
src/charging-station/ocpp/auth/types/AuthTypes.ts
src/charging-station/ocpp/auth/utils/AuthHelpers.ts
src/charging-station/ocpp/auth/utils/AuthValidators.ts
src/charging-station/ocpp/auth/utils/index.ts
src/charging-station/ocpp/index.ts
src/charging-station/ui-server/AbstractUIServer.ts
src/charging-station/ui-server/UIHttpServer.ts
src/charging-station/ui-server/UIMCPServer.ts
src/charging-station/ui-server/UIServerFactory.ts
src/charging-station/ui-server/UIWebSocketServer.ts
src/charging-station/ui-server/ui-services/AbstractUIService.ts
src/utils/ErrorUtils.ts
src/utils/Utils.ts
src/utils/index.ts
tests/TEST_STYLE_GUIDE.md
tests/charging-station/Helpers.test.ts
tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-ClearCache.test.ts
tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-GroupIdStop.test.ts
tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-MasterPass.test.ts
tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStartTransaction.test.ts
tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStopTransaction.test.ts
tests/charging-station/ocpp/2.0/OCPP20Integration-Certificate.test.ts
tests/charging-station/ocpp/2.0/OCPP20Integration.test.ts
tests/charging-station/ocpp/2.0/OCPP20ResponseService-CacheUpdate.test.ts
tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-TransactionEvent.test.ts
tests/charging-station/ocpp/IdTagAuthorization.test.ts [new file with mode: 0644]
tests/charging-station/ocpp/OCPPServiceUtils-authorization.test.ts [deleted file]
tests/charging-station/ocpp/auth/OCPPAuthIntegration.test.ts
tests/charging-station/ocpp/auth/adapters/OCPP16AuthAdapter.test.ts
tests/charging-station/ocpp/auth/adapters/OCPP20AuthAdapter.test.ts
tests/charging-station/ocpp/auth/factories/AuthComponentFactory.test.ts
tests/charging-station/ocpp/auth/helpers/MockFactories.ts
tests/charging-station/ocpp/auth/services/OCPPAuthServiceFactory.test.ts
tests/charging-station/ocpp/auth/services/OCPPAuthServiceImpl.test.ts
tests/charging-station/ocpp/auth/strategies/CertificateAuthStrategy.test.ts
tests/charging-station/ocpp/auth/types/AuthTypes.test.ts
tests/charging-station/ocpp/auth/utils/AuthHelpers.test.ts
tests/charging-station/ocpp/auth/utils/AuthValidators.test.ts
tests/charging-station/ui-server/UIHttpServer.test.ts
tests/charging-station/ui-server/UIMCPServer.integration.test.ts
tests/charging-station/ui-server/UIMCPServer.test.ts
tests/charging-station/ui-server/UIServerFactory.test.ts
tests/charging-station/ui-server/UIServerTestUtils.ts
tests/helpers/OCPPAuthIntegrationTest.ts
tests/utils/Utils.test.ts