]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commit
fix(simulator): normalize supervision URL at UI dispatch and station config (#2181)
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 3 Nov 2026 20:21:41 +0000 (21:21 +0100)
committerGitHub <noreply@github.com>
Tue, 3 Nov 2026 20:21:41 +0000 (21:21 +0100)
commit9ef343ead5e239eb84c6ac375cf23c326184ef90
tree7deb6cf0ce023a4ee6a06552def3bdb67af6a3e9
parent7e8ca4281d5a1af847707e41a2cb637adedc5ac0
fix(simulator): normalize supervision URL at UI dispatch and station config (#2181)

* fix(simulator): normalize supervision URL at UI dispatch and station config

A SET_SUPERVISION_URL request carrying NBSP or EM SPACE around the scheme was
accepted by the UI payload gate and the raw, untrimmed URL was forwarded to the
charging station. The station's parseSupervisionUrl used a bare `new URL()` that
never trimmed whitespace, so the two layers dialled different URLs.

Both layers now route the URL through the shared SupervisionUrlSchema, which
trims Unicode whitespace and enforces the ws/wss/http/https/ws+unix scheme.

- UI dispatch: replace getRequestPayloadValidationError with
  parseRequestPayloadForDispatch, which overlays the parsed (normalized)
  supervision URL values onto the original payload instead of discarding them.
- Station: parseSupervisionUrl uses SupervisionUrlSchema.safeParse so the
  normalization and scheme validation apply to stored config URLs too.
- Tests: unit tests for parseRequestPayloadForDispatch (NBSP trim, field
  preservation, rejection) and an end-to-end test capturing the value the
  station actually receives.

* test(ui): assert dispatch fires before narrowing in normalization test

The regression test narrowed on the captured payload with early returns,
so a request no longer broadcast would pass silently. Add explicit
assertions that sendRequest fired and carried a payload before the
unknown-object guards, so a lost dispatch now fails the test outright.

* fix(simulator): trim supervision URL before appending station identity

wsConnectionUrl appended the charging-station identity to the configured
supervision URL base before the OCPP configuration value was normalized.
Trailing NBSP/EM SPACE (U+00A0/U+2003) — which the WHATWG URL parser does
not trim — became internal whitespace percent-encoded into the dialed path
for example OCPP16%C2%A0/identity.

Trim the base URL before appending the identity; the derived URL is still
validated by parseSupervisionUrl. Add a regression test asserting both a
trailing NBSP and a trailing EM SPACE are trimmed instead of encoded.

* test(ui): assert malformed dispatch payloads fail explicitly

The supervision-URL normalization regression test narrowed the dispatched
payload with early `if (...) return` guards, so a payload that was not a
non-null object or was missing the `url` property silently passed without
ever checking the normalization.

Replace those narrowing guards with explicit `assert.fail(...)` checks that
fail the test outright, matching the repo's own guard idiom, so a lost or
malformed dispatch is no longer masked.

* test(ui): cover normalization of station option URLs

* docs(simulator): clarify supervision URL contracts and test descriptions
src/charging-station/ChargingStation.ts
src/charging-station/ui-server/ui-services/AbstractUIService.ts
src/charging-station/ui-server/ui-services/UIServiceRequestPayloadSchemas.ts
tests/charging-station/ChargingStation-WsConnectionUrlIdentity.test.ts
tests/charging-station/ui-server/ui-services/AbstractUIService.test.ts
tests/charging-station/ui-server/ui-services/UIServiceRequestPayloadSchemas.test.ts