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.
Files changed (219) hide show
  1. package/dist/core.decorator.js +1 -30
  2. package/dist/default/default-authentication.class.js +25 -0
  3. package/dist/default/express-server.class.js +11 -4
  4. package/dist/default/log-default.class.js +0 -6
  5. package/dist/factory/authentication-factory.class.js +11 -0
  6. package/dist/factory/log-factory.class.js +9 -0
  7. package/dist/route.decorator.js +92 -2
  8. package/dist/typespeed.d.ts +40 -3
  9. package/dist/typespeed.js +3 -1
  10. package/package.json +1 -1
  11. package/src/core.decorator.ts +1 -29
  12. package/src/default/default-authentication.class.ts +10 -0
  13. package/src/default/express-server.class.ts +12 -5
  14. package/src/default/log-default.class.ts +0 -10
  15. package/src/factory/authentication-factory.class.ts +9 -0
  16. package/src/factory/log-factory.class.ts +9 -2
  17. package/src/route.decorator.ts +91 -3
  18. package/src/typespeed.d.ts +40 -3
  19. package/src/typespeed.ts +1 -0
  20. package/test/node_modules/.package-lock.json +65 -101
  21. package/test/node_modules/@types/body-parser/LICENSE +21 -0
  22. package/test/node_modules/@types/body-parser/README.md +16 -0
  23. package/test/node_modules/@types/body-parser/index.d.ts +107 -0
  24. package/test/node_modules/@types/body-parser/package.json +58 -0
  25. package/test/node_modules/@types/connect/LICENSE +21 -0
  26. package/test/node_modules/@types/connect/README.md +16 -0
  27. package/test/node_modules/@types/connect/index.d.ts +93 -0
  28. package/test/node_modules/@types/connect/package.json +32 -0
  29. package/test/node_modules/@types/express/LICENSE +21 -0
  30. package/test/node_modules/@types/express/README.md +16 -0
  31. package/test/node_modules/@types/express/index.d.ts +136 -0
  32. package/test/node_modules/@types/express/package.json +45 -0
  33. package/test/node_modules/@types/express-serve-static-core/LICENSE +21 -0
  34. package/test/node_modules/@types/express-serve-static-core/README.md +16 -0
  35. package/test/node_modules/@types/express-serve-static-core/index.d.ts +1281 -0
  36. package/test/node_modules/@types/express-serve-static-core/package.json +55 -0
  37. package/test/node_modules/@types/mime/LICENSE +21 -0
  38. package/test/node_modules/@types/mime/Mime.d.ts +10 -0
  39. package/test/node_modules/@types/mime/README.md +16 -0
  40. package/test/node_modules/@types/mime/index.d.ts +35 -0
  41. package/test/node_modules/@types/mime/lite.d.ts +7 -0
  42. package/test/node_modules/@types/mime/package.json +29 -0
  43. package/test/node_modules/@types/qs/LICENSE +21 -0
  44. package/test/node_modules/@types/qs/README.md +16 -0
  45. package/test/node_modules/@types/qs/index.d.ts +62 -0
  46. package/test/node_modules/@types/qs/package.json +65 -0
  47. package/test/node_modules/@types/range-parser/LICENSE +21 -0
  48. package/test/node_modules/@types/range-parser/README.md +55 -0
  49. package/test/node_modules/@types/range-parser/index.d.ts +35 -0
  50. package/test/node_modules/@types/range-parser/package.json +25 -0
  51. package/test/node_modules/@types/send/LICENSE +21 -0
  52. package/test/node_modules/@types/send/README.md +16 -0
  53. package/test/node_modules/@types/send/index.d.ts +231 -0
  54. package/test/node_modules/@types/send/package.json +33 -0
  55. package/test/node_modules/@types/serve-static/LICENSE +21 -0
  56. package/test/node_modules/@types/serve-static/README.md +16 -0
  57. package/test/node_modules/@types/serve-static/index.d.ts +113 -0
  58. package/test/node_modules/@types/serve-static/package.json +38 -0
  59. package/test/src/config.json +5 -0
  60. package/test/src/custom-log.class.ts +6 -0
  61. package/test/src/jwt-authentication.class.ts +29 -0
  62. package/test/src/test-request.class.ts +36 -0
  63. package/test/node_modules/@acuminous/bitsyntax/.github/workflows/node-js-ci.yml +0 -17
  64. package/test/node_modules/@acuminous/bitsyntax/.github/workflows/node-js-publish.yml +0 -30
  65. package/test/node_modules/@acuminous/bitsyntax/LICENSE +0 -6
  66. package/test/node_modules/@acuminous/bitsyntax/LICENSE-MIT +0 -21
  67. package/test/node_modules/@acuminous/bitsyntax/Makefile +0 -15
  68. package/test/node_modules/@acuminous/bitsyntax/README.md +0 -308
  69. package/test/node_modules/@acuminous/bitsyntax/index.js +0 -10
  70. package/test/node_modules/@acuminous/bitsyntax/lib/compile.js +0 -303
  71. package/test/node_modules/@acuminous/bitsyntax/lib/constructor.js +0 -142
  72. package/test/node_modules/@acuminous/bitsyntax/lib/grammar.pegjs +0 -67
  73. package/test/node_modules/@acuminous/bitsyntax/lib/interp.js +0 -232
  74. package/test/node_modules/@acuminous/bitsyntax/lib/parse.js +0 -32
  75. package/test/node_modules/@acuminous/bitsyntax/lib/parser.js +0 -1173
  76. package/test/node_modules/@acuminous/bitsyntax/lib/pattern.js +0 -119
  77. package/test/node_modules/@acuminous/bitsyntax/package.json +0 -36
  78. package/test/node_modules/@acuminous/bitsyntax/test/consing.test.js +0 -50
  79. package/test/node_modules/@acuminous/bitsyntax/test/matching.test.js +0 -193
  80. package/test/node_modules/amqplib/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  81. package/test/node_modules/amqplib/.github/workflows/test.yml +0 -38
  82. package/test/node_modules/amqplib/CHANGELOG.md +0 -430
  83. package/test/node_modules/amqplib/LICENSE +0 -6
  84. package/test/node_modules/amqplib/LICENSE-MIT +0 -21
  85. package/test/node_modules/amqplib/Makefile +0 -47
  86. package/test/node_modules/amqplib/README.md +0 -157
  87. package/test/node_modules/amqplib/bin/generate-defs.js +0 -722
  88. package/test/node_modules/amqplib/callback_api.js +0 -22
  89. package/test/node_modules/amqplib/channel_api.js +0 -16
  90. package/test/node_modules/amqplib/examples/headers.js +0 -42
  91. package/test/node_modules/amqplib/examples/receive_generator.js +0 -39
  92. package/test/node_modules/amqplib/examples/send_generators.js +0 -42
  93. package/test/node_modules/amqplib/examples/ssl.js +0 -64
  94. package/test/node_modules/amqplib/examples/tutorials/README.md +0 -93
  95. package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log.js +0 -28
  96. package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log_direct.js +0 -30
  97. package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log_topic.js +0 -27
  98. package/test/node_modules/amqplib/examples/tutorials/callback_api/new_task.js +0 -27
  99. package/test/node_modules/amqplib/examples/tutorials/callback_api/receive.js +0 -30
  100. package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs.js +0 -36
  101. package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs_direct.js +0 -56
  102. package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs_topic.js +0 -55
  103. package/test/node_modules/amqplib/examples/tutorials/callback_api/rpc_client.js +0 -49
  104. package/test/node_modules/amqplib/examples/tutorials/callback_api/rpc_server.js +0 -45
  105. package/test/node_modules/amqplib/examples/tutorials/callback_api/send.js +0 -29
  106. package/test/node_modules/amqplib/examples/tutorials/callback_api/worker.js +0 -35
  107. package/test/node_modules/amqplib/examples/tutorials/emit_log.js +0 -19
  108. package/test/node_modules/amqplib/examples/tutorials/emit_log_direct.js +0 -20
  109. package/test/node_modules/amqplib/examples/tutorials/emit_log_topic.js +0 -19
  110. package/test/node_modules/amqplib/examples/tutorials/new_task.js +0 -18
  111. package/test/node_modules/amqplib/examples/tutorials/package.json +0 -16
  112. package/test/node_modules/amqplib/examples/tutorials/receive.js +0 -21
  113. package/test/node_modules/amqplib/examples/tutorials/receive_logs.js +0 -28
  114. package/test/node_modules/amqplib/examples/tutorials/receive_logs_direct.js +0 -44
  115. package/test/node_modules/amqplib/examples/tutorials/receive_logs_topic.js +0 -43
  116. package/test/node_modules/amqplib/examples/tutorials/rpc_client.js +0 -52
  117. package/test/node_modules/amqplib/examples/tutorials/rpc_server.js +0 -39
  118. package/test/node_modules/amqplib/examples/tutorials/send.js +0 -23
  119. package/test/node_modules/amqplib/examples/tutorials/worker.js +0 -28
  120. package/test/node_modules/amqplib/examples/waitForConfirms.js +0 -22
  121. package/test/node_modules/amqplib/lib/api_args.js +0 -314
  122. package/test/node_modules/amqplib/lib/bitset.js +0 -130
  123. package/test/node_modules/amqplib/lib/callback_model.js +0 -327
  124. package/test/node_modules/amqplib/lib/channel.js +0 -499
  125. package/test/node_modules/amqplib/lib/channel_model.js +0 -302
  126. package/test/node_modules/amqplib/lib/codec.js +0 -321
  127. package/test/node_modules/amqplib/lib/connect.js +0 -189
  128. package/test/node_modules/amqplib/lib/connection.js +0 -663
  129. package/test/node_modules/amqplib/lib/credentials.js +0 -42
  130. package/test/node_modules/amqplib/lib/defs.js +0 -4966
  131. package/test/node_modules/amqplib/lib/error.js +0 -24
  132. package/test/node_modules/amqplib/lib/format.js +0 -40
  133. package/test/node_modules/amqplib/lib/frame.js +0 -113
  134. package/test/node_modules/amqplib/lib/heartbeat.js +0 -89
  135. package/test/node_modules/amqplib/lib/mux.js +0 -129
  136. package/test/node_modules/amqplib/package.json +0 -37
  137. package/test/node_modules/amqplib/test/bitset.js +0 -69
  138. package/test/node_modules/amqplib/test/callback_api.js +0 -312
  139. package/test/node_modules/amqplib/test/channel.js +0 -621
  140. package/test/node_modules/amqplib/test/channel_api.js +0 -596
  141. package/test/node_modules/amqplib/test/codec.js +0 -237
  142. package/test/node_modules/amqplib/test/connect.js +0 -197
  143. package/test/node_modules/amqplib/test/connection.js +0 -390
  144. package/test/node_modules/amqplib/test/data.js +0 -254
  145. package/test/node_modules/amqplib/test/frame.js +0 -198
  146. package/test/node_modules/amqplib/test/mux.js +0 -204
  147. package/test/node_modules/amqplib/test/util.js +0 -219
  148. package/test/node_modules/buffer-more-ints/.travis.yml +0 -6
  149. package/test/node_modules/buffer-more-ints/LICENSE +0 -19
  150. package/test/node_modules/buffer-more-ints/README.md +0 -69
  151. package/test/node_modules/buffer-more-ints/buffer-more-ints-tests.js +0 -183
  152. package/test/node_modules/buffer-more-ints/buffer-more-ints.js +0 -432
  153. package/test/node_modules/buffer-more-ints/package.json +0 -19
  154. package/test/node_modules/buffer-more-ints/polyfill.js +0 -71
  155. package/test/node_modules/core-util-is/LICENSE +0 -19
  156. package/test/node_modules/core-util-is/README.md +0 -3
  157. package/test/node_modules/core-util-is/lib/util.js +0 -107
  158. package/test/node_modules/core-util-is/package.json +0 -38
  159. package/test/node_modules/debug/LICENSE +0 -20
  160. package/test/node_modules/debug/README.md +0 -481
  161. package/test/node_modules/debug/package.json +0 -59
  162. package/test/node_modules/debug/src/browser.js +0 -269
  163. package/test/node_modules/debug/src/common.js +0 -274
  164. package/test/node_modules/debug/src/index.js +0 -10
  165. package/test/node_modules/debug/src/node.js +0 -263
  166. package/test/node_modules/inherits/LICENSE +0 -16
  167. package/test/node_modules/inherits/README.md +0 -42
  168. package/test/node_modules/inherits/inherits.js +0 -9
  169. package/test/node_modules/inherits/inherits_browser.js +0 -27
  170. package/test/node_modules/inherits/package.json +0 -29
  171. package/test/node_modules/isarray/README.md +0 -54
  172. package/test/node_modules/isarray/build/build.js +0 -209
  173. package/test/node_modules/isarray/component.json +0 -19
  174. package/test/node_modules/isarray/index.js +0 -3
  175. package/test/node_modules/isarray/package.json +0 -25
  176. package/test/node_modules/ms/index.js +0 -162
  177. package/test/node_modules/ms/license.md +0 -21
  178. package/test/node_modules/ms/package.json +0 -37
  179. package/test/node_modules/ms/readme.md +0 -60
  180. package/test/node_modules/querystringify/LICENSE +0 -22
  181. package/test/node_modules/querystringify/README.md +0 -61
  182. package/test/node_modules/querystringify/index.js +0 -118
  183. package/test/node_modules/querystringify/package.json +0 -38
  184. package/test/node_modules/readable-stream/LICENSE +0 -18
  185. package/test/node_modules/readable-stream/README.md +0 -15
  186. package/test/node_modules/readable-stream/duplex.js +0 -1
  187. package/test/node_modules/readable-stream/float.patch +0 -923
  188. package/test/node_modules/readable-stream/lib/_stream_duplex.js +0 -89
  189. package/test/node_modules/readable-stream/lib/_stream_passthrough.js +0 -46
  190. package/test/node_modules/readable-stream/lib/_stream_readable.js +0 -951
  191. package/test/node_modules/readable-stream/lib/_stream_transform.js +0 -209
  192. package/test/node_modules/readable-stream/lib/_stream_writable.js +0 -477
  193. package/test/node_modules/readable-stream/package.json +0 -32
  194. package/test/node_modules/readable-stream/passthrough.js +0 -1
  195. package/test/node_modules/readable-stream/readable.js +0 -10
  196. package/test/node_modules/readable-stream/transform.js +0 -1
  197. package/test/node_modules/readable-stream/writable.js +0 -1
  198. package/test/node_modules/requires-port/.travis.yml +0 -19
  199. package/test/node_modules/requires-port/LICENSE +0 -22
  200. package/test/node_modules/requires-port/README.md +0 -47
  201. package/test/node_modules/requires-port/index.js +0 -38
  202. package/test/node_modules/requires-port/package.json +0 -47
  203. package/test/node_modules/requires-port/test.js +0 -98
  204. package/test/node_modules/safe-buffer/LICENSE +0 -21
  205. package/test/node_modules/safe-buffer/README.md +0 -584
  206. package/test/node_modules/safe-buffer/index.d.ts +0 -187
  207. package/test/node_modules/safe-buffer/index.js +0 -62
  208. package/test/node_modules/safe-buffer/package.json +0 -37
  209. package/test/node_modules/string_decoder/LICENSE +0 -20
  210. package/test/node_modules/string_decoder/README.md +0 -7
  211. package/test/node_modules/string_decoder/index.js +0 -221
  212. package/test/node_modules/string_decoder/package.json +0 -25
  213. package/test/node_modules/url-parse/LICENSE +0 -22
  214. package/test/node_modules/url-parse/README.md +0 -153
  215. package/test/node_modules/url-parse/dist/url-parse.js +0 -755
  216. package/test/node_modules/url-parse/dist/url-parse.min.js +0 -1
  217. package/test/node_modules/url-parse/dist/url-parse.min.js.map +0 -1
  218. package/test/node_modules/url-parse/index.js +0 -589
  219. package/test/node_modules/url-parse/package.json +0 -49
@@ -1,390 +0,0 @@
1
- 'use strict';
2
-
3
- var assert = require('assert');
4
- var defs = require('../lib/defs');
5
- var Connection = require('../lib/connection').Connection;
6
- var HEARTBEAT = require('../lib/frame').HEARTBEAT;
7
- var HB_BUF = require('../lib/frame').HEARTBEAT_BUF;
8
- var util = require('./util');
9
- var succeed = util.succeed, fail = util.fail, latch = util.latch;
10
- var completes = util.completes;
11
- var kCallback = util.kCallback;
12
-
13
- var LOG_ERRORS = process.env.LOG_ERRORS;
14
-
15
- var OPEN_OPTS = {
16
- // start-ok
17
- 'clientProperties': {},
18
- 'mechanism': 'PLAIN',
19
- 'response': Buffer.from(['', 'guest', 'guest'].join(String.fromCharCode(0))),
20
- 'locale': 'en_US',
21
-
22
- // tune-ok
23
- 'channelMax': 0,
24
- 'frameMax': 0,
25
- 'heartbeat': 0,
26
-
27
- // open
28
- 'virtualHost': '/',
29
- 'capabilities': '',
30
- 'insist': 0
31
- };
32
- module.exports.OPEN_OPTS = OPEN_OPTS;
33
-
34
- function happy_open(send, wait) {
35
- // kick it off
36
- send(defs.ConnectionStart,
37
- {versionMajor: 0,
38
- versionMinor: 9,
39
- serverProperties: {},
40
- mechanisms: Buffer.from('PLAIN'),
41
- locales: Buffer.from('en_US')});
42
- return wait(defs.ConnectionStartOk)()
43
- .then(function(f) {
44
- send(defs.ConnectionTune,
45
- {channelMax: 0,
46
- heartbeat: 0,
47
- frameMax: 0});
48
- })
49
- .then(wait(defs.ConnectionTuneOk))
50
- .then(wait(defs.ConnectionOpen))
51
- .then(function(f) {
52
- send(defs.ConnectionOpenOk,
53
- {knownHosts: ''});
54
- });
55
- }
56
- module.exports.connection_handshake = happy_open;
57
-
58
- function connectionTest(client, server) {
59
- return function(done) {
60
- var bothDone = latch(2, done);
61
- var pair = util.socketPair();
62
- var c = new Connection(pair.client);
63
- if (LOG_ERRORS) c.on('error', console.warn);
64
- client(c, bothDone);
65
-
66
- // NB only not a race here because the writes are synchronous
67
- var protocolHeader = pair.server.read(8);
68
- assert.deepEqual(Buffer.from("AMQP" + String.fromCharCode(0,0,9,1)),
69
- protocolHeader);
70
-
71
- var s = util.runServer(pair.server, function(send, wait) {
72
- server(send, wait, bothDone, pair.server);
73
- });
74
- };
75
- }
76
-
77
- suite("Connection errors", function() {
78
-
79
- test("socket close during open", function(done) {
80
- // RabbitMQ itself will take at least 3 seconds to close the socket
81
- // in the event of a handshake problem. Instead of using a live
82
- // connection, I'm just going to pretend.
83
- var pair = util.socketPair();
84
- var conn = new Connection(pair.client);
85
- pair.server.on('readable', function() {
86
- pair.server.end();
87
- });
88
- conn.open({}, kCallback(fail(done), succeed(done)));
89
- });
90
-
91
- test("bad frame during open", function(done) {
92
- var ss = util.socketPair();
93
- var conn = new (require('../lib/connection').Connection)(ss.client);
94
- ss.server.on('readable', function() {
95
- ss.server.write(Buffer.from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
96
- });
97
- conn.open({}, kCallback(fail(done), succeed(done)));
98
- });
99
-
100
- });
101
-
102
- suite("Connection open", function() {
103
-
104
- test("happy", connectionTest(
105
- function(c, done) {
106
- c.open(OPEN_OPTS, kCallback(succeed(done), fail(done)));
107
- },
108
- function(send, wait, done) {
109
- happy_open(send, wait).then(succeed(done), fail(done));
110
- }));
111
-
112
- test("wrong first frame", connectionTest(
113
- function(c, done) {
114
- c.open(OPEN_OPTS, kCallback(fail(done), succeed(done)));
115
- },
116
- function(send, wait, done) {
117
- // bad server! bad! whatever were you thinking?
118
- completes(function() {
119
- send(defs.ConnectionTune,
120
- {channelMax: 0,
121
- heartbeat: 0,
122
- frameMax: 0});
123
- }, done);
124
- }));
125
-
126
- test("unexpected socket close", connectionTest(
127
- function(c, done) {
128
- c.open(OPEN_OPTS, kCallback(fail(done), succeed(done)));
129
- },
130
- function(send, wait, done, socket) {
131
- send(defs.ConnectionStart,
132
- {versionMajor: 0,
133
- versionMinor: 9,
134
- serverProperties: {},
135
- mechanisms: Buffer.from('PLAIN'),
136
- locales: Buffer.from('en_US')});
137
- return wait(defs.ConnectionStartOk)()
138
- .then(function() {
139
- socket.end();
140
- })
141
- .then(succeed(done), fail(done));
142
- }));
143
-
144
- });
145
-
146
- suite("Connection running", function() {
147
-
148
- test("wrong frame on channel 0", connectionTest(
149
- function(c, done) {
150
- c.on('error', succeed(done));
151
- c.open(OPEN_OPTS);
152
- },
153
- function(send, wait, done) {
154
- happy_open(send, wait)
155
- .then(function() {
156
- // there's actually nothing that would plausibly be sent to a
157
- // just opened connection, so this is violating more than one
158
- // rule. Nonetheless.
159
- send(defs.ChannelOpenOk, {channelId: Buffer.from('')}, 0);
160
- })
161
- .then(wait(defs.ConnectionClose))
162
- .then(function(close) {
163
- send(defs.ConnectionCloseOk, {}, 0);
164
- }).then(succeed(done), fail(done));
165
- }));
166
-
167
- test("unopened channel", connectionTest(
168
- function(c, done) {
169
- c.on('error', succeed(done));
170
- c.open(OPEN_OPTS);
171
- },
172
- function(send, wait, done) {
173
- happy_open(send, wait)
174
- .then(function() {
175
- // there's actually nothing that would plausibly be sent to a
176
- // just opened connection, so this is violating more than one
177
- // rule. Nonetheless.
178
- send(defs.ChannelOpenOk, {channelId: Buffer.from('')}, 3);
179
- })
180
- .then(wait(defs.ConnectionClose))
181
- .then(function(close) {
182
- send(defs.ConnectionCloseOk, {}, 0);
183
- }).then(succeed(done), fail(done));
184
- }));
185
-
186
- test("unexpected socket close", connectionTest(
187
- function(c, done) {
188
- var errorAndClosed = latch(2, done);
189
- c.on('error', succeed(errorAndClosed));
190
- c.on('close', succeed(errorAndClosed));
191
- c.open(OPEN_OPTS, kCallback(function() {
192
- c.sendHeartbeat();
193
- }, fail(errorAndClosed)));
194
- },
195
- function(send, wait, done, socket) {
196
- happy_open(send, wait)
197
- .then(wait())
198
- .then(function() {
199
- socket.end();
200
- }).then(succeed(done));
201
- }));
202
-
203
- test("connection.blocked", connectionTest(
204
- function(c, done) {
205
- c.on('blocked', succeed(done));
206
- c.open(OPEN_OPTS);
207
- },
208
- function(send, wait, done, socket) {
209
- happy_open(send, wait)
210
- .then(function() {
211
- send(defs.ConnectionBlocked, {reason: 'felt like it'}, 0);
212
- })
213
- .then(succeed(done));
214
- }));
215
-
216
- test("connection.unblocked", connectionTest(
217
- function(c, done) {
218
- c.on('unblocked', succeed(done));
219
- c.open(OPEN_OPTS);
220
- },
221
- function(send, wait, done, socket) {
222
- happy_open(send, wait)
223
- .then(function() {
224
- send(defs.ConnectionUnblocked, {}, 0);
225
- })
226
- .then(succeed(done));
227
- }));
228
-
229
-
230
- });
231
-
232
- suite("Connection close", function() {
233
-
234
- test("happy", connectionTest(
235
- function(c, done0) {
236
- var done = latch(2, done0);
237
- c.on('close', done);
238
- c.open(OPEN_OPTS, kCallback(function(_ok) {
239
- c.close(kCallback(succeed(done), fail(done)));
240
- }, function() {}));
241
- },
242
- function(send, wait, done) {
243
- happy_open(send, wait)
244
- .then(wait(defs.ConnectionClose))
245
- .then(function(close) {
246
- send(defs.ConnectionCloseOk, {});
247
- })
248
- .then(succeed(done), fail(done));
249
- }));
250
-
251
- test("interleaved close frames", connectionTest(
252
- function(c, done0) {
253
- var done = latch(2, done0);
254
- c.on('close', done);
255
- c.open(OPEN_OPTS, kCallback(function(_ok) {
256
- c.close(kCallback(succeed(done), fail(done)));
257
- }, done));
258
- },
259
- function(send, wait, done) {
260
- happy_open(send, wait)
261
- .then(wait(defs.ConnectionClose))
262
- .then(function(f) {
263
- send(defs.ConnectionClose, {
264
- replyText: "Ha!",
265
- replyCode: defs.constants.REPLY_SUCCESS,
266
- methodId: 0, classId: 0
267
- });
268
- })
269
- .then(wait(defs.ConnectionCloseOk))
270
- .then(function(f) {
271
- send(defs.ConnectionCloseOk, {});
272
- })
273
- .then(succeed(done), fail(done));
274
- }));
275
-
276
- test("server error close", connectionTest(
277
- function(c, done0) {
278
- var done = latch(2, done0);
279
- c.on('close', succeed(done));
280
- c.on('error', succeed(done));
281
- c.open(OPEN_OPTS);
282
- },
283
- function(send, wait, done) {
284
- happy_open(send, wait)
285
- .then(function(f) {
286
- send(defs.ConnectionClose, {
287
- replyText: "Begone",
288
- replyCode: defs.constants.INTERNAL_ERROR,
289
- methodId: 0, classId: 0
290
- });
291
- })
292
- .then(wait(defs.ConnectionCloseOk))
293
- .then(succeed(done), fail(done));
294
- }));
295
-
296
- test("operator-intiated close", connectionTest(
297
- function(c, done) {
298
- c.on('close', succeed(done));
299
- c.on('error', fail(done));
300
- c.open(OPEN_OPTS);
301
- },
302
- function(send, wait, done) {
303
- happy_open(send, wait)
304
- .then(function(f) {
305
- send(defs.ConnectionClose, {
306
- replyText: "Begone",
307
- replyCode: defs.constants.CONNECTION_FORCED,
308
- methodId: 0, classId: 0
309
- });
310
- })
311
- .then(wait(defs.ConnectionCloseOk))
312
- .then(succeed(done), fail(done));
313
- }));
314
-
315
-
316
- test("double close", connectionTest(
317
- function(c, done) {
318
- c.open(OPEN_OPTS, kCallback(function() {
319
- c.close();
320
- // NB no synchronisation, we do this straight away
321
- assert.throws(function() {
322
- c.close();
323
- });
324
- done();
325
- }, done));
326
- },
327
- function(send, wait, done) {
328
- happy_open(send, wait)
329
- .then(wait(defs.ConnectionClose))
330
- .then(function() {
331
- send(defs.ConnectionCloseOk, {});
332
- })
333
- .then(succeed(done), fail(done));
334
- }));
335
-
336
- });
337
-
338
- suite("heartbeats", function() {
339
-
340
- var heartbeat = require('../lib/heartbeat');
341
-
342
- setup(function() {
343
- heartbeat.UNITS_TO_MS = 20;
344
- });
345
-
346
- teardown(function() {
347
- heartbeat.UNITS_TO_MS = 1000;
348
- });
349
-
350
- test("send heartbeat after open", connectionTest(
351
- function(c, done) {
352
- completes(function() {
353
- var opts = Object.create(OPEN_OPTS);
354
- opts.heartbeat = 1;
355
- // Don't leave the error waiting to happen for the next test, this
356
- // confuses mocha awfully
357
- c.on('error', function() {});
358
- c.open(opts);
359
- }, done);
360
- },
361
- function(send, wait, done, socket) {
362
- var timer;
363
- happy_open(send, wait)
364
- .then(function() {
365
- timer = setInterval(function() {
366
- socket.write(HB_BUF);
367
- }, heartbeat.UNITS_TO_MS);
368
- })
369
- .then(wait())
370
- .then(function(hb) {
371
- if (hb === HEARTBEAT) done();
372
- else done("Next frame after silence not a heartbeat");
373
- clearInterval(timer);
374
- });
375
- }));
376
-
377
- test("detect lack of heartbeats", connectionTest(
378
- function(c, done) {
379
- var opts = Object.create(OPEN_OPTS);
380
- opts.heartbeat = 1;
381
- c.on('error', succeed(done));
382
- c.open(opts);
383
- },
384
- function(send, wait, done, socket) {
385
- happy_open(send, wait)
386
- .then(succeed(done), fail(done));
387
- // conspicuously not sending anything ...
388
- }));
389
-
390
- });
@@ -1,254 +0,0 @@
1
- // Property-based testing representations of various things in AMQP
2
-
3
- 'use strict';
4
-
5
- var C = require('claire');
6
- var forAll = C.forAll;
7
- var arb = C.data;
8
- var transform = C.transform;
9
- var repeat = C.repeat;
10
- var label = C.label;
11
- var sequence = C.sequence;
12
- var asGenerator = C.asGenerator;
13
- var sized = C.sized;
14
- var recursive = C.recursive;
15
- var choice = C.choice;
16
- var Undefined = C.Undefined;
17
-
18
- // Stub these out so we can use outside tests
19
- // if (!suite) var suite = function() {}
20
- // if (!test) var test = function() {}
21
-
22
- // These aren't exported in claire/index. so I could have to reproduce
23
- // them I guess.
24
- function choose(a, b) {
25
- return Math.random() * (b - a) + a;
26
- }
27
-
28
- function chooseInt(a, b) {
29
- return Math.floor(choose(a, b));
30
- }
31
-
32
- function rangeInt(name, a, b) {
33
- return label(name,
34
- asGenerator(function(_) { return chooseInt(a, b); }));
35
- }
36
-
37
- function toFloat32(i) {
38
- var b = Buffer.alloc(4);
39
- b.writeFloatBE(i, 0);
40
- return b.readFloatBE(0);
41
- }
42
-
43
- function floatChooser(maxExp) {
44
- return function() {
45
- var n = Number.NaN;
46
- while (isNaN(n)) {
47
- var mantissa = Math.random() * 2 - 1;
48
- var exponent = chooseInt(0, maxExp);
49
- n = Math.pow(mantissa, exponent);
50
- }
51
- return n;
52
- }
53
- }
54
-
55
- function explicitType(t, underlying) {
56
- return label(t, transform(function(n) {
57
- return {'!': t, value: n};
58
- }, underlying));
59
- }
60
-
61
- // FIXME null, byte array, others?
62
-
63
- var Octet = rangeInt('octet', 0, 255);
64
- var ShortStr = label('shortstr',
65
- transform(function(s) {
66
- return s.substr(0, 255);
67
- }, arb.Str));
68
-
69
- var LongStr = label('longstr',
70
- transform(
71
- function(bytes) { return Buffer.from(bytes); },
72
- repeat(Octet)));
73
-
74
- var UShort = rangeInt('short-uint', 0, 0xffff);
75
- var ULong = rangeInt('long-uint', 0, 0xffffffff);
76
- var ULongLong = rangeInt('longlong-uint', 0, 0xffffffffffffffff);
77
- var Short = rangeInt('short-int', -0x8000, 0x7fff);
78
- var Long = rangeInt('long-int', -0x80000000, 0x7fffffff);
79
- var LongLong = rangeInt('longlong-int', -0x8000000000000000,
80
- 0x7fffffffffffffff);
81
- var Bit = label('bit', arb.Bool);
82
- var Double = label('double', asGenerator(floatChooser(308)));
83
- var Float = label('float', transform(toFloat32, floatChooser(38)));
84
- var Timestamp = label('timestamp', transform(
85
- function(n) {
86
- return {'!': 'timestamp', value: n};
87
- }, ULongLong));
88
- var Decimal = label('decimal', transform(
89
- function(args) {
90
- return {'!': 'decimal', value: {places: args[1], digits: args[0]}};
91
- }, sequence(arb.UInt, Octet)));
92
-
93
- // Signed 8 bit int
94
- var Byte = rangeInt('byte', -128, 127);
95
-
96
- // Explicitly typed values
97
- var ExByte = explicitType('byte', Byte);
98
- var ExInt8 = explicitType('int8', Byte);
99
- var ExShort = explicitType('short', Short);
100
- var ExInt16 = explicitType('int16', Short);
101
- var ExInt = explicitType('int', Long);
102
- var ExInt32 = explicitType('int32', Long);
103
- var ExLong = explicitType('long', LongLong);
104
- var ExInt64 = explicitType('int64', LongLong);
105
-
106
- var FieldArray = label('field-array', recursive(function() {
107
- return arb.Array(
108
- arb.Null,
109
- LongStr, ShortStr,
110
- Octet, UShort, ULong, ULongLong,
111
- Byte, Short, Long, LongLong,
112
- ExByte, ExInt8, ExShort, ExInt16,
113
- ExInt, ExInt32, ExLong, ExInt64,
114
- Bit, Float, Double, FieldTable, FieldArray)
115
- }));
116
-
117
- var FieldTable = label('table', recursive(function() {
118
- return sized(function() { return 5; },
119
- arb.Object(
120
- arb.Null,
121
- LongStr, ShortStr, Octet,
122
- UShort, ULong, ULongLong,
123
- Byte, Short, Long, LongLong,
124
- ExByte, ExInt8, ExShort, ExInt16,
125
- ExInt, ExInt32, ExLong, ExInt64,
126
- Bit, Float, Double, FieldArray, FieldTable))
127
- }));
128
-
129
- // Internal tests of our properties
130
- var domainProps = [
131
- [Octet, function(n) { return n >= 0 && n < 256; }],
132
- [ShortStr, function(s) { return typeof s === 'string' && s.length < 256; }],
133
- [LongStr, function(s) { return Buffer.isBuffer(s); }],
134
- [UShort, function(n) { return n >= 0 && n <= 0xffff; }],
135
- [ULong, function(n) { return n >= 0 && n <= 0xffffffff; }],
136
- [ULongLong, function(n) {
137
- return n >= 0 && n <= 0xffffffffffffffff; }],
138
- [Short, function(n) { return n >= -0x8000 && n <= 0x8000; }],
139
- [Long, function(n) { return n >= -0x80000000 && n < 0x80000000; }],
140
- [LongLong, function(n) { return n >= -0x8000000000000000 && n < 0x8000000000000000; }],
141
- [Bit, function(b) { return typeof b === 'boolean'; }],
142
- [Double, function(f) { return !isNaN(f) && isFinite(f); }],
143
- [Float, function(f) { return !isNaN(f) && isFinite(f) && (Math.log(Math.abs(f)) * Math.LOG10E) < 309; }],
144
- [Decimal, function(d) {
145
- return d['!'] === 'decimal' &&
146
- d.value['places'] <= 255 &&
147
- d.value['digits'] <= 0xffffffff;
148
- }],
149
- [Timestamp, function(t) { return t['!'] === 'timestamp'; }],
150
- [FieldTable, function(t) { return typeof t === 'object'; }],
151
- [FieldArray, function(a) { return Array.isArray(a); }]
152
- ];
153
-
154
- suite("Domains", function() {
155
- domainProps.forEach(function(p) {
156
- test(p[0] + ' domain',
157
- forAll(p[0]).satisfy(p[1]).asTest({times: 500}));
158
- });
159
- });
160
-
161
- // For methods and properties (as opposed to field table values) it's
162
- // easier just to accept and produce numbers for timestamps.
163
- var ArgTimestamp = label('timestamp', ULongLong);
164
-
165
- // These are the domains used in method arguments
166
- var ARG_TYPES = {
167
- 'octet': Octet,
168
- 'shortstr': ShortStr,
169
- 'longstr': LongStr,
170
- 'short': UShort,
171
- 'long': ULong,
172
- 'longlong': ULongLong,
173
- 'bit': Bit,
174
- 'table': FieldTable,
175
- 'timestamp': ArgTimestamp
176
- };
177
-
178
- function argtype(thing) {
179
- if (thing.default === undefined) {
180
- return ARG_TYPES[thing.type];
181
- }
182
- else {
183
- return choice(ARG_TYPES[thing.type], Undefined);
184
- }
185
- }
186
-
187
- function zipObject(vals, names) {
188
- var obj = {};
189
- vals.forEach(function(v, i) { obj[names[i]] = v; });
190
- return obj;
191
- }
192
-
193
- function name(arg) { return arg.name; }
194
-
195
- var defs = require('../lib/defs');
196
-
197
- function method(info) {
198
- var domain = sequence.apply(null, info.args.map(argtype));
199
- var names = info.args.map(name);
200
- return label(info.name, transform(function(fieldVals) {
201
- return {id: info.id,
202
- fields: zipObject(fieldVals, names)};
203
- }, domain));
204
- }
205
-
206
- function properties(info) {
207
- var types = info.args.map(argtype);
208
- types.unshift(ULongLong); // size
209
- var domain = sequence.apply(null, types);
210
- var names = info.args.map(name);
211
- return label(info.name, transform(function(fieldVals) {
212
- return {id: info.id,
213
- size: fieldVals[0],
214
- fields: zipObject(fieldVals.slice(1), names)};
215
- }, domain));
216
- }
217
-
218
- var methods = [];
219
- var propertieses = [];
220
-
221
- for (var k in defs) {
222
- if (k.substr(0, 10) === 'methodInfo') {
223
- methods.push(method(defs[k]));
224
- methods[defs[k].name] = method(defs[k]);
225
- }
226
- else if (k.substr(0, 14) === 'propertiesInfo') {
227
- propertieses.push(properties(defs[k]));
228
- propertieses[defs[k].name] = properties(defs[k]);
229
- }
230
- };
231
-
232
- module.exports = {
233
- Octet: Octet,
234
- ShortStr: ShortStr,
235
- LongStr: LongStr,
236
- UShort: UShort,
237
- ULong: ULong,
238
- ULongLong: ULongLong,
239
- Short: Short,
240
- Long: Long,
241
- LongLong: LongLong,
242
- Bit: Bit,
243
- Double: Double,
244
- Float: Float,
245
- Timestamp: Timestamp,
246
- Decimal: Decimal,
247
- FieldArray: FieldArray,
248
- FieldTable: FieldTable,
249
-
250
- methods: methods,
251
- properties: propertieses
252
- };
253
-
254
- module.exports.rangeInt = rangeInt;