Smart charging - added URL check before calling optimizer
MODIFY
src/utils/Constants.ts
src/utils/Constants.ts
@@ -293,6 +293,7 @@ export default class Constants {
public static readonly REGEX_VALIDATION_LATITUDE = /^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?)$/;
public static readonly REGEX_VALIDATION_LONGITUDE = /^[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/;
+ public static readonly REGEX_URL_PATTERN = /^(?:https?|wss?):\/\/((?:[\w-]+)(?:\.[\w-]+)*)(?:[\w.,@?^=%&amp;:\/~+#-]*[\w@?^=%&amp;\/~+#-])?$/;
public static readonly MAX_GPS_DISTANCE_METERS = 40000000; // Earth
public static readonly EXCEPTION_JSON_KEYS_IN_SENSITIVE_DATA = Object.freeze([

MODIFY
test/api/SmartChargingTest.ts
test/api/SmartChargingTest.ts
@@ -318,6 +318,15 @@ describe('Smart Charging Service', function() {
expect(response.data).containSubset(Constants.REST_RESPONSE_SUCCESS);
});
+ it('Should not connect to Smart Charging Provider with invalid URL', async () => {
+ const sapSmartChargingSettings = TestData.getSmartChargingSettings();
+ sapSmartChargingSettings.password = await Cypher.encrypt(testData.tenantContext.getTenant().id, sapSmartChargingSettings.password);
+ sapSmartChargingSettings.optimizerUrl = '';
+ await TestData.saveSmartChargingSettings(testData, sapSmartChargingSettings);
+ const response = await testData.userService.smartChargingApi.testConnection({});
+ expect(response.data.message).include('SAP Smart Charging service configuration is incorrect');
+ });
+
describe('Test for three phased site area', () => {
before(() => {
testData.siteContext = testData.tenantContext.getSiteContext(ContextDefinition.SITE_CONTEXTS.SITE_BASIC);

Smart charging - added URL check before calling optimizer