From 8c588b25e52de73e5bccf648da5c0220be4b90f6 Mon Sep 17 00:00:00 2001 From: Ege Korkan Date: Tue, 8 Aug 2023 23:45:18 +0200 Subject: [PATCH 1/5] mqtt: add strict type check to config --- packages/binding-mqtt/tsconfig.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/binding-mqtt/tsconfig.json b/packages/binding-mqtt/tsconfig.json index e9fa7c062..df9cd1d90 100644 --- a/packages/binding-mqtt/tsconfig.json +++ b/packages/binding-mqtt/tsconfig.json @@ -2,7 +2,8 @@ "extends": "../../tsconfig.json", "compilerOptions": { "outDir": "dist", - "rootDir": "src" + "rootDir": "src", + "strict": true }, "include": ["src/**/*"], "references": [{ "path": "../td-tools" }, { "path": "../core" }] From d7664ab80f935bae48299b437f1c8e0fedaf4113 Mon Sep 17 00:00:00 2001 From: Ege Korkan Date: Tue, 8 Aug 2023 23:45:45 +0200 Subject: [PATCH 2/5] mqtt: fix typo --- packages/binding-mqtt/src/mqtt.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/binding-mqtt/src/mqtt.ts b/packages/binding-mqtt/src/mqtt.ts index b5e5418a4..459557c34 100644 --- a/packages/binding-mqtt/src/mqtt.ts +++ b/packages/binding-mqtt/src/mqtt.ts @@ -47,7 +47,7 @@ export class MqttForm extends Form { } export interface MqttClientConfig { - // username & password are redundated here (also find them in MqttClientSecurityParameters) + // username & password are redundant here (also find them in MqttClientSecurityParameters) // because MqttClient.setSecurity() method can inject authentication credentials into this interface // which will be then passed to mqtt.connect() once for all username?: string; From b55df3755f0a7911b87413ba9be0c15f6b22e302 Mon Sep 17 00:00:00 2001 From: Ege Korkan Date: Tue, 8 Aug 2023 23:48:13 +0200 Subject: [PATCH 3/5] mqtt: start handling undefined types --- packages/binding-mqtt/src/mqtt-client.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/binding-mqtt/src/mqtt-client.ts b/packages/binding-mqtt/src/mqtt-client.ts index 2b1f2d15a..fce985d95 100644 --- a/packages/binding-mqtt/src/mqtt-client.ts +++ b/packages/binding-mqtt/src/mqtt-client.ts @@ -40,7 +40,7 @@ export default class MqttClient implements ProtocolClient { this.scheme = "mqtt" + (secure ? "s" : ""); } - private client: mqtt.MqttClient = undefined; + private client: mqtt.MqttClient | undefined = undefined; public subscribeResource( form: MqttForm, @@ -166,8 +166,14 @@ export default class MqttClient implements ProtocolClient { const security: TD.SecurityScheme = metadata[0]; if (security.scheme === "basic") { - this.config.username = credentials.username; - this.config.password = credentials.password; + if (credentials === undefined) { + // FIXME: This error message should be reworded and adapt to logging convention + throw new Error("binding-mqtt: security wants to be basic but you have provided no credentials"); + } else { + this.config.username = credentials.username; + this.config.password = credentials.password; + } + } return true; } From e5a8d0a9251c41115df1e0ea0883e88edb0a297f Mon Sep 17 00:00:00 2001 From: Ege Korkan Date: Wed, 9 Aug 2023 00:00:12 +0200 Subject: [PATCH 4/5] chore: run format --- packages/binding-mqtt/src/mqtt-client.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/binding-mqtt/src/mqtt-client.ts b/packages/binding-mqtt/src/mqtt-client.ts index fce985d95..d21ae798f 100644 --- a/packages/binding-mqtt/src/mqtt-client.ts +++ b/packages/binding-mqtt/src/mqtt-client.ts @@ -173,7 +173,6 @@ export default class MqttClient implements ProtocolClient { this.config.username = credentials.username; this.config.password = credentials.password; } - } return true; } From 7ff47a613492bdc0f45ae067457ae082a8def1d2 Mon Sep 17 00:00:00 2001 From: Cristiano Aguzzi Date: Wed, 9 Aug 2023 09:32:13 +0200 Subject: [PATCH 5/5] style(binding-mqtt/mqtt-client): use ? instead of | undefined Co-authored-by: Jan Romann --- packages/binding-mqtt/src/mqtt-client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/binding-mqtt/src/mqtt-client.ts b/packages/binding-mqtt/src/mqtt-client.ts index d21ae798f..bbb9d1cf5 100644 --- a/packages/binding-mqtt/src/mqtt-client.ts +++ b/packages/binding-mqtt/src/mqtt-client.ts @@ -40,7 +40,7 @@ export default class MqttClient implements ProtocolClient { this.scheme = "mqtt" + (secure ? "s" : ""); } - private client: mqtt.MqttClient | undefined = undefined; + private client?: mqtt.MqttClient; public subscribeResource( form: MqttForm,