Skip to content

Commit 0ae302a

Browse files
committed
[test] Fix nits
1 parent 1117af6 commit 0ae302a

File tree

1 file changed

+50
-46
lines changed

1 file changed

+50
-46
lines changed

test/websocket.test.js

+50-46
Original file line numberDiff line numberDiff line change
@@ -1273,14 +1273,11 @@ describe('WebSocket', () => {
12731273
ws.close();
12741274
});
12751275

1276-
const ws = new WebSocket(
1277-
`wss://localhost:${server.address().port}`,
1278-
{
1279-
auth: 'foo:bar',
1280-
followRedirects: true,
1281-
rejectUnauthorized: false
1282-
}
1283-
);
1276+
const ws = new WebSocket(`wss://localhost:${port}`, {
1277+
auth: 'foo:bar',
1278+
followRedirects: true,
1279+
rejectUnauthorized: false
1280+
});
12841281

12851282
assert.strictEqual(
12861283
ws._req.getHeader('Authorization'),
@@ -1297,13 +1294,7 @@ describe('WebSocket', () => {
12971294
});
12981295
});
12991296

1300-
it('drops the Authorization, and Cookie headers', (done) => {
1301-
const headers = {
1302-
authorization: 'Basic Zm9vOmJhcg==',
1303-
cookie: 'foo=bar',
1304-
host: 'foo'
1305-
};
1306-
1297+
it('drops the Authorization and Cookie headers', (done) => {
13071298
const httpServer = http.createServer();
13081299
const httpsServer = https.createServer({
13091300
cert: fs.readFileSync('test/fixtures/certificate.pem'),
@@ -1322,20 +1313,27 @@ describe('WebSocket', () => {
13221313
);
13231314
});
13241315

1316+
const headers = {
1317+
authorization: 'Basic Zm9vOmJhcg==',
1318+
cookie: 'foo=bar',
1319+
host: 'foo'
1320+
};
1321+
13251322
const wss = new WebSocket.Server({ server: httpServer });
13261323

13271324
wss.on('connection', (ws, req) => {
13281325
assert.strictEqual(req.headers.authorization, undefined);
13291326
assert.strictEqual(req.headers.cookie, undefined);
1330-
assert.strictEqual(req.headers.host, 'foo');
1327+
assert.strictEqual(req.headers.host, headers.host);
13311328

13321329
ws.close();
13331330
});
13341331

1335-
const ws = new WebSocket(
1336-
`wss://localhost:${server.address().port}`,
1337-
{ headers, followRedirects: true, rejectUnauthorized: false }
1338-
);
1332+
const ws = new WebSocket(`wss://localhost:${port}`, {
1333+
followRedirects: true,
1334+
headers,
1335+
rejectUnauthorized: false
1336+
});
13391337

13401338
const firstRequest = ws._req;
13411339

@@ -1362,12 +1360,6 @@ describe('WebSocket', () => {
13621360

13631361
describe("If there is at least one 'redirect' event listener", () => {
13641362
it('does not drop any headers by default', (done) => {
1365-
const headers = {
1366-
authorization: 'Basic Zm9vOmJhcg==',
1367-
cookie: 'foo=bar',
1368-
host: 'foo'
1369-
};
1370-
13711363
const httpServer = http.createServer();
13721364
const httpsServer = https.createServer({
13731365
cert: fs.readFileSync('test/fixtures/certificate.pem'),
@@ -1386,6 +1378,12 @@ describe('WebSocket', () => {
13861378
);
13871379
});
13881380

1381+
const headers = {
1382+
authorization: 'Basic Zm9vOmJhcg==',
1383+
cookie: 'foo=bar',
1384+
host: 'foo'
1385+
};
1386+
13891387
const wss = new WebSocket.Server({ server: httpServer });
13901388

13911389
wss.on('connection', (ws, req) => {
@@ -1399,10 +1397,11 @@ describe('WebSocket', () => {
13991397
ws.close();
14001398
});
14011399

1402-
const ws = new WebSocket(
1403-
`wss://localhost:${server.address().port}`,
1404-
{ headers, followRedirects: true, rejectUnauthorized: false }
1405-
);
1400+
const ws = new WebSocket(`wss://localhost:${port}`, {
1401+
followRedirects: true,
1402+
headers,
1403+
rejectUnauthorized: false
1404+
});
14061405

14071406
const firstRequest = ws._req;
14081407

@@ -1478,7 +1477,7 @@ describe('WebSocket', () => {
14781477
});
14791478
});
14801479

1481-
it('drops the Authorization, Cookie, and Host headers', (done) => {
1480+
it('drops the Authorization, Cookie and Host headers', (done) => {
14821481
const wss = new WebSocket.Server({ port: 0 }, () => {
14831482
const port = wss.address().port;
14841483

@@ -1489,24 +1488,28 @@ describe('WebSocket', () => {
14891488
);
14901489
});
14911490

1491+
const headers = {
1492+
authorization: 'Basic Zm9vOmJhcg==',
1493+
cookie: 'foo=bar',
1494+
host: 'foo'
1495+
};
1496+
14921497
const ws = new WebSocket(
14931498
`ws://localhost:${server.address().port}`,
1494-
{
1495-
headers: {
1496-
Authorization: 'Basic Zm9vOmJhcg==',
1497-
Cookie: 'foo=bar',
1498-
Host: 'foo'
1499-
},
1500-
followRedirects: true
1501-
}
1499+
{ followRedirects: true, headers }
15021500
);
15031501

1502+
const firstRequest = ws._req;
1503+
15041504
assert.strictEqual(
1505-
ws._req.getHeader('Authorization'),
1506-
'Basic Zm9vOmJhcg=='
1505+
firstRequest.getHeader('Authorization'),
1506+
headers.authorization
15071507
);
1508-
assert.strictEqual(ws._req.getHeader('Cookie'), 'foo=bar');
1509-
assert.strictEqual(ws._req.getHeader('Host'), 'foo');
1508+
assert.strictEqual(
1509+
firstRequest.getHeader('Cookie'),
1510+
headers.cookie
1511+
);
1512+
assert.strictEqual(firstRequest.getHeader('Host'), headers.host);
15101513

15111514
ws.on('close', (code) => {
15121515
assert.strictEqual(code, 1005);
@@ -1524,6 +1527,7 @@ describe('WebSocket', () => {
15241527
req.headers.host,
15251528
`localhost:${wss.address().port}`
15261529
);
1530+
15271531
ws.close();
15281532
});
15291533
});
@@ -1549,7 +1553,7 @@ describe('WebSocket', () => {
15491553

15501554
const ws = new WebSocket(
15511555
`ws://localhost:${server.address().port}`,
1552-
{ headers, followRedirects: true }
1556+
{ followRedirects: true, headers }
15531557
);
15541558

15551559
const firstRequest = ws._req;
@@ -1643,8 +1647,8 @@ describe('WebSocket', () => {
16431647
};
16441648

16451649
const ws = new WebSocket(`ws://localhost:${server.address().port}`, {
1646-
headers,
1647-
followRedirects: true
1650+
followRedirects: true,
1651+
headers
16481652
});
16491653

16501654
ws.on('redirect', (url, req) => {

0 commit comments

Comments
 (0)