mqtt 2.18.5 → 2.18.9

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.
Files changed (66) hide show
  1. package/CONTRIBUTING.md +27 -27
  2. package/LICENSE.md +15 -15
  3. package/README.md +612 -612
  4. package/bin/pub.js +146 -146
  5. package/bin/sub.js +123 -123
  6. package/dist/mqtt.js +14275 -10729
  7. package/dist/mqtt.min.js +1 -1
  8. package/doc/help.txt +8 -8
  9. package/doc/publish.txt +26 -26
  10. package/doc/subscribe.txt +26 -26
  11. package/examples/client/secure-client.js +24 -24
  12. package/examples/client/simple-both.js +13 -13
  13. package/examples/client/simple-publish.js +7 -7
  14. package/examples/client/simple-subscribe.js +9 -9
  15. package/examples/tls client/crt.ca.cg.pem +34 -34
  16. package/examples/tls client/mqttclient.js +48 -48
  17. package/examples/tls client/tls-cert.pem +13 -13
  18. package/examples/tls client/tls-key.pem +15 -15
  19. package/examples/wss/client.js +49 -49
  20. package/examples/wss/client_with_proxy.js +58 -58
  21. package/lib/client.js +1129 -1102
  22. package/lib/connect/index.js +149 -149
  23. package/lib/connect/tcp.js +19 -19
  24. package/lib/connect/tls.js +41 -41
  25. package/lib/connect/ws.js +92 -92
  26. package/lib/connect/wx.js +110 -110
  27. package/lib/store.js +140 -140
  28. package/lib/validations.js +52 -52
  29. package/mqtt.js +41 -41
  30. package/package.json +107 -111
  31. package/test/abstract_client.js +2667 -2533
  32. package/test/abstract_store.js +135 -133
  33. package/test/browser/server.js +132 -132
  34. package/test/browser/test.js +92 -92
  35. package/test/browser/wx.js +93 -93
  36. package/test/client.js +544 -544
  37. package/test/helpers/private-csr.pem +16 -16
  38. package/test/helpers/private-key.pem +27 -27
  39. package/test/helpers/public-cert.pem +19 -19
  40. package/test/helpers/public-key.pem +9 -9
  41. package/test/helpers/server.js +52 -52
  42. package/test/helpers/server_process.js +9 -9
  43. package/test/helpers/tls-cert.pem +14 -14
  44. package/test/helpers/tls-csr.pem +11 -11
  45. package/test/helpers/tls-key.pem +15 -15
  46. package/test/helpers/wrong-cert.pem +13 -13
  47. package/test/helpers/wrong-csr.pem +11 -11
  48. package/test/helpers/wrong-key.pem +15 -15
  49. package/test/mocha.opts +4 -4
  50. package/test/mqtt.js +230 -230
  51. package/test/mqtt_store.js +9 -9
  52. package/test/secure_client.js +157 -157
  53. package/test/server.js +65 -65
  54. package/test/store.js +10 -10
  55. package/test/typescript/broker-connect-subscribe-and-publish.ts +22 -22
  56. package/test/typescript/tsconfig.json +14 -14
  57. package/test/util.js +13 -13
  58. package/test/websocket_client.js +144 -144
  59. package/types/index.d.ts +27 -27
  60. package/types/lib/client-options.d.ts +137 -137
  61. package/types/lib/client.d.ts +196 -196
  62. package/types/lib/connect/index.d.ts +10 -10
  63. package/types/lib/store-options.d.ts +6 -6
  64. package/types/lib/store.d.ts +46 -46
  65. package/test/typescript/broker-connect-subscribe-and-publish.js +0 -24
  66. package/test/typescript/broker-connect-subscribe-and-publish.js.map +0 -1
package/test/mqtt.js CHANGED
@@ -1,230 +1,230 @@
1
- 'use strict'
2
-
3
- var fs = require('fs')
4
- var path = require('path')
5
- var mqtt = require('../')
6
-
7
- describe('mqtt', function () {
8
- describe('#connect', function () {
9
- var sslOpts, sslOpts2
10
- it('should return an MqttClient when connect is called with mqtt:/ url', function () {
11
- var c = mqtt.connect('mqtt://localhost:1883')
12
-
13
- c.should.be.instanceOf(mqtt.MqttClient)
14
- c.end()
15
- })
16
-
17
- it('should throw an error when called with no protocol specified', function () {
18
- (function () {
19
- var c = mqtt.connect('foo.bar.com')
20
- c.end()
21
- }).should.throw('Missing protocol')
22
- })
23
-
24
- it('should throw an error when called with no protocol specified - with options', function () {
25
- (function () {
26
- var c = mqtt.connect('tcp://foo.bar.com', { protocol: null })
27
- c.end()
28
- }).should.throw('Missing protocol')
29
- })
30
-
31
- it('should return an MqttClient with username option set', function () {
32
- var c = mqtt.connect('mqtt://user:pass@localhost:1883')
33
-
34
- c.should.be.instanceOf(mqtt.MqttClient)
35
- c.options.should.have.property('username', 'user')
36
- c.options.should.have.property('password', 'pass')
37
- c.end()
38
- })
39
-
40
- it('should return an MqttClient with username and password options set', function () {
41
- var c = mqtt.connect('mqtt://user@localhost:1883')
42
-
43
- c.should.be.instanceOf(mqtt.MqttClient)
44
- c.options.should.have.property('username', 'user')
45
- c.end()
46
- })
47
-
48
- it('should return an MqttClient with the clientid with random value', function () {
49
- var c = mqtt.connect('mqtt://user@localhost:1883')
50
-
51
- c.should.be.instanceOf(mqtt.MqttClient)
52
- c.options.should.have.property('clientId')
53
- c.end()
54
- })
55
-
56
- it('should return an MqttClient with the clientid with empty string', function () {
57
- var c = mqtt.connect('mqtt://user@localhost:1883?clientId=')
58
-
59
- c.should.be.instanceOf(mqtt.MqttClient)
60
- c.options.should.have.property('clientId', '')
61
- c.end()
62
- })
63
-
64
- it('should return an MqttClient with the clientid option set', function () {
65
- var c = mqtt.connect('mqtt://user@localhost:1883?clientId=123')
66
-
67
- c.should.be.instanceOf(mqtt.MqttClient)
68
- c.options.should.have.property('clientId', '123')
69
- c.end()
70
- })
71
-
72
- it('should return an MqttClient when connect is called with tcp:/ url', function () {
73
- var c = mqtt.connect('tcp://localhost')
74
-
75
- c.should.be.instanceOf(mqtt.MqttClient)
76
- c.end()
77
- })
78
-
79
- it('should return an MqttClient with correct host when called with a host and port', function () {
80
- var c = mqtt.connect('tcp://user:pass@localhost:1883')
81
-
82
- c.options.should.have.property('hostname', 'localhost')
83
- c.options.should.have.property('port', 1883)
84
- c.end()
85
- })
86
-
87
- sslOpts = {
88
- keyPath: path.join(__dirname, 'helpers', 'private-key.pem'),
89
- certPath: path.join(__dirname, 'helpers', 'public-cert.pem'),
90
- caPaths: [path.join(__dirname, 'helpers', 'public-cert.pem')]
91
- }
92
-
93
- it('should return an MqttClient when connect is called with mqtts:/ url', function () {
94
- var c = mqtt.connect('mqtts://localhost', sslOpts)
95
-
96
- c.options.should.have.property('protocol', 'mqtts')
97
-
98
- c.on('error', function () {})
99
-
100
- c.should.be.instanceOf(mqtt.MqttClient)
101
- c.end()
102
- })
103
-
104
- it('should return an MqttClient when connect is called with ssl:/ url', function () {
105
- var c = mqtt.connect('ssl://localhost', sslOpts)
106
-
107
- c.options.should.have.property('protocol', 'ssl')
108
-
109
- c.on('error', function () {})
110
-
111
- c.should.be.instanceOf(mqtt.MqttClient)
112
- c.end()
113
- })
114
-
115
- it('should return an MqttClient when connect is called with ws:/ url', function () {
116
- var c = mqtt.connect('ws://localhost', sslOpts)
117
-
118
- c.options.should.have.property('protocol', 'ws')
119
-
120
- c.on('error', function () {})
121
-
122
- c.should.be.instanceOf(mqtt.MqttClient)
123
- c.end()
124
- })
125
-
126
- it('should return an MqttClient when connect is called with wss:/ url', function () {
127
- var c = mqtt.connect('wss://localhost', sslOpts)
128
-
129
- c.options.should.have.property('protocol', 'wss')
130
-
131
- c.on('error', function () {})
132
-
133
- c.should.be.instanceOf(mqtt.MqttClient)
134
- c.end()
135
- })
136
-
137
- sslOpts2 = {
138
- key: fs.readFileSync(path.join(__dirname, 'helpers', 'private-key.pem')),
139
- cert: fs.readFileSync(path.join(__dirname, 'helpers', 'public-cert.pem')),
140
- ca: [fs.readFileSync(path.join(__dirname, 'helpers', 'public-cert.pem'))]
141
- }
142
-
143
- it('should throw an error when it is called with cert and key set but no protocol specified', function () {
144
- // to do rewrite wrap function
145
- (function () {
146
- var c = mqtt.connect(sslOpts2)
147
- c.end()
148
- }).should.throw('Missing secure protocol key')
149
- })
150
-
151
- it('should throw an error when it is called with cert and key set and protocol other than allowed: mqtt,mqtts,ws,wss,wxs', function () {
152
- (function () {
153
- sslOpts2.protocol = 'UNKNOWNPROTOCOL'
154
- var c = mqtt.connect(sslOpts2)
155
- c.end()
156
- }).should.throw()
157
- })
158
-
159
- it('should return a MqttClient with mqtts set when connect is called key and cert set and protocol mqtt', function () {
160
- sslOpts2.protocol = 'mqtt'
161
- var c = mqtt.connect(sslOpts2)
162
-
163
- c.options.should.have.property('protocol', 'mqtts')
164
-
165
- c.on('error', function () {})
166
-
167
- c.should.be.instanceOf(mqtt.MqttClient)
168
- })
169
-
170
- it('should return a MqttClient with mqtts set when connect is called key and cert set and protocol mqtts', function () {
171
- sslOpts2.protocol = 'mqtts'
172
- var c = mqtt.connect(sslOpts2)
173
-
174
- c.options.should.have.property('protocol', 'mqtts')
175
-
176
- c.on('error', function () {})
177
-
178
- c.should.be.instanceOf(mqtt.MqttClient)
179
- })
180
-
181
- it('should return a MqttClient with wss set when connect is called key and cert set and protocol ws', function () {
182
- sslOpts2.protocol = 'ws'
183
- var c = mqtt.connect(sslOpts2)
184
-
185
- c.options.should.have.property('protocol', 'wss')
186
-
187
- c.on('error', function () {})
188
-
189
- c.should.be.instanceOf(mqtt.MqttClient)
190
- })
191
-
192
- it('should return a MqttClient with wss set when connect is called key and cert set and protocol wss', function () {
193
- sslOpts2.protocol = 'wss'
194
- var c = mqtt.connect(sslOpts2)
195
-
196
- c.options.should.have.property('protocol', 'wss')
197
-
198
- c.on('error', function () {})
199
-
200
- c.should.be.instanceOf(mqtt.MqttClient)
201
- })
202
-
203
- it('should return an MqttClient with the clientid with option of clientId as empty string', function () {
204
- var c = mqtt.connect('mqtt://localhost:1883', {
205
- clientId: ''
206
- })
207
-
208
- c.should.be.instanceOf(mqtt.MqttClient)
209
- c.options.should.have.property('clientId', '')
210
- })
211
-
212
- it('should return an MqttClient with the clientid with option of clientId empty', function () {
213
- var c = mqtt.connect('mqtt://localhost:1883')
214
-
215
- c.should.be.instanceOf(mqtt.MqttClient)
216
- c.options.should.have.property('clientId')
217
- c.end()
218
- })
219
-
220
- it('should return an MqttClient with the clientid with option of with specific clientId', function () {
221
- var c = mqtt.connect('mqtt://localhost:1883', {
222
- clientId: '123'
223
- })
224
-
225
- c.should.be.instanceOf(mqtt.MqttClient)
226
- c.options.should.have.property('clientId', '123')
227
- c.end()
228
- })
229
- })
230
- })
1
+ 'use strict'
2
+
3
+ var fs = require('fs')
4
+ var path = require('path')
5
+ var mqtt = require('../')
6
+
7
+ describe('mqtt', function () {
8
+ describe('#connect', function () {
9
+ var sslOpts, sslOpts2
10
+ it('should return an MqttClient when connect is called with mqtt:/ url', function () {
11
+ var c = mqtt.connect('mqtt://localhost:1883')
12
+
13
+ c.should.be.instanceOf(mqtt.MqttClient)
14
+ c.end()
15
+ })
16
+
17
+ it('should throw an error when called with no protocol specified', function () {
18
+ (function () {
19
+ var c = mqtt.connect('foo.bar.com')
20
+ c.end()
21
+ }).should.throw('Missing protocol')
22
+ })
23
+
24
+ it('should throw an error when called with no protocol specified - with options', function () {
25
+ (function () {
26
+ var c = mqtt.connect('tcp://foo.bar.com', { protocol: null })
27
+ c.end()
28
+ }).should.throw('Missing protocol')
29
+ })
30
+
31
+ it('should return an MqttClient with username option set', function () {
32
+ var c = mqtt.connect('mqtt://user:pass@localhost:1883')
33
+
34
+ c.should.be.instanceOf(mqtt.MqttClient)
35
+ c.options.should.have.property('username', 'user')
36
+ c.options.should.have.property('password', 'pass')
37
+ c.end()
38
+ })
39
+
40
+ it('should return an MqttClient with username and password options set', function () {
41
+ var c = mqtt.connect('mqtt://user@localhost:1883')
42
+
43
+ c.should.be.instanceOf(mqtt.MqttClient)
44
+ c.options.should.have.property('username', 'user')
45
+ c.end()
46
+ })
47
+
48
+ it('should return an MqttClient with the clientid with random value', function () {
49
+ var c = mqtt.connect('mqtt://user@localhost:1883')
50
+
51
+ c.should.be.instanceOf(mqtt.MqttClient)
52
+ c.options.should.have.property('clientId')
53
+ c.end()
54
+ })
55
+
56
+ it('should return an MqttClient with the clientid with empty string', function () {
57
+ var c = mqtt.connect('mqtt://user@localhost:1883?clientId=')
58
+
59
+ c.should.be.instanceOf(mqtt.MqttClient)
60
+ c.options.should.have.property('clientId', '')
61
+ c.end()
62
+ })
63
+
64
+ it('should return an MqttClient with the clientid option set', function () {
65
+ var c = mqtt.connect('mqtt://user@localhost:1883?clientId=123')
66
+
67
+ c.should.be.instanceOf(mqtt.MqttClient)
68
+ c.options.should.have.property('clientId', '123')
69
+ c.end()
70
+ })
71
+
72
+ it('should return an MqttClient when connect is called with tcp:/ url', function () {
73
+ var c = mqtt.connect('tcp://localhost')
74
+
75
+ c.should.be.instanceOf(mqtt.MqttClient)
76
+ c.end()
77
+ })
78
+
79
+ it('should return an MqttClient with correct host when called with a host and port', function () {
80
+ var c = mqtt.connect('tcp://user:pass@localhost:1883')
81
+
82
+ c.options.should.have.property('hostname', 'localhost')
83
+ c.options.should.have.property('port', 1883)
84
+ c.end()
85
+ })
86
+
87
+ sslOpts = {
88
+ keyPath: path.join(__dirname, 'helpers', 'private-key.pem'),
89
+ certPath: path.join(__dirname, 'helpers', 'public-cert.pem'),
90
+ caPaths: [path.join(__dirname, 'helpers', 'public-cert.pem')]
91
+ }
92
+
93
+ it('should return an MqttClient when connect is called with mqtts:/ url', function () {
94
+ var c = mqtt.connect('mqtts://localhost', sslOpts)
95
+
96
+ c.options.should.have.property('protocol', 'mqtts')
97
+
98
+ c.on('error', function () {})
99
+
100
+ c.should.be.instanceOf(mqtt.MqttClient)
101
+ c.end()
102
+ })
103
+
104
+ it('should return an MqttClient when connect is called with ssl:/ url', function () {
105
+ var c = mqtt.connect('ssl://localhost', sslOpts)
106
+
107
+ c.options.should.have.property('protocol', 'ssl')
108
+
109
+ c.on('error', function () {})
110
+
111
+ c.should.be.instanceOf(mqtt.MqttClient)
112
+ c.end()
113
+ })
114
+
115
+ it('should return an MqttClient when connect is called with ws:/ url', function () {
116
+ var c = mqtt.connect('ws://localhost', sslOpts)
117
+
118
+ c.options.should.have.property('protocol', 'ws')
119
+
120
+ c.on('error', function () {})
121
+
122
+ c.should.be.instanceOf(mqtt.MqttClient)
123
+ c.end()
124
+ })
125
+
126
+ it('should return an MqttClient when connect is called with wss:/ url', function () {
127
+ var c = mqtt.connect('wss://localhost', sslOpts)
128
+
129
+ c.options.should.have.property('protocol', 'wss')
130
+
131
+ c.on('error', function () {})
132
+
133
+ c.should.be.instanceOf(mqtt.MqttClient)
134
+ c.end()
135
+ })
136
+
137
+ sslOpts2 = {
138
+ key: fs.readFileSync(path.join(__dirname, 'helpers', 'private-key.pem')),
139
+ cert: fs.readFileSync(path.join(__dirname, 'helpers', 'public-cert.pem')),
140
+ ca: [fs.readFileSync(path.join(__dirname, 'helpers', 'public-cert.pem'))]
141
+ }
142
+
143
+ it('should throw an error when it is called with cert and key set but no protocol specified', function () {
144
+ // to do rewrite wrap function
145
+ (function () {
146
+ var c = mqtt.connect(sslOpts2)
147
+ c.end()
148
+ }).should.throw('Missing secure protocol key')
149
+ })
150
+
151
+ it('should throw an error when it is called with cert and key set and protocol other than allowed: mqtt,mqtts,ws,wss,wxs', function () {
152
+ (function () {
153
+ sslOpts2.protocol = 'UNKNOWNPROTOCOL'
154
+ var c = mqtt.connect(sslOpts2)
155
+ c.end()
156
+ }).should.throw()
157
+ })
158
+
159
+ it('should return a MqttClient with mqtts set when connect is called key and cert set and protocol mqtt', function () {
160
+ sslOpts2.protocol = 'mqtt'
161
+ var c = mqtt.connect(sslOpts2)
162
+
163
+ c.options.should.have.property('protocol', 'mqtts')
164
+
165
+ c.on('error', function () {})
166
+
167
+ c.should.be.instanceOf(mqtt.MqttClient)
168
+ })
169
+
170
+ it('should return a MqttClient with mqtts set when connect is called key and cert set and protocol mqtts', function () {
171
+ sslOpts2.protocol = 'mqtts'
172
+ var c = mqtt.connect(sslOpts2)
173
+
174
+ c.options.should.have.property('protocol', 'mqtts')
175
+
176
+ c.on('error', function () {})
177
+
178
+ c.should.be.instanceOf(mqtt.MqttClient)
179
+ })
180
+
181
+ it('should return a MqttClient with wss set when connect is called key and cert set and protocol ws', function () {
182
+ sslOpts2.protocol = 'ws'
183
+ var c = mqtt.connect(sslOpts2)
184
+
185
+ c.options.should.have.property('protocol', 'wss')
186
+
187
+ c.on('error', function () {})
188
+
189
+ c.should.be.instanceOf(mqtt.MqttClient)
190
+ })
191
+
192
+ it('should return a MqttClient with wss set when connect is called key and cert set and protocol wss', function () {
193
+ sslOpts2.protocol = 'wss'
194
+ var c = mqtt.connect(sslOpts2)
195
+
196
+ c.options.should.have.property('protocol', 'wss')
197
+
198
+ c.on('error', function () {})
199
+
200
+ c.should.be.instanceOf(mqtt.MqttClient)
201
+ })
202
+
203
+ it('should return an MqttClient with the clientid with option of clientId as empty string', function () {
204
+ var c = mqtt.connect('mqtt://localhost:1883', {
205
+ clientId: ''
206
+ })
207
+
208
+ c.should.be.instanceOf(mqtt.MqttClient)
209
+ c.options.should.have.property('clientId', '')
210
+ })
211
+
212
+ it('should return an MqttClient with the clientid with option of clientId empty', function () {
213
+ var c = mqtt.connect('mqtt://localhost:1883')
214
+
215
+ c.should.be.instanceOf(mqtt.MqttClient)
216
+ c.options.should.have.property('clientId')
217
+ c.end()
218
+ })
219
+
220
+ it('should return an MqttClient with the clientid with option of with specific clientId', function () {
221
+ var c = mqtt.connect('mqtt://localhost:1883', {
222
+ clientId: '123'
223
+ })
224
+
225
+ c.should.be.instanceOf(mqtt.MqttClient)
226
+ c.options.should.have.property('clientId', '123')
227
+ c.end()
228
+ })
229
+ })
230
+ })
@@ -1,9 +1,9 @@
1
- 'use strict'
2
-
3
- var mqtt = require('../lib/connect')
4
-
5
- describe('store in lib/connect/index.js (webpack entry point)', function () {
6
- it('should create store', function (done) {
7
- done(null, new mqtt.Store())
8
- })
9
- })
1
+ 'use strict'
2
+
3
+ var mqtt = require('../lib/connect')
4
+
5
+ describe('store in lib/connect/index.js (webpack entry point)', function () {
6
+ it('should create store', function (done) {
7
+ done(null, new mqtt.Store())
8
+ })
9
+ })