refactor: refine UI Server configuration checks
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 15 Feb 2024 21:49:42 +0000 (22:49 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 15 Feb 2024 21:49:42 +0000 (22:49 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ui-server/AbstractUIServer.ts
src/charging-station/ui-server/UIServerFactory.ts

index 49ac635969b47388734fac8c7a85280d488774c0..495729fa27e39c3e8369f19980dd3eb395f35c32 100644 (file)
@@ -137,7 +137,7 @@ export abstract class AbstractUIServer {
   }
 
   private isValidProtocolBasicAuth (req: IncomingMessage, next: (err?: Error) => void): boolean {
-    const authorizationProtocol = req.headers['sec-websocket-protocol']?.split(',').pop()?.trim()
+    const authorizationProtocol = req.headers['sec-websocket-protocol']?.split(/,\s+/).pop()
     const [username, password] = this.getUsernameAndPasswordFromAuthorizationToken(
       // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
       `${authorizationProtocol}${Array(((4 - (authorizationProtocol!.length % 4)) % 4) + 1).join('=')}`
index 3df4566356cee97e6c33893aa6fe7d36003d6aac..eccbbf0d052ad6c85abd92d8ce11e215e8daf4a7 100644 (file)
@@ -36,11 +36,14 @@ export class UIServerFactory {
     ) {
       throw new BaseError('Protocol basic authentication is not supported for HTTP UI server')
     }
-    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-    if (!UIServerUtils.isLoopback(uiServerConfiguration.options!.host!)) {
+    if (
+      uiServerConfiguration.authentication?.enabled !== true &&
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      !UIServerUtils.isLoopback(uiServerConfiguration.options!.host!)
+    ) {
       console.warn(
         chalk.yellow(
-          'Loopback address not detected in UI server configuration. This is not recommended'
+          'Non loopback address in UI server configuration without authentication enabled. This is not recommended'
         )
       )
     }