amqplib 0.5.1 → 0.5.2
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/CHANGELOG.md +21 -0
- package/Makefile +1 -1
- package/README.md +2 -2
- package/callback_api.js +1 -0
- package/channel_api.js +1 -0
- package/examples/headers.js +2 -2
- package/examples/receive_generator.js +39 -0
- package/examples/send_generators.js +1 -1
- package/examples/ssl.js +1 -1
- package/examples/tutorials/callback_api/emit_log.js +1 -1
- package/examples/tutorials/callback_api/emit_log_direct.js +1 -1
- package/examples/tutorials/callback_api/emit_log_topic.js +1 -1
- package/examples/tutorials/callback_api/new_task.js +1 -1
- package/examples/tutorials/callback_api/rpc_client.js +1 -1
- package/examples/tutorials/callback_api/rpc_server.js +1 -1
- package/examples/tutorials/callback_api/send.js +1 -1
- package/examples/tutorials/emit_log.js +1 -1
- package/examples/tutorials/emit_log_direct.js +1 -1
- package/examples/tutorials/emit_log_topic.js +1 -1
- package/examples/tutorials/new_task.js +1 -1
- package/examples/tutorials/rpc_client.js +1 -1
- package/examples/tutorials/rpc_server.js +1 -1
- package/examples/tutorials/send.js +1 -1
- package/examples/waitForConfirms.js +1 -1
- package/lib/channel.js +2 -2
- package/lib/codec.js +64 -38
- package/lib/connect.js +33 -12
- package/lib/connection.js +4 -3
- package/lib/credentials.js +6 -3
- package/lib/defs.js +75 -75
- package/lib/frame.js +2 -1
- package/package.json +4 -3
- package/test/callback_api.js +6 -5
- package/test/channel.js +15 -14
- package/test/channel_api.js +25 -24
- package/test/codec.js +48 -9
- package/test/connect.js +63 -3
- package/test/connection.js +10 -9
- package/test/data.js +32 -9
- package/test/frame.js +4 -4
- package/test/util.js +14 -0
- package/.npmignore +0 -9
package/test/callback_api.js
CHANGED
|
@@ -8,6 +8,7 @@ var schedule = util.schedule;
|
|
|
8
8
|
var randomString = util.randomString;
|
|
9
9
|
var kCallback = util.kCallback;
|
|
10
10
|
var domain = require('domain');
|
|
11
|
+
var Buffer = require('safe-buffer').Buffer;
|
|
11
12
|
|
|
12
13
|
var URL = process.env.URL || 'amqp://localhost';
|
|
13
14
|
|
|
@@ -159,7 +160,7 @@ channel_test('send to queue and consume noAck', function(ch, done) {
|
|
|
159
160
|
else done(new Error("message content doesn't match:" +
|
|
160
161
|
msg + " =/= " + m.content.toString()));
|
|
161
162
|
}, {noAck: true, exclusive: true});
|
|
162
|
-
ch.sendToQueue(q.queue,
|
|
163
|
+
ch.sendToQueue(q.queue, Buffer.from(msg));
|
|
163
164
|
});
|
|
164
165
|
});
|
|
165
166
|
|
|
@@ -175,7 +176,7 @@ channel_test('send to queue and consume ack', function(ch, done) {
|
|
|
175
176
|
else done(new Error("message content doesn't match:" +
|
|
176
177
|
msg + " =/= " + m.content.toString()));
|
|
177
178
|
}, {noAck: false, exclusive: true});
|
|
178
|
-
ch.sendToQueue(q.queue,
|
|
179
|
+
ch.sendToQueue(q.queue, Buffer.from(msg));
|
|
179
180
|
});
|
|
180
181
|
});
|
|
181
182
|
|
|
@@ -183,7 +184,7 @@ channel_test('send to and get from queue', function(ch, done) {
|
|
|
183
184
|
ch.assertQueue('', {exclusive: true}, function(e, q) {
|
|
184
185
|
if (e != null) return done(e);
|
|
185
186
|
var msg = randomString();
|
|
186
|
-
ch.sendToQueue(q.queue,
|
|
187
|
+
ch.sendToQueue(q.queue, Buffer.from(msg));
|
|
187
188
|
waitForMessages(ch, q.queue, function(e, _) {
|
|
188
189
|
if (e != null) return done(e);
|
|
189
190
|
ch.get(q.queue, {noAck: true}, function(e, m) {
|
|
@@ -210,12 +211,12 @@ confirm_channel_test('Receive confirmation', function(ch, done) {
|
|
|
210
211
|
// An unroutable message, on the basis that you're not allowed a
|
|
211
212
|
// queue with an empty name, and you can't make bindings to the
|
|
212
213
|
// default exchange. Tricky eh?
|
|
213
|
-
ch.publish('', '',
|
|
214
|
+
ch.publish('', '', Buffer.from('foo'), {}, done);
|
|
214
215
|
});
|
|
215
216
|
|
|
216
217
|
confirm_channel_test('Wait for confirms', function(ch, done) {
|
|
217
218
|
for (var i=0; i < 1000; i++) {
|
|
218
|
-
ch.publish('', '',
|
|
219
|
+
ch.publish('', '', Buffer.from('foo'), {});
|
|
219
220
|
}
|
|
220
221
|
ch.waitForConfirms(done);
|
|
221
222
|
});
|
package/test/channel.js
CHANGED
|
@@ -12,6 +12,7 @@ var completes = util.completes;
|
|
|
12
12
|
var defs = require('../lib/defs');
|
|
13
13
|
var conn_handshake = require('./connection').connection_handshake;
|
|
14
14
|
var OPEN_OPTS = require('./connection').OPEN_OPTS;
|
|
15
|
+
var Buffer = require('safe-buffer').Buffer;
|
|
15
16
|
|
|
16
17
|
var LOG_ERRORS = process.env.LOG_ERRORS;
|
|
17
18
|
|
|
@@ -59,7 +60,7 @@ function channel_handshake(send, await) {
|
|
|
59
60
|
return await(defs.ChannelOpen)()
|
|
60
61
|
.then(function(open) {
|
|
61
62
|
assert.notEqual(0, open.channel);
|
|
62
|
-
send(defs.ChannelOpenOk, {channelId:
|
|
63
|
+
send(defs.ChannelOpenOk, {channelId: Buffer.from('')}, open.channel);
|
|
63
64
|
return open.channel;
|
|
64
65
|
});
|
|
65
66
|
}
|
|
@@ -304,7 +305,7 @@ test("publish all < single chunk threshold", channelTest(
|
|
|
304
305
|
ch.sendMessage({
|
|
305
306
|
exchange: 'foo', routingKey: 'bar',
|
|
306
307
|
mandatory: false, immediate: false, ticket: 0
|
|
307
|
-
}, {},
|
|
308
|
+
}, {}, Buffer.from('foobar'));
|
|
308
309
|
})
|
|
309
310
|
.then(succeed(done), fail(done));
|
|
310
311
|
},
|
|
@@ -324,7 +325,7 @@ test("publish content > single chunk threshold", channelTest(
|
|
|
324
325
|
ch.sendMessage({
|
|
325
326
|
exchange: 'foo', routingKey: 'bar',
|
|
326
327
|
mandatory: false, immediate: false, ticket: 0
|
|
327
|
-
}, {},
|
|
328
|
+
}, {}, Buffer.alloc(3000));
|
|
328
329
|
}, done);
|
|
329
330
|
},
|
|
330
331
|
function(send, await, done, ch) {
|
|
@@ -344,8 +345,8 @@ test("publish method & headers > threshold", channelTest(
|
|
|
344
345
|
exchange: 'foo', routingKey: 'bar',
|
|
345
346
|
mandatory: false, immediate: false, ticket: 0
|
|
346
347
|
}, {
|
|
347
|
-
headers: {foo:
|
|
348
|
-
},
|
|
348
|
+
headers: {foo: Buffer.alloc(3000)}
|
|
349
|
+
}, Buffer.from('foobar'));
|
|
349
350
|
}, done);
|
|
350
351
|
},
|
|
351
352
|
function(send, await, done, ch) {
|
|
@@ -364,11 +365,11 @@ test("publish zero-length message", channelTest(
|
|
|
364
365
|
ch.sendMessage({
|
|
365
366
|
exchange: 'foo', routingKey: 'bar',
|
|
366
367
|
mandatory: false, immediate: false, ticket: 0
|
|
367
|
-
}, {},
|
|
368
|
+
}, {}, Buffer.alloc(0));
|
|
368
369
|
ch.sendMessage({
|
|
369
370
|
exchange: 'foo', routingKey: 'bar',
|
|
370
371
|
mandatory: false, immediate: false, ticket: 0
|
|
371
|
-
}, {},
|
|
372
|
+
}, {}, Buffer.alloc(0));
|
|
372
373
|
}, done);
|
|
373
374
|
},
|
|
374
375
|
function(send, await, done, ch) {
|
|
@@ -390,7 +391,7 @@ test("delivery", channelTest(
|
|
|
390
391
|
},
|
|
391
392
|
function(send, await, done, ch) {
|
|
392
393
|
completes(function() {
|
|
393
|
-
send(defs.BasicDeliver, DELIVER_FIELDS, ch,
|
|
394
|
+
send(defs.BasicDeliver, DELIVER_FIELDS, ch, Buffer.from('barfoo'));
|
|
394
395
|
}, done);
|
|
395
396
|
}));
|
|
396
397
|
|
|
@@ -399,13 +400,13 @@ test("zero byte msg", channelTest(
|
|
|
399
400
|
open(ch);
|
|
400
401
|
ch.on('delivery', function(m) {
|
|
401
402
|
completes(function() {
|
|
402
|
-
assert.deepEqual(
|
|
403
|
+
assert.deepEqual(Buffer.alloc(0), m.content);
|
|
403
404
|
}, done);
|
|
404
405
|
});
|
|
405
406
|
},
|
|
406
407
|
function(send, await, done, ch) {
|
|
407
408
|
completes(function() {
|
|
408
|
-
send(defs.BasicDeliver, DELIVER_FIELDS, ch,
|
|
409
|
+
send(defs.BasicDeliver, DELIVER_FIELDS, ch, Buffer.from(''));
|
|
409
410
|
}, done);
|
|
410
411
|
}));
|
|
411
412
|
|
|
@@ -452,7 +453,7 @@ test("bad properties send", channelTest(
|
|
|
452
453
|
ch.sendMessage({routingKey: 'foo',
|
|
453
454
|
exchange: 'amq.direct'},
|
|
454
455
|
{contentEncoding: 7},
|
|
455
|
-
|
|
456
|
+
Buffer.from('foobar'));
|
|
456
457
|
});
|
|
457
458
|
}, done);
|
|
458
459
|
},
|
|
@@ -474,7 +475,7 @@ test("bad consumer", channelTest(
|
|
|
474
475
|
open(ch);
|
|
475
476
|
},
|
|
476
477
|
function(send, await, done, ch) {
|
|
477
|
-
send(defs.BasicDeliver, DELIVER_FIELDS, ch,
|
|
478
|
+
send(defs.BasicDeliver, DELIVER_FIELDS, ch, Buffer.from('barfoo'));
|
|
478
479
|
return await(defs.ChannelClose)()
|
|
479
480
|
.then(function() {
|
|
480
481
|
send(defs.ChannelCloseOk, {}, ch);
|
|
@@ -501,7 +502,7 @@ test("bad send in consumer", channelTest(
|
|
|
501
502
|
function(send, await, done, ch) {
|
|
502
503
|
completes(function() {
|
|
503
504
|
send(defs.BasicDeliver, DELIVER_FIELDS, ch,
|
|
504
|
-
|
|
505
|
+
Buffer.from('barfoo'));
|
|
505
506
|
}, done);
|
|
506
507
|
return await(defs.ChannelClose)()
|
|
507
508
|
.then(function() {
|
|
@@ -520,7 +521,7 @@ test("return", channelTest(
|
|
|
520
521
|
},
|
|
521
522
|
function(send, await, done, ch) {
|
|
522
523
|
completes(function() {
|
|
523
|
-
send(defs.BasicReturn, DELIVER_FIELDS, ch,
|
|
524
|
+
send(defs.BasicReturn, DELIVER_FIELDS, ch, Buffer.from('barfoo'));
|
|
524
525
|
}, done);
|
|
525
526
|
}));
|
|
526
527
|
|
package/test/channel_api.js
CHANGED
|
@@ -7,6 +7,7 @@ var succeed = util.succeed, fail = util.fail;
|
|
|
7
7
|
var schedule = util.schedule;
|
|
8
8
|
var randomString = util.randomString;
|
|
9
9
|
var Promise = require('bluebird');
|
|
10
|
+
var Buffer = require('safe-buffer').Buffer;
|
|
10
11
|
|
|
11
12
|
var URL = process.env.URL || 'amqp://localhost';
|
|
12
13
|
|
|
@@ -23,7 +24,7 @@ function expectFail(promise) {
|
|
|
23
24
|
|
|
24
25
|
// I'll rely on operations being rejected, rather than the channel
|
|
25
26
|
// close error, to detect failure.
|
|
26
|
-
function ignore() {}
|
|
27
|
+
function ignore () {}
|
|
27
28
|
function ignoreErrors(c) {
|
|
28
29
|
c.on('error', ignore); return c;
|
|
29
30
|
}
|
|
@@ -112,7 +113,7 @@ chtest("fail on reasserting exchange with different type",
|
|
|
112
113
|
chtest("channel break on publishing to non-exchange", function(ch) {
|
|
113
114
|
return new Promise(function(resolve) {
|
|
114
115
|
ch.on('error', resolve);
|
|
115
|
-
ch.publish(randomString(), '',
|
|
116
|
+
ch.publish(randomString(), '', Buffer.from('foobar'));
|
|
116
117
|
});
|
|
117
118
|
});
|
|
118
119
|
|
|
@@ -179,7 +180,7 @@ chtest("send to queue and get from queue", function(ch) {
|
|
|
179
180
|
var msg = randomString();
|
|
180
181
|
return Promise.join(ch.assertQueue(q, QUEUE_OPTS), ch.purgeQueue(q))
|
|
181
182
|
.then(function() {
|
|
182
|
-
ch.sendToQueue(q,
|
|
183
|
+
ch.sendToQueue(q, Buffer.from(msg));
|
|
183
184
|
return waitForMessages(q);
|
|
184
185
|
})
|
|
185
186
|
.then(function() {
|
|
@@ -193,7 +194,7 @@ chtest("send to queue and get from queue", function(ch) {
|
|
|
193
194
|
|
|
194
195
|
chtest("send (and get) zero content to queue", function(ch) {
|
|
195
196
|
var q = 'test.send-to-q';
|
|
196
|
-
var msg =
|
|
197
|
+
var msg = Buffer.alloc(0);
|
|
197
198
|
return Promise.join(
|
|
198
199
|
ch.assertQueue(q, QUEUE_OPTS),
|
|
199
200
|
ch.purgeQueue(q))
|
|
@@ -224,7 +225,7 @@ chtest("route message", function(ch) {
|
|
|
224
225
|
ch.purgeQueue(q),
|
|
225
226
|
ch.bindQueue(q, ex, '', {}))
|
|
226
227
|
.then(function() {
|
|
227
|
-
ch.publish(ex, '',
|
|
228
|
+
ch.publish(ex, '', Buffer.from(msg));
|
|
228
229
|
return waitForMessages(q);})
|
|
229
230
|
.then(function() {
|
|
230
231
|
return ch.get(q, {noAck: true});})
|
|
@@ -239,7 +240,7 @@ chtest("purge queue", function(ch) {
|
|
|
239
240
|
var q = 'test.purge-queue';
|
|
240
241
|
return ch.assertQueue(q, {durable: false})
|
|
241
242
|
.then(function() {
|
|
242
|
-
ch.sendToQueue(q,
|
|
243
|
+
ch.sendToQueue(q, Buffer.from('foobar'));
|
|
243
244
|
return waitForMessages(q);})
|
|
244
245
|
.then(function() {
|
|
245
246
|
ch.purgeQueue(q);
|
|
@@ -262,7 +263,7 @@ chtest("unbind queue", function(ch) {
|
|
|
262
263
|
ch.purgeQueue(q),
|
|
263
264
|
ch.bindQueue(q, ex, '', {}))
|
|
264
265
|
.then(function() {
|
|
265
|
-
ch.publish(ex, '',
|
|
266
|
+
ch.publish(ex, '', Buffer.from('foobar'));
|
|
266
267
|
return waitForMessages(q);})
|
|
267
268
|
.then(function() { // message got through!
|
|
268
269
|
return ch.get(q, {noAck:true})
|
|
@@ -271,9 +272,9 @@ chtest("unbind queue", function(ch) {
|
|
|
271
272
|
return ch.unbindQueue(q, ex, '', {});})
|
|
272
273
|
.then(function() {
|
|
273
274
|
// via the no-longer-existing binding
|
|
274
|
-
ch.publish(ex, '',
|
|
275
|
+
ch.publish(ex, '', Buffer.from(viabinding));
|
|
275
276
|
// direct to the queue
|
|
276
|
-
ch.sendToQueue(q,
|
|
277
|
+
ch.sendToQueue(q, Buffer.from(direct));
|
|
277
278
|
return waitForMessages(q);})
|
|
278
279
|
.then(function() {return ch.get(q)})
|
|
279
280
|
.then(function(m) {
|
|
@@ -305,7 +306,7 @@ chtest("consume via exchange-exchange binding", function(ch) {
|
|
|
305
306
|
}
|
|
306
307
|
ch.consume(q, delivery, {noAck: true})
|
|
307
308
|
.then(function() {
|
|
308
|
-
ch.publish(ex1, rk,
|
|
309
|
+
ch.publish(ex1, rk, Buffer.from(msg));
|
|
309
310
|
});
|
|
310
311
|
});
|
|
311
312
|
});
|
|
@@ -327,7 +328,7 @@ chtest("unbind exchange", function(ch) {
|
|
|
327
328
|
ch.bindExchange(dest, source, '', {}),
|
|
328
329
|
ch.bindQueue(q, dest, '', {}))
|
|
329
330
|
.then(function() {
|
|
330
|
-
ch.publish(source, '',
|
|
331
|
+
ch.publish(source, '', Buffer.from('foobar'));
|
|
331
332
|
return waitForMessages(q);})
|
|
332
333
|
.then(function() { // message got through!
|
|
333
334
|
return ch.get(q, {noAck:true})
|
|
@@ -336,9 +337,9 @@ chtest("unbind exchange", function(ch) {
|
|
|
336
337
|
return ch.unbindExchange(dest, source, '', {});})
|
|
337
338
|
.then(function() {
|
|
338
339
|
// via the no-longer-existing binding
|
|
339
|
-
ch.publish(source, '',
|
|
340
|
+
ch.publish(source, '', Buffer.from(viabinding));
|
|
340
341
|
// direct to the queue
|
|
341
|
-
ch.sendToQueue(q,
|
|
342
|
+
ch.sendToQueue(q, Buffer.from(direct));
|
|
342
343
|
return waitForMessages(q);})
|
|
343
344
|
.then(function() {return ch.get(q)})
|
|
344
345
|
.then(function(m) {
|
|
@@ -360,7 +361,7 @@ chtest("cancel consumer", function(ch) {
|
|
|
360
361
|
ch.consume(q, resolve, {noAck:true})
|
|
361
362
|
.then(function(ok) {
|
|
362
363
|
ctag = ok.consumerTag;
|
|
363
|
-
ch.sendToQueue(q,
|
|
364
|
+
ch.sendToQueue(q, Buffer.from('foo'));
|
|
364
365
|
}));
|
|
365
366
|
});
|
|
366
367
|
|
|
@@ -368,7 +369,7 @@ chtest("cancel consumer", function(ch) {
|
|
|
368
369
|
return recv1.then(function() {
|
|
369
370
|
var recv2 = Promise.join(
|
|
370
371
|
ch.cancel(ctag).then(function() {
|
|
371
|
-
return ch.sendToQueue(q,
|
|
372
|
+
return ch.sendToQueue(q, Buffer.from('bar'));
|
|
372
373
|
}),
|
|
373
374
|
// but check a message did arrive in the queue
|
|
374
375
|
waitForMessages(q))
|
|
@@ -412,8 +413,8 @@ chtest("ack", function(ch) {
|
|
|
412
413
|
ch.assertQueue(q, QUEUE_OPTS),
|
|
413
414
|
ch.purgeQueue(q))
|
|
414
415
|
.then(function() {
|
|
415
|
-
ch.sendToQueue(q,
|
|
416
|
-
ch.sendToQueue(q,
|
|
416
|
+
ch.sendToQueue(q, Buffer.from(msg1));
|
|
417
|
+
ch.sendToQueue(q, Buffer.from(msg2));
|
|
417
418
|
return waitForMessages(q, 2);
|
|
418
419
|
})
|
|
419
420
|
.then(function() {
|
|
@@ -441,7 +442,7 @@ chtest("nack", function(ch) {
|
|
|
441
442
|
return Promise.join(
|
|
442
443
|
ch.assertQueue(q, QUEUE_OPTS), ch.purgeQueue(q))
|
|
443
444
|
.then(function() {
|
|
444
|
-
ch.sendToQueue(q,
|
|
445
|
+
ch.sendToQueue(q, Buffer.from(msg1));
|
|
445
446
|
return waitForMessages(q);})
|
|
446
447
|
.then(function() {
|
|
447
448
|
return ch.get(q, {noAck: false})})
|
|
@@ -466,7 +467,7 @@ chtest("reject", function(ch) {
|
|
|
466
467
|
return Promise.join(
|
|
467
468
|
ch.assertQueue(q, QUEUE_OPTS), ch.purgeQueue(q))
|
|
468
469
|
.then(function() {
|
|
469
|
-
ch.sendToQueue(q,
|
|
470
|
+
ch.sendToQueue(q, Buffer.from(msg1));
|
|
470
471
|
return waitForMessages(q);})
|
|
471
472
|
.then(function() {
|
|
472
473
|
return ch.get(q, {noAck: false})})
|
|
@@ -488,8 +489,8 @@ chtest("prefetch", function(ch) {
|
|
|
488
489
|
ch.assertQueue(q, QUEUE_OPTS), ch.purgeQueue(q),
|
|
489
490
|
ch.prefetch(1))
|
|
490
491
|
.then(function() {
|
|
491
|
-
ch.sendToQueue(q,
|
|
492
|
-
ch.sendToQueue(q,
|
|
492
|
+
ch.sendToQueue(q, Buffer.from('foobar'));
|
|
493
|
+
ch.sendToQueue(q, Buffer.from('foobar'));
|
|
493
494
|
return waitForMessages(q, 2);
|
|
494
495
|
})
|
|
495
496
|
.then(function() {
|
|
@@ -526,7 +527,7 @@ confirmtest('message is confirmed', function(ch) {
|
|
|
526
527
|
return Promise.join(
|
|
527
528
|
ch.assertQueue(q, QUEUE_OPTS), ch.purgeQueue(q))
|
|
528
529
|
.then(function() {
|
|
529
|
-
return ch.sendToQueue(q,
|
|
530
|
+
return ch.sendToQueue(q, Buffer.from('bleep'));
|
|
530
531
|
});
|
|
531
532
|
});
|
|
532
533
|
|
|
@@ -550,7 +551,7 @@ confirmtest('multiple confirms', function(ch) {
|
|
|
550
551
|
|
|
551
552
|
function sendAndPushPromise() {
|
|
552
553
|
var conf = Promise.fromCallback(function(cb) {
|
|
553
|
-
return ch.sendToQueue(q,
|
|
554
|
+
return ch.sendToQueue(q, Buffer.from('bleep'), {}, cb);
|
|
554
555
|
});
|
|
555
556
|
cs.push(conf);
|
|
556
557
|
}
|
|
@@ -575,7 +576,7 @@ confirmtest('multiple confirms', function(ch) {
|
|
|
575
576
|
|
|
576
577
|
confirmtest('wait for confirms', function(ch) {
|
|
577
578
|
for (var i=0; i < 1000; i++) {
|
|
578
|
-
ch.publish('', '',
|
|
579
|
+
ch.publish('', '', Buffer.from('foobar'), {});
|
|
579
580
|
}
|
|
580
581
|
return ch.waitForConfirms();
|
|
581
582
|
})
|
package/test/codec.js
CHANGED
|
@@ -4,7 +4,7 @@ var codec = require('../lib/codec');
|
|
|
4
4
|
var defs = require('../lib/defs');
|
|
5
5
|
var assert = require('assert');
|
|
6
6
|
var ints = require('buffer-more-ints');
|
|
7
|
-
|
|
7
|
+
var Buffer = require('safe-buffer').Buffer
|
|
8
8
|
var C = require('claire');
|
|
9
9
|
var forAll = C.forAll;
|
|
10
10
|
|
|
@@ -31,12 +31,12 @@ var testCases = [
|
|
|
31
31
|
['float value', {double: 0.5}, [6,100,111,117,98,108,101,100,63,224,0,0,0,0,0,0]],
|
|
32
32
|
['negative float value', {double: -0.5}, [6,100,111,117,98,108,101,100,191,224,0,0,0,0,0,0]],
|
|
33
33
|
// %% test some boundaries of precision?
|
|
34
|
-
|
|
34
|
+
|
|
35
35
|
// string
|
|
36
36
|
['string', {string: "boop"}, [6,115,116,114,105,110,103,83,0,0,0,4,98,111,111,112]],
|
|
37
37
|
|
|
38
38
|
// buffer -> byte array
|
|
39
|
-
['byte array from buffer', {bytes:
|
|
39
|
+
['byte array from buffer', {bytes: Buffer.from([1,2,3,4])},
|
|
40
40
|
[5,98,121,116,101,115,120,0,0,0,4,1,2,3,4]],
|
|
41
41
|
|
|
42
42
|
// boolean, void
|
|
@@ -64,12 +64,12 @@ function bufferToArray(b) {
|
|
|
64
64
|
return Array.prototype.slice.call(b);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
suite("
|
|
67
|
+
suite("Implicit encodings", function() {
|
|
68
68
|
|
|
69
69
|
testCases.forEach(function(tc) {
|
|
70
70
|
var name = tc[0], val = tc[1], expect = tc[2];
|
|
71
71
|
test(name, function() {
|
|
72
|
-
var buffer =
|
|
72
|
+
var buffer = Buffer.alloc(1000);
|
|
73
73
|
var size = codec.encodeTable(buffer, val, 0);
|
|
74
74
|
var result = buffer.slice(4, size);
|
|
75
75
|
assert.deepEqual(expect, bufferToArray(result));
|
|
@@ -82,11 +82,11 @@ suite("Explicit encodings", function() {
|
|
|
82
82
|
var amqp = require('./data');
|
|
83
83
|
|
|
84
84
|
function roundtrip_table(t) {
|
|
85
|
-
var buf =
|
|
85
|
+
var buf = Buffer.alloc(4096);
|
|
86
86
|
var size = codec.encodeTable(buf, t, 0);
|
|
87
87
|
var decoded = codec.decodeFields(buf.slice(4, size)); // ignore the length-prefix
|
|
88
88
|
try {
|
|
89
|
-
assert.deepEqual(t, decoded);
|
|
89
|
+
assert.deepEqual(removeExplicitTypes(t), decoded);
|
|
90
90
|
}
|
|
91
91
|
catch (e) { return false; }
|
|
92
92
|
return true;
|
|
@@ -119,6 +119,45 @@ suite("Roundtrip values", function() {
|
|
|
119
119
|
});
|
|
120
120
|
});
|
|
121
121
|
|
|
122
|
+
// When encoding, you can supply explicitly-typed fields like `{'!':
|
|
123
|
+
// int32, 50}`. Most of these do not appear in the decoded values, so
|
|
124
|
+
// to compare like-to-like we have to remove them from the input.
|
|
125
|
+
function removeExplicitTypes(input) {
|
|
126
|
+
switch (typeof input) {
|
|
127
|
+
case 'object':
|
|
128
|
+
if (input == null) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
if (Array.isArray(input)) {
|
|
132
|
+
var newArr = [];
|
|
133
|
+
for (var i = 0; i < input.length; i++) {
|
|
134
|
+
newArr[i] = removeExplicitTypes(input[i]);
|
|
135
|
+
}
|
|
136
|
+
return newArr;
|
|
137
|
+
}
|
|
138
|
+
if (Buffer.isBuffer(input)) {
|
|
139
|
+
return input;
|
|
140
|
+
}
|
|
141
|
+
switch (input['!']) {
|
|
142
|
+
case 'timestamp':
|
|
143
|
+
case 'decimal':
|
|
144
|
+
case 'float':
|
|
145
|
+
return input;
|
|
146
|
+
case undefined:
|
|
147
|
+
var newObj = {}
|
|
148
|
+
for (var k in input) {
|
|
149
|
+
newObj[k] = removeExplicitTypes(input[k]);
|
|
150
|
+
}
|
|
151
|
+
return newObj;
|
|
152
|
+
default:
|
|
153
|
+
return input.value;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
default:
|
|
157
|
+
return input;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
122
161
|
// Asserts that the decoded fields are equal to the original fields,
|
|
123
162
|
// or equal to a default where absent in the original. The defaults
|
|
124
163
|
// depend on the type of method or properties.
|
|
@@ -141,11 +180,11 @@ function assertEqualModuloDefaults(original, decodedFields) {
|
|
|
141
180
|
// given as strings rather than buffers, but the decoded values
|
|
142
181
|
// will be buffers.
|
|
143
182
|
assert.deepEqual((arg.type === 'longstr') ?
|
|
144
|
-
|
|
183
|
+
Buffer.from(arg.default) : arg.default,
|
|
145
184
|
decodedValue);
|
|
146
185
|
}
|
|
147
186
|
else {
|
|
148
|
-
assert.deepEqual(originalValue, decodedValue);
|
|
187
|
+
assert.deepEqual(removeExplicitTypes(originalValue), decodedValue);
|
|
149
188
|
}
|
|
150
189
|
}
|
|
151
190
|
catch (assertionErr) {
|
package/test/connect.js
CHANGED
|
@@ -1,21 +1,65 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var connect = require('../lib/connect').connect;
|
|
4
|
+
var Buffer = require('safe-buffer').Buffer
|
|
5
|
+
var credentialsFromUrl = require('../lib/connect').credentialsFromUrl;
|
|
4
6
|
var assert = require('assert');
|
|
5
7
|
var util = require('./util');
|
|
6
8
|
var net = require('net');
|
|
7
9
|
var fail = util.fail, succeed = util.succeed,
|
|
8
|
-
kCallback = util.kCallback
|
|
10
|
+
kCallback = util.kCallback,
|
|
11
|
+
succeedIfAttributeEquals = util.succeedIfAttributeEquals;
|
|
12
|
+
var format = require('util').format;
|
|
9
13
|
|
|
10
14
|
var URL = process.env.URL || 'amqp://localhost';
|
|
11
15
|
|
|
16
|
+
suite("Credentials", function() {
|
|
17
|
+
|
|
18
|
+
function checkCreds(creds, user, pass, done) {
|
|
19
|
+
if (creds.mechanism != 'PLAIN') {
|
|
20
|
+
return done('expected mechanism PLAIN');
|
|
21
|
+
}
|
|
22
|
+
if (creds.username != user || creds.password != pass) {
|
|
23
|
+
return done(format("expected '%s', '%s'; got '%s', '%s'",
|
|
24
|
+
user, pass, creds.username, creds.password));
|
|
25
|
+
}
|
|
26
|
+
done();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
test("no creds", function(done) {
|
|
30
|
+
var parts = {auth: ''};
|
|
31
|
+
var creds = credentialsFromUrl(parts);
|
|
32
|
+
checkCreds(creds, 'guest', 'guest', done);
|
|
33
|
+
});
|
|
34
|
+
test("usual user:pass", function(done) {
|
|
35
|
+
var parts = {auth: 'user:pass'};
|
|
36
|
+
var creds = credentialsFromUrl(parts);
|
|
37
|
+
checkCreds(creds, 'user', 'pass', done);
|
|
38
|
+
});
|
|
39
|
+
test("missing user", function(done) {
|
|
40
|
+
var parts = {auth: ':password'};
|
|
41
|
+
var creds = credentialsFromUrl(parts);
|
|
42
|
+
checkCreds(creds, '', 'password', done);
|
|
43
|
+
});
|
|
44
|
+
test("missing password", function(done) {
|
|
45
|
+
var parts = {auth: 'username'};
|
|
46
|
+
var creds = credentialsFromUrl(parts);
|
|
47
|
+
checkCreds(creds, 'username', '', done);
|
|
48
|
+
});
|
|
49
|
+
test("colon in password", function(done) {
|
|
50
|
+
var parts = {auth: 'username:pass:word'};
|
|
51
|
+
var creds = credentialsFromUrl(parts);
|
|
52
|
+
checkCreds(creds, 'username', 'pass:word', done);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
12
56
|
suite("Connect API", function() {
|
|
13
57
|
|
|
14
58
|
test("Connection refused", function(done) {
|
|
15
59
|
connect('amqp://localhost:23450', {},
|
|
16
60
|
kCallback(fail(done), succeed(done)));
|
|
17
61
|
});
|
|
18
|
-
|
|
62
|
+
|
|
19
63
|
// %% this ought to fail the promise, rather than throwing an error
|
|
20
64
|
test("bad URL", function() {
|
|
21
65
|
assert.throws(function() {
|
|
@@ -33,6 +77,22 @@ suite("Connect API", function() {
|
|
|
33
77
|
connect(u, {}, kCallback(fail(done), succeed(done)));
|
|
34
78
|
});
|
|
35
79
|
|
|
80
|
+
test("using custom heartbeat option", function(done) {
|
|
81
|
+
var url = require('url');
|
|
82
|
+
var parts = url.parse(URL, true);
|
|
83
|
+
var config = parts.query || {};
|
|
84
|
+
config.heartbeat = 20;
|
|
85
|
+
connect(config, {}, kCallback(succeedIfAttributeEquals('heartbeat', 20, done), fail(done)));
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("wrongly typed heartbeat option", function(done) {
|
|
89
|
+
var url = require('url');
|
|
90
|
+
var parts = url.parse(URL, true);
|
|
91
|
+
var config = parts.query || {};
|
|
92
|
+
config.heartbeat = 'NOT A NUMBER';
|
|
93
|
+
connect(config, {}, kCallback(fail(done), succeed(done)));
|
|
94
|
+
});
|
|
95
|
+
|
|
36
96
|
test("using plain credentials", function(done) {
|
|
37
97
|
var url = require('url');
|
|
38
98
|
var parts = url.parse(URL, true);
|
|
@@ -48,7 +108,7 @@ suite("Connect API", function() {
|
|
|
48
108
|
test("using unsupported mechanism", function(done) {
|
|
49
109
|
var creds = {
|
|
50
110
|
mechanism: 'UNSUPPORTED',
|
|
51
|
-
response: function() { return
|
|
111
|
+
response: function() { return Buffer.from(''); }
|
|
52
112
|
};
|
|
53
113
|
connect(URL, {credentials: creds},
|
|
54
114
|
kCallback(fail(done), succeed(done)));
|
package/test/connection.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var assert = require('assert');
|
|
4
4
|
var defs = require('../lib/defs');
|
|
5
|
+
var Buffer = require('safe-buffer').Buffer;
|
|
5
6
|
var Connection = require('../lib/connection').Connection;
|
|
6
7
|
var HEARTBEAT = require('../lib/frame').HEARTBEAT;
|
|
7
8
|
var HB_BUF = require('../lib/frame').HEARTBEAT_BUF;
|
|
@@ -16,7 +17,7 @@ var OPEN_OPTS = {
|
|
|
16
17
|
// start-ok
|
|
17
18
|
'clientProperties': {},
|
|
18
19
|
'mechanism': 'PLAIN',
|
|
19
|
-
'response':
|
|
20
|
+
'response': Buffer.from(['', 'guest', 'guest'].join(String.fromCharCode(0))),
|
|
20
21
|
'locale': 'en_US',
|
|
21
22
|
|
|
22
23
|
// tune-ok
|
|
@@ -37,8 +38,8 @@ function happy_open(send, await) {
|
|
|
37
38
|
{versionMajor: 0,
|
|
38
39
|
versionMinor: 9,
|
|
39
40
|
serverProperties: {},
|
|
40
|
-
mechanisms:
|
|
41
|
-
locales:
|
|
41
|
+
mechanisms: Buffer.from('PLAIN'),
|
|
42
|
+
locales: Buffer.from('en_US')});
|
|
42
43
|
return await(defs.ConnectionStartOk)()
|
|
43
44
|
.then(function(f) {
|
|
44
45
|
send(defs.ConnectionTune,
|
|
@@ -65,7 +66,7 @@ function connectionTest(client, server) {
|
|
|
65
66
|
|
|
66
67
|
// NB only not a race here because the writes are synchronous
|
|
67
68
|
var protocolHeader = pair.server.read(8);
|
|
68
|
-
assert.deepEqual(
|
|
69
|
+
assert.deepEqual(Buffer.from("AMQP" + String.fromCharCode(0,0,9,1)),
|
|
69
70
|
protocolHeader);
|
|
70
71
|
|
|
71
72
|
var s = util.runServer(pair.server, function(send, await) {
|
|
@@ -92,7 +93,7 @@ suite("Connection errors", function() {
|
|
|
92
93
|
var ss = util.socketPair();
|
|
93
94
|
var conn = new (require('../lib/connection').Connection)(ss.client);
|
|
94
95
|
ss.server.on('readable', function() {
|
|
95
|
-
ss.server.write(
|
|
96
|
+
ss.server.write(Buffer.from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
|
|
96
97
|
});
|
|
97
98
|
conn.open({}, kCallback(fail(done), succeed(done)));
|
|
98
99
|
});
|
|
@@ -132,8 +133,8 @@ test("unexpected socket close", connectionTest(
|
|
|
132
133
|
{versionMajor: 0,
|
|
133
134
|
versionMinor: 9,
|
|
134
135
|
serverProperties: {},
|
|
135
|
-
mechanisms:
|
|
136
|
-
locales:
|
|
136
|
+
mechanisms: Buffer.from('PLAIN'),
|
|
137
|
+
locales: Buffer.from('en_US')});
|
|
137
138
|
return await(defs.ConnectionStartOk)()
|
|
138
139
|
.then(function() {
|
|
139
140
|
socket.end();
|
|
@@ -156,7 +157,7 @@ test("wrong frame on channel 0", connectionTest(
|
|
|
156
157
|
// there's actually nothing that would plausibly be sent to a
|
|
157
158
|
// just opened connection, so this is violating more than one
|
|
158
159
|
// rule. Nonetheless.
|
|
159
|
-
send(defs.ChannelOpenOk, {channelId:
|
|
160
|
+
send(defs.ChannelOpenOk, {channelId: Buffer.from('')}, 0);
|
|
160
161
|
})
|
|
161
162
|
.then(await(defs.ConnectionClose))
|
|
162
163
|
.then(function(close) {
|
|
@@ -175,7 +176,7 @@ test("unopened channel", connectionTest(
|
|
|
175
176
|
// there's actually nothing that would plausibly be sent to a
|
|
176
177
|
// just opened connection, so this is violating more than one
|
|
177
178
|
// rule. Nonetheless.
|
|
178
|
-
send(defs.ChannelOpenOk, {channelId:
|
|
179
|
+
send(defs.ChannelOpenOk, {channelId: Buffer.from('')}, 3);
|
|
179
180
|
})
|
|
180
181
|
.then(await(defs.ConnectionClose))
|
|
181
182
|
.then(function(close) {
|