Repository navigation
feat(ocpp2): add TransactionEvent command support - #1607
Merged
Merged
Conversation
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds comprehensive OCPP authentication support and TransactionEvent command functionality for OCPP 2.0. The changes introduce a unified authentication system that works across OCPP 1.6 and 2.0, along with context-aware TransactionEvent handling.
Key changes:
- Introduces UUIDv4 type for type-safe UUID handling
- Implements unified authentication architecture with multiple strategies (Local, Remote, Certificate)
- Adds extensive test coverage for authentication components
- Implements context-aware TriggerReason selection for OCPP 2.0 TransactionEvents
Reviewed Changes
Copilot reviewed 49 out of 49 changed files in this pull request and generated 20 comments.
Show a summary per file
| File | Description |
|---|---|
| ui/web/src/types/UUID.ts | Defines UUIDv4 type for standardized UUID format |
| ui/web/src/composables/Utils.ts | Updates UUID utilities to use UUIDv4 type |
| src/charging-station/ocpp/auth/types/AuthTypes.ts | Core authentication type definitions and enums |
| src/charging-station/ocpp/auth/utils/*.ts | Validation and helper utilities for auth |
| src/charging-station/ocpp/auth/strategies/*.ts | Authentication strategy implementations |
| tests/charging-station/ocpp/auth/**/*.test.ts | Comprehensive test suite for auth system |
| src/types/ocpp/2.0/Transaction.ts | OCPP 2.0 TransactionContext interface |
| tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-TransactionEvent.test.ts | TransactionEvent tests |
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
Add InMemoryAuthCache with comprehensive security features: - LRU eviction when cache reaches capacity - TTL-based automatic expiration (configurable, default 1h) - Built-in rate limiting (10 req/min per identifier, configurable) - Memory usage tracking and comprehensive statistics - 45 conformance tests covering G03.FR.01 requirements Security improvements: - Mitigates S2 (rate limiting prevents DoS on auth endpoints) - Mitigates S3 (TTL prevents stale authorization persistence) - Tracks evictions, hits, misses, expired entries Completes Phase 2.3 (Security Hardening) and G03.FR.01 cache tests.
Update factory, interfaces, and service to support cache integration: - AuthComponentFactory.createAuthCache() now instantiates InMemoryAuthCache - Add evictions field to CacheStats interface - Add rateLimit field to AuthStats interface (blockedRequests, rateLimitedIdentifiers, totalChecks) - Make OCPPAuthServiceImpl.getStats() async to fetch cache stats from strategies - Update factory test to expect cache instance Enables monitoring of cache evictions and rate limiting events.
…cess Changed test to access token-3 instead of token-1 twice to properly verify LRU eviction behavior. Now expects token-1 (oldest) to be evicted instead of token-2.
Add configurable authorization behavior to OCPP 2.0 mock server: - Whitelist/blacklist mode for token validation - Offline mode simulation (network failure) - Rate limiting simulation (NotAtThisTime responses) - Pre-authorization for remote start transactions - CLI arguments for runtime configuration This enables comprehensive testing of: - G03.FR.02 (offline authorization) - G03.FR.03 (remote start pre-authorization) - G03.FR.04 (whitelist/blacklist management)
Add 9 tests for OCPP 2.0 offline authorization scenarios: G03.FR.02.001 - Offline detection (3 tests): - Detect station offline when not in accepted state - Detect station online when in accepted state - Verify correct OCPP version G03.FR.02.002 - Remote availability check (2 tests): - Return false when offline even with valid config - Handle errors gracefully when checking availability G03.FR.02.003 - Configuration validation (3 tests): - Initialize with default configuration - Validate configuration schema for offline auth - Monitor offline state via getStatus method These tests verify the adapter correctly detects offline state and reports availability for fallback to LocalAuthStrategy.
- Implement 20 unit tests for RequestStartTransaction with pre-authorization - Cover successful remote start with valid token (G03.FR.03.001) - Cover remote start rejected with blocked token (G03.FR.03.002) - Cover remote start with group token validation (G03.FR.03.003) - Cover remote start without EVSE ID error cases (G03.FR.03.004) - Cover remote start on occupied connector (G03.FR.03.005) - Cover remote start with charging profile (G03.FR.03.006) - Add request validation checks (G03.FR.03.007) - Add service initialization tests (G03.FR.03.008) - All tests validate OCPP 2.0.1 data structures - Update task completion tracking (Phase 2.2: 67% complete) Effort: 2.5j | Tests: 20 | Status: ✅ All passing
- Mark G03.FR.03 remote start tests complete (20 tests) - Document G03.FR.04 blocker (SendLocalList not implemented) - Update Phase 2 completion: 94% (25.5j/27j) - Total progress: 43j/74j (58%) Phase 2.2 pragmatically complete with gaps documented.
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
Mock isRemoteAvailable and sendTransactionEvent to avoid singleton dependency issues that cause test failures on Windows CI environment. The OCPP20VariableManager singleton behaves differently across platforms, and mocking isolates unit tests from runtime dependencies.
Ensure transactionEvseSent and transactionIdTokenSent are reset alongside transactionSeqNo to prevent test order dependencies across platforms (fixes Windows CI failures).
…ile validation - Add validateIdentifierString() for OCPP 2.0.1 identifier validation - Accept non-empty string ≤36 chars for transactionId (UUID is RECOMMENDED) - Enforce TxProfile purpose for RequestStartTransaction (OCPP 2.0.1 §2.10) - Reject chargingProfile.transactionId in RequestStartTransaction - Add comprehensive unit tests for new validation logic
…2.0.1 E02.FR.09/10) Implements periodic transaction event transmission at configurable TxUpdatedInterval: - Add transactionTxUpdatedSetInterval field to ConnectorStatus type - Implement startTxUpdatedInterval() and stopTxUpdatedInterval() methods - Export OCPP20TransactionEventEnumType and OCPP20TriggerReasonEnumType - Export OCPP20ServiceUtils from ocpp/index.ts - Timer lifecycle: starts on RequestStartTransaction - Timer cleanup: stops on RequestStopTransaction - OCPP 2.0 only, guards prevent 1.6 activation - Safely handles null/undefined connectors and intervals - Follows E02.FR.09/10 specification All tests passing (121/121), lint passing, build successful.
…ne queueing - Add comprehensive tests for TxUpdatedInterval timer lifecycle (start/stop) - Test MeterValuePeriodic trigger reason for periodic TransactionEvents - Verify seqNo increment across periodic events - Test independent timers per connector - Add offline queueing tests for WebSocket disconnection scenarios - Test seqNo preservation in queued events - Verify FIFO queue drain order on reconnection - Test seqNo continuity across online→offline→online transitions - Test independent queues per connector
- Remove unnecessary eslint-disable camelcase directive - Fix unused parameter warning with underscore prefix - Rename variables from snake_case to camelCase
Add setInstanceForTesting() method to OCPPAuthServiceFactory to allow tests to inject mock auth services without relying on ESM module internals. This fixes Windows CI failures caused by ESM module caching differences between platforms. Changes: - Add OCPPAuthServiceFactory.setInstanceForTesting() static method - Update createMockAuthService() to return proper OCPPAuthService type - Update RequestStartTransaction tests to use new method - Update RequestStopTransaction tests to use new method - Remove dynamic import workarounds that failed on Windows
…factory - Add globalThis-based instance sharing to OCPPAuthServiceFactory Required for cross-module mock injection with dynamic imports - Add missing mock methods to ChargingStationFactory: - isWebSocketConnectionOpened() - prevents offline queueing in tests - getNumberOfEvses() - required for EVSE validation - startTxUpdatedInterval() / stopTxUpdatedInterval() - for timer tests - Remove redundant null check in validateChargingProfile() TypeScript types guarantee id and stackLevel are always present
…plementation The test incorrectly expected UUID format validation, but the actual OCPP 2.0.1 spec and implementation only validates identifier strings (non-empty, ≤36 characters). Updated test to use a >36 char string and expect the correct error message.
…entQueue from serialization The new connector status fields transactionTxUpdatedSetInterval (NodeJS.Timeout) and transactionEventQueue (runtime queue) cannot be serialized to JSON and must be excluded when saving charging station configuration.
|
|
This was referenced Feb 20, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




PR Checklist
Does this PR introduce a breaking change?
If yes please indicate it in the title and add migration info into the documentation.