Check for CS registration status before issuing OCPP commands
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 19 Dec 2021 17:32:40 +0000 (18:32 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 19 Dec 2021 17:32:40 +0000 (18:32 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
package-lock.json
package.json
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/charging-station/ocpp/1.6/OCPP16ResponseService.ts

index 57453b9a5fcb613a985db90f961191f3bdee7db2..20597b30e4af671b517696268933dfb515ce2e4f 100644 (file)
@@ -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",
       }
     },
     "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",
       }
     },
     "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",
       }
     },
     "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",
       }
     },
     "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": {
       }
     },
     "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",
       }
     },
     "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",
       ]
     },
     "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"
       }
       }
     },
     "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",
       }
     },
     "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"
       }
     },
     "@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",
       }
     },
     "@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",
       }
     },
     "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": {
       }
     },
     "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": {
       }
     },
     "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",
       }
     },
     "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",
       "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",
       },
       "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",
       "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": {
index bf6ddb2ac3a2ba136ffaa0eab8a28d827e463319..50499a7d92fcce3696eff547516651da923c64e3 100644 (file)
@@ -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",
     "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",
index 1136c93b568721fbc2cac483f29232e36cb347ad..c4a0989e24d9fc0e078097f48f6ec47bc91c631c 100644 (file)
@@ -47,18 +47,22 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
 
   public async handleRequest(messageId: string, commandName: OCPP16IncomingRequestCommand, commandPayload: Record<string, unknown>): Promise<void> {
     let result: Record<string, unknown>;
-    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);
index d429e04569a5100bcf92095ff018c8f596ee434a..ca5c01570b96be7a0574a41dddc560d8e37ce10a 100644 (file)
@@ -33,16 +33,20 @@ export default class OCPP16ResponseService extends OCPPResponseService {
   }
 
   public async handleResponse(commandName: OCPP16RequestCommand, payload: Record<string, unknown> | string, requestPayload: Record<string, unknown>): Promise<void> {
-    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);
     }
   }