Skip to content
File

Blob: src/workerd/api/node/tests/http-agent-nodejs-test.js

javascript131 lines
1// Copyright (c) 2017-2022 Cloudflare, Inc.
2// Licensed under the Apache 2.0 license found in the LICENSE file or at:
3// https://opensource.org/licenses/Apache-2.0
4 
5import http from 'node:http';
6import https from 'node:https';
7import { strictEqual, ok } from 'node:assert';
8 
9export const checkPortsSetCorrectly = {
10 test(_ctrl, env) {
11 const keys = ['SIDECAR_HOSTNAME', 'PONG_SERVER_PORT'];
12 for (const key of keys) {
13 strictEqual(typeof env[key], 'string');
14 ok(env[key].length > 0);
15 }
16 },
17};
18 
19// Test is taken from test/parallel/test-http-agent-getname.js
20export const testHttpAgentGetName = {
21 async test() {
22 const agent = new http.Agent();
23 
24 // Default to localhost
25 strictEqual(
26 agent.getName({
27 port: 80,
28 localAddress: '192.168.1.1',
29 }),
30 'localhost:80:192.168.1.1'
31 );
32 
33 // empty argument
34 strictEqual(agent.getName(), 'localhost::');
35 
36 // empty options
37 strictEqual(agent.getName({}), 'localhost::');
38 
39 // pass all arguments
40 strictEqual(
41 agent.getName({
42 host: '0.0.0.0',
43 port: 80,
44 localAddress: '192.168.1.1',
45 }),
46 '0.0.0.0:80:192.168.1.1'
47 );
48 
49 // unix socket
50 strictEqual(
51 agent.getName({
52 socketPath: '/tmp/foo/bar',
53 }),
54 `localhost:::/tmp/foo/bar`
55 );
56 
57 for (const family of [0, null, undefined, 'bogus'])
58 strictEqual(agent.getName({ family }), 'localhost::');
59 
60 for (const family of [4, 6])
61 strictEqual(agent.getName({ family }), `localhost:::${family}`);
62 },
63};
64 
65// Test is taken from test/parallel/test-http-agent-null.js
66export const testHttpAgentNull = {
67 async test(_ctrl, env) {
68 const { promise, resolve } = Promise.withResolvers();
69 http.get(
70 {
71 agent: null,
72 port: env.PONG_SERVER_PORT,
73 host: env.SIDECAR_HOSTNAME,
74 },
75 resolve
76 );
77 await promise;
78 },
79};
80 
81// Test is taken from test/parallel/test-https-agent-constructor.js
82export const testHttpsAgentConstructor = {
83 async test() {
84 ok(new https.Agent() instanceof https.Agent);
85 strictEqual(typeof https.request, 'function');
86 strictEqual(typeof http.get, 'function');
87 },
88};
89 
90// Tests covering http-agent
91// - [ ] test/parallel/test-http-agent-abort-controller.js
92// - [ ] test/parallel/test-http-agent-close.js
93// - [ ] test/parallel/test-http-agent-destroyed-socket.js
94// - [ ] test/parallel/test-http-agent-domain-reused-gc.js
95// - [ ] test/parallel/test-http-agent-error-on-idle.js
96// - [ ] test/parallel/test-http-agent-false.js
97// - [x] test/parallel/test-http-agent-getname.js
98// - [ ] test/parallel/test-http-agent-keepalive-delay.js
99// - [ ] test/parallel/test-http-agent-keepalive.js
100// - [ ] test/parallel/test-http-agent-maxsockets-respected.js
101// - [ ] test/parallel/test-http-agent-maxsockets.js
102// - [ ] test/parallel/test-http-agent-maxtotalsockets.js
103// - [ ] test/parallel/test-http-agent-no-protocol.js
104// - [x] test/parallel/test-http-agent-null.js
105// - [ ] test/parallel/test-http-agent-remove.js
106// - [ ] test/parallel/test-http-agent-reuse-drained-socket-only.js
107// - [ ] test/parallel/test-http-agent-scheduling.js
108// - [ ] test/parallel/test-http-agent-timeout-option.js
109// - [ ] test/parallel/test-http-agent-timeout.js
110// - [ ] test/parallel/test-http-agent-uninitialized-with-handle.js
111// - [ ] test/parallel/test-http-agent.js
112// - [ ] test/parallel/test-https-agent-abort-controller.js
113// - [ ] test/parallel/test-https-agent-additional-options.js
114// - [x] test/parallel/test-https-agent-constructor.js
115// - [ ] test/parallel/test-https-agent-create-connection.js
116// - [ ] test/parallel/test-https-agent-disable-session-reuse.js
117// - [ ] test/parallel/test-https-agent-getname.js
118// - [ ] test/parallel/test-https-agent-keylog.js
119// - [ ] test/parallel/test-https-agent-servername.js
120// - [ ] test/parallel/test-https-agent-session-eviction.js
121// - [ ] test/parallel/test-https-agent-session-injection.js
122// - [ ] test/parallel/test-https-agent-session-reuse.js
123// - [ ] test/parallel/test-https-agent-sni.js
124// - [ ] test/parallel/test-https-agent-sockets-leak.js
125// - [ ] test/parallel/test-https-agent-unref-socket.js
126// - [ ] test/parallel/test-https-agent.js
127 
128// Tests doesn't make sense for workerd:
129//
130// - [ ] test/parallel/test-http-agent-uninitialized.js