aedes 0.46.3 → 0.48.0
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/ci.yml +25 -5
- package/.github/workflows/sast.yml +29 -0
- package/README.md +2 -2
- package/aedes.d.ts +3 -9
- package/aedes.js +40 -20
- package/docs/Aedes.md +5 -3
- package/lib/client.js +15 -4
- package/lib/handlers/connect.js +4 -4
- package/lib/handlers/subscribe.js +7 -8
- package/lib/utils.js +11 -1
- package/package.json +20 -22
- package/test/auth.js +28 -10
- package/test/basic.js +8 -4
- package/test/bridge.js +57 -0
- package/test/client-pub-sub.js +7 -5
- package/test/connect.js +4 -4
- package/test/events.js +42 -1
- package/test/helper.js +11 -11
- package/test/meta.js +1 -1
- package/test/not-blocking.js +5 -5
- package/test/qos2.js +4 -2
- package/test/retain.js +2 -2
- package/test/topics.js +4 -4
- package/test/types/aedes.test-d.ts +17 -14
- package/test/will.js +66 -15
- package/types/.eslintrc.json +7 -5
- package/types/client.d.ts +28 -23
- package/types/instance.d.ts +98 -97
- package/types/packet.d.ts +18 -12
- package/types/tsconfig.json +6 -4
package/.github/workflows/ci.yml
CHANGED
|
@@ -11,21 +11,39 @@ on:
|
|
|
11
11
|
- '*.md'
|
|
12
12
|
|
|
13
13
|
jobs:
|
|
14
|
+
dependency-review:
|
|
15
|
+
name: Dependency Review
|
|
16
|
+
if: github.event_name == 'pull_request'
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
permissions:
|
|
19
|
+
contents: read
|
|
20
|
+
steps:
|
|
21
|
+
- name: Check out repo
|
|
22
|
+
uses: actions/checkout@v3
|
|
23
|
+
with:
|
|
24
|
+
persist-credentials: false
|
|
25
|
+
|
|
26
|
+
- name: Dependency review
|
|
27
|
+
uses: actions/dependency-review-action@v2
|
|
28
|
+
|
|
14
29
|
test:
|
|
15
30
|
runs-on: ${{ matrix.os }}
|
|
16
|
-
|
|
31
|
+
permissions:
|
|
32
|
+
contents: read
|
|
17
33
|
strategy:
|
|
18
34
|
matrix:
|
|
19
|
-
node-version: [
|
|
35
|
+
node-version: [14, 16, '*']
|
|
20
36
|
os: [ubuntu-latest, windows-latest, macOS-latest]
|
|
21
|
-
|
|
22
37
|
steps:
|
|
23
|
-
- uses: actions/checkout@
|
|
38
|
+
- uses: actions/checkout@v3
|
|
39
|
+
with:
|
|
40
|
+
persist-credentials: false
|
|
24
41
|
|
|
25
42
|
- name: Use Node.js
|
|
26
|
-
uses: actions/setup-node@
|
|
43
|
+
uses: actions/setup-node@v3
|
|
27
44
|
with:
|
|
28
45
|
node-version: ${{ matrix.node-version }}
|
|
46
|
+
check-latest: true
|
|
29
47
|
|
|
30
48
|
- name: Install
|
|
31
49
|
run: |
|
|
@@ -49,6 +67,8 @@ jobs:
|
|
|
49
67
|
coverage:
|
|
50
68
|
needs: test
|
|
51
69
|
runs-on: ubuntu-latest
|
|
70
|
+
permissions:
|
|
71
|
+
contents: read
|
|
52
72
|
steps:
|
|
53
73
|
- name: Coveralls Finished
|
|
54
74
|
uses: coverallsapp/github-action@master
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
name: sast
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches-ignore:
|
|
6
|
+
- 'dependabot/**'
|
|
7
|
+
pull_request:
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
analyze:
|
|
11
|
+
name: Analyze
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
permissions:
|
|
14
|
+
contents: read
|
|
15
|
+
security-events: write
|
|
16
|
+
strategy:
|
|
17
|
+
fail-fast: true
|
|
18
|
+
matrix:
|
|
19
|
+
language: [ 'javascript' ]
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v3
|
|
22
|
+
with:
|
|
23
|
+
persist-credentials: false
|
|
24
|
+
|
|
25
|
+
- uses: github/codeql-action/init@v2
|
|
26
|
+
with:
|
|
27
|
+
languages: ${{ matrix.language }}
|
|
28
|
+
|
|
29
|
+
- uses: github/codeql-action/analyze@v2
|
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ Barebone MQTT server that can run on any stream servers
|
|
|
24
24
|
- [Features](#features)
|
|
25
25
|
- [Examples](#examples)
|
|
26
26
|
- [Clusters](#clusters)
|
|
27
|
-
- [
|
|
27
|
+
- [Extensions](#extensions)
|
|
28
28
|
- [Middleware Plugins](#middleware-plugins)
|
|
29
29
|
- [Persistence](#persistence)
|
|
30
30
|
- [MQEmitter](#mqemitter)
|
|
@@ -107,7 +107,7 @@ Brokers that support the [Bridge Protocol][bridge_protocol] can connect to
|
|
|
107
107
|
Aedes. When connecting with this special protocol, subscriptions work as usual
|
|
108
108
|
except that the `retain` flag in the packet is propagated as-is.
|
|
109
109
|
|
|
110
|
-
##
|
|
110
|
+
## Extensions
|
|
111
111
|
|
|
112
112
|
- [aedes-logging]: Logging module for Aedes, based on Pino
|
|
113
113
|
- [aedes-stats]: Stats for Aedes
|
package/aedes.d.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export declare function Server (options?: AedesOptions): Aedes
|
|
5
|
-
|
|
6
|
-
export * from './types/instance'
|
|
7
|
-
export * from './types/packet'
|
|
8
|
-
export * from './types/client'
|
|
9
|
-
export default aedes
|
|
1
|
+
/// <reference path="./types/instance.d.ts" />
|
|
2
|
+
/// <reference path="./types/client.d.ts" />
|
|
3
|
+
/// <reference path="./types/packet.d.ts" />
|
package/aedes.js
CHANGED
|
@@ -5,14 +5,13 @@ const util = require('util')
|
|
|
5
5
|
const parallel = require('fastparallel')
|
|
6
6
|
const series = require('fastseries')
|
|
7
7
|
const { v4: uuidv4 } = require('uuid')
|
|
8
|
-
const bulk = require('bulk-write-stream')
|
|
9
8
|
const reusify = require('reusify')
|
|
10
|
-
const { pipeline } = require('
|
|
9
|
+
const { pipeline } = require('stream')
|
|
11
10
|
const Packet = require('aedes-packet')
|
|
12
11
|
const memory = require('aedes-persistence')
|
|
13
12
|
const mqemitter = require('mqemitter')
|
|
14
13
|
const Client = require('./lib/client')
|
|
15
|
-
const { $SYS_PREFIX } = require('./lib/utils')
|
|
14
|
+
const { $SYS_PREFIX, bulk } = require('./lib/utils')
|
|
16
15
|
|
|
17
16
|
module.exports = Aedes.Server = Aedes
|
|
18
17
|
|
|
@@ -80,10 +79,19 @@ function Aedes (opts) {
|
|
|
80
79
|
this.brokers = {}
|
|
81
80
|
|
|
82
81
|
const heartbeatTopic = $SYS_PREFIX + that.id + '/heartbeat'
|
|
82
|
+
const birthTopic = $SYS_PREFIX + that.id + '/birth'
|
|
83
|
+
|
|
83
84
|
this._heartbeatInterval = setInterval(heartbeat, opts.heartbeatInterval)
|
|
84
85
|
|
|
85
86
|
const bufId = Buffer.from(that.id, 'utf8')
|
|
86
87
|
|
|
88
|
+
// in a cluster env this is used to warn other broker instances
|
|
89
|
+
// that this broker is alive
|
|
90
|
+
that.publish({
|
|
91
|
+
topic: birthTopic,
|
|
92
|
+
payload: bufId
|
|
93
|
+
}, noop)
|
|
94
|
+
|
|
87
95
|
function heartbeat () {
|
|
88
96
|
that.publish({
|
|
89
97
|
topic: heartbeatTopic,
|
|
@@ -102,7 +110,7 @@ function Aedes (opts) {
|
|
|
102
110
|
|
|
103
111
|
pipeline(
|
|
104
112
|
that.persistence.streamWill(that.brokers),
|
|
105
|
-
bulk
|
|
113
|
+
bulk(receiveWills),
|
|
106
114
|
function done (err) {
|
|
107
115
|
if (err) {
|
|
108
116
|
that.emit('error', err)
|
|
@@ -116,27 +124,25 @@ function Aedes (opts) {
|
|
|
116
124
|
}
|
|
117
125
|
|
|
118
126
|
function checkAndPublish (will, done) {
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
that.brokers[will.brokerId] + (3 * opts.heartbeatInterval) <
|
|
122
|
-
Date.now()
|
|
123
|
-
|
|
124
|
-
if (needsPublishing) {
|
|
125
|
-
// randomize this, so that multiple brokers
|
|
126
|
-
// do not publish the same wills at the same time
|
|
127
|
-
that.publish(will, function publishWill (err) {
|
|
128
|
-
if (err) {
|
|
129
|
-
return done(err)
|
|
130
|
-
}
|
|
127
|
+
const notPublish =
|
|
128
|
+
that.brokers[will.brokerId] !== undefined && that.brokers[will.brokerId] + (3 * opts.heartbeatInterval) >= Date.now()
|
|
131
129
|
|
|
130
|
+
if (notPublish) return done()
|
|
131
|
+
|
|
132
|
+
// randomize this, so that multiple brokers
|
|
133
|
+
// do not publish the same wills at the same time
|
|
134
|
+
this.authorizePublish(that.clients[will.clientId] || null, will, function (err) {
|
|
135
|
+
if (err) { return doneWill() }
|
|
136
|
+
that.publish(will, doneWill)
|
|
137
|
+
|
|
138
|
+
function doneWill (err) {
|
|
139
|
+
if (err) { return done(err) }
|
|
132
140
|
that.persistence.delWill({
|
|
133
141
|
id: will.clientId,
|
|
134
142
|
brokerId: will.brokerId
|
|
135
143
|
}, done)
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
done()
|
|
139
|
-
}
|
|
144
|
+
}
|
|
145
|
+
})
|
|
140
146
|
}
|
|
141
147
|
|
|
142
148
|
this.mq.on($SYS_PREFIX + '+/heartbeat', function storeBroker (packet, done) {
|
|
@@ -144,6 +150,19 @@ function Aedes (opts) {
|
|
|
144
150
|
done()
|
|
145
151
|
})
|
|
146
152
|
|
|
153
|
+
this.mq.on($SYS_PREFIX + '+/birth', function brokerBorn (packet, done) {
|
|
154
|
+
const brokerId = packet.payload.toString()
|
|
155
|
+
|
|
156
|
+
// reset duplicates counter
|
|
157
|
+
if (brokerId !== that.id) {
|
|
158
|
+
for (const clientId in that.clients) {
|
|
159
|
+
delete that.clients[clientId].duplicates[brokerId]
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
done()
|
|
164
|
+
})
|
|
165
|
+
|
|
147
166
|
this.mq.on($SYS_PREFIX + '+/new/clients', function closeSameClients (packet, done) {
|
|
148
167
|
const serverId = packet.topic.split('/')[1]
|
|
149
168
|
const clientId = packet.payload.toString()
|
|
@@ -171,6 +190,7 @@ function storeRetained (packet, done) {
|
|
|
171
190
|
}
|
|
172
191
|
|
|
173
192
|
function emitPacket (packet, done) {
|
|
193
|
+
if (this.client) packet.clientId = this.client.id
|
|
174
194
|
this.broker.mq.emit(packet, done)
|
|
175
195
|
}
|
|
176
196
|
|
package/docs/Aedes.md
CHANGED
|
@@ -186,7 +186,7 @@ const server = require('net').createServer(aedes.handle)
|
|
|
186
186
|
|
|
187
187
|
Directly subscribe a `topic` in server side. Bypass [`authorizeSubscribe`](#handler-authorizesubscribe-client-subscription-callback)
|
|
188
188
|
|
|
189
|
-
The `topic` and `deliverfunc` is a compound key to differentiate the uniqueness of its subscription pool. `topic` could be the one that is existed, in this case `deliverfunc` will be invoked as well as `SUBSCRIBE` does.
|
|
189
|
+
The `topic` and `deliverfunc` is a compound key to differentiate the uniqueness of its subscription pool. `topic` could be the one that is existed, in this case `deliverfunc` will be invoked as well as [`SUBSCRIBE`][SUBSCRIBE] does.
|
|
190
190
|
|
|
191
191
|
`deliverfunc` supports backpressue.
|
|
192
192
|
|
|
@@ -291,7 +291,7 @@ Please refer to [Connect Return Code](http://docs.oasis-open.org/mqtt/mqtt/v3.1.
|
|
|
291
291
|
|
|
292
292
|
## Handler: authorizePublish (client, packet, callback)
|
|
293
293
|
|
|
294
|
-
- client: [`<Client>`](./Client.md)
|
|
294
|
+
- client: [`<Client>`](./Client.md) | `null`
|
|
295
295
|
- packet: `<object>` [`PUBLISH`][PUBLISH]
|
|
296
296
|
- callback: `<Function>` `(error) => void`
|
|
297
297
|
- error `<Error>` | `null`
|
|
@@ -301,6 +301,8 @@ Invoked when
|
|
|
301
301
|
1. publish LWT to all online clients
|
|
302
302
|
2. incoming client publish
|
|
303
303
|
|
|
304
|
+
`client` is `null` when aedes publishes obsolete LWT without connected clients
|
|
305
|
+
|
|
304
306
|
If invoked `callback` with no errors, server authorizes the packet otherwise emits `clientError` with `error`. If an `error` occurs the client connection will be closed, but no error is returned to the client (MQTT-3.3.5-2)
|
|
305
307
|
|
|
306
308
|
```js
|
|
@@ -337,7 +339,7 @@ function defaultAuthorizePublish (client, packet, callback) {
|
|
|
337
339
|
Invoked when
|
|
338
340
|
|
|
339
341
|
1. restore subscriptions in non-clean session.
|
|
340
|
-
2. incoming client `SUBSCRIBE`
|
|
342
|
+
2. incoming client [`SUBSCRIBE`][SUBSCRIBE]
|
|
341
343
|
|
|
342
344
|
`subscription` is a dictionary object like `{ topic: hello, qos: 0 }`.
|
|
343
345
|
|
package/lib/client.js
CHANGED
|
@@ -10,7 +10,7 @@ const QoSPacket = require('./qos-packet')
|
|
|
10
10
|
const handleSubscribe = require('./handlers/subscribe')
|
|
11
11
|
const handleUnsubscribe = require('./handlers/unsubscribe')
|
|
12
12
|
const handle = require('./handlers')
|
|
13
|
-
const { pipeline } = require('
|
|
13
|
+
const { pipeline } = require('stream')
|
|
14
14
|
const { through } = require('./utils')
|
|
15
15
|
|
|
16
16
|
module.exports = Client
|
|
@@ -89,9 +89,20 @@ function Client (broker, conn, req) {
|
|
|
89
89
|
conn.on('end', this.close.bind(this))
|
|
90
90
|
this._eos = eos(this.conn, this.close.bind(this))
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
const getToForwardPacket = (_packet) => {
|
|
93
|
+
// Mqttv5 3.8.3.1: https://docs.oasis-open.org/mqtt/mqtt/v5.0/mqtt-v5.0.html#_Toc3901169
|
|
94
|
+
// prevent to forward messages sent by the same client when no-local flag is set
|
|
95
|
+
if (_packet.clientId === that.id && _packet.nl) return
|
|
96
|
+
|
|
93
97
|
const toForward = dedupe(that, _packet) &&
|
|
94
98
|
that.broker.authorizeForward(that, _packet)
|
|
99
|
+
|
|
100
|
+
return toForward
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
this.deliver0 = function deliverQoS0 (_packet, cb) {
|
|
104
|
+
const toForward = getToForwardPacket(_packet)
|
|
105
|
+
|
|
95
106
|
if (toForward) {
|
|
96
107
|
// Give nodejs some time to clear stacks, or we will see
|
|
97
108
|
// "Maximum call stack size exceeded" in a very high load
|
|
@@ -114,8 +125,8 @@ function Client (broker, conn, req) {
|
|
|
114
125
|
that.deliver0(_packet, cb)
|
|
115
126
|
return
|
|
116
127
|
}
|
|
117
|
-
const toForward =
|
|
118
|
-
|
|
128
|
+
const toForward = getToForwardPacket(_packet)
|
|
129
|
+
|
|
119
130
|
if (toForward) {
|
|
120
131
|
setImmediate(() => {
|
|
121
132
|
const packet = new QoSPacket(toForward, that)
|
package/lib/handlers/connect.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const retimer = require('retimer')
|
|
4
|
-
const { pipeline } = require('
|
|
4
|
+
const { pipeline } = require('stream')
|
|
5
5
|
const write = require('../write')
|
|
6
6
|
const QoSPacket = require('../qos-packet')
|
|
7
7
|
const { through } = require('../utils')
|
|
@@ -70,7 +70,7 @@ function init (client, packet, done) {
|
|
|
70
70
|
const error = new Error(errorMessages[returnCode])
|
|
71
71
|
error.errorCode = returnCode
|
|
72
72
|
doConnack(
|
|
73
|
-
{ client
|
|
73
|
+
{ client, returnCode, sessionPresent: false },
|
|
74
74
|
done.bind(this, error))
|
|
75
75
|
return
|
|
76
76
|
}
|
|
@@ -156,8 +156,8 @@ function fetchSubs (arg, done) {
|
|
|
156
156
|
if (!this.packet.clean) {
|
|
157
157
|
client.broker.persistence.subscriptionsByClient({
|
|
158
158
|
id: client.id,
|
|
159
|
-
done
|
|
160
|
-
arg
|
|
159
|
+
done,
|
|
160
|
+
arg
|
|
161
161
|
}, gotSubs)
|
|
162
162
|
return
|
|
163
163
|
}
|
|
@@ -142,13 +142,12 @@ function addSubs (sub, done) {
|
|
|
142
142
|
const nl = this.nl
|
|
143
143
|
let func = qos > 0 ? client.deliverQoS : client.deliver0
|
|
144
144
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
145
|
+
const deliverFunc = func
|
|
146
|
+
func = function handlePacketSubscription (_packet, cb) {
|
|
147
|
+
_packet = new Packet(_packet, broker)
|
|
148
|
+
_packet.nl = nl
|
|
149
|
+
if (!rap) _packet.retain = false
|
|
150
|
+
deliverFunc(_packet, cb)
|
|
152
151
|
}
|
|
153
152
|
|
|
154
153
|
// [MQTT-4.7.2-1]
|
|
@@ -218,7 +217,7 @@ function completeSubscribe (err) {
|
|
|
218
217
|
topic: $SYS_PREFIX + broker.id + '/new/subscribes',
|
|
219
218
|
payload: Buffer.from(JSON.stringify({
|
|
220
219
|
clientId: client.id,
|
|
221
|
-
subs
|
|
220
|
+
subs
|
|
222
221
|
}), 'utf8')
|
|
223
222
|
}, noop)
|
|
224
223
|
|
package/lib/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { Transform } = require('
|
|
3
|
+
const { Transform, Writable } = require('stream')
|
|
4
4
|
|
|
5
5
|
function validateTopic (topic, message) {
|
|
6
6
|
const end = topic.length - 1
|
|
@@ -37,8 +37,18 @@ function through (transform) {
|
|
|
37
37
|
})
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
function bulk (fn) {
|
|
41
|
+
return new Writable({
|
|
42
|
+
objectMode: true,
|
|
43
|
+
writev: function (chunks, cb) {
|
|
44
|
+
fn(chunks.map(chunk => chunk.chunk), cb)
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
40
49
|
module.exports = {
|
|
41
50
|
validateTopic,
|
|
42
51
|
through,
|
|
52
|
+
bulk,
|
|
43
53
|
$SYS_PREFIX: '$SYS/'
|
|
44
54
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aedes",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.48.0",
|
|
4
4
|
"description": "Stream-based MQTT broker",
|
|
5
5
|
"main": "aedes.js",
|
|
6
6
|
"types": "aedes.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"lint": "npm run lint:standard && npm run lint:typescript && npm run lint:markdown",
|
|
9
|
-
"lint:fix": "standard --fix",
|
|
9
|
+
"lint:fix": "standard --fix && eslint -c types/.eslintrc.json --fix aedes.d.ts types/**/*.ts test/types/**/*.test-d.ts",
|
|
10
10
|
"lint:standard": "standard --verbose | snazzy",
|
|
11
11
|
"lint:typescript": "eslint -c types/.eslintrc.json aedes.d.ts types/**/*.ts test/types/**/*.test-d.ts",
|
|
12
12
|
"lint:markdown": "markdownlint docs/*.md README.md",
|
|
@@ -94,43 +94,41 @@
|
|
|
94
94
|
},
|
|
95
95
|
"homepage": "https://github.com/moscajs/aedes#readme",
|
|
96
96
|
"engines": {
|
|
97
|
-
"node": ">=
|
|
97
|
+
"node": ">=14"
|
|
98
98
|
},
|
|
99
99
|
"devDependencies": {
|
|
100
|
-
"@sinonjs/fake-timers": "^9.1.
|
|
101
|
-
"@types/node": "^
|
|
102
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
103
|
-
"@typescript-eslint/parser": "^5.
|
|
100
|
+
"@sinonjs/fake-timers": "^9.1.2",
|
|
101
|
+
"@types/node": "^18.6.1",
|
|
102
|
+
"@typescript-eslint/eslint-plugin": "^5.31.0",
|
|
103
|
+
"@typescript-eslint/parser": "^5.31.0",
|
|
104
104
|
"concat-stream": "^2.0.0",
|
|
105
105
|
"duplexify": "^4.1.2",
|
|
106
106
|
"license-checker": "^25.0.1",
|
|
107
|
-
"markdownlint-cli": "^0.
|
|
108
|
-
"mqtt": "^4.3.
|
|
107
|
+
"markdownlint-cli": "^0.32.1",
|
|
108
|
+
"mqtt": "^4.3.7",
|
|
109
109
|
"mqtt-connection": "^4.1.0",
|
|
110
110
|
"pre-commit": "^1.2.2",
|
|
111
111
|
"proxyquire": "^2.1.3",
|
|
112
|
-
"release-it": "^
|
|
112
|
+
"release-it": "^15.2.0",
|
|
113
113
|
"snazzy": "^9.0.0",
|
|
114
|
-
"standard": "^
|
|
115
|
-
"tap": "^
|
|
116
|
-
"tsd": "^0.
|
|
117
|
-
"typescript": "^4.
|
|
114
|
+
"standard": "^17.0.0",
|
|
115
|
+
"tap": "^16.3.0",
|
|
116
|
+
"tsd": "^0.23.0",
|
|
117
|
+
"typescript": "^4.7.4",
|
|
118
118
|
"websocket-stream": "^5.5.2"
|
|
119
119
|
},
|
|
120
120
|
"dependencies": {
|
|
121
|
-
"aedes-packet": "^
|
|
122
|
-
"aedes-persistence": "^
|
|
123
|
-
"bulk-write-stream": "^2.0.1",
|
|
121
|
+
"aedes-packet": "^3.0.0",
|
|
122
|
+
"aedes-persistence": "^9.1.2",
|
|
124
123
|
"end-of-stream": "^1.4.4",
|
|
125
124
|
"fastfall": "^1.5.1",
|
|
126
125
|
"fastparallel": "^2.4.1",
|
|
127
126
|
"fastseries": "^2.0.0",
|
|
128
|
-
"hyperid": "^3.0.
|
|
129
|
-
"mqemitter": "^
|
|
130
|
-
"mqtt-packet": "^
|
|
131
|
-
"readable-stream": "^3.6.0",
|
|
127
|
+
"hyperid": "^3.0.1",
|
|
128
|
+
"mqemitter": "^5.0.0",
|
|
129
|
+
"mqtt-packet": "^8.1.1",
|
|
132
130
|
"retimer": "^3.0.0",
|
|
133
131
|
"reusify": "^1.0.4",
|
|
134
|
-
"uuid": "^
|
|
132
|
+
"uuid": "^9.0.0"
|
|
135
133
|
}
|
|
136
134
|
}
|
package/test/auth.js
CHANGED
|
@@ -422,7 +422,7 @@ test('authentication error when non numeric return code is passed', function (t)
|
|
|
422
422
|
test('authorize publish', function (t) {
|
|
423
423
|
t.plan(4)
|
|
424
424
|
|
|
425
|
-
const s = connect(setup())
|
|
425
|
+
const s = connect(setup(), { clientId: 'my-client-xyz' })
|
|
426
426
|
t.teardown(s.broker.close.bind(s.broker))
|
|
427
427
|
|
|
428
428
|
const expected = {
|
|
@@ -445,6 +445,7 @@ test('authorize publish', function (t) {
|
|
|
445
445
|
t.notOk(Object.prototype.hasOwnProperty.call(packet, 'messageId'), 'should not contain messageId in QoS 0')
|
|
446
446
|
expected.brokerId = s.broker.id
|
|
447
447
|
expected.brokerCounter = s.broker.counter
|
|
448
|
+
expected.clientId = 'my-client-xyz'
|
|
448
449
|
delete expected.length
|
|
449
450
|
t.same(packet, expected, 'packet matches')
|
|
450
451
|
cb()
|
|
@@ -460,7 +461,7 @@ test('authorize publish', function (t) {
|
|
|
460
461
|
test('authorize waits for authenticate', function (t) {
|
|
461
462
|
t.plan(6)
|
|
462
463
|
|
|
463
|
-
const s = setup()
|
|
464
|
+
const s = setup(aedes({ clientId: 'my-client-xyz-2' }))
|
|
464
465
|
t.teardown(s.broker.close.bind(s.broker))
|
|
465
466
|
|
|
466
467
|
s.broker.authenticate = function (client, username, password, cb) {
|
|
@@ -485,7 +486,8 @@ test('authorize waits for authenticate', function (t) {
|
|
|
485
486
|
qos: 0,
|
|
486
487
|
retain: false,
|
|
487
488
|
length: 12,
|
|
488
|
-
dup: false
|
|
489
|
+
dup: false,
|
|
490
|
+
clientId: 'my-client'
|
|
489
491
|
}
|
|
490
492
|
|
|
491
493
|
s.broker.mq.on('hello', function (packet, cb) {
|
|
@@ -519,12 +521,13 @@ test('authorize publish from configOptions', function (t) {
|
|
|
519
521
|
t.plan(4)
|
|
520
522
|
|
|
521
523
|
const s = connect(setup(aedes({
|
|
524
|
+
clientId: 'my-client-xyz-3',
|
|
522
525
|
authorizePublish: function (client, packet, cb) {
|
|
523
526
|
t.ok(client, 'client exists')
|
|
524
527
|
t.same(packet, expected, 'packet matches')
|
|
525
528
|
cb()
|
|
526
529
|
}
|
|
527
|
-
})))
|
|
530
|
+
})), { clientId: 'my-client-xyz-3' })
|
|
528
531
|
t.teardown(s.broker.close.bind(s.broker))
|
|
529
532
|
|
|
530
533
|
const expected = {
|
|
@@ -541,6 +544,7 @@ test('authorize publish from configOptions', function (t) {
|
|
|
541
544
|
t.notOk(Object.prototype.hasOwnProperty.call(packet, 'messageId'), 'should not contain messageId in QoS 0')
|
|
542
545
|
expected.brokerId = s.broker.id
|
|
543
546
|
expected.brokerCounter = s.broker.counter
|
|
547
|
+
expected.clientId = 'my-client-xyz-3'
|
|
544
548
|
delete expected.length
|
|
545
549
|
t.same(packet, expected, 'packet matches')
|
|
546
550
|
cb()
|
|
@@ -589,7 +593,7 @@ test('do not authorize publish', function (t) {
|
|
|
589
593
|
test('modify qos out of range in authorize publish ', function (t) {
|
|
590
594
|
t.plan(2)
|
|
591
595
|
|
|
592
|
-
const s = connect(setup())
|
|
596
|
+
const s = connect(setup(), { clientId: 'my-client-xyz-4' })
|
|
593
597
|
t.teardown(s.broker.close.bind(s.broker))
|
|
594
598
|
|
|
595
599
|
const expected = {
|
|
@@ -599,7 +603,8 @@ test('modify qos out of range in authorize publish ', function (t) {
|
|
|
599
603
|
qos: 0,
|
|
600
604
|
retain: false,
|
|
601
605
|
length: 12,
|
|
602
|
-
dup: false
|
|
606
|
+
dup: false,
|
|
607
|
+
clientId: 'my-client-xyz-4'
|
|
603
608
|
}
|
|
604
609
|
|
|
605
610
|
s.broker.authorizePublish = function (client, packet, cb) {
|
|
@@ -805,12 +810,19 @@ test('negate multiple subscriptions', function (t) {
|
|
|
805
810
|
test('negate subscription with correct persistence', function (t) {
|
|
806
811
|
t.plan(6)
|
|
807
812
|
|
|
813
|
+
// rh, rap, nl are undefined because mqtt.parser is set to MQTT 3.1.1 and will thus erase these props from s.inStream.write
|
|
808
814
|
const expected = [{
|
|
809
815
|
topic: 'hello',
|
|
810
|
-
qos: 0
|
|
816
|
+
qos: 0,
|
|
817
|
+
rh: undefined,
|
|
818
|
+
rap: undefined,
|
|
819
|
+
nl: undefined
|
|
811
820
|
}, {
|
|
812
821
|
topic: 'world',
|
|
813
|
-
qos: 0
|
|
822
|
+
qos: 0,
|
|
823
|
+
rh: undefined,
|
|
824
|
+
rap: undefined,
|
|
825
|
+
nl: undefined
|
|
814
826
|
}]
|
|
815
827
|
|
|
816
828
|
const broker = aedes()
|
|
@@ -839,10 +851,16 @@ test('negate subscription with correct persistence', function (t) {
|
|
|
839
851
|
messageId: 24,
|
|
840
852
|
subscriptions: [{
|
|
841
853
|
topic: 'hello',
|
|
842
|
-
qos: 0
|
|
854
|
+
qos: 0,
|
|
855
|
+
rh: 0,
|
|
856
|
+
rap: true,
|
|
857
|
+
nl: false
|
|
843
858
|
}, {
|
|
844
859
|
topic: 'world',
|
|
845
|
-
qos: 0
|
|
860
|
+
qos: 0,
|
|
861
|
+
rh: 0,
|
|
862
|
+
rap: true,
|
|
863
|
+
nl: false
|
|
846
864
|
}]
|
|
847
865
|
})
|
|
848
866
|
})
|
package/test/basic.js
CHANGED
|
@@ -20,7 +20,7 @@ test('test aedes.Server', function (t) {
|
|
|
20
20
|
test('publish QoS 0', function (t) {
|
|
21
21
|
t.plan(2)
|
|
22
22
|
|
|
23
|
-
const s = connect(setup())
|
|
23
|
+
const s = connect(setup(), { clientId: 'my-client-xyz-5' })
|
|
24
24
|
t.teardown(s.broker.close.bind(s.broker))
|
|
25
25
|
|
|
26
26
|
const expected = {
|
|
@@ -29,7 +29,8 @@ test('publish QoS 0', function (t) {
|
|
|
29
29
|
payload: Buffer.from('world'),
|
|
30
30
|
qos: 0,
|
|
31
31
|
retain: false,
|
|
32
|
-
dup: false
|
|
32
|
+
dup: false,
|
|
33
|
+
clientId: 'my-client-xyz-5'
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
s.broker.mq.on('hello', function (packet, cb) {
|
|
@@ -128,7 +129,7 @@ test('publish to $SYS topic throws error', function (t) {
|
|
|
128
129
|
qos: 0,
|
|
129
130
|
retain: false
|
|
130
131
|
}
|
|
131
|
-
const expectedSubs = ele.clean ? null : [{ topic: 'hello', qos: ele.qos }]
|
|
132
|
+
const expectedSubs = ele.clean ? null : [{ topic: 'hello', qos: ele.qos, rh: undefined, rap: undefined, nl: undefined }]
|
|
132
133
|
|
|
133
134
|
subscribe(t, s, 'hello', ele.qos, function () {
|
|
134
135
|
s.outStream.once('data', function (packet) {
|
|
@@ -188,7 +189,10 @@ test('return write errors to callback', function (t) {
|
|
|
188
189
|
qos: 0,
|
|
189
190
|
retain: false
|
|
190
191
|
}
|
|
191
|
-
const subs = [
|
|
192
|
+
const subs = [
|
|
193
|
+
{ topic: 'hello', qos: ele.qos, rh: undefined, rap: undefined, nl: undefined },
|
|
194
|
+
{ topic: 'world', qos: ele.qos, rh: undefined, rap: undefined, nl: undefined }
|
|
195
|
+
]
|
|
192
196
|
const expectedSubs = ele.clean ? null : subs
|
|
193
197
|
|
|
194
198
|
subscribeMultiple(t, s, subs, [ele.qos, ele.qos], function () {
|