node-red-contrib-aedes 0.6.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,7 +9,7 @@ jobs:
9
9
 
10
10
  strategy:
11
11
  matrix:
12
- node-version: [12.x, 14.x, 16.x]
12
+ node-version: [14.x, 16.x, 18.x]
13
13
 
14
14
  steps:
15
15
  - uses: actions/checkout@v2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # node-red-contrib-aedes Changelog
2
2
 
3
+ ## May 29, 2022, Version 0.8.1
4
+ ### Notable changes
5
+ - Fix issue with incomplete credentials
6
+
7
+
8
+ ## May 22, 2022, Version 0.8
9
+ ### Notable changes
10
+ - Update aedes to version 0.47
11
+
12
+ ## Feb 18, 2022, Version 0.7
13
+ ### Notable changes
14
+ - Fix Close Time Out Issue
3
15
  ## Oct 17, 2021, Version 0.6
4
16
  ### Notable changes
5
17
  - Add output node for publish events
package/aedes.js CHANGED
@@ -169,8 +169,10 @@ module.exports = function (RED) {
169
169
 
170
170
  if (this.credentials && this.username && this.password) {
171
171
  const authenticate = function (client, username, password, callback) {
172
- const authorized = (username === node.username && password.toString() === node.password);
173
- if (authorized) { client.user = username; }
172
+ const authorized = (username === node.username && password && password.toString() === node.password);
173
+ if (authorized) {
174
+ client.user = username;
175
+ }
174
176
  callback(null, authorized);
175
177
  };
176
178
 
@@ -194,7 +196,11 @@ module.exports = function (RED) {
194
196
  client: client
195
197
  }
196
198
  };
197
- node.status({ fill: 'green', shape: 'dot', text: RED._('aedes-mqtt-broker.status.connected', { count: broker.connectedClients }) });
199
+ node.status({
200
+ fill: 'green',
201
+ shape: 'dot',
202
+ text: RED._('aedes-mqtt-broker.status.connected', { count: broker.connectedClients })
203
+ });
198
204
  node.send([msg, null]);
199
205
  });
200
206
 
@@ -206,7 +212,11 @@ module.exports = function (RED) {
206
212
  }
207
213
  };
208
214
  node.send([msg, null]);
209
- node.status({ fill: 'green', shape: 'dot', text: RED._('aedes-mqtt-broker.status.connected', { count: broker.connectedClients }) });
215
+ node.status({
216
+ fill: 'green',
217
+ shape: 'dot',
218
+ text: RED._('aedes-mqtt-broker.status.connected', { count: broker.connectedClients })
219
+ });
210
220
  });
211
221
 
212
222
  broker.on('clientError', function (client, err) {
@@ -218,7 +228,11 @@ module.exports = function (RED) {
218
228
  }
219
229
  };
220
230
  node.send([msg, null]);
221
- node.status({ fill: 'green', shape: 'dot', text: RED._('aedes-mqtt-broker.status.connected', { count: broker.connectedClients }) });
231
+ node.status({
232
+ fill: 'green',
233
+ shape: 'dot',
234
+ text: RED._('aedes-mqtt-broker.status.connected', { count: broker.connectedClients })
235
+ });
222
236
  });
223
237
 
224
238
  broker.on('connectionError', function (client, err) {
@@ -230,7 +244,11 @@ module.exports = function (RED) {
230
244
  }
231
245
  };
232
246
  node.send([msg, null]);
233
- node.status({ fill: 'green', shape: 'dot', text: RED._('aedes-mqtt-broker.status.connected', { count: broker.connectedClients }) });
247
+ node.status({
248
+ fill: 'green',
249
+ shape: 'dot',
250
+ text: RED._('aedes-mqtt-broker.status.connected', { count: broker.connectedClients })
251
+ });
234
252
  });
235
253
 
236
254
  broker.on('keepaliveTimeout', function (client) {
@@ -241,7 +259,11 @@ module.exports = function (RED) {
241
259
  }
242
260
  };
243
261
  node.send([msg, null]);
244
- node.status({ fill: 'green', shape: 'dot', text: RED._('aedes-mqtt-broker.status.connected', { count: broker.connectedClients }) });
262
+ node.status({
263
+ fill: 'green',
264
+ shape: 'dot',
265
+ text: RED._('aedes-mqtt-broker.status.connected', { count: broker.connectedClients })
266
+ });
245
267
  });
246
268
 
247
269
  broker.on('subscribe', function (subscription, client) {
@@ -287,27 +309,29 @@ module.exports = function (RED) {
287
309
  });
288
310
 
289
311
  this.on('close', function (done) {
290
- broker.close(function () {
291
- node.log('Unbinding aedes mqtt server from port: ' + config.mqtt_port);
292
- server.close(function () {
293
- node.debug('after server.close(): ');
294
- if (node.mqtt_ws_path !== '') {
295
- node.log('Unbinding aedes mqtt server from ws path: ' + node.fullPath);
296
- delete listenerNodes[node.fullPath];
297
- node.server.close();
298
- }
299
- if (wss) {
300
- node.log('Unbinding aedes mqtt server from ws port: ' + config.mqtt_ws_port);
301
- wss.close(function () {
302
- node.debug('after wss.close(): ');
303
- httpServer.close(function () {
304
- node.debug('after httpServer.close(): ');
305
- done();
312
+ process.nextTick(function onCloseDelayed () {
313
+ broker.close(function () {
314
+ node.log('Unbinding aedes mqtt server from port: ' + config.mqtt_port);
315
+ server.close(function () {
316
+ node.debug('after server.close(): ');
317
+ if (node.mqtt_ws_path !== '') {
318
+ node.log('Unbinding aedes mqtt server from ws path: ' + node.fullPath);
319
+ delete listenerNodes[node.fullPath];
320
+ node.server.close();
321
+ }
322
+ if (wss) {
323
+ node.log('Unbinding aedes mqtt server from ws port: ' + config.mqtt_ws_port);
324
+ wss.close(function () {
325
+ node.debug('after wss.close(): ');
326
+ httpServer.close(function () {
327
+ node.debug('after httpServer.close(): ');
328
+ done();
329
+ });
306
330
  });
307
- });
308
- } else {
309
- done();
310
- }
331
+ } else {
332
+ done();
333
+ }
334
+ });
311
335
  });
312
336
  });
313
337
  });
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "node-red-contrib-aedes",
3
- "version": "0.6.0",
3
+ "version": "0.8.1",
4
4
  "description": "Node Red MQTT broker node based on aedes.js",
5
5
  "dependencies": {
6
- "aedes": "^0.46.0",
7
- "aedes-persistence-mongodb": "^8.2.0",
6
+ "aedes": "^0.47.0",
7
+ "aedes-persistence-mongodb": "^9.0.0",
8
8
  "websocket-stream": "^5.5.2"
9
9
  },
10
10
  "devDependencies": {
11
- "mqtt": "^4.2.6",
11
+ "mqtt": "^4.3.7",
12
12
  "node-red-node-test-helper": "^0.2.7"
13
13
  },
14
14
  "scripts": {
15
- "test": "semistandard --verbose | snazzy && mocha test/**/*_spec.js"
15
+ "test": "semistandard --verbose | snazzy && mocha test/**/*.js --exit"
16
16
  },
17
17
  "node-red": {
18
18
  "nodes": {
@@ -5,6 +5,9 @@ const aedesNode = require('../aedes.js');
5
5
  const mqttNode = require('../node_modules/node-red/node_modules/@node-red/nodes/core/network/10-mqtt.js');
6
6
  const mqtt = require('mqtt/mqtt.js');
7
7
 
8
+ const credentialsOK = { n1: { username: 'test', password: 'test' }, b1: { user: 'test', password: 'test' } };
9
+ const credentialsMissing = { n1: { username: 'test', password: 'test' }, b1: { user: 'test' } };
10
+
8
11
  helper.init(require.resolve('node-red'));
9
12
 
10
13
  describe('Aedes Broker TCP tests', function () {
@@ -70,8 +73,87 @@ describe('Aedes Broker TCP tests', function () {
70
73
  msg.should.have.property('topic', 'clientReady');
71
74
  done();
72
75
  });
73
- }
74
- );
76
+ });
77
+ });
78
+
79
+ it('should not connect an mqtt client with missing authentication', function (done) {
80
+ this.timeout(10000); // have to wait for the inject with delay of 10 seconds
81
+ const flow = [
82
+ {
83
+ id: 'n1',
84
+ type: 'aedes broker',
85
+ mqtt_port: '1883',
86
+ name: 'Aedes 1883',
87
+ wires: [
88
+ ['n2'], []
89
+ ]
90
+ },
91
+ {
92
+ id: 'n2',
93
+ type: 'helper'
94
+ }, {
95
+ id: 'n3',
96
+ type: 'mqtt in',
97
+ name: 'Aedes1 1883',
98
+ topic: 'test1883',
99
+ broker: 'b1'
100
+ }, {
101
+ id: 'b1',
102
+ type: 'mqtt-broker',
103
+ name: 'Broker',
104
+ broker: 'localhost',
105
+ port: '1883'
106
+ }
107
+ ];
108
+
109
+ helper.load([aedesNode, mqttNode], flow, credentialsMissing,
110
+ function () {
111
+ const n2 = helper.getNode('n2');
112
+ n2.on('input', function (msg) {
113
+ msg.should.have.property('topic', 'clientError');
114
+ done();
115
+ });
116
+ });
117
+ });
118
+
119
+ it('should connect an mqtt client with authentication', function (done) {
120
+ this.timeout(10000); // have to wait for the inject with delay of 10 seconds
121
+ const flow = [
122
+ {
123
+ id: 'n1',
124
+ type: 'aedes broker',
125
+ mqtt_port: '1883',
126
+ name: 'Aedes 1883',
127
+ wires: [
128
+ ['n2'], []
129
+ ]
130
+ },
131
+ {
132
+ id: 'n2',
133
+ type: 'helper'
134
+ }, {
135
+ id: 'n3',
136
+ type: 'mqtt in',
137
+ name: 'Aedes1 1883',
138
+ topic: 'test1883',
139
+ broker: 'b1'
140
+ }, {
141
+ id: 'b1',
142
+ type: 'mqtt-broker',
143
+ name: 'Broker',
144
+ broker: 'localhost',
145
+ port: '1883'
146
+ }
147
+ ];
148
+
149
+ helper.load([aedesNode, mqttNode], flow, credentialsOK,
150
+ function () {
151
+ const n2 = helper.getNode('n2');
152
+ n2.on('input', function (msg) {
153
+ msg.should.have.property('topic', 'clientReady');
154
+ done();
155
+ });
156
+ });
75
157
  });
76
158
 
77
159
  it('a subscriber should receive a message from a publisher', function (done) {