Added CS RequestOcppParams validation
ADD
src/assets/server/rest/v1/schemas/chargingstation/chargingstation-ocpp-request-parameters.json
+{
+ "title": "Request Charging Station OCPP parameters",
+ "type": "object",
+ "properties": {
+ "chargeBoxID": {
+ "$ref": "chargingstation.json#/definitions/id"
+ },
+ "forceUpdateOCPPParamsFromTemplate": {
+ "type": "boolean",
+ "sanitize": "mongo"
+ }
+ },
+ "required": [
+ "chargeBoxID"
+ ]
+}

MODIFY
src/server/rest/v1/service/ChargingStationService.ts
src/server/rest/v1/service/ChargingStationService.ts
@@ -751,7 +751,7 @@ export default class ChargingStationService {
public static async handleRequestChargingStationOcppParameters(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const filteredRequest = ChargingStationSecurity.filterRequestChargingStationOcppParametersRequest(req.body);
+ const filteredRequest = ChargingStationValidator.getInstance().validateChargingStationRequestOCPPParametersReq(req.body);
UtilsService.assertIdIsProvided(action, filteredRequest.chargeBoxID, MODULE_NAME, 'handleRequestChargingStationOcppParameters', req.user);
// Check auth
if (!Authorizations.canReadChargingStation(req.user)) {

MODIFY
src/server/rest/v1/validator/ChargingStationValidator.ts
src/server/rest/v1/validator/ChargingStationValidator.ts
-import { HttpChargingStationCommandRequest, HttpChargingStationsRequest } from '../../../../types/requests/HttpChargingStationRequest';
+import { HttpChargingStationCommandRequest, HttpChargingStationOcppParametersRequest, HttpChargingStationsRequest } from '../../../../types/requests/HttpChargingStationRequest';
import HttpByIDRequest from '../../../../types/requests/HttpByIDRequest';
import Schema from './Schema';
@@ -12,6 +12,7 @@ export default class ChargingStationValidator extends SchemaValidator {
private chargingStationGet: Schema;
private chargingStationDelete: Schema;
private chargingStationAction: Schema;
+ private chargingStationRequestOCPPParameters: Schema;
private constructor() {
@@ -20,6 +21,7 @@ export default class ChargingStationValidator extends SchemaValidator {
this.chargingStationGet = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/chargingstation-get.json`, 'utf8'));
this.chargingStationDelete = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/chargingstation-delete.json`, 'utf8'));
this.chargingStationAction = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/chargingstation-action.json`, 'utf8'));
+ this.chargingStationRequestOCPPParameters = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/chargingstation-ocpp-request-parameters.json`, 'utf8'));
}
public static getInstance(): ChargingStationValidator {
@@ -52,4 +54,10 @@ export default class ChargingStationValidator extends SchemaValidator {
this.validate(this.chargingStationAction, data);
return data;
}
+
+ public validateChargingStationRequestOCPPParametersReq(data: any): HttpChargingStationOcppParametersRequest {
+ // Validate schema
+ this.validate(this.chargingStationRequestOCPPParameters, data);
+ return data;
+ }
}

Added CS RequestOcppParams validation