Skip to content

fix(simulator): encode station identity in WebSocket connection URL - #2177

Merged
jerome-benoit merged 6 commits into
SAP:mainfrom
VitorCoelho:fix/encode-station-identity-in-ws-url
Oct 31, 2026
Merged

jerome-benoit merged 6 commits into
SAP:mainfrom
VitorCoelho:fix/encode-station-identity-in-ws-url

Conversation

@VitorCoelho

Copy link
Copy Markdown
Contributor

PR Checklist

  • Please add a description of your changes.
  • Please ensure title follows conventional commits.
  • We need your changes to come with unit tests in order to keep this project in quality and easy to maintain.
  • If your changes contain any new feature please be sure to document it. (no new feature; the fix is explained in a code comment next to the change)
  • Please add a link to the open issue or task that this pull request will resolve.

Does this PR introduce a breaking change?

  • Yes
  • No

If yes please indicate it in the title and add migration info into the documentation.


Closes #2176

Summary

ChargingStation.wsConnectionUrl appended the raw chargingStationId to the supervision URL. A reserved character in the identity therefore became URL syntax instead of part of the identity:

Identity Before After
FRESH#1 .../OCPP16/FRESH + fragment #1 → ws throws The URL contains a fragment identifier .../OCPP16/FRESH%231
CS?1 .../OCPP16/CS + query ?1 .../OCPP16/CS%3F1
CS/1 two path segments CS and 1 .../OCPP16/CS%2F1
CS 1 WHATWG parser rewrites to CS%201 by luck .../OCPP16/CS%201 (now intentional)
CS%1 .../OCPP16/CS%1 (malformed escape) .../OCPP16/CS%251
CS-1 .../OCPP16/CS-1 unchanged

OCPP-J 1.6 section 3.1.1 requires the identity path segment to be percent-encoded as per RFC 3986. The identity is now passed through encodeURIComponent only when the connection URL is composed; the raw identity is unchanged everywhere else (station info, templates, logs, configuration keys, UI). Both the supervision URL from the station info and the one taken from the OCPP configuration key (supervisionUrlOcppConfiguration) go through the same getter, so both paths are covered.

Testing

New tests/charging-station/ChargingStation-WsConnectionUrlIdentity.test.ts:

  • an ordinary identity (CS-1) produces the same URL as before;
  • each reserved character above is encoded into a single path segment: pathname ends with the encoded identity, search and hash are empty, and decodeURIComponent of the last segment gives back the raw identity;
  • the OCPP configuration key path (supervisionUrlOcppConfiguration: true, key ocppcentraladdress) is encoded the same way;
  • against a real ws WebSocketServer on TCP and on a Unix socket (ws+unix:), the server receives /OCPP16/<encoded identity> as the request path, i.e. the identity survives the round trip as one segment.

Without the fix, 4 of the 5 tests fail (the fragment case throws inside ws, the others land on a different path). With it, 5/5 pass; pnpm lint, pnpm typecheck and the neighbouring tests/charging-station/*.test.ts suites are clean.

…ervision connection URL

ChargingStation.wsConnectionUrl appended the raw chargingStationId to the
supervision URL, so a reserved character in the identity became URL syntax:
'FRESH#1' turned into the fragment 'SAP#1' (ws throws 'The URL contains a
fragment identifier'), 'A?B' into a query and 'A/B' into two path segments.
OCPP-J 1.6 section 3.1.1 requires the identity to be percent-encoded as per
RFC 3986. Encode it with encodeURIComponent when composing the connection
URL only; the raw identity is unchanged everywhere else.

Closes SAP#2176

Signed-off-by: VitorCoelho <vitorc195@gmail.com>
…ision connection URL

Exercise ChargingStation.wsConnectionUrl with identities holding reserved
characters (' ', '%', '/', '?', '#'), through the station info and the OCPP
configuration key paths, and against real TCP and Unix socket WebSocket
servers that must observe a single encoded path segment.

Signed-off-by: VitorCoelho <vitorc195@gmail.com>

@hyperspace-pr-bot hyperspace-pr-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 PR Review — Fix/encode station identity in ws url

🟡 Suggestions (1 open, 1 total)
CategoryFindingFile
⚙️ CorrectnessRFC 3986 reserved characters remain unencodedcharging-station/ChargingStation.ts:283

You're seeing this review as part of a pilot for our new /review+ experience. To help us continuously improve, check the feedback boxes on the comments below or share your thoughts in our Community channel.


PR Bot Information

Version: 1.33.24

  • Experiment Variant: treatment
  • LLM: gpt-5.6-sol
  • Correlation ID: dc3f77e0-d482-11f1-80d7-8098ddabf910
  • Event Trigger: issue_comment.created
  • Agent Instructions:
  • File Content Strategy: Full file content

Comment thread src/charging-station/ChargingStation.ts Resolved
@hyperspace-pr-bot hyperspace-pr-bot Bot deleted a comment from jerome-benoit Oct 30, 2026

@jerome-benoit jerome-benoit left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested

Two confirmed issues need fixes before merge:

  • The encoded connection URL no longer round-trips through the existing Web UI URL editor. Saving without changing the URL duplicates the station identity.
  • The new Unix-socket test fails on Windows and breaks the simulator CI job.

Verification: 35 targeted tests passed on Linux with Node 24.22.2. The UI round-trip regression was reproduced against the base and head using the existing UI helper, real ChargingStation instances, and a local TCP WebSocket server, on both supervision-source branches. The Windows failure is directly documented in the CI job log.

The identity-encoding approach itself is appropriate; please update its existing consumer and make the transport-specific test portable.

PR title

Please rename Fix/encode station identity in ws url to follow the repository Conventional Commits requirement, for example:

fix(simulator): encode station identity in WebSocket connection URL

This is PR metadata compliance, separate from the two P2 code findings above.

Comment thread src/charging-station/ChargingStation.ts Resolved
…rvision URL

The connection URL published to the UI now ends with the identity encoded
as one path segment, but stripStationId only matched the raw '/<id>'
suffix. SetSupervisionUrlDialog therefore prefilled the full connection
URL as the base URL and a save without editing it (for example a
credentials-only update) stored that as the base and appended the
identity again ('/OCPP16/CS%2B1/CS%2B1').

Match the encoded suffix first and keep the raw one for URLs composed
without encoding.

Signed-off-by: VitorCoelho <vitorc195@gmail.com>
Prefill for 'CS+1', 'CS@1', 'CS 1' and 'FRESH#1', and a credentials-only
save that must resend the base URL unchanged.

Signed-off-by: VitorCoelho <vitorc195@gmail.com>
On Windows the socket path is not a listenable filesystem path
('listen EACCES'), which failed the simulator CI job. Only the Unix
transport case is skipped on win32; the TCP case still runs everywhere.

Signed-off-by: VitorCoelho <vitorc195@gmail.com>

@jerome-benoit jerome-benoit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review: functional fixes verified

The two P2 findings from my previous review are fixed on 793445b1: the UI now removes the encoded identity before resubmitting the base URL, and only the Unix transport test is skipped on Windows. The current Windows simulator jobs pass. These findings no longer justify blocking the PR.

Required before merge: PR title

The title Fix/encode station identity in ws url still does not meet the repository Conventional Commits requirement. Please rename it, for example:

fix(simulator): encode station identity in WebSocket connection URL

This request for changes concerns that remaining contribution requirement, not a remaining P1/P2 code defect.

Non-blocking test cleanup

The inline P3 suggestion concerns real station resources left active after the new tests. It is not a CI regression: the official runner already uses --test-force-exit.

Verification

  • Fresh source review and two independent analyses, with findings cross-validated.
  • Node 24.22.2: 35 targeted simulator tests and 58 Web UI dialog tests passed.
  • 44 real TCP/Unix round trips passed across both supervision-source branches, including station-data publication, the existing UI helper, credentials-only setter updates, and server-observed paths. Raw identity and hash remained unchanged.
  • Current Windows CI confirms TCP runs and Unix is skipped.

The bot suggestion to additionally escape !'()* is not a demonstrated correctness issue: RFC 3986 §3.3 permits these characters within a path segment. No additional escaping is required by the consumers examined.

@VitorCoelho VitorCoelho changed the title Fix/encode station identity in ws url fix(simulator): encode station identity in WebSocket connection URL Oct 31, 2026
…ncoding tests

The test file built real ChargingStation instances and never deleted
them, so their BroadcastChannels stayed open and the file only finished
because the CI runner forces exit. Each test now records the stations it
creates and afterEach awaits station.delete(false) for each of them
before the templates are removed. Without --test-force-exit the file
now exits on its own.

Signed-off-by: VitorCoelho <vitorc195@gmail.com>

@jerome-benoit jerome-benoit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

The previous findings are addressed: the UI removes the encoded identity correctly, the Unix test is skipped only on Windows, real test stations are torn down, and the title follows Conventional Commits.

Verification

  • Five identity tests exit naturally without forced termination.
  • 289 targeted simulator tests and 58 UI dialog tests passed on the integrated code.
  • 48 real TCP/Unix round trips passed across both supervision sources; raw identity and hash remain unchanged.
  • Integration with main (298b8469) preserves the OCPP and storage fixes.

No remaining actionable finding. Pre-existing endpoint coverage and UI normalization gaps remain tracked separately in #2172 and #2173.

@jerome-benoit
jerome-benoit added this pull request to the merge queue Oct 31, 2026
Merged via the queue into SAP:main with commit 02009d0 Oct 31, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Encode charging station identity in supervision URL path

2 participants