deno.land / std@0.166.0 / node / _tools / test / parallel / test-net-listen-invalid-port.js

test-net-listen-invalid-port.js
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// deno-fmt-ignore-file// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.// Taken from Node 16.13.0// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';const common = require('../common');
// This test ensures that port numbers are validated in *all* kinds of `listen`// calls. If an invalid port is supplied, ensures a `RangeError` is thrown.// https://github.com/nodejs/node/issues/5727
const assert = require('assert');const net = require('net');
const invalidPort = -1 >>> 0;
// TODO: support net.Server() without new
new net.Server().listen(0, function() { const address = this.address(); const key = `${address.family}:${address.address}:0`;
assert.strictEqual(this._connectionKey, key); this.close();});
// The first argument is a configuration objectassert.throws(() => { new net.Server().listen({ port: invalidPort }, common.mustNotCall());}, { code: 'ERR_SOCKET_BAD_PORT', name: 'RangeError'});
// The first argument is the port, no IP given.assert.throws(() => { new net.Server().listen(invalidPort, common.mustNotCall());}, { code: 'ERR_SOCKET_BAD_PORT', name: 'RangeError'});
// The first argument is the port, the second an IP.assert.throws(() => { new net.Server().listen(invalidPort, '0.0.0.0', common.mustNotCall());}, { code: 'ERR_SOCKET_BAD_PORT', name: 'RangeError'});
std

Version Info

Tagged at
a year ago