amqplib 1.0.1 → 1.0.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 +3 -0
- package/lib/connect.js +15 -5
- package/package.json +2 -3
- package/test/connect.test.js +0 -41
- package/test/uri_spec.test.js +210 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# Change log for amqplib
|
|
2
2
|
|
|
3
|
+
## v1.0.2
|
|
4
|
+
- Replace url-parse with WHATWG URL API
|
|
5
|
+
|
|
3
6
|
## v1.0.1
|
|
4
7
|
- Fix TLS connection failure when connecting to an AMQPS broker using an IP address (IPv4 or IPv6) — setting servername to an IP is not permitted by TLS SNI and throws ERR_INVALID_ARG_VALUE in Node.js 25+
|
|
5
8
|
|
package/lib/connect.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const URL = require('url
|
|
1
|
+
const { URL } = require('node:url');
|
|
2
2
|
const QS = require('node:querystring');
|
|
3
3
|
const net = require('node:net');
|
|
4
4
|
const tls = require('node:tls');
|
|
@@ -124,14 +124,24 @@ function connect(url, socketOptions, openCallback) {
|
|
|
124
124
|
|
|
125
125
|
fields = openFrames(url.vhost, config, sockopts.credentials || credentials.plain(user, pass), extraClientProperties);
|
|
126
126
|
} else {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
127
|
+
let parts;
|
|
128
|
+
try {
|
|
129
|
+
parts = new URL(url);
|
|
130
|
+
} catch (_e) {
|
|
131
|
+
parts = {};
|
|
132
|
+
}
|
|
133
|
+
const host = (parts.hostname || '').replace(/^\[|\]$/g, '');
|
|
134
|
+
protocol = parts.protocol || '';
|
|
130
135
|
sockopts.host = host;
|
|
131
136
|
if (!sockopts.servername && !net.isIP(host)) sockopts.servername = host;
|
|
132
137
|
sockopts.port = parseInt(parts.port, 10) || (protocol === 'amqp:' ? 5672 : 5671);
|
|
133
138
|
const vhost = parts.pathname ? parts.pathname.substr(1) : null;
|
|
134
|
-
|
|
139
|
+
const query = QS.parse(parts.search ? parts.search.slice(1) : '');
|
|
140
|
+
// QS.parse returns arrays for duplicate keys; match url-parse's first-value-wins behavior.
|
|
141
|
+
for (const key in query) {
|
|
142
|
+
if (Array.isArray(query[key])) query[key] = query[key][0];
|
|
143
|
+
}
|
|
144
|
+
fields = openFrames(vhost, query, sockopts.credentials || credentialsFromUrl(parts), extraClientProperties);
|
|
135
145
|
}
|
|
136
146
|
|
|
137
147
|
let sockok = false;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "amqplib",
|
|
3
3
|
"homepage": "http://amqp-node.github.io/amqplib/",
|
|
4
4
|
"main": "./channel_api.js",
|
|
5
|
-
"version": "1.0.
|
|
5
|
+
"version": "1.0.2",
|
|
6
6
|
"description": "An AMQP 0-9-1 (e.g., RabbitMQ) library and client.",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -12,8 +12,7 @@
|
|
|
12
12
|
"node": ">=18"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"buffer-more-ints": "~1.0.0"
|
|
16
|
-
"url-parse": "~1.5.10"
|
|
15
|
+
"buffer-more-ints": "~1.0.0"
|
|
17
16
|
},
|
|
18
17
|
"devDependencies": {
|
|
19
18
|
"@biomejs/biome": "^2.2.2",
|
package/test/connect.test.js
CHANGED
|
@@ -2,53 +2,12 @@ const { describe, it, afterEach } = require('node:test');
|
|
|
2
2
|
const assert = require('node:assert');
|
|
3
3
|
const net = require('node:net');
|
|
4
4
|
const connect = require('../lib/connect').connect;
|
|
5
|
-
const credentialsFromUrl = require('../lib/connect').credentialsFromUrl;
|
|
6
5
|
const defs = require('../lib/defs');
|
|
7
6
|
const { plain, amqplain } = require('../lib/credentials')
|
|
8
7
|
const { latch, runServer } = require('./lib/util');
|
|
9
8
|
|
|
10
|
-
const urlparse = require('url-parse');
|
|
11
|
-
|
|
12
9
|
describe('Connect', () => {
|
|
13
10
|
|
|
14
|
-
describe('Credentials', () => {
|
|
15
|
-
function assertCredentials(creds, username, password) {
|
|
16
|
-
assert.strictEqual(creds.mechanism, 'PLAIN');
|
|
17
|
-
assert.strictEqual(creds.username, username);
|
|
18
|
-
assert.strictEqual(creds.password, password);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
it('no creds', () => {
|
|
22
|
-
const parts = urlparse('amqp://localhost');
|
|
23
|
-
const creds = credentialsFromUrl(parts);
|
|
24
|
-
assertCredentials(creds, 'guest', 'guest');
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('usual user:pass', () => {
|
|
28
|
-
const parts = urlparse('amqp://user:pass@localhost');
|
|
29
|
-
const creds = credentialsFromUrl(parts);
|
|
30
|
-
assertCredentials(creds, 'user', 'pass');
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('missing user', () => {
|
|
34
|
-
const parts = urlparse('amqps://:password@localhost');
|
|
35
|
-
const creds = credentialsFromUrl(parts);
|
|
36
|
-
assertCredentials(creds, '', 'password');
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('missing password', () => {
|
|
40
|
-
const parts = urlparse('amqps://username:@localhost');
|
|
41
|
-
const creds = credentialsFromUrl(parts);
|
|
42
|
-
assertCredentials(creds, 'username', '');
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('escaped colons', () => {
|
|
46
|
-
const parts = urlparse('amqp://user%3Aname:pass%3Aword@localhost');
|
|
47
|
-
const creds = credentialsFromUrl(parts);
|
|
48
|
-
assertCredentials(creds, 'user:name', 'pass:word');
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
11
|
describe('Connect API', () => {
|
|
53
12
|
|
|
54
13
|
let connection;
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
const { describe, it } = require('node:test');
|
|
2
|
+
const assert = require('node:assert');
|
|
3
|
+
const net = require('node:net');
|
|
4
|
+
const connect = require('../lib/connect').connect;
|
|
5
|
+
const defs = require('../lib/defs');
|
|
6
|
+
const { runServer } = require('./lib/util');
|
|
7
|
+
|
|
8
|
+
function captureHandshake(url, callback) {
|
|
9
|
+
let server;
|
|
10
|
+
const captured = {};
|
|
11
|
+
|
|
12
|
+
server = net.createServer((socket) => {
|
|
13
|
+
socket.once('data', (_header) => {
|
|
14
|
+
runServer(socket, (send, wait) => {
|
|
15
|
+
send(defs.ConnectionStart, {
|
|
16
|
+
versionMajor: 0,
|
|
17
|
+
versionMinor: 9,
|
|
18
|
+
serverProperties: {},
|
|
19
|
+
mechanisms: Buffer.from('PLAIN'),
|
|
20
|
+
locales: Buffer.from('en_US'),
|
|
21
|
+
});
|
|
22
|
+
wait(defs.ConnectionStartOk)().then((startOk) => {
|
|
23
|
+
const parts = startOk.fields.response.toString().split('\0');
|
|
24
|
+
captured.username = parts[1];
|
|
25
|
+
captured.password = parts[2];
|
|
26
|
+
send(defs.ConnectionTune, { channelMax: 0, heartbeat: 0, frameMax: 0 });
|
|
27
|
+
return wait(defs.ConnectionTuneOk)();
|
|
28
|
+
}).then(() => {
|
|
29
|
+
return wait(defs.ConnectionOpen)();
|
|
30
|
+
}).then((open) => {
|
|
31
|
+
captured.vhost = open.fields.virtualHost;
|
|
32
|
+
send(defs.ConnectionClose, {
|
|
33
|
+
replyCode: 200,
|
|
34
|
+
replyText: 'ok',
|
|
35
|
+
classId: 0,
|
|
36
|
+
methodId: 0,
|
|
37
|
+
});
|
|
38
|
+
}).catch((err) => {
|
|
39
|
+
server.close();
|
|
40
|
+
callback(err);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
socket.once('end', () => {
|
|
45
|
+
server.close(() => callback(null, captured));
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
server.listen(0, () => {
|
|
51
|
+
const port = server.address().port;
|
|
52
|
+
const urlWithPort = url.replace('TESTPORT', String(port));
|
|
53
|
+
connect(urlWithPort, {}, (_err) => {});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
describe('AMQP URI spec', () => {
|
|
58
|
+
|
|
59
|
+
describe('credentials', () => {
|
|
60
|
+
|
|
61
|
+
it('no userinfo defaults to guest/guest', (_t, done) => {
|
|
62
|
+
captureHandshake('amqp://localhost:TESTPORT', (err, result) => {
|
|
63
|
+
assert.ifError(err);
|
|
64
|
+
assert.strictEqual(result.username, 'guest');
|
|
65
|
+
assert.strictEqual(result.password, 'guest');
|
|
66
|
+
done();
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('plain user:pass', (_t, done) => {
|
|
71
|
+
captureHandshake('amqp://user:pass@localhost:TESTPORT', (err, result) => {
|
|
72
|
+
assert.ifError(err);
|
|
73
|
+
assert.strictEqual(result.username, 'user');
|
|
74
|
+
assert.strictEqual(result.password, 'pass');
|
|
75
|
+
done();
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('empty username', (_t, done) => {
|
|
80
|
+
captureHandshake('amqp://:password@localhost:TESTPORT', (err, result) => {
|
|
81
|
+
assert.ifError(err);
|
|
82
|
+
assert.strictEqual(result.username, '');
|
|
83
|
+
assert.strictEqual(result.password, 'password');
|
|
84
|
+
done();
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('empty password', (_t, done) => {
|
|
89
|
+
captureHandshake('amqp://username:@localhost:TESTPORT', (err, result) => {
|
|
90
|
+
assert.ifError(err);
|
|
91
|
+
assert.strictEqual(result.username, 'username');
|
|
92
|
+
assert.strictEqual(result.password, '');
|
|
93
|
+
done();
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Issue #385: colon in username or password must be percent-encoded
|
|
98
|
+
it('percent-encoded colon (%3A) in username and password', (_t, done) => {
|
|
99
|
+
captureHandshake('amqp://user%3Aname:pass%3Aword@localhost:TESTPORT', (err, result) => {
|
|
100
|
+
assert.ifError(err);
|
|
101
|
+
assert.strictEqual(result.username, 'user:name');
|
|
102
|
+
assert.strictEqual(result.password, 'pass:word');
|
|
103
|
+
done();
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// Issue #483: @ in password must be percent-encoded as %40
|
|
108
|
+
it('percent-encoded @ (%40) in password', (_t, done) => {
|
|
109
|
+
captureHandshake('amqp://user:p%40ssword@localhost:TESTPORT', (err, result) => {
|
|
110
|
+
assert.ifError(err);
|
|
111
|
+
assert.strictEqual(result.username, 'user');
|
|
112
|
+
assert.strictEqual(result.password, 'p@ssword');
|
|
113
|
+
done();
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// RabbitMQ URI spec example: amqp://user:passw%23rd@host:10000/vhost
|
|
118
|
+
it('percent-encoded # (%23) in password', (_t, done) => {
|
|
119
|
+
captureHandshake('amqp://user:passw%23rd@localhost:TESTPORT', (err, result) => {
|
|
120
|
+
assert.ifError(err);
|
|
121
|
+
assert.strictEqual(result.username, 'user');
|
|
122
|
+
assert.strictEqual(result.password, 'passw#rd');
|
|
123
|
+
done();
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('percent-encoded % (%25) in password', (_t, done) => {
|
|
128
|
+
captureHandshake('amqp://user:pass%25word@localhost:TESTPORT', (err, result) => {
|
|
129
|
+
assert.ifError(err);
|
|
130
|
+
assert.strictEqual(result.username, 'user');
|
|
131
|
+
assert.strictEqual(result.password, 'pass%word');
|
|
132
|
+
done();
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// RabbitMQ URI spec example: amqp://user%61:%61pass@ho%61st:10000/v%2fhost
|
|
137
|
+
it('percent-encoded letters (%61 = "a") in username and password', (_t, done) => {
|
|
138
|
+
captureHandshake('amqp://user%61:%61pass@localhost:TESTPORT', (err, result) => {
|
|
139
|
+
assert.ifError(err);
|
|
140
|
+
assert.strictEqual(result.username, 'usera');
|
|
141
|
+
assert.strictEqual(result.password, 'apass');
|
|
142
|
+
done();
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe('vhost', () => {
|
|
149
|
+
|
|
150
|
+
it('no path defaults to vhost /', (_t, done) => {
|
|
151
|
+
captureHandshake('amqp://localhost:TESTPORT', (err, result) => {
|
|
152
|
+
assert.ifError(err);
|
|
153
|
+
assert.strictEqual(result.vhost, '/');
|
|
154
|
+
done();
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('explicit / path gives vhost /', (_t, done) => {
|
|
159
|
+
captureHandshake('amqp://localhost:TESTPORT/', (err, result) => {
|
|
160
|
+
assert.ifError(err);
|
|
161
|
+
assert.strictEqual(result.vhost, '/');
|
|
162
|
+
done();
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('named vhost', (_t, done) => {
|
|
167
|
+
captureHandshake('amqp://localhost:TESTPORT/myvhost', (err, result) => {
|
|
168
|
+
assert.ifError(err);
|
|
169
|
+
assert.strictEqual(result.vhost, 'myvhost');
|
|
170
|
+
done();
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
// The RabbitMQ spec requires %2F to represent a literal / in a vhost
|
|
175
|
+
it('percent-encoded slash (%2F) in vhost decodes to /', (_t, done) => {
|
|
176
|
+
captureHandshake('amqp://localhost:TESTPORT/%2F', (err, result) => {
|
|
177
|
+
assert.ifError(err);
|
|
178
|
+
assert.strictEqual(result.vhost, '/');
|
|
179
|
+
done();
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('percent-encoded slash lowercase (%2f) in vhost decodes to /', (_t, done) => {
|
|
184
|
+
captureHandshake('amqp://localhost:TESTPORT/%2f', (err, result) => {
|
|
185
|
+
assert.ifError(err);
|
|
186
|
+
assert.strictEqual(result.vhost, '/');
|
|
187
|
+
done();
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
// RabbitMQ URI spec example: /v%2fhost => "v/host"
|
|
192
|
+
it('mixed percent-encoding in vhost (v%2Fhost decodes to "v/host")', (_t, done) => {
|
|
193
|
+
captureHandshake('amqp://localhost:TESTPORT/v%2Fhost', (err, result) => {
|
|
194
|
+
assert.ifError(err);
|
|
195
|
+
assert.strictEqual(result.vhost, 'v/host');
|
|
196
|
+
done();
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('percent-encoded space (%20) in vhost', (_t, done) => {
|
|
201
|
+
captureHandshake('amqp://localhost:TESTPORT/my%20vhost', (err, result) => {
|
|
202
|
+
assert.ifError(err);
|
|
203
|
+
assert.strictEqual(result.vhost, 'my vhost');
|
|
204
|
+
done();
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
});
|