From 124f3553d1516addeb523e3ae364ab727bae8d04 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 19 Dec 2021 18:32:40 +0100 Subject: [PATCH] Check for CS registration status before issuing OCPP commands MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- package-lock.json | 114 +++++++++--------- package.json | 6 +- .../ocpp/1.6/OCPP16IncomingRequestService.ts | 24 ++-- .../ocpp/1.6/OCPP16ResponseService.ts | 20 +-- 4 files changed, 86 insertions(+), 78 deletions(-) diff --git a/package-lock.json b/package-lock.json index 57453b9a..20597b30 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,7 +32,7 @@ "@rollup/plugin-json": "^4.1.0", "@types/mocha": "^9.0.0", "@types/mochawesome": "^6.2.1", - "@types/node": "^16.11.13", + "@types/node": "^16.11.14", "@types/proper-lockfile": "^4.1.2", "@types/tar": "^6.1.1", "@types/uuid": "^8.3.3", @@ -42,9 +42,9 @@ "auto-changelog": "^2.3.0", "clinic": "^10.0.0", "cross-env": "^7.0.3", - "eslint": "^8.4.1", + "eslint": "^8.5.0", "eslint-plugin-import": "^2.25.3", - "eslint-plugin-jsdoc": "^37.2.2", + "eslint-plugin-jsdoc": "^37.3.0", "eslint-plugin-node": "^11.1.0", "expect": "^27.4.2", "mocha": "^9.1.3", @@ -532,9 +532,9 @@ } }, "node_modules/@clinic/doctor": { - "version": "9.0.0", - "resolved": "https://registry.npmjs.org/@clinic/doctor/-/doctor-9.0.0.tgz", - "integrity": "sha512-opIWn42Y4QPk4fidF5mvltwbeqSmJDaOl36I4EWyz/tA9Gh8JCsZEGxE+NwC9H+Wh0TeZf9Nl4+xRirIaLn7Cg==", + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/@clinic/doctor/-/doctor-9.1.0.tgz", + "integrity": "sha512-rVdrbGTz3C2UnGrjPsbEX4MCiHtizxT+OfjCqvb1bvaGaweFrykXiEVG5xwt/jsDqKoZsiiBdt5LH8pGx3X+Dg==", "dev": true, "dependencies": { "@clinic/clinic-common": "^7.0.0", @@ -1619,9 +1619,9 @@ } }, "node_modules/@types/node": { - "version": "16.11.13", - "resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.13.tgz", - "integrity": "sha512-eUXZzHLHoZqj1frtUetNkUetYoJ6X55UmrVnFD4DMhVeAmwLjniZhtBmsRiemQh4uq4G3vUra/Ws/hs9vEvL3Q==" + "version": "16.11.14", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.14.tgz", + "integrity": "sha512-mK6BKLpL0bG6v2CxHbm0ed6RcZrAtTHBTd/ZpnlVPVa3HkumsqLE4BC4u6TQ8D7pnrRbOU0am6epuALs+Ncnzw==" }, "node_modules/@types/object-path": { "version": "0.11.1", @@ -3566,9 +3566,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001286", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001286.tgz", - "integrity": "sha512-zaEMRH6xg8ESMi2eQ3R4eZ5qw/hJiVsO/HlLwniIwErij0JDr9P+8V4dtx1l+kLq6j3yy8l8W4fst1lBnat5wQ==", + "version": "1.0.30001291", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001291.tgz", + "integrity": "sha512-roMV5V0HNGgJ88s42eE70sstqGW/gwFndosYrikHthw98N5tLnOTxFqMLQjZVRxTWFlJ4rn+MsgXrR7MDPY4jA==", "dev": true, "funding": { "type": "opencollective", @@ -5433,9 +5433,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.18", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.18.tgz", - "integrity": "sha512-i7nKjGGBE1+YUIbfLObA1EZPmN7J1ITEllbhusDk+KIk6V6gUxN9PFe36v+Sd+8Cg0k3cgUv9lQhQZalr8rggw==", + "version": "1.4.24", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.24.tgz", + "integrity": "sha512-erwx5r69B/WFfFuF2jcNN0817BfDBdC4765kQ6WltOMuwsimlQo3JTEq0Cle+wpHralwdeX3OfAtw/mHxPK0Wg==", "dev": true }, "node_modules/elliptic": { @@ -5783,9 +5783,9 @@ } }, "node_modules/eslint": { - "version": "8.4.1", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.4.1.tgz", - "integrity": "sha512-TxU/p7LB1KxQ6+7aztTnO7K0i+h0tDi81YRY9VzB6Id71kNz+fFYnf5HD5UOQmxkzcoa0TlVZf9dpMtUv0GpWg==", + "version": "8.5.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.5.0.tgz", + "integrity": "sha512-tVGSkgNbOfiHyVte8bCM8OmX+xG9PzVG/B4UCF60zx7j61WIVY/AqJECDgpLD4DbbESD0e174gOg3ZlrX15GDg==", "dev": true, "dependencies": { "@eslint/eslintrc": "^1.0.5", @@ -6010,9 +6010,9 @@ } }, "node_modules/eslint-plugin-jsdoc": { - "version": "37.2.2", - "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-37.2.2.tgz", - "integrity": "sha512-ChNYa4JBfEgyx7Fuy3obZM0w1jxd1DFdkMDk9QVrLfdZubtXCVK5Lvx+GKExeCxKLU33wLnOOBoImUL2/16JWQ==", + "version": "37.3.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-37.3.0.tgz", + "integrity": "sha512-76fXAjqrfcqLpa3JjnDIXYHM8zlrNJYEXv6xvTyMcgbQ/gl0OmoEmPAGV9HxbhbJ9hhcW5fTVemRIwhGUwqJcw==", "dev": true, "dependencies": { "@es-joy/jsdoccomment": "0.13.0", @@ -8288,9 +8288,9 @@ ] }, "node_modules/ignore": { - "version": "5.1.9", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.9.tgz", - "integrity": "sha512-2zeMQpbKz5dhZ9IwL0gbxSW5w0NK/MSAMtNuhgIHEPmaU3vPdKPL0UdvUCXs5SS4JAwsBxysK5sFMW8ocFiVjQ==", + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.0.tgz", + "integrity": "sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==", "engines": { "node": ">= 4" } @@ -10508,9 +10508,9 @@ } }, "node_modules/mariadb/node_modules/@types/node": { - "version": "14.18.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.0.tgz", - "integrity": "sha512-0GeIl2kmVMXEnx8tg1SlG6Gg8vkqirrW752KqolYo1PHevhhZN3bhJ67qHj+bQaINhX0Ra3TlWwRvMCd9iEfNQ==" + "version": "14.18.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.1.tgz", + "integrity": "sha512-fTFWOFrgAkj737w1o0HLTIgisgYHnsZfeiqhG1Ltrf/iJjudEbUwetQAsfrtVE49JGwvpEzQR+EbMkIqG4227g==" }, "node_modules/mariadb/node_modules/iconv-lite": { "version": "0.6.3", @@ -13064,9 +13064,9 @@ } }, "node_modules/object-inspect": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.11.1.tgz", - "integrity": "sha512-If7BjFlpkzzBeV1cqgT3OSWT3azyoxDGajR+iGnFBfVV2EWyDyWaZZW2ERDjUaY2QM8i5jI3Sj7mhsM4DDAqWA==", + "version": "1.12.0", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.0.tgz", + "integrity": "sha512-Ho2z80bVIvJloH+YzRmpZVQe87+qASmBUKZDWgx9cu+KDrX2ZDH/3tMy+gXbZETVGs2M8YdxObOh7XAtim9Y0g==", "dev": true, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -19639,9 +19639,9 @@ } }, "@clinic/doctor": { - "version": "9.0.0", - "resolved": "https://registry.npmjs.org/@clinic/doctor/-/doctor-9.0.0.tgz", - "integrity": "sha512-opIWn42Y4QPk4fidF5mvltwbeqSmJDaOl36I4EWyz/tA9Gh8JCsZEGxE+NwC9H+Wh0TeZf9Nl4+xRirIaLn7Cg==", + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/@clinic/doctor/-/doctor-9.1.0.tgz", + "integrity": "sha512-rVdrbGTz3C2UnGrjPsbEX4MCiHtizxT+OfjCqvb1bvaGaweFrykXiEVG5xwt/jsDqKoZsiiBdt5LH8pGx3X+Dg==", "dev": true, "requires": { "@clinic/clinic-common": "^7.0.0", @@ -20470,9 +20470,9 @@ } }, "@types/node": { - "version": "16.11.13", - "resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.13.tgz", - "integrity": "sha512-eUXZzHLHoZqj1frtUetNkUetYoJ6X55UmrVnFD4DMhVeAmwLjniZhtBmsRiemQh4uq4G3vUra/Ws/hs9vEvL3Q==" + "version": "16.11.14", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.14.tgz", + "integrity": "sha512-mK6BKLpL0bG6v2CxHbm0ed6RcZrAtTHBTd/ZpnlVPVa3HkumsqLE4BC4u6TQ8D7pnrRbOU0am6epuALs+Ncnzw==" }, "@types/object-path": { "version": "0.11.1", @@ -22030,9 +22030,9 @@ } }, "caniuse-lite": { - "version": "1.0.30001286", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001286.tgz", - "integrity": "sha512-zaEMRH6xg8ESMi2eQ3R4eZ5qw/hJiVsO/HlLwniIwErij0JDr9P+8V4dtx1l+kLq6j3yy8l8W4fst1lBnat5wQ==", + "version": "1.0.30001291", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001291.tgz", + "integrity": "sha512-roMV5V0HNGgJ88s42eE70sstqGW/gwFndosYrikHthw98N5tLnOTxFqMLQjZVRxTWFlJ4rn+MsgXrR7MDPY4jA==", "dev": true }, "capture-stack-trace": { @@ -23573,9 +23573,9 @@ } }, "electron-to-chromium": { - "version": "1.4.18", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.18.tgz", - "integrity": "sha512-i7nKjGGBE1+YUIbfLObA1EZPmN7J1ITEllbhusDk+KIk6V6gUxN9PFe36v+Sd+8Cg0k3cgUv9lQhQZalr8rggw==", + "version": "1.4.24", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.24.tgz", + "integrity": "sha512-erwx5r69B/WFfFuF2jcNN0817BfDBdC4765kQ6WltOMuwsimlQo3JTEq0Cle+wpHralwdeX3OfAtw/mHxPK0Wg==", "dev": true }, "elliptic": { @@ -23875,9 +23875,9 @@ } }, "eslint": { - "version": "8.4.1", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.4.1.tgz", - "integrity": "sha512-TxU/p7LB1KxQ6+7aztTnO7K0i+h0tDi81YRY9VzB6Id71kNz+fFYnf5HD5UOQmxkzcoa0TlVZf9dpMtUv0GpWg==", + "version": "8.5.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.5.0.tgz", + "integrity": "sha512-tVGSkgNbOfiHyVte8bCM8OmX+xG9PzVG/B4UCF60zx7j61WIVY/AqJECDgpLD4DbbESD0e174gOg3ZlrX15GDg==", "dev": true, "requires": { "@eslint/eslintrc": "^1.0.5", @@ -24095,9 +24095,9 @@ } }, "eslint-plugin-jsdoc": { - "version": "37.2.2", - "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-37.2.2.tgz", - "integrity": "sha512-ChNYa4JBfEgyx7Fuy3obZM0w1jxd1DFdkMDk9QVrLfdZubtXCVK5Lvx+GKExeCxKLU33wLnOOBoImUL2/16JWQ==", + "version": "37.3.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-37.3.0.tgz", + "integrity": "sha512-76fXAjqrfcqLpa3JjnDIXYHM8zlrNJYEXv6xvTyMcgbQ/gl0OmoEmPAGV9HxbhbJ9hhcW5fTVemRIwhGUwqJcw==", "dev": true, "requires": { "@es-joy/jsdoccomment": "0.13.0", @@ -25852,9 +25852,9 @@ "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==" }, "ignore": { - "version": "5.1.9", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.9.tgz", - "integrity": "sha512-2zeMQpbKz5dhZ9IwL0gbxSW5w0NK/MSAMtNuhgIHEPmaU3vPdKPL0UdvUCXs5SS4JAwsBxysK5sFMW8ocFiVjQ==" + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.0.tgz", + "integrity": "sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==" }, "ignore-walk": { "version": "3.0.4", @@ -27548,9 +27548,9 @@ }, "dependencies": { "@types/node": { - "version": "14.18.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.0.tgz", - "integrity": "sha512-0GeIl2kmVMXEnx8tg1SlG6Gg8vkqirrW752KqolYo1PHevhhZN3bhJ67qHj+bQaINhX0Ra3TlWwRvMCd9iEfNQ==" + "version": "14.18.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.1.tgz", + "integrity": "sha512-fTFWOFrgAkj737w1o0HLTIgisgYHnsZfeiqhG1Ltrf/iJjudEbUwetQAsfrtVE49JGwvpEzQR+EbMkIqG4227g==" }, "iconv-lite": { "version": "0.6.3", @@ -29629,9 +29629,9 @@ "integrity": "sha512-gScRMn0bS5fH+IuwyIFgnh9zBdo4DV+6GhygmWM9HyNJSgS0hScp1f5vjtm7oIIOiT9trXrShAkLFSc2IqKNgw==" }, "object-inspect": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.11.1.tgz", - "integrity": "sha512-If7BjFlpkzzBeV1cqgT3OSWT3azyoxDGajR+iGnFBfVV2EWyDyWaZZW2ERDjUaY2QM8i5jI3Sj7mhsM4DDAqWA==", + "version": "1.12.0", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.0.tgz", + "integrity": "sha512-Ho2z80bVIvJloH+YzRmpZVQe87+qASmBUKZDWgx9cu+KDrX2ZDH/3tMy+gXbZETVGs2M8YdxObOh7XAtim9Y0g==", "dev": true }, "object-keys": { diff --git a/package.json b/package.json index bf6ddb2a..50499a7d 100644 --- a/package.json +++ b/package.json @@ -94,7 +94,7 @@ "@rollup/plugin-json": "^4.1.0", "@types/mocha": "^9.0.0", "@types/mochawesome": "^6.2.1", - "@types/node": "^16.11.13", + "@types/node": "^16.11.14", "@types/proper-lockfile": "^4.1.2", "@types/tar": "^6.1.1", "@types/uuid": "^8.3.3", @@ -104,9 +104,9 @@ "auto-changelog": "^2.3.0", "clinic": "^10.0.0", "cross-env": "^7.0.3", - "eslint": "^8.4.1", + "eslint": "^8.5.0", "eslint-plugin-import": "^2.25.3", - "eslint-plugin-jsdoc": "^37.2.2", + "eslint-plugin-jsdoc": "^37.3.0", "eslint-plugin-node": "^11.1.0", "expect": "^27.4.2", "mocha": "^9.1.3", diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 1136c93b..c4a0989e 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -47,18 +47,22 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer public async handleRequest(messageId: string, commandName: OCPP16IncomingRequestCommand, commandPayload: Record): Promise { let result: Record; - if (this.incomingRequestHandlers.has(commandName)) { - try { - // Call the method to build the result - result = await this.incomingRequestHandlers.get(commandName)(commandPayload); - } catch (error) { - // Log - logger.error(this.chargingStation.logPrefix() + ' Handle request error: %j', error); - throw error; + if (this.chargingStation.isRegistered()) { + if (this.incomingRequestHandlers.has(commandName)) { + try { + // Call the method to build the result + result = await this.incomingRequestHandlers.get(commandName)(commandPayload); + } catch (error) { + // Log + logger.error(this.chargingStation.logPrefix() + ' Handle request error: %j', error); + throw error; + } + } else { + // Throw exception + throw new OCPPError(ErrorType.NOT_IMPLEMENTED, `${commandName} is not implemented to handle request payload ${JSON.stringify(commandPayload, null, 2)}`, commandName); } } else { - // Throw exception - throw new OCPPError(ErrorType.NOT_IMPLEMENTED, `${commandName} is not implemented to handle request payload ${JSON.stringify(commandPayload, null, 2)}`, commandName); + throw new OCPPError(ErrorType.SECURITY_ERROR, `The charging station is not registered on the central server. ${commandName} cannot be not issued to handle request payload ${JSON.stringify(commandPayload, null, 2)}`, commandName); } // Send the built result await this.chargingStation.ocppRequestService.sendResult(messageId, result, commandName); diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index d429e045..ca5c0157 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -33,16 +33,20 @@ export default class OCPP16ResponseService extends OCPPResponseService { } public async handleResponse(commandName: OCPP16RequestCommand, payload: Record | string, requestPayload: Record): Promise { - if (this.responseHandlers.has(commandName)) { - try { - await this.responseHandlers.get(commandName)(payload, requestPayload); - } catch (error) { - logger.error(this.chargingStation.logPrefix() + ' Handle request response error: %j', error); - throw error; + if (this.chargingStation.isRegistered() || commandName === OCPP16RequestCommand.BOOT_NOTIFICATION) { + if (this.responseHandlers.has(commandName)) { + try { + await this.responseHandlers.get(commandName)(payload, requestPayload); + } catch (error) { + logger.error(this.chargingStation.logPrefix() + ' Handle request response error: %j', error); + throw error; + } + } else { + // Throw exception + throw new OCPPError(ErrorType.NOT_IMPLEMENTED, `${commandName} is not implemented to handle request response payload ${JSON.stringify(payload, null, 2)}`, commandName); } } else { - // Throw exception - throw new OCPPError(ErrorType.NOT_IMPLEMENTED, `${commandName} is not implemented to handle request response payload ${JSON.stringify(payload, null, 2)}`, commandName); + throw new OCPPError(ErrorType.SECURITY_ERROR, `The charging station is not registered on the central server. ${commandName} cannot be not issued to handle request response payload ${JSON.stringify(payload, null, 2)}`, commandName); } } -- 2.34.1