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.
- package/.github/workflows/nodejs.yml +1 -1
- package/CHANGELOG.md +12 -0
- package/aedes.js +51 -27
- package/package.json +5 -5
- package/test/aedes_spec.js +84 -2
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) {
|
|
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({
|
|
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({
|
|
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({
|
|
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({
|
|
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({
|
|
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
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
node.
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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
|
-
|
|
309
|
-
|
|
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.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "Node Red MQTT broker node based on aedes.js",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"aedes": "^0.
|
|
7
|
-
"aedes-persistence-mongodb": "^
|
|
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.
|
|
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
|
|
15
|
+
"test": "semistandard --verbose | snazzy && mocha test/**/*.js --exit"
|
|
16
16
|
},
|
|
17
17
|
"node-red": {
|
|
18
18
|
"nodes": {
|
package/test/aedes_spec.js
CHANGED
|
@@ -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) {
|