]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commit
fix(simulator): reject a performance storage URI that is not an absolute URL (#2169)
authorVitor Coelho <6161176+VitorCoelho@users.noreply.github.com>
Fri, 30 Oct 2026 16:23:20 +0000 (16:23 +0000)
committerGitHub <noreply@github.com>
Fri, 30 Oct 2026 16:23:20 +0000 (16:23 +0000)
commita8f2f1749ac36aa1421e178274f895746053250c
tree8651ecca53d21aeb698f205593ea4eab420755ec
parentf8487b2d256fa3e476a4544a750b23af0152c03c
fix(simulator): reject a performance storage URI that is not an absolute URL (#2169)

* fix(simulator): reject a performance storage URI that is not an absolute URL

performanceStorage.uri (and its deprecated URI alias) accepted any
string, but the simulator parses it with new URL() while building the
configuration at module load and in the Storage constructor. A value
such as "not a url" or a relative path like "performance/records.json"
therefore crashed the simulator with a bare "TypeError: Invalid URL"
that did not name the field.

Validate the value with URL.canParse() in the configuration schema so
it is reported as a configuration error on performanceStorage.uri (or
performanceStorage.URI) instead. The narrowing is folded into the
unreleased configuration schema version 2.

Closes #2142

Signed-off-by: VitorCoelho <vitorc195@gmail.com>
* test(utils): cover absolute performance storage URIs

Signed-off-by: VitorCoelho <vitorc195@gmail.com>
* fix(simulator): validate performanceStorage.uri only where the simulator parses it

The simulator parses the URI at load time for the jsonfile and sqlite
storage types and when it opens an enabled storage. Values the simulator
never reads, including the deprecated URI alias, are left unvalidated so
existing configurations keep loading.

Signed-off-by: VitorCoelho <vitorc195@gmail.com>
* test(utils): cover performanceStorage.uri only where the simulator parses it

Signed-off-by: VitorCoelho <vitorc195@gmail.com>
* fix(simulator): validate performanceStorage.uri for remote backends with enabled omitted

The mongodb, mysql and mariadb backends inherit 'enabled: true' from the
default storage configuration, so the storage is opened and the URI parsed
unless 'enabled' is false. Treat an omitted 'enabled' as enabled for them.

Signed-off-by: VitorCoelho <vitorc195@gmail.com>
* test(utils): cover performanceStorage.uri validation with enabled omitted

mongodb, mysql and mariadb sections without 'enabled' now reject a
relative uri; sections with 'enabled: false' and a bare '{ enabled: true }'
section are still accepted.

Signed-off-by: VitorCoelho <vitorc195@gmail.com>
* refactor(simulator): share the performance storage enabled default with the schema

The schema resolved an omitted 'performanceStorage.enabled' with
'enabled !== false', which re-encodes the 'enabled: true' default of
defaultStorageConfiguration in Configuration.ts. Move that boolean to
Constants.DEFAULT_PERFORMANCE_STORAGE_ENABLED, use it in the runtime default
and resolve the schema fallback with 'value.enabled ?? default', so a change
to the canonical default is followed by validation. No behaviour change.

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

Signed-off-by: VitorCoelho <vitorc195@gmail.com>
Co-authored-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/utils/Configuration.ts
src/utils/ConfigurationMigrations.ts
src/utils/ConfigurationSchema.ts
src/utils/Constants.ts
tests/utils/ConfigurationSchema.test.ts