typespeed 2.0.21 → 2.0.23
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/dist/core.decorator.js +1 -30
- package/dist/default/default-authentication.class.js +25 -0
- package/dist/default/express-server.class.js +11 -4
- package/dist/default/log-default.class.js +0 -6
- package/dist/factory/authentication-factory.class.js +11 -0
- package/dist/factory/log-factory.class.js +9 -0
- package/dist/route.decorator.js +92 -2
- package/dist/typespeed.d.ts +40 -3
- package/dist/typespeed.js +3 -1
- package/package.json +1 -1
- package/src/core.decorator.ts +1 -29
- package/src/default/default-authentication.class.ts +10 -0
- package/src/default/express-server.class.ts +12 -5
- package/src/default/log-default.class.ts +0 -10
- package/src/factory/authentication-factory.class.ts +9 -0
- package/src/factory/log-factory.class.ts +9 -2
- package/src/route.decorator.ts +91 -3
- package/src/typespeed.d.ts +40 -3
- package/src/typespeed.ts +1 -0
- package/test/node_modules/.package-lock.json +65 -101
- package/test/node_modules/@types/body-parser/LICENSE +21 -0
- package/test/node_modules/@types/body-parser/README.md +16 -0
- package/test/node_modules/@types/body-parser/index.d.ts +107 -0
- package/test/node_modules/@types/body-parser/package.json +58 -0
- package/test/node_modules/@types/connect/LICENSE +21 -0
- package/test/node_modules/@types/connect/README.md +16 -0
- package/test/node_modules/@types/connect/index.d.ts +93 -0
- package/test/node_modules/@types/connect/package.json +32 -0
- package/test/node_modules/@types/express/LICENSE +21 -0
- package/test/node_modules/@types/express/README.md +16 -0
- package/test/node_modules/@types/express/index.d.ts +136 -0
- package/test/node_modules/@types/express/package.json +45 -0
- package/test/node_modules/@types/express-serve-static-core/LICENSE +21 -0
- package/test/node_modules/@types/express-serve-static-core/README.md +16 -0
- package/test/node_modules/@types/express-serve-static-core/index.d.ts +1281 -0
- package/test/node_modules/@types/express-serve-static-core/package.json +55 -0
- package/test/node_modules/@types/mime/LICENSE +21 -0
- package/test/node_modules/@types/mime/Mime.d.ts +10 -0
- package/test/node_modules/@types/mime/README.md +16 -0
- package/test/node_modules/@types/mime/index.d.ts +35 -0
- package/test/node_modules/@types/mime/lite.d.ts +7 -0
- package/test/node_modules/@types/mime/package.json +29 -0
- package/test/node_modules/@types/qs/LICENSE +21 -0
- package/test/node_modules/@types/qs/README.md +16 -0
- package/test/node_modules/@types/qs/index.d.ts +62 -0
- package/test/node_modules/@types/qs/package.json +65 -0
- package/test/node_modules/@types/range-parser/LICENSE +21 -0
- package/test/node_modules/@types/range-parser/README.md +55 -0
- package/test/node_modules/@types/range-parser/index.d.ts +35 -0
- package/test/node_modules/@types/range-parser/package.json +25 -0
- package/test/node_modules/@types/send/LICENSE +21 -0
- package/test/node_modules/@types/send/README.md +16 -0
- package/test/node_modules/@types/send/index.d.ts +231 -0
- package/test/node_modules/@types/send/package.json +33 -0
- package/test/node_modules/@types/serve-static/LICENSE +21 -0
- package/test/node_modules/@types/serve-static/README.md +16 -0
- package/test/node_modules/@types/serve-static/index.d.ts +113 -0
- package/test/node_modules/@types/serve-static/package.json +38 -0
- package/test/src/config.json +5 -0
- package/test/src/custom-log.class.ts +6 -0
- package/test/src/jwt-authentication.class.ts +29 -0
- package/test/src/test-request.class.ts +36 -0
- package/test/node_modules/@acuminous/bitsyntax/.github/workflows/node-js-ci.yml +0 -17
- package/test/node_modules/@acuminous/bitsyntax/.github/workflows/node-js-publish.yml +0 -30
- package/test/node_modules/@acuminous/bitsyntax/LICENSE +0 -6
- package/test/node_modules/@acuminous/bitsyntax/LICENSE-MIT +0 -21
- package/test/node_modules/@acuminous/bitsyntax/Makefile +0 -15
- package/test/node_modules/@acuminous/bitsyntax/README.md +0 -308
- package/test/node_modules/@acuminous/bitsyntax/index.js +0 -10
- package/test/node_modules/@acuminous/bitsyntax/lib/compile.js +0 -303
- package/test/node_modules/@acuminous/bitsyntax/lib/constructor.js +0 -142
- package/test/node_modules/@acuminous/bitsyntax/lib/grammar.pegjs +0 -67
- package/test/node_modules/@acuminous/bitsyntax/lib/interp.js +0 -232
- package/test/node_modules/@acuminous/bitsyntax/lib/parse.js +0 -32
- package/test/node_modules/@acuminous/bitsyntax/lib/parser.js +0 -1173
- package/test/node_modules/@acuminous/bitsyntax/lib/pattern.js +0 -119
- package/test/node_modules/@acuminous/bitsyntax/package.json +0 -36
- package/test/node_modules/@acuminous/bitsyntax/test/consing.test.js +0 -50
- package/test/node_modules/@acuminous/bitsyntax/test/matching.test.js +0 -193
- package/test/node_modules/amqplib/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- package/test/node_modules/amqplib/.github/workflows/test.yml +0 -38
- package/test/node_modules/amqplib/CHANGELOG.md +0 -430
- package/test/node_modules/amqplib/LICENSE +0 -6
- package/test/node_modules/amqplib/LICENSE-MIT +0 -21
- package/test/node_modules/amqplib/Makefile +0 -47
- package/test/node_modules/amqplib/README.md +0 -157
- package/test/node_modules/amqplib/bin/generate-defs.js +0 -722
- package/test/node_modules/amqplib/callback_api.js +0 -22
- package/test/node_modules/amqplib/channel_api.js +0 -16
- package/test/node_modules/amqplib/examples/headers.js +0 -42
- package/test/node_modules/amqplib/examples/receive_generator.js +0 -39
- package/test/node_modules/amqplib/examples/send_generators.js +0 -42
- package/test/node_modules/amqplib/examples/ssl.js +0 -64
- package/test/node_modules/amqplib/examples/tutorials/README.md +0 -93
- package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log.js +0 -28
- package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log_direct.js +0 -30
- package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log_topic.js +0 -27
- package/test/node_modules/amqplib/examples/tutorials/callback_api/new_task.js +0 -27
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive.js +0 -30
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs.js +0 -36
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs_direct.js +0 -56
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs_topic.js +0 -55
- package/test/node_modules/amqplib/examples/tutorials/callback_api/rpc_client.js +0 -49
- package/test/node_modules/amqplib/examples/tutorials/callback_api/rpc_server.js +0 -45
- package/test/node_modules/amqplib/examples/tutorials/callback_api/send.js +0 -29
- package/test/node_modules/amqplib/examples/tutorials/callback_api/worker.js +0 -35
- package/test/node_modules/amqplib/examples/tutorials/emit_log.js +0 -19
- package/test/node_modules/amqplib/examples/tutorials/emit_log_direct.js +0 -20
- package/test/node_modules/amqplib/examples/tutorials/emit_log_topic.js +0 -19
- package/test/node_modules/amqplib/examples/tutorials/new_task.js +0 -18
- package/test/node_modules/amqplib/examples/tutorials/package.json +0 -16
- package/test/node_modules/amqplib/examples/tutorials/receive.js +0 -21
- package/test/node_modules/amqplib/examples/tutorials/receive_logs.js +0 -28
- package/test/node_modules/amqplib/examples/tutorials/receive_logs_direct.js +0 -44
- package/test/node_modules/amqplib/examples/tutorials/receive_logs_topic.js +0 -43
- package/test/node_modules/amqplib/examples/tutorials/rpc_client.js +0 -52
- package/test/node_modules/amqplib/examples/tutorials/rpc_server.js +0 -39
- package/test/node_modules/amqplib/examples/tutorials/send.js +0 -23
- package/test/node_modules/amqplib/examples/tutorials/worker.js +0 -28
- package/test/node_modules/amqplib/examples/waitForConfirms.js +0 -22
- package/test/node_modules/amqplib/lib/api_args.js +0 -314
- package/test/node_modules/amqplib/lib/bitset.js +0 -130
- package/test/node_modules/amqplib/lib/callback_model.js +0 -327
- package/test/node_modules/amqplib/lib/channel.js +0 -499
- package/test/node_modules/amqplib/lib/channel_model.js +0 -302
- package/test/node_modules/amqplib/lib/codec.js +0 -321
- package/test/node_modules/amqplib/lib/connect.js +0 -189
- package/test/node_modules/amqplib/lib/connection.js +0 -663
- package/test/node_modules/amqplib/lib/credentials.js +0 -42
- package/test/node_modules/amqplib/lib/defs.js +0 -4966
- package/test/node_modules/amqplib/lib/error.js +0 -24
- package/test/node_modules/amqplib/lib/format.js +0 -40
- package/test/node_modules/amqplib/lib/frame.js +0 -113
- package/test/node_modules/amqplib/lib/heartbeat.js +0 -89
- package/test/node_modules/amqplib/lib/mux.js +0 -129
- package/test/node_modules/amqplib/package.json +0 -37
- package/test/node_modules/amqplib/test/bitset.js +0 -69
- package/test/node_modules/amqplib/test/callback_api.js +0 -312
- package/test/node_modules/amqplib/test/channel.js +0 -621
- package/test/node_modules/amqplib/test/channel_api.js +0 -596
- package/test/node_modules/amqplib/test/codec.js +0 -237
- package/test/node_modules/amqplib/test/connect.js +0 -197
- package/test/node_modules/amqplib/test/connection.js +0 -390
- package/test/node_modules/amqplib/test/data.js +0 -254
- package/test/node_modules/amqplib/test/frame.js +0 -198
- package/test/node_modules/amqplib/test/mux.js +0 -204
- package/test/node_modules/amqplib/test/util.js +0 -219
- package/test/node_modules/buffer-more-ints/.travis.yml +0 -6
- package/test/node_modules/buffer-more-ints/LICENSE +0 -19
- package/test/node_modules/buffer-more-ints/README.md +0 -69
- package/test/node_modules/buffer-more-ints/buffer-more-ints-tests.js +0 -183
- package/test/node_modules/buffer-more-ints/buffer-more-ints.js +0 -432
- package/test/node_modules/buffer-more-ints/package.json +0 -19
- package/test/node_modules/buffer-more-ints/polyfill.js +0 -71
- package/test/node_modules/core-util-is/LICENSE +0 -19
- package/test/node_modules/core-util-is/README.md +0 -3
- package/test/node_modules/core-util-is/lib/util.js +0 -107
- package/test/node_modules/core-util-is/package.json +0 -38
- package/test/node_modules/debug/LICENSE +0 -20
- package/test/node_modules/debug/README.md +0 -481
- package/test/node_modules/debug/package.json +0 -59
- package/test/node_modules/debug/src/browser.js +0 -269
- package/test/node_modules/debug/src/common.js +0 -274
- package/test/node_modules/debug/src/index.js +0 -10
- package/test/node_modules/debug/src/node.js +0 -263
- package/test/node_modules/inherits/LICENSE +0 -16
- package/test/node_modules/inherits/README.md +0 -42
- package/test/node_modules/inherits/inherits.js +0 -9
- package/test/node_modules/inherits/inherits_browser.js +0 -27
- package/test/node_modules/inherits/package.json +0 -29
- package/test/node_modules/isarray/README.md +0 -54
- package/test/node_modules/isarray/build/build.js +0 -209
- package/test/node_modules/isarray/component.json +0 -19
- package/test/node_modules/isarray/index.js +0 -3
- package/test/node_modules/isarray/package.json +0 -25
- package/test/node_modules/ms/index.js +0 -162
- package/test/node_modules/ms/license.md +0 -21
- package/test/node_modules/ms/package.json +0 -37
- package/test/node_modules/ms/readme.md +0 -60
- package/test/node_modules/querystringify/LICENSE +0 -22
- package/test/node_modules/querystringify/README.md +0 -61
- package/test/node_modules/querystringify/index.js +0 -118
- package/test/node_modules/querystringify/package.json +0 -38
- package/test/node_modules/readable-stream/LICENSE +0 -18
- package/test/node_modules/readable-stream/README.md +0 -15
- package/test/node_modules/readable-stream/duplex.js +0 -1
- package/test/node_modules/readable-stream/float.patch +0 -923
- package/test/node_modules/readable-stream/lib/_stream_duplex.js +0 -89
- package/test/node_modules/readable-stream/lib/_stream_passthrough.js +0 -46
- package/test/node_modules/readable-stream/lib/_stream_readable.js +0 -951
- package/test/node_modules/readable-stream/lib/_stream_transform.js +0 -209
- package/test/node_modules/readable-stream/lib/_stream_writable.js +0 -477
- package/test/node_modules/readable-stream/package.json +0 -32
- package/test/node_modules/readable-stream/passthrough.js +0 -1
- package/test/node_modules/readable-stream/readable.js +0 -10
- package/test/node_modules/readable-stream/transform.js +0 -1
- package/test/node_modules/readable-stream/writable.js +0 -1
- package/test/node_modules/requires-port/.travis.yml +0 -19
- package/test/node_modules/requires-port/LICENSE +0 -22
- package/test/node_modules/requires-port/README.md +0 -47
- package/test/node_modules/requires-port/index.js +0 -38
- package/test/node_modules/requires-port/package.json +0 -47
- package/test/node_modules/requires-port/test.js +0 -98
- package/test/node_modules/safe-buffer/LICENSE +0 -21
- package/test/node_modules/safe-buffer/README.md +0 -584
- package/test/node_modules/safe-buffer/index.d.ts +0 -187
- package/test/node_modules/safe-buffer/index.js +0 -62
- package/test/node_modules/safe-buffer/package.json +0 -37
- package/test/node_modules/string_decoder/LICENSE +0 -20
- package/test/node_modules/string_decoder/README.md +0 -7
- package/test/node_modules/string_decoder/index.js +0 -221
- package/test/node_modules/string_decoder/package.json +0 -25
- package/test/node_modules/url-parse/LICENSE +0 -22
- package/test/node_modules/url-parse/README.md +0 -153
- package/test/node_modules/url-parse/dist/url-parse.js +0 -755
- package/test/node_modules/url-parse/dist/url-parse.min.js +0 -1
- package/test/node_modules/url-parse/dist/url-parse.min.js.map +0 -1
- package/test/node_modules/url-parse/index.js +0 -589
- package/test/node_modules/url-parse/package.json +0 -49
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var codec = require('../lib/codec');
|
|
4
|
-
var defs = require('../lib/defs');
|
|
5
|
-
var assert = require('assert');
|
|
6
|
-
var ints = require('buffer-more-ints');
|
|
7
|
-
var C = require('claire');
|
|
8
|
-
var forAll = C.forAll;
|
|
9
|
-
|
|
10
|
-
// These just test known encodings; to generate the answers I used
|
|
11
|
-
// RabbitMQ's binary generator module.
|
|
12
|
-
|
|
13
|
-
var testCases = [
|
|
14
|
-
// integers
|
|
15
|
-
['byte', {byte: 112}, [4,98,121,116,101,98,112]],
|
|
16
|
-
['byte max value', {byte: 127}, [4,98,121,116,101,98,127]],
|
|
17
|
-
['byte min value', {byte: -128}, [4,98,121,116,101,98,128]],
|
|
18
|
-
['< -128 promoted to signed short', {short: -129}, [5,115,104,111,114,116,115,255,127]],
|
|
19
|
-
['> 127 promoted to short', {short: 128}, [5,115,104,111,114,116,115,0,128]],
|
|
20
|
-
['< 2^15 still a short', {short: 0x7fff}, [5,115,104,111,114,116,115,127,255]],
|
|
21
|
-
['-2^15 still a short', {short: -0x8000}, [5,115,104,111,114,116,115,128,0]],
|
|
22
|
-
['>= 2^15 promoted to int', {int: 0x8000}, [3,105,110,116,73,0,0,128,0]],
|
|
23
|
-
['< -2^15 promoted to int', {int: -0x8001}, [3,105,110,116,73,255,255,127,255]],
|
|
24
|
-
['< 2^31 still an int', {int: 0x7fffffff}, [3,105,110,116,73,127,255,255,255]],
|
|
25
|
-
['>= -2^31 still an int', {int: -0x80000000}, [3,105,110,116,73,128,0,0,0]],
|
|
26
|
-
['>= 2^31 promoted to long', {long: 0x80000000}, [4,108,111,110,103,108,0,0,0,0,128,0,0,0]],
|
|
27
|
-
['< -2^31 promoted to long', {long: -0x80000001}, [4,108,111,110,103,108,255,255,255,255,127,255,255,255]],
|
|
28
|
-
|
|
29
|
-
// floating point
|
|
30
|
-
['float value', {double: 0.5}, [6,100,111,117,98,108,101,100,63,224,0,0,0,0,0,0]],
|
|
31
|
-
['negative float value', {double: -0.5}, [6,100,111,117,98,108,101,100,191,224,0,0,0,0,0,0]],
|
|
32
|
-
// %% test some boundaries of precision?
|
|
33
|
-
|
|
34
|
-
// string
|
|
35
|
-
['string', {string: "boop"}, [6,115,116,114,105,110,103,83,0,0,0,4,98,111,111,112]],
|
|
36
|
-
|
|
37
|
-
// buffer -> byte array
|
|
38
|
-
['byte array from buffer', {bytes: Buffer.from([1,2,3,4])},
|
|
39
|
-
[5,98,121,116,101,115,120,0,0,0,4,1,2,3,4]],
|
|
40
|
-
|
|
41
|
-
// boolean, void
|
|
42
|
-
['true', {bool: true}, [4,98,111,111,108,116,1]],
|
|
43
|
-
['false', {bool: false}, [4,98,111,111,108,116,0]],
|
|
44
|
-
['null', {'void': null}, [4,118,111,105,100,86]],
|
|
45
|
-
|
|
46
|
-
// array, object
|
|
47
|
-
['array', {array: [6, true, "foo"]},
|
|
48
|
-
[5,97,114,114,97,121,65,0,0,0,12,98,6,116,1,83,0,0,0,3,102,111,111]],
|
|
49
|
-
['object', {object: {foo: "bar", baz: 12}},
|
|
50
|
-
[6,111,98,106,101,99,116,70,0,0,0,18,3,102,111,111,83,0,
|
|
51
|
-
0,0,3,98,97,114,3,98,97,122,98,12]],
|
|
52
|
-
|
|
53
|
-
// exotic types
|
|
54
|
-
['timestamp', {timestamp: {'!': 'timestamp', value: 1357212277527}},
|
|
55
|
-
[9,116,105,109,101,115,116,97,109,112,84,0,0,1,60,0,39,219,23]],
|
|
56
|
-
['decimal', {decimal: {'!': 'decimal', value: {digits: 2345, places: 2}}},
|
|
57
|
-
[7,100,101,99,105,109,97,108,68,2,0,0,9,41]],
|
|
58
|
-
['float', {float: {'!': 'float', value: 0.1}},
|
|
59
|
-
[5,102,108,111,97,116,102,61,204,204,205]],
|
|
60
|
-
];
|
|
61
|
-
|
|
62
|
-
function bufferToArray(b) {
|
|
63
|
-
return Array.prototype.slice.call(b);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
suite("Implicit encodings", function() {
|
|
67
|
-
|
|
68
|
-
testCases.forEach(function(tc) {
|
|
69
|
-
var name = tc[0], val = tc[1], expect = tc[2];
|
|
70
|
-
test(name, function() {
|
|
71
|
-
var buffer = Buffer.alloc(1000);
|
|
72
|
-
var size = codec.encodeTable(buffer, val, 0);
|
|
73
|
-
var result = buffer.slice(4, size);
|
|
74
|
-
assert.deepEqual(expect, bufferToArray(result));
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
// Whole frames
|
|
80
|
-
|
|
81
|
-
var amqp = require('./data');
|
|
82
|
-
|
|
83
|
-
function roundtrip_table(t) {
|
|
84
|
-
var buf = Buffer.alloc(4096);
|
|
85
|
-
var size = codec.encodeTable(buf, t, 0);
|
|
86
|
-
var decoded = codec.decodeFields(buf.slice(4, size)); // ignore the length-prefix
|
|
87
|
-
try {
|
|
88
|
-
assert.deepEqual(removeExplicitTypes(t), decoded);
|
|
89
|
-
}
|
|
90
|
-
catch (e) { return false; }
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function roundtrips(T) {
|
|
95
|
-
return forAll(T).satisfy(function(v) { return roundtrip_table({value: v}); });
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
suite("Roundtrip values", function() {
|
|
99
|
-
[
|
|
100
|
-
amqp.Octet,
|
|
101
|
-
amqp.ShortStr,
|
|
102
|
-
amqp.LongStr,
|
|
103
|
-
amqp.UShort,
|
|
104
|
-
amqp.ULong,
|
|
105
|
-
amqp.ULongLong,
|
|
106
|
-
amqp.UShort,
|
|
107
|
-
amqp.Short,
|
|
108
|
-
amqp.Long,
|
|
109
|
-
amqp.Bit,
|
|
110
|
-
amqp.Decimal,
|
|
111
|
-
amqp.Timestamp,
|
|
112
|
-
amqp.Double,
|
|
113
|
-
amqp.Float,
|
|
114
|
-
amqp.FieldArray,
|
|
115
|
-
amqp.FieldTable
|
|
116
|
-
].forEach(function(T) {
|
|
117
|
-
test(T.toString() + ' roundtrip', roundtrips(T).asTest());
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
// When encoding, you can supply explicitly-typed fields like `{'!':
|
|
122
|
-
// int32, 50}`. Most of these do not appear in the decoded values, so
|
|
123
|
-
// to compare like-to-like we have to remove them from the input.
|
|
124
|
-
function removeExplicitTypes(input) {
|
|
125
|
-
switch (typeof input) {
|
|
126
|
-
case 'object':
|
|
127
|
-
if (input == null) {
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
if (Array.isArray(input)) {
|
|
131
|
-
var newArr = [];
|
|
132
|
-
for (var i = 0; i < input.length; i++) {
|
|
133
|
-
newArr[i] = removeExplicitTypes(input[i]);
|
|
134
|
-
}
|
|
135
|
-
return newArr;
|
|
136
|
-
}
|
|
137
|
-
if (Buffer.isBuffer(input)) {
|
|
138
|
-
return input;
|
|
139
|
-
}
|
|
140
|
-
switch (input['!']) {
|
|
141
|
-
case 'timestamp':
|
|
142
|
-
case 'decimal':
|
|
143
|
-
case 'float':
|
|
144
|
-
return input;
|
|
145
|
-
case undefined:
|
|
146
|
-
var newObj = {}
|
|
147
|
-
for (var k in input) {
|
|
148
|
-
newObj[k] = removeExplicitTypes(input[k]);
|
|
149
|
-
}
|
|
150
|
-
return newObj;
|
|
151
|
-
default:
|
|
152
|
-
return input.value;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
default:
|
|
156
|
-
return input;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Asserts that the decoded fields are equal to the original fields,
|
|
161
|
-
// or equal to a default where absent in the original. The defaults
|
|
162
|
-
// depend on the type of method or properties.
|
|
163
|
-
//
|
|
164
|
-
// This works slightly different for methods and properties: for
|
|
165
|
-
// methods, each field must have a value, so the default is
|
|
166
|
-
// substituted for undefined values when encoding; for properties,
|
|
167
|
-
// fields may be absent in the encoded value, so a default is
|
|
168
|
-
// substituted for missing fields when decoding. The effect is the
|
|
169
|
-
// same so far as these tests are concerned.
|
|
170
|
-
function assertEqualModuloDefaults(original, decodedFields) {
|
|
171
|
-
var args = defs.info(original.id).args;
|
|
172
|
-
for (var i=0; i < args.length; i++) {
|
|
173
|
-
var arg = args[i];
|
|
174
|
-
var originalValue = original.fields[arg.name];
|
|
175
|
-
var decodedValue = decodedFields[arg.name];
|
|
176
|
-
try {
|
|
177
|
-
if (originalValue === undefined) {
|
|
178
|
-
// longstr gets special treatment here, since the defaults are
|
|
179
|
-
// given as strings rather than buffers, but the decoded values
|
|
180
|
-
// will be buffers.
|
|
181
|
-
assert.deepEqual((arg.type === 'longstr') ?
|
|
182
|
-
Buffer.from(arg.default) : arg.default,
|
|
183
|
-
decodedValue);
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
assert.deepEqual(removeExplicitTypes(originalValue), decodedValue);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
catch (assertionErr) {
|
|
190
|
-
var methodOrProps = defs.info(original.id).name;
|
|
191
|
-
assertionErr.message += ' (frame ' + methodOrProps +
|
|
192
|
-
' field ' + arg.name + ')';
|
|
193
|
-
throw assertionErr;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
// %%% TODO make sure there's no surplus fields
|
|
197
|
-
return true;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// This is handy for elsewhere
|
|
201
|
-
module.exports.assertEqualModuloDefaults = assertEqualModuloDefaults;
|
|
202
|
-
|
|
203
|
-
function roundtripMethod(Method) {
|
|
204
|
-
return forAll(Method).satisfy(function(method) {
|
|
205
|
-
var buf = defs.encodeMethod(method.id, 0, method.fields);
|
|
206
|
-
// FIXME depends on framing, ugh
|
|
207
|
-
var fs1 = defs.decode(method.id, buf.slice(11, buf.length));
|
|
208
|
-
assertEqualModuloDefaults(method, fs1);
|
|
209
|
-
return true;
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
function roundtripProperties(Properties) {
|
|
214
|
-
return forAll(Properties).satisfy(function(properties) {
|
|
215
|
-
var buf = defs.encodeProperties(properties.id, 0, properties.size,
|
|
216
|
-
properties.fields);
|
|
217
|
-
// FIXME depends on framing, ugh
|
|
218
|
-
var fs1 = defs.decode(properties.id, buf.slice(19, buf.length));
|
|
219
|
-
assert.equal(properties.size, ints.readUInt64BE(buf, 11));
|
|
220
|
-
assertEqualModuloDefaults(properties, fs1);
|
|
221
|
-
return true;
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
suite("Roundtrip methods", function() {
|
|
226
|
-
amqp.methods.forEach(function(Method) {
|
|
227
|
-
test(Method.toString() + ' roundtrip',
|
|
228
|
-
roundtripMethod(Method).asTest());
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
suite("Roundtrip properties", function() {
|
|
233
|
-
amqp.properties.forEach(function(Properties) {
|
|
234
|
-
test(Properties.toString() + ' roundtrip',
|
|
235
|
-
roundtripProperties(Properties).asTest());
|
|
236
|
-
});
|
|
237
|
-
});
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var connect = require('../lib/connect').connect;
|
|
4
|
-
var credentialsFromUrl = require('../lib/connect').credentialsFromUrl;
|
|
5
|
-
var defs = require('../lib/defs');
|
|
6
|
-
var assert = require('assert');
|
|
7
|
-
var util = require('./util');
|
|
8
|
-
var net = require('net');
|
|
9
|
-
var fail = util.fail, succeed = util.succeed, latch = util.latch,
|
|
10
|
-
kCallback = util.kCallback,
|
|
11
|
-
succeedIfAttributeEquals = util.succeedIfAttributeEquals;
|
|
12
|
-
var format = require('util').format;
|
|
13
|
-
|
|
14
|
-
var URL = process.env.URL || 'amqp://localhost';
|
|
15
|
-
|
|
16
|
-
var urlparse = require('url-parse');
|
|
17
|
-
|
|
18
|
-
suite("Credentials", function() {
|
|
19
|
-
|
|
20
|
-
function checkCreds(creds, user, pass, done) {
|
|
21
|
-
if (creds.mechanism != 'PLAIN') {
|
|
22
|
-
return done('expected mechanism PLAIN');
|
|
23
|
-
}
|
|
24
|
-
if (creds.username != user || creds.password != pass) {
|
|
25
|
-
return done(format("expected '%s', '%s'; got '%s', '%s'",
|
|
26
|
-
user, pass, creds.username, creds.password));
|
|
27
|
-
}
|
|
28
|
-
done();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
test("no creds", function(done) {
|
|
32
|
-
var parts = urlparse('amqp://localhost');
|
|
33
|
-
var creds = credentialsFromUrl(parts);
|
|
34
|
-
checkCreds(creds, 'guest', 'guest', done);
|
|
35
|
-
});
|
|
36
|
-
test("usual user:pass", function(done) {
|
|
37
|
-
var parts = urlparse('amqp://user:pass@localhost')
|
|
38
|
-
var creds = credentialsFromUrl(parts);
|
|
39
|
-
checkCreds(creds, 'user', 'pass', done);
|
|
40
|
-
});
|
|
41
|
-
test("missing user", function(done) {
|
|
42
|
-
var parts = urlparse('amqps://:password@localhost');
|
|
43
|
-
var creds = credentialsFromUrl(parts);
|
|
44
|
-
checkCreds(creds, '', 'password', done);
|
|
45
|
-
});
|
|
46
|
-
test("missing password", function(done) {
|
|
47
|
-
var parts = urlparse('amqps://username:@localhost');
|
|
48
|
-
var creds = credentialsFromUrl(parts);
|
|
49
|
-
checkCreds(creds, 'username', '', done);
|
|
50
|
-
});
|
|
51
|
-
test("escaped colons", function(done) {
|
|
52
|
-
var parts = urlparse('amqp://user%3Aname:pass%3Aword@localhost')
|
|
53
|
-
var creds = credentialsFromUrl(parts);
|
|
54
|
-
checkCreds(creds, 'user:name', 'pass:word', done);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
suite("Connect API", function() {
|
|
59
|
-
|
|
60
|
-
test("Connection refused", function(done) {
|
|
61
|
-
connect('amqp://localhost:23450', {},
|
|
62
|
-
kCallback(fail(done), succeed(done)));
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
// %% this ought to fail the promise, rather than throwing an error
|
|
66
|
-
test("bad URL", function() {
|
|
67
|
-
assert.throws(function() {
|
|
68
|
-
connect('blurble');
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test("wrongly typed open option", function(done) {
|
|
73
|
-
var url = require('url');
|
|
74
|
-
var parts = url.parse(URL, true);
|
|
75
|
-
var q = parts.query || {};
|
|
76
|
-
q.frameMax = 'NOT A NUMBER';
|
|
77
|
-
parts.query = q;
|
|
78
|
-
var u = url.format(parts);
|
|
79
|
-
connect(u, {}, kCallback(fail(done), succeed(done)));
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test("serverProperties", function(done) {
|
|
83
|
-
var url = require('url');
|
|
84
|
-
var parts = url.parse(URL, true);
|
|
85
|
-
var config = parts.query || {};
|
|
86
|
-
connect(config, {}, function(err, connection) {
|
|
87
|
-
if (err) { return done(err); }
|
|
88
|
-
assert.equal(connection.serverProperties.product, 'RabbitMQ');
|
|
89
|
-
done();
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test("using custom heartbeat option", function(done) {
|
|
94
|
-
var url = require('url');
|
|
95
|
-
var parts = url.parse(URL, true);
|
|
96
|
-
var config = parts.query || {};
|
|
97
|
-
config.heartbeat = 20;
|
|
98
|
-
connect(config, {}, kCallback(succeedIfAttributeEquals('heartbeat', 20, done), fail(done)));
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
test("wrongly typed heartbeat option", function(done) {
|
|
102
|
-
var url = require('url');
|
|
103
|
-
var parts = url.parse(URL, true);
|
|
104
|
-
var config = parts.query || {};
|
|
105
|
-
config.heartbeat = 'NOT A NUMBER';
|
|
106
|
-
connect(config, {}, kCallback(fail(done), succeed(done)));
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
test("using plain credentials", function(done) {
|
|
110
|
-
var url = require('url');
|
|
111
|
-
var parts = url.parse(URL, true);
|
|
112
|
-
var u = 'guest', p = 'guest';
|
|
113
|
-
if (parts.auth) {
|
|
114
|
-
var auth = parts.auth.split(":");
|
|
115
|
-
u = auth[0], p = auth[1];
|
|
116
|
-
}
|
|
117
|
-
connect(URL, {credentials: require('../lib/credentials').plain(u, p)},
|
|
118
|
-
kCallback(succeed(done), fail(done)));
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
test("using amqplain credentials", function(done) {
|
|
122
|
-
var url = require('url');
|
|
123
|
-
var parts = url.parse(URL, true);
|
|
124
|
-
var u = 'guest', p = 'guest';
|
|
125
|
-
if (parts.auth) {
|
|
126
|
-
var auth = parts.auth.split(":");
|
|
127
|
-
u = auth[0], p = auth[1];
|
|
128
|
-
}
|
|
129
|
-
connect(URL, {credentials: require('../lib/credentials').amqplain(u, p)},
|
|
130
|
-
kCallback(succeed(done), fail(done)));
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
test("using unsupported mechanism", function(done) {
|
|
134
|
-
var creds = {
|
|
135
|
-
mechanism: 'UNSUPPORTED',
|
|
136
|
-
response: function() { return Buffer.from(''); }
|
|
137
|
-
};
|
|
138
|
-
connect(URL, {credentials: creds},
|
|
139
|
-
kCallback(fail(done), succeed(done)));
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
test("with a given connection timeout", function(done) {
|
|
143
|
-
var timeoutServer = net.createServer(function() {}).listen(31991);
|
|
144
|
-
|
|
145
|
-
connect('amqp://localhost:31991', {timeout: 50}, function(err, val) {
|
|
146
|
-
timeoutServer.close();
|
|
147
|
-
if (val) done(new Error('Expected connection timeout, did not'));
|
|
148
|
-
else done();
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
suite('Errors on connect', function() {
|
|
154
|
-
var server
|
|
155
|
-
teardown(function() {
|
|
156
|
-
if (server) {
|
|
157
|
-
server.close();
|
|
158
|
-
}
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
test("closes underlying connection on authentication error", function(done) {
|
|
162
|
-
var bothDone = latch(2, done);
|
|
163
|
-
server = net.createServer(function(socket) {
|
|
164
|
-
socket.once('data', function(protocolHeader) {
|
|
165
|
-
assert.deepStrictEqual(
|
|
166
|
-
protocolHeader,
|
|
167
|
-
Buffer.from("AMQP" + String.fromCharCode(0,0,9,1))
|
|
168
|
-
);
|
|
169
|
-
util.runServer(socket, function(send, wait) {
|
|
170
|
-
send(defs.ConnectionStart,
|
|
171
|
-
{versionMajor: 0,
|
|
172
|
-
versionMinor: 9,
|
|
173
|
-
serverProperties: {},
|
|
174
|
-
mechanisms: Buffer.from('PLAIN'),
|
|
175
|
-
locales: Buffer.from('en_US')});
|
|
176
|
-
wait(defs.ConnectionStartOk)().then(function() {
|
|
177
|
-
send(defs.ConnectionClose,
|
|
178
|
-
{replyCode: 403,
|
|
179
|
-
replyText: 'ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN',
|
|
180
|
-
classId: 0,
|
|
181
|
-
methodId: 0});
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
// Wait for the connection to be closed after the authentication error
|
|
187
|
-
socket.once('end', function() {
|
|
188
|
-
bothDone();
|
|
189
|
-
});
|
|
190
|
-
}).listen(0);
|
|
191
|
-
|
|
192
|
-
connect('amqp://localhost:' + server.address().port, {}, function(err) {
|
|
193
|
-
if (!err) bothDone(new Error('Expected authentication error'));
|
|
194
|
-
bothDone();
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
});
|