From 2fae5da00a402be83de1f73ebfc4a072826bb7ae Mon Sep 17 00:00:00 2001 From: reginaldalfret Date: Sun, 4 Oct 2026 09:29:02 +0530 Subject: [PATCH 1/6] fix(charging-station): throw BaseError on invalid supervision URL and revert state on set failure Signed-off-by: reginaldalfret --- src/charging-station/ChargingStation.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 92b5fb663..6e20993ed 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -1848,8 +1848,14 @@ export class ChargingStation extends EventEmitter { ) { setConfigurationKeyValue(this, this.stationInfo.supervisionUrlOcppKey, url) } else if (this.stationInfo != null) { + const prevSupervisionUrls = this.stationInfo.supervisionUrls this.stationInfo.supervisionUrls = url - this.configuredSupervisionUrl = this.getConfiguredSupervisionUrl() + try { + this.configuredSupervisionUrl = this.getConfiguredSupervisionUrl() + } catch (error) { + this.stationInfo.supervisionUrls = prevSupervisionUrls + throw error + } } if (this.stationInfo != null) { applyCredentials(this.stationInfo) @@ -2466,7 +2472,13 @@ export class ChargingStation extends EventEmitter { configuredSupervisionUrl = supervisionUrls } if (isNotEmptyString(configuredSupervisionUrl)) { - return new URL(configuredSupervisionUrl) + try { + return new URL(configuredSupervisionUrl) + } catch (error) { + const errorMsg = `Invalid supervision url '${configuredSupervisionUrl}' configured` + logger.error(`${this.logPrefix()} ${moduleName}.getConfiguredSupervisionUrl: ${errorMsg}`, error) + throw new BaseError(errorMsg, { cause: error }) + } } const errorMsg = 'No supervision url(s) configured' logger.error(`${this.logPrefix()} ${moduleName}.getConfiguredSupervisionUrl: ${errorMsg}`) From 1fbb41c84e3138a039d9fd7883be0b65e1557785 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Sun, 4 Oct 2026 12:45:08 +0000 Subject: [PATCH 2/6] [autofix.ci] apply automated fixes --- src/charging-station/ChargingStation.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 6e20993ed..338e39af5 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -2476,7 +2476,10 @@ export class ChargingStation extends EventEmitter { return new URL(configuredSupervisionUrl) } catch (error) { const errorMsg = `Invalid supervision url '${configuredSupervisionUrl}' configured` - logger.error(`${this.logPrefix()} ${moduleName}.getConfiguredSupervisionUrl: ${errorMsg}`, error) + logger.error( + `${this.logPrefix()} ${moduleName}.getConfiguredSupervisionUrl: ${errorMsg}`, + error + ) throw new BaseError(errorMsg, { cause: error }) } } From 1ee5c4f8b0642071d14ddb9e38284dc3042a009c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 7 Oct 2026 01:21:42 +0200 Subject: [PATCH 3/6] fix(charging-station): guard every supervision URL parsing path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The invalid-supervision-URL fix only covered the stationInfo branch of setSupervisionUrl and passed a cause option BaseError does not accept, so the file did not typecheck. Route every URL construction through a single parseSupervisionUrl helper that raises a BaseError naming the offending field, covering the template/config path, the OCPP-configuration key branch and the wsConnectionUrl getter, and add the regression tests the issue requires. Signed-off-by: Jérôme Benoit --- cspell.config.yaml | 1 + src/charging-station/ChargingStation.ts | 53 ++++++++++------ .../ChargingStation-ResetIdentity.test.ts | 63 +++++++++++++++++++ 3 files changed, 98 insertions(+), 19 deletions(-) diff --git a/cspell.config.yaml b/cspell.config.yaml index 706d62362..6a513962c 100644 --- a/cspell.config.yaml +++ b/cspell.config.yaml @@ -106,3 +106,4 @@ words: - HSTS - Hsts - hsts + - ocppcentraladdress diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 338e39af5..d206c0056 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -245,19 +245,24 @@ export class ChargingStation extends EventEmitter { } public get wsConnectionUrl (): URL { - const wsConnectionBaseUrlStr = `${ - // eslint-disable-next-line @typescript-eslint/restrict-template-expressions + const supervisionUrlOcppKey = this.stationInfo?.supervisionUrlOcppConfiguration === true && - isNotEmptyString(this.stationInfo.supervisionUrlOcppKey) && - isNotEmptyString(getConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey)?.value) - ? getConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey)?.value - : this.configuredSupervisionUrl.href - }` - return new URL( + isNotEmptyString(this.stationInfo.supervisionUrlOcppKey) + ? this.stationInfo.supervisionUrlOcppKey + : undefined + const configuredSupervisionUrl = + supervisionUrlOcppKey != null + ? getConfigurationKey(this, supervisionUrlOcppKey)?.value + : undefined + const wsConnectionBaseUrlStr = isNotEmptyString(configuredSupervisionUrl) + ? configuredSupervisionUrl + : this.configuredSupervisionUrl.href + return this.parseSupervisionUrl( `${wsConnectionBaseUrlStr}${ !wsConnectionBaseUrlStr.endsWith('/') ? '/' : '' // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - }${this.stationInfo?.chargingStationId}` + }${this.stationInfo?.chargingStationId}`, + supervisionUrlOcppKey ?? 'supervisionUrls' ) } @@ -1846,6 +1851,7 @@ export class ChargingStation extends EventEmitter { this.stationInfo?.supervisionUrlOcppConfiguration === true && isNotEmptyString(this.stationInfo.supervisionUrlOcppKey) ) { + this.parseSupervisionUrl(url, this.stationInfo.supervisionUrlOcppKey) setConfigurationKeyValue(this, this.stationInfo.supervisionUrlOcppKey, url) } else if (this.stationInfo != null) { const prevSupervisionUrls = this.stationInfo.supervisionUrls @@ -2472,16 +2478,7 @@ export class ChargingStation extends EventEmitter { configuredSupervisionUrl = supervisionUrls } if (isNotEmptyString(configuredSupervisionUrl)) { - try { - return new URL(configuredSupervisionUrl) - } catch (error) { - const errorMsg = `Invalid supervision url '${configuredSupervisionUrl}' configured` - logger.error( - `${this.logPrefix()} ${moduleName}.getConfiguredSupervisionUrl: ${errorMsg}`, - error - ) - throw new BaseError(errorMsg, { cause: error }) - } + return this.parseSupervisionUrl(configuredSupervisionUrl, 'supervisionUrls') } const errorMsg = 'No supervision url(s) configured' logger.error(`${this.logPrefix()} ${moduleName}.getConfiguredSupervisionUrl: ${errorMsg}`) @@ -3743,6 +3740,24 @@ export class ChargingStation extends EventEmitter { ) } + /** + * Parses a supervision URL, raising a structured configuration error naming + * the offending field and station instead of leaking the `TypeError` thrown + * by `new URL()`. The original error is logged with its stack. + * @param supervisionUrl - Supervision URL string to parse. + * @param field - Configuration field or OCPP configuration key holding it. + * @returns The parsed supervision URL. + */ + private parseSupervisionUrl (supervisionUrl: string, field: string): URL { + try { + return new URL(supervisionUrl) + } catch (error) { + const errorMsg = `Invalid supervision url '${supervisionUrl}' configured in '${field}'` + logger.error(`${this.logPrefix()} ${moduleName}.parseSupervisionUrl: ${errorMsg}`, error) + throw new BaseError(errorMsg) + } + } + private async performDelete (): Promise { const stopPromise = this.started || this.stopPromise != null ? this.stop() : undefined if (stopPromise != null) { diff --git a/tests/charging-station/ChargingStation-ResetIdentity.test.ts b/tests/charging-station/ChargingStation-ResetIdentity.test.ts index d50614b43..3fd6d72b1 100644 --- a/tests/charging-station/ChargingStation-ResetIdentity.test.ts +++ b/tests/charging-station/ChargingStation-ResetIdentity.test.ts @@ -13,6 +13,7 @@ import type { ChargingStation } from '../../src/charging-station/ChargingStation import type { ChargingStationOptions } from '../../src/types/index.js' import { SharedLRUCache } from '../../src/charging-station/SharedLRUCache.js' +import { BaseError } from '../../src/exception/index.js' import { sleep } from '../../src/utils/index.js' import { standardCleanup } from '../helpers/TestLifecycleHelpers.js' import { @@ -203,4 +204,66 @@ await describe('ChargingStation keeps its identity across a reset', async () => assert.strictEqual(station.wsConnectionUrl.host, 'localhost:7777') }) + + await it('should reject a malformed supervision URL with a field-naming configuration error', () => { + // A template with a relative or malformed supervision URL must surface a + // structured configuration error, never the bare `TypeError` from `new URL()`. + for (const malformedUrl of ['/relative', 'not a url']) { + assert.throws( + () => + createStationFromTemplate(copyStationTemplate({ supervisionUrls: malformedUrl }), { + supervisionUrls: malformedUrl, + }), + (error: unknown) => + error instanceof BaseError && + error.message.includes(malformedUrl) && + error.message.includes('supervisionUrls') + ) + } + }) + + await it('should revert stationInfo.supervisionUrls when setSupervisionUrl rejects the URL', () => { + const station = createStationFromTemplate(copyStationTemplate()) + const initialSupervisionUrls = station.stationInfo?.supervisionUrls + + assert.throws( + () => { + station.setSupervisionUrl('not a url') + }, + (error: unknown) => error instanceof BaseError && error.message.includes('supervisionUrls') + ) + assert.strictEqual(station.stationInfo?.supervisionUrls, initialSupervisionUrls) + // The retained creation options are only mirrored on success, so a rejected + // update must not leak into the reset/template-reload path either. + assert.strictEqual( + internalsOf(station).creationOptions?.supervisionUrls, + initialSupervisionUrls + ) + }) + + await it('should reject a malformed URL on the OCPP-configuration supervision branch', () => { + // This branch writes the URL into an OCPP configuration key and never calls + // getConfiguredSupervisionUrl, so it needs its own validation: a value that + // is not checked here would surface later as a bare TypeError from + // wsConnectionUrl. + const supervisionUrlOcppKey = 'ocppcentraladdress' + const station = createStationFromTemplate( + copyStationTemplate({ + supervisionUrlOcppConfiguration: true, + supervisionUrlOcppKey, + }), + { supervisionUrlOcppConfiguration: true, supervisionUrlOcppKey } + ) + const initialWsConnectionUrl = station.wsConnectionUrl.href + + assert.throws( + () => { + station.setSupervisionUrl('not a url') + }, + (error: unknown) => + error instanceof BaseError && error.message.includes(supervisionUrlOcppKey) + ) + // The rejected value must not have reached the OCPP configuration key. + assert.strictEqual(station.wsConnectionUrl.href, initialWsConnectionUrl) + }) }) From fbad081ab03b811edbafff7fe469e3da71655002 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 7 Oct 2026 04:32:38 +0200 Subject: [PATCH 4/6] test(charging-station): cover every supervision URL guard and isolate the suite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The getter guard added by the previous commit had no test: reverting it left the suite green. The three supervision URL tests also leaked a temp template directory each, because a station built with the default persistence writes its configuration after the synchronous afterEach ran cleanup. Move them into a dedicated ChargingStation-SupervisionUrl suite with an async teardown that drains the pending write, disable persistence on every station they build, add the missing getter regression, drop two inert creation options and pin the exact BaseError message and name. Name the charging station in the diagnostic and report the configured base URL instead of the derived one, so the error matches the issue acceptance criteria and no longer quotes a value the operator never configured. Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStation.ts | 24 ++- .../ChargingStation-ResetIdentity.test.ts | 63 ------- .../ChargingStation-SupervisionUrl.test.ts | 155 ++++++++++++++++++ 3 files changed, 176 insertions(+), 66 deletions(-) create mode 100644 tests/charging-station/ChargingStation-SupervisionUrl.test.ts diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 54d2a3794..b25b2d77b 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -265,12 +265,20 @@ export class ChargingStation extends EventEmitter { const wsConnectionBaseUrlStr = isNotEmptyString(configuredSupervisionUrl) ? configuredSupervisionUrl : this.configuredSupervisionUrl.href + // Only the OCPP configuration key is labelled as such when it actually + // supplied the value; an absent or empty key falls back to the configured + // supervision URL, so the diagnostic must not name the OCPP key. + const supervisionUrlField = + supervisionUrlOcppKey != null && isNotEmptyString(configuredSupervisionUrl) + ? supervisionUrlOcppKey + : 'supervisionUrls' return this.parseSupervisionUrl( `${wsConnectionBaseUrlStr}${ !wsConnectionBaseUrlStr.endsWith('/') ? '/' : '' // eslint-disable-next-line @typescript-eslint/restrict-template-expressions }${this.stationInfo?.chargingStationId}`, - supervisionUrlOcppKey ?? 'supervisionUrls' + supervisionUrlField, + wsConnectionBaseUrlStr ) } @@ -3751,13 +3759,23 @@ export class ChargingStation extends EventEmitter { * by `new URL()`. The original error is logged with its stack. * @param supervisionUrl - Supervision URL string to parse. * @param field - Configuration field or OCPP configuration key holding it. + * @param reportedUrl - Configured value quoted in the diagnostic; defaults to + * `supervisionUrl`. The `wsConnectionUrl` getter passes the configured base + * URL because it parses a derived URL (base plus charging station identity). * @returns The parsed supervision URL. */ - private parseSupervisionUrl (supervisionUrl: string, field: string): URL { + private parseSupervisionUrl ( + supervisionUrl: string, + field: string, + reportedUrl = supervisionUrl + ): URL { try { return new URL(supervisionUrl) } catch (error) { - const errorMsg = `Invalid supervision url '${supervisionUrl}' configured in '${field}'` + const chargingStationId = this.stationInfo?.chargingStationId + const errorMsg = `${ + isNotEmptyString(chargingStationId) ? `${chargingStationId}: ` : '' + }Invalid supervision url '${reportedUrl}' configured in '${field}'` logger.error(`${this.logPrefix()} ${moduleName}.parseSupervisionUrl: ${errorMsg}`, error) throw new BaseError(errorMsg) } diff --git a/tests/charging-station/ChargingStation-ResetIdentity.test.ts b/tests/charging-station/ChargingStation-ResetIdentity.test.ts index 3fd6d72b1..d50614b43 100644 --- a/tests/charging-station/ChargingStation-ResetIdentity.test.ts +++ b/tests/charging-station/ChargingStation-ResetIdentity.test.ts @@ -13,7 +13,6 @@ import type { ChargingStation } from '../../src/charging-station/ChargingStation import type { ChargingStationOptions } from '../../src/types/index.js' import { SharedLRUCache } from '../../src/charging-station/SharedLRUCache.js' -import { BaseError } from '../../src/exception/index.js' import { sleep } from '../../src/utils/index.js' import { standardCleanup } from '../helpers/TestLifecycleHelpers.js' import { @@ -204,66 +203,4 @@ await describe('ChargingStation keeps its identity across a reset', async () => assert.strictEqual(station.wsConnectionUrl.host, 'localhost:7777') }) - - await it('should reject a malformed supervision URL with a field-naming configuration error', () => { - // A template with a relative or malformed supervision URL must surface a - // structured configuration error, never the bare `TypeError` from `new URL()`. - for (const malformedUrl of ['/relative', 'not a url']) { - assert.throws( - () => - createStationFromTemplate(copyStationTemplate({ supervisionUrls: malformedUrl }), { - supervisionUrls: malformedUrl, - }), - (error: unknown) => - error instanceof BaseError && - error.message.includes(malformedUrl) && - error.message.includes('supervisionUrls') - ) - } - }) - - await it('should revert stationInfo.supervisionUrls when setSupervisionUrl rejects the URL', () => { - const station = createStationFromTemplate(copyStationTemplate()) - const initialSupervisionUrls = station.stationInfo?.supervisionUrls - - assert.throws( - () => { - station.setSupervisionUrl('not a url') - }, - (error: unknown) => error instanceof BaseError && error.message.includes('supervisionUrls') - ) - assert.strictEqual(station.stationInfo?.supervisionUrls, initialSupervisionUrls) - // The retained creation options are only mirrored on success, so a rejected - // update must not leak into the reset/template-reload path either. - assert.strictEqual( - internalsOf(station).creationOptions?.supervisionUrls, - initialSupervisionUrls - ) - }) - - await it('should reject a malformed URL on the OCPP-configuration supervision branch', () => { - // This branch writes the URL into an OCPP configuration key and never calls - // getConfiguredSupervisionUrl, so it needs its own validation: a value that - // is not checked here would surface later as a bare TypeError from - // wsConnectionUrl. - const supervisionUrlOcppKey = 'ocppcentraladdress' - const station = createStationFromTemplate( - copyStationTemplate({ - supervisionUrlOcppConfiguration: true, - supervisionUrlOcppKey, - }), - { supervisionUrlOcppConfiguration: true, supervisionUrlOcppKey } - ) - const initialWsConnectionUrl = station.wsConnectionUrl.href - - assert.throws( - () => { - station.setSupervisionUrl('not a url') - }, - (error: unknown) => - error instanceof BaseError && error.message.includes(supervisionUrlOcppKey) - ) - // The rejected value must not have reached the OCPP configuration key. - assert.strictEqual(station.wsConnectionUrl.href, initialWsConnectionUrl) - }) }) diff --git a/tests/charging-station/ChargingStation-SupervisionUrl.test.ts b/tests/charging-station/ChargingStation-SupervisionUrl.test.ts new file mode 100644 index 000000000..1f9ccd34a --- /dev/null +++ b/tests/charging-station/ChargingStation-SupervisionUrl.test.ts @@ -0,0 +1,155 @@ +/** + * @file Tests that a charging station rejects a malformed supervision URL with a structured configuration error. + * @description A relative or malformed supervision URL must surface a `BaseError` + * naming the offending field and the station instead of leaking the `TypeError` + * from `new URL()`, on every entry path: template/configuration loading, + * `setSupervisionUrl` (both branches) and the `wsConnectionUrl` getter. + */ +import assert from 'node:assert/strict' +import { afterEach, describe, it } from 'node:test' + +import type { ChargingStation } from '../../src/charging-station/ChargingStation.js' +import type { ChargingStationOptions } from '../../src/types/index.js' + +import { flushMicrotasks, standardCleanup } from '../helpers/TestLifecycleHelpers.js' +import { + cleanupStationTemplates, + copyStationTemplate, + createStationFromTemplate, +} from './helpers/StationHelpers.realStation.js' + +// OCPP configuration key used by the shipped station templates that route the +// supervision URL through the OCPP configuration (`supervisionUrlOcppConfiguration`). +const OCPP_SUPERVISION_URL_KEY = 'ocppcentraladdress' +const MALFORMED_SUPERVISION_URL = 'not a url' +// Fixed identity so the getter diagnostic (base URL plus station identity) is +// independent of the worker index. +const FIXED_STATION_NAME = 'CS-URL' + +const stationInternalsOf = ( + station: ChargingStation +): { creationOptions?: ChargingStationOptions } => + station as unknown as { creationOptions?: ChargingStationOptions } + +await describe('ChargingStation supervision URL validation', async () => { + afterEach(async () => { + // A station built with persistence writes its configuration from an + // AsyncLock continuation, i.e. after this synchronous teardown point. + // Drain it so `cleanupStationTemplates()` removes every temp dir. + await flushMicrotasks() + standardCleanup() + cleanupStationTemplates() + }) + + await it('should reject a malformed supervision URL with a field-naming configuration error', () => { + // A template with a relative or malformed supervision URL must surface a + // structured configuration error, never the bare `TypeError` from `new URL()`. + for (const malformedUrl of ['/relative', MALFORMED_SUPERVISION_URL]) { + assert.throws( + () => + createStationFromTemplate(copyStationTemplate({ supervisionUrls: malformedUrl }), { + baseName: FIXED_STATION_NAME, + fixedName: true, + persistentConfiguration: false, + supervisionUrls: malformedUrl, + }), + { + message: `${FIXED_STATION_NAME}: Invalid supervision url '${malformedUrl}' configured in 'supervisionUrls'`, + name: 'BaseError', + } + ) + } + }) + + await it('should revert stationInfo.supervisionUrls when setSupervisionUrl rejects the URL', () => { + const station = createStationFromTemplate(copyStationTemplate(), { + baseName: FIXED_STATION_NAME, + fixedName: true, + persistentConfiguration: false, + }) + const initialSupervisionUrls = station.stationInfo?.supervisionUrls + + assert.throws( + () => { + station.setSupervisionUrl(MALFORMED_SUPERVISION_URL) + }, + { + message: `${FIXED_STATION_NAME}: Invalid supervision url '${MALFORMED_SUPERVISION_URL}' configured in 'supervisionUrls'`, + name: 'BaseError', + } + ) + assert.strictEqual(station.stationInfo?.supervisionUrls, initialSupervisionUrls) + // The retained creation options are only mirrored on success, so a rejected + // update must not leak into the reset/template-reload path either. + assert.strictEqual( + stationInternalsOf(station).creationOptions?.supervisionUrls, + initialSupervisionUrls + ) + }) + + await it('should reject a malformed URL on the OCPP-configuration supervision branch', () => { + // This branch writes the URL into an OCPP configuration key and never calls + // getConfiguredSupervisionUrl, so it needs its own validation: a value that + // is not checked here would surface later as a bare TypeError from + // wsConnectionUrl. + const station = createStationFromTemplate( + copyStationTemplate({ + supervisionUrlOcppConfiguration: true, + supervisionUrlOcppKey: OCPP_SUPERVISION_URL_KEY, + }), + { baseName: FIXED_STATION_NAME, fixedName: true, persistentConfiguration: false } + ) + const initialWsConnectionUrl = station.wsConnectionUrl.href + + assert.throws( + () => { + station.setSupervisionUrl(MALFORMED_SUPERVISION_URL) + }, + { + message: `${FIXED_STATION_NAME}: Invalid supervision url '${MALFORMED_SUPERVISION_URL}' configured in '${OCPP_SUPERVISION_URL_KEY}'`, + name: 'BaseError', + } + ) + // The rejected value must not have reached the OCPP configuration key. + assert.strictEqual(station.wsConnectionUrl.href, initialWsConnectionUrl) + }) + + await it('should reject a malformed supervision URL seeded in the OCPP configuration key', () => { + // The OCPP configuration key can carry the supervision URL without going + // through setSupervisionUrl (template Configuration, or an OCPP + // ChangeConfiguration). The wsConnectionUrl getter is the only place that + // parses it, so it must raise the structured error too. + const station = createStationFromTemplate( + copyStationTemplate({ + Configuration: { + configurationKey: [ + { + key: OCPP_SUPERVISION_URL_KEY, + readonly: false, + value: MALFORMED_SUPERVISION_URL, + }, + ], + }, + supervisionUrlOcppConfiguration: true, + supervisionUrlOcppKey: OCPP_SUPERVISION_URL_KEY, + }), + { baseName: FIXED_STATION_NAME, fixedName: true, persistentConfiguration: false } + ) + + assert.throws(() => station.wsConnectionUrl, { + message: `${FIXED_STATION_NAME}: Invalid supervision url '${MALFORMED_SUPERVISION_URL}' configured in '${OCPP_SUPERVISION_URL_KEY}'`, + name: 'BaseError', + }) + }) + + await it('should accept a valid supervision URL on every entry path', () => { + const station = createStationFromTemplate(copyStationTemplate(), { + baseName: FIXED_STATION_NAME, + fixedName: true, + persistentConfiguration: false, + }) + + station.setSupervisionUrl('ws://localhost:8888/') + assert.strictEqual(station.wsConnectionUrl.href, `ws://localhost:8888/${FIXED_STATION_NAME}`) + }) +}) From b3e4393c608b98e0c8ce1ffb94a056572fa472c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 7 Oct 2026 19:44:45 +0200 Subject: [PATCH 5/6] fix(charging-station): normalize supervision URL before persisting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- README.md | 1 + src/charging-station/ChargingStation.ts | 15 +-- .../ChargingStation-Configuration.test.ts | 16 --- .../ChargingStation-SupervisionUrl.test.ts | 102 ++++++++++++++++++ .../fixtures/supervisionUrlWorker.mjs | 85 +++++++++++++++ 5 files changed, 193 insertions(+), 26 deletions(-) create mode 100644 tests/charging-station/fixtures/supervisionUrlWorker.mjs diff --git a/README.md b/README.md index 99182f474..6da012609 100644 --- a/README.md +++ b/README.md @@ -1130,6 +1130,7 @@ Set the WebSocket header _Sec-WebSocket-Protocol_ to `ui0.0.1`. `supervisionPassword?`: string } `url` is required and must be an absolute URL. `supervisionUser` must not contain `:` (RFC 7617). `supervisionUser` and `supervisionPassword` are each optional and independent: a string (including `""`, which clears the field) updates the value; omitting the field preserves the existing value. Changes take effect on the next WebSocket (re)connect. + When the supervision URL is stored in an OCPP configuration key, the key contains the normalized absolute URL (for example, `"ws://example.org "` becomes `"ws://example.org/"`). A URL parsing failure leaves the previous URL, credentials, retained creation options, and persistent configuration unchanged. - Response: `PDU`: { diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index b25b2d77b..9d4b7b2d7 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -1864,8 +1864,8 @@ export class ChargingStation extends EventEmitter { this.stationInfo?.supervisionUrlOcppConfiguration === true && isNotEmptyString(this.stationInfo.supervisionUrlOcppKey) ) { - this.parseSupervisionUrl(url, this.stationInfo.supervisionUrlOcppKey) - setConfigurationKeyValue(this, this.stationInfo.supervisionUrlOcppKey, url) + const supervisionUrl = this.parseSupervisionUrl(url, this.stationInfo.supervisionUrlOcppKey) + setConfigurationKeyValue(this, this.stationInfo.supervisionUrlOcppKey, supervisionUrl.href) } else if (this.stationInfo != null) { const prevSupervisionUrls = this.stationInfo.supervisionUrls this.stationInfo.supervisionUrls = url @@ -1878,14 +1878,9 @@ export class ChargingStation extends EventEmitter { } if (this.stationInfo != null) { applyCredentials(this.stationInfo) - // Mirror the update into the retained creation options so a later reset() or - // template reload re-applies this URL, not the creation-time one — for BOTH - // branches above. On a cache-cold reinitialization (reload) a non-persistent - // station's supervisionUrlOcppKey is absent and re-seeded from - // configuredSupervisionUrl (i.e. stationInfo.supervisionUrls, written from - // these options), so without the mirror the reload would restore the old URL. - // (A warm reset() reuses the cached template whose in-place key mutation - // already carries it.) In-memory only: a full restart reverts to the originals. + // Retain the caller's URL and credentials for non-persistent resets and + // template reloads, which rebuild OCPP configuration from these options. + // getConfiguredSupervisionUrl normalizes the URL again before reseeding the key. if (this.creationOptions != null) { this.creationOptions.supervisionUrls = url applyCredentials(this.creationOptions) diff --git a/tests/charging-station/ChargingStation-Configuration.test.ts b/tests/charging-station/ChargingStation-Configuration.test.ts index 03a452410..421e908f6 100644 --- a/tests/charging-station/ChargingStation-Configuration.test.ts +++ b/tests/charging-station/ChargingStation-Configuration.test.ts @@ -357,22 +357,6 @@ await describe('ChargingStation Configuration Management', async () => { cleanupChargingStation(station2) }) - await it('should support setSupervisionUrl method if available', () => { - // Arrange - const result = createMockChargingStation() - station = result.station - - // Act & Assert - setSupervisionUrl should be a function if available - if ('setSupervisionUrl' in station && typeof station.setSupervisionUrl === 'function') { - assert.doesNotThrow(() => { - station?.setSupervisionUrl('ws://new-server:8080') - }) - } else { - // Mock station may not have setSupervisionUrl, which is expected - assert.notStrictEqual(station, undefined) - } - }) - // === Configuration Loading & Persistence === await it('should have template file reference', () => { diff --git a/tests/charging-station/ChargingStation-SupervisionUrl.test.ts b/tests/charging-station/ChargingStation-SupervisionUrl.test.ts index 1f9ccd34a..64227322a 100644 --- a/tests/charging-station/ChargingStation-SupervisionUrl.test.ts +++ b/tests/charging-station/ChargingStation-SupervisionUrl.test.ts @@ -7,10 +7,12 @@ */ import assert from 'node:assert/strict' import { afterEach, describe, it } from 'node:test' +import { Worker } from 'node:worker_threads' import type { ChargingStation } from '../../src/charging-station/ChargingStation.js' import type { ChargingStationOptions } from '../../src/types/index.js' +import { BaseError } from '../../src/exception/BaseError.js' import { flushMicrotasks, standardCleanup } from '../helpers/TestLifecycleHelpers.js' import { cleanupStationTemplates, @@ -31,6 +33,24 @@ const stationInternalsOf = ( ): { creationOptions?: ChargingStationOptions } => station as unknown as { creationOptions?: ChargingStationOptions } +interface SupervisionUrlWorkerScenario { + accepted: SupervisionUrlWorkerState + persistedAfter: string + persistedBefore: string + rejected: SupervisionUrlWorkerState + rejection?: Pick + supervisionUrlOcppConfiguration: boolean +} + +interface SupervisionUrlWorkerState { + connectionUrl: string + creationOptions?: ChargingStationOptions + ocppUrl?: string + stationInfo: Pick< + ChargingStationOptions, + 'supervisionPassword' | 'supervisionUrls' | 'supervisionUser' + > +} await describe('ChargingStation supervision URL validation', async () => { afterEach(async () => { // A station built with persistence writes its configuration from an @@ -142,6 +162,88 @@ await describe('ChargingStation supervision URL validation', async () => { }) }) + await it('should normalize supervision URLs in a worker and preserve persisted state on rejection', async () => { + // Arrange: a real worker exercises the updated event and both storage branches. + const url = 'wss://EXAMPLE.org:443 ' + const updatedUrls: string[] = [] + const worker = new Worker(new URL('./fixtures/supervisionUrlWorker.mjs', import.meta.url), { + execArgv: [], + workerData: { key: OCPP_SUPERVISION_URL_KEY, stationId: FIXED_STATION_NAME, url }, + }) + try { + // Act: the fixture performs a valid update, then a rejected update, and drains persistence. + const scenarios = await new Promise((resolve, reject) => { + worker.on('message', (message: { data: unknown; event: string }) => { + if (message.event === 'supervisionUrlResult') { + resolve(message.data as SupervisionUrlWorkerScenario[]) + } else if (message.event === 'supervisionUrlFailure') { + const failure = message.data as Pick + const error = new BaseError(failure.message) + error.stack = failure.stack + reject(error) + } else if (message.event === 'updated') { + updatedUrls.push((message.data as { supervisionUrl: string }).supervisionUrl) + } + }) + worker.once('error', reject) + worker.once('exit', code => { + reject( + new BaseError( + `Supervision URL worker exited before returning results (code ${code.toString()})` + ) + ) + }) + }) + + // Assert: successful normalization preserves raw reset options and rejected updates change nothing. + assert.deepStrictEqual( + scenarios.map(scenario => scenario.supervisionUrlOcppConfiguration), + [false, true] + ) + assert.deepStrictEqual(updatedUrls, [ + `wss://example.org/${FIXED_STATION_NAME}`, + `wss://example.org/${FIXED_STATION_NAME}`, + ]) + for (const scenario of scenarios) { + const field = scenario.supervisionUrlOcppConfiguration + ? OCPP_SUPERVISION_URL_KEY + : 'supervisionUrls' + assert.strictEqual( + scenario.accepted.connectionUrl, + `wss://example.org/${FIXED_STATION_NAME}` + ) + assert.strictEqual(scenario.accepted.creationOptions?.supervisionUrls, url) + assert.strictEqual(scenario.accepted.creationOptions.supervisionUser, 'new-user') + assert.strictEqual(scenario.accepted.creationOptions.supervisionPassword, '') + assert.strictEqual(scenario.accepted.stationInfo.supervisionUser, 'new-user') + assert.strictEqual(scenario.accepted.stationInfo.supervisionPassword, '') + const persisted = JSON.parse(scenario.persistedBefore) as { + configurationKey?: { key: string; value: string }[] + stationInfo?: ChargingStationOptions + } + assert.strictEqual(persisted.stationInfo?.supervisionUser, 'new-user') + assert.strictEqual(persisted.stationInfo.supervisionPassword, '') + if (scenario.supervisionUrlOcppConfiguration) { + assert.strictEqual(scenario.accepted.ocppUrl, 'wss://example.org/') + assert.strictEqual( + persisted.configurationKey?.find(key => key.key === OCPP_SUPERVISION_URL_KEY)?.value, + 'wss://example.org/' + ) + } else { + assert.strictEqual(scenario.accepted.stationInfo.supervisionUrls, url) + assert.strictEqual(persisted.stationInfo.supervisionUrls, url) + } + assert.deepStrictEqual(scenario.rejection, { + message: `${FIXED_STATION_NAME}: Invalid supervision url '${MALFORMED_SUPERVISION_URL}' configured in '${field}'`, + name: 'BaseError', + }) + assert.deepStrictEqual(scenario.rejected, scenario.accepted) + assert.strictEqual(scenario.persistedAfter, scenario.persistedBefore) + } + } finally { + await worker.terminate() + } + }) await it('should accept a valid supervision URL on every entry path', () => { const station = createStationFromTemplate(copyStationTemplate(), { baseName: FIXED_STATION_NAME, diff --git a/tests/charging-station/fixtures/supervisionUrlWorker.mjs b/tests/charging-station/fixtures/supervisionUrlWorker.mjs new file mode 100644 index 000000000..38c01dd0e --- /dev/null +++ b/tests/charging-station/fixtures/supervisionUrlWorker.mjs @@ -0,0 +1,85 @@ +/** + * @file Real-worker supervision URL update scenarios. + * @description Exercises the updated payload and persisted configuration without opening a socket. + */ +import { readFileSync } from 'node:fs' +import { parentPort, workerData } from 'node:worker_threads' +// eslint-disable-next-line n/no-unpublished-import -- Test-only TypeScript loader. +import { register } from 'tsx/esm/api' + +const unregister = register() +const { getConfigurationKey } = + await import('../../../src/charging-station/ConfigurationKeyUtils.ts') +const { flushMicrotasks, standardCleanup } = await import('../../helpers/TestLifecycleHelpers.ts') +const { + cleanupStationTemplates, + copyStationTemplate, + createStationFromTemplate, + resolvePersistedConfigurationFile, +} = await import('../helpers/StationHelpers.realStation.ts') + +const scenarios = [] +let station +let failure +try { + for (const supervisionUrlOcppConfiguration of [false, true]) { + const template = copyStationTemplate({ + supervisionUrlOcppConfiguration, + supervisionUrlOcppKey: workerData.key, + }) + station = createStationFromTemplate(template, { + baseName: workerData.stationId, + fixedName: true, + persistentConfiguration: true, + supervisionPassword: 'old-password', + supervisionUrls: 'ws://localhost:9999/', + supervisionUser: 'old-user', + }) + await station.pendingConfigurationSave + const captureState = () => ({ + connectionUrl: station.wsConnectionUrl.href, + creationOptions: structuredClone(station.creationOptions), + ocppUrl: getConfigurationKey(station, workerData.key)?.value, + stationInfo: { + supervisionPassword: station.stationInfo?.supervisionPassword, + supervisionUrls: station.stationInfo?.supervisionUrls, + supervisionUser: station.stationInfo?.supervisionUser, + }, + }) + + // In a worker, updated synchronously builds a payload that reads wsConnectionUrl. + station.setSupervisionUrl(workerData.url, 'new-user', '') + await station.pendingConfigurationSave + const accepted = captureState() + const configurationFile = resolvePersistedConfigurationFile(template) + const persistedBefore = readFileSync(configurationFile, 'utf8') + let rejection + try { + station.setSupervisionUrl('not a url', 'rejected-user', 'rejected-password') + } catch (error) { + rejection = { message: error.message, name: error.name } + } + await station.pendingConfigurationSave + scenarios.push({ + accepted, + persistedAfter: readFileSync(configurationFile, 'utf8'), + persistedBefore, + rejected: captureState(), + rejection, + supervisionUrlOcppConfiguration, + }) + } +} catch (error) { + failure = { message: error.message, stack: error.stack } +} finally { + await station?.pendingConfigurationSave + await flushMicrotasks() + standardCleanup() + cleanupStationTemplates() + unregister() +} +parentPort?.postMessage( + failure == null + ? { data: scenarios, event: 'supervisionUrlResult' } + : { data: failure, event: 'supervisionUrlFailure' } +) From 22e505f61e8da9bb6c8508bb0c89c1868c14d5c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 7 Oct 2026 20:36:09 +0200 Subject: [PATCH 6/6] refactor: reuse test helpers and keep README user-focused MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- README.md | 1 - .../ChargingStation-SupervisionUrl.test.ts | 79 +++++++++++-------- .../fixtures/supervisionUrlWorker.mjs | 1 - 3 files changed, 46 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 6da012609..99182f474 100644 --- a/README.md +++ b/README.md @@ -1130,7 +1130,6 @@ Set the WebSocket header _Sec-WebSocket-Protocol_ to `ui0.0.1`. `supervisionPassword?`: string } `url` is required and must be an absolute URL. `supervisionUser` must not contain `:` (RFC 7617). `supervisionUser` and `supervisionPassword` are each optional and independent: a string (including `""`, which clears the field) updates the value; omitting the field preserves the existing value. Changes take effect on the next WebSocket (re)connect. - When the supervision URL is stored in an OCPP configuration key, the key contains the normalized absolute URL (for example, `"ws://example.org "` becomes `"ws://example.org/"`). A URL parsing failure leaves the previous URL, credentials, retained creation options, and persistent configuration unchanged. - Response: `PDU`: { diff --git a/tests/charging-station/ChargingStation-SupervisionUrl.test.ts b/tests/charging-station/ChargingStation-SupervisionUrl.test.ts index 64227322a..74eb6322e 100644 --- a/tests/charging-station/ChargingStation-SupervisionUrl.test.ts +++ b/tests/charging-station/ChargingStation-SupervisionUrl.test.ts @@ -10,29 +10,39 @@ import { afterEach, describe, it } from 'node:test' import { Worker } from 'node:worker_threads' import type { ChargingStation } from '../../src/charging-station/ChargingStation.js' -import type { ChargingStationOptions } from '../../src/types/index.js' import { BaseError } from '../../src/exception/BaseError.js' +import { + type ChargingStationConfiguration, + type ChargingStationData, + type ChargingStationOptions, + type ChargingStationWorkerMessage, + ChargingStationWorkerMessageEvents, +} from '../../src/types/index.js' import { flushMicrotasks, standardCleanup } from '../helpers/TestLifecycleHelpers.js' +import { TEST_SUPERVISION_URL_ALT_PORT } from '../utils/TestNetworkConstants.js' +import { TEST_CHARGING_STATION_BASE_NAME } from './ChargingStationTestConstants.js' import { cleanupStationTemplates, copyStationTemplate, createStationFromTemplate, } from './helpers/StationHelpers.realStation.js' -// OCPP configuration key used by the shipped station templates that route the -// supervision URL through the OCPP configuration (`supervisionUrlOcppConfiguration`). +// Shipped templates use this custom key instead of the default ConnectionUrl; +// retain it to verify diagnostics name the configured key, not the default. const OCPP_SUPERVISION_URL_KEY = 'ocppcentraladdress' const MALFORMED_SUPERVISION_URL = 'not a url' -// Fixed identity so the getter diagnostic (base URL plus station identity) is -// independent of the worker index. -const FIXED_STATION_NAME = 'CS-URL' const stationInternalsOf = ( station: ChargingStation ): { creationOptions?: ChargingStationOptions } => station as unknown as { creationOptions?: ChargingStationOptions } +type SupervisionUrlWorkerMessage = + | ChargingStationWorkerMessage + | { data: Pick; event: 'supervisionUrlFailure' } + | { data: SupervisionUrlWorkerScenario[]; event: 'supervisionUrlResult' } + interface SupervisionUrlWorkerScenario { accepted: SupervisionUrlWorkerState persistedAfter: string @@ -68,13 +78,13 @@ await describe('ChargingStation supervision URL validation', async () => { assert.throws( () => createStationFromTemplate(copyStationTemplate({ supervisionUrls: malformedUrl }), { - baseName: FIXED_STATION_NAME, + baseName: TEST_CHARGING_STATION_BASE_NAME, fixedName: true, persistentConfiguration: false, supervisionUrls: malformedUrl, }), { - message: `${FIXED_STATION_NAME}: Invalid supervision url '${malformedUrl}' configured in 'supervisionUrls'`, + message: `${TEST_CHARGING_STATION_BASE_NAME}: Invalid supervision url '${malformedUrl}' configured in 'supervisionUrls'`, name: 'BaseError', } ) @@ -83,7 +93,7 @@ await describe('ChargingStation supervision URL validation', async () => { await it('should revert stationInfo.supervisionUrls when setSupervisionUrl rejects the URL', () => { const station = createStationFromTemplate(copyStationTemplate(), { - baseName: FIXED_STATION_NAME, + baseName: TEST_CHARGING_STATION_BASE_NAME, fixedName: true, persistentConfiguration: false, }) @@ -94,7 +104,7 @@ await describe('ChargingStation supervision URL validation', async () => { station.setSupervisionUrl(MALFORMED_SUPERVISION_URL) }, { - message: `${FIXED_STATION_NAME}: Invalid supervision url '${MALFORMED_SUPERVISION_URL}' configured in 'supervisionUrls'`, + message: `${TEST_CHARGING_STATION_BASE_NAME}: Invalid supervision url '${MALFORMED_SUPERVISION_URL}' configured in 'supervisionUrls'`, name: 'BaseError', } ) @@ -117,7 +127,7 @@ await describe('ChargingStation supervision URL validation', async () => { supervisionUrlOcppConfiguration: true, supervisionUrlOcppKey: OCPP_SUPERVISION_URL_KEY, }), - { baseName: FIXED_STATION_NAME, fixedName: true, persistentConfiguration: false } + { baseName: TEST_CHARGING_STATION_BASE_NAME, fixedName: true, persistentConfiguration: false } ) const initialWsConnectionUrl = station.wsConnectionUrl.href @@ -126,7 +136,7 @@ await describe('ChargingStation supervision URL validation', async () => { station.setSupervisionUrl(MALFORMED_SUPERVISION_URL) }, { - message: `${FIXED_STATION_NAME}: Invalid supervision url '${MALFORMED_SUPERVISION_URL}' configured in '${OCPP_SUPERVISION_URL_KEY}'`, + message: `${TEST_CHARGING_STATION_BASE_NAME}: Invalid supervision url '${MALFORMED_SUPERVISION_URL}' configured in '${OCPP_SUPERVISION_URL_KEY}'`, name: 'BaseError', } ) @@ -153,11 +163,11 @@ await describe('ChargingStation supervision URL validation', async () => { supervisionUrlOcppConfiguration: true, supervisionUrlOcppKey: OCPP_SUPERVISION_URL_KEY, }), - { baseName: FIXED_STATION_NAME, fixedName: true, persistentConfiguration: false } + { baseName: TEST_CHARGING_STATION_BASE_NAME, fixedName: true, persistentConfiguration: false } ) assert.throws(() => station.wsConnectionUrl, { - message: `${FIXED_STATION_NAME}: Invalid supervision url '${MALFORMED_SUPERVISION_URL}' configured in '${OCPP_SUPERVISION_URL_KEY}'`, + message: `${TEST_CHARGING_STATION_BASE_NAME}: Invalid supervision url '${MALFORMED_SUPERVISION_URL}' configured in '${OCPP_SUPERVISION_URL_KEY}'`, name: 'BaseError', }) }) @@ -168,21 +178,24 @@ await describe('ChargingStation supervision URL validation', async () => { const updatedUrls: string[] = [] const worker = new Worker(new URL('./fixtures/supervisionUrlWorker.mjs', import.meta.url), { execArgv: [], - workerData: { key: OCPP_SUPERVISION_URL_KEY, stationId: FIXED_STATION_NAME, url }, + workerData: { + key: OCPP_SUPERVISION_URL_KEY, + stationId: TEST_CHARGING_STATION_BASE_NAME, + url, + }, }) try { // Act: the fixture performs a valid update, then a rejected update, and drains persistence. const scenarios = await new Promise((resolve, reject) => { - worker.on('message', (message: { data: unknown; event: string }) => { + worker.on('message', (message: SupervisionUrlWorkerMessage) => { if (message.event === 'supervisionUrlResult') { - resolve(message.data as SupervisionUrlWorkerScenario[]) + resolve(message.data) } else if (message.event === 'supervisionUrlFailure') { - const failure = message.data as Pick - const error = new BaseError(failure.message) - error.stack = failure.stack + const error = new BaseError(message.data.message) + error.stack = message.data.stack reject(error) - } else if (message.event === 'updated') { - updatedUrls.push((message.data as { supervisionUrl: string }).supervisionUrl) + } else if (message.event === ChargingStationWorkerMessageEvents.updated) { + updatedUrls.push(message.data.supervisionUrl) } }) worker.once('error', reject) @@ -201,8 +214,8 @@ await describe('ChargingStation supervision URL validation', async () => { [false, true] ) assert.deepStrictEqual(updatedUrls, [ - `wss://example.org/${FIXED_STATION_NAME}`, - `wss://example.org/${FIXED_STATION_NAME}`, + `wss://example.org/${TEST_CHARGING_STATION_BASE_NAME}`, + `wss://example.org/${TEST_CHARGING_STATION_BASE_NAME}`, ]) for (const scenario of scenarios) { const field = scenario.supervisionUrlOcppConfiguration @@ -210,17 +223,14 @@ await describe('ChargingStation supervision URL validation', async () => { : 'supervisionUrls' assert.strictEqual( scenario.accepted.connectionUrl, - `wss://example.org/${FIXED_STATION_NAME}` + `wss://example.org/${TEST_CHARGING_STATION_BASE_NAME}` ) assert.strictEqual(scenario.accepted.creationOptions?.supervisionUrls, url) assert.strictEqual(scenario.accepted.creationOptions.supervisionUser, 'new-user') assert.strictEqual(scenario.accepted.creationOptions.supervisionPassword, '') assert.strictEqual(scenario.accepted.stationInfo.supervisionUser, 'new-user') assert.strictEqual(scenario.accepted.stationInfo.supervisionPassword, '') - const persisted = JSON.parse(scenario.persistedBefore) as { - configurationKey?: { key: string; value: string }[] - stationInfo?: ChargingStationOptions - } + const persisted = JSON.parse(scenario.persistedBefore) as ChargingStationConfiguration assert.strictEqual(persisted.stationInfo?.supervisionUser, 'new-user') assert.strictEqual(persisted.stationInfo.supervisionPassword, '') if (scenario.supervisionUrlOcppConfiguration) { @@ -234,7 +244,7 @@ await describe('ChargingStation supervision URL validation', async () => { assert.strictEqual(persisted.stationInfo.supervisionUrls, url) } assert.deepStrictEqual(scenario.rejection, { - message: `${FIXED_STATION_NAME}: Invalid supervision url '${MALFORMED_SUPERVISION_URL}' configured in '${field}'`, + message: `${TEST_CHARGING_STATION_BASE_NAME}: Invalid supervision url '${MALFORMED_SUPERVISION_URL}' configured in '${field}'`, name: 'BaseError', }) assert.deepStrictEqual(scenario.rejected, scenario.accepted) @@ -246,12 +256,15 @@ await describe('ChargingStation supervision URL validation', async () => { }) await it('should accept a valid supervision URL on every entry path', () => { const station = createStationFromTemplate(copyStationTemplate(), { - baseName: FIXED_STATION_NAME, + baseName: TEST_CHARGING_STATION_BASE_NAME, fixedName: true, persistentConfiguration: false, }) - station.setSupervisionUrl('ws://localhost:8888/') - assert.strictEqual(station.wsConnectionUrl.href, `ws://localhost:8888/${FIXED_STATION_NAME}`) + station.setSupervisionUrl(TEST_SUPERVISION_URL_ALT_PORT) + assert.strictEqual( + station.wsConnectionUrl.href, + `${TEST_SUPERVISION_URL_ALT_PORT}/${TEST_CHARGING_STATION_BASE_NAME}` + ) }) }) diff --git a/tests/charging-station/fixtures/supervisionUrlWorker.mjs b/tests/charging-station/fixtures/supervisionUrlWorker.mjs index 38c01dd0e..23f11ff72 100644 --- a/tests/charging-station/fixtures/supervisionUrlWorker.mjs +++ b/tests/charging-station/fixtures/supervisionUrlWorker.mjs @@ -32,7 +32,6 @@ try { fixedName: true, persistentConfiguration: true, supervisionPassword: 'old-password', - supervisionUrls: 'ws://localhost:9999/', supervisionUser: 'old-user', }) await station.pendingConfigurationSave