Skip to content

Commit 12ff03c

Browse files
committed
Add tests for proxy with unix socket
1 parent a588fcd commit 12ff03c

File tree

6 files changed

+33
-17
lines changed

6 files changed

+33
-17
lines changed

bin/configurable-http-proxy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ options.storageBackend = args.storageBackend;
325325

326326
var proxy = new ConfigurableProxy(options);
327327

328-
var listen = parseListenOptions(args);
328+
var listen = parseListenOptions(args, log);
329329

330330
proxy.proxyServer.listen(...listen.proxyTarget);
331331
proxy.apiServer.listen(...listen.apiTarget);

lib/configproxy.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,40 +24,40 @@ const require = createRequire(import.meta.url);
2424

2525
const __dirname = path.dirname(fileURLToPath(import.meta.url));
2626

27-
export function parseListenOptions(args) {
27+
export function parseListenOptions(args, logger) {
2828
var listen = {};
2929

3030
if (args.socket) {
3131
listen.proxyTarget = [args.socket];
32-
log.warn(
32+
logger.warn(
3333
"Proxy will listen on UNIX domain socket, --ip and --port options will be ignored."
3434
);
3535
} else {
3636
listen.port = parseInt(args.port) || 8000;
3737
if (args.ip === "*") {
3838
// handle ip=* alias for all interfaces
39-
log.warn(
39+
logger.warn(
4040
"Interpreting ip='*' as all-interfaces. Preferred usage is 0.0.0.0 for all IPv4 or '' for all-interfaces."
4141
);
4242
args.ip = "";
4343
}
4444
listen.ip = args.ip;
4545
listen.proxyTarget = [listen.port, listen.ip];
4646
}
47-
47+
4848
if (args.apiSocket) {
4949
listen.apiSocket = [args.apiSocket];
50-
log.warn(
50+
logger.warn(
5151
"API server will listen on UNIX domain socket, --api-ip and --api-port options will be ignored."
5252
);
5353
} else {
54-
listen.apiPort = args.apiPort ? parseInt(args.apiPort) : (listen.port ? listen.port + 1 : 8001);
54+
listen.apiPort = args.apiPort ? parseInt(args.apiPort) : listen.port ? listen.port + 1 : 8001;
5555
listen.apiTarget = [listen.apiPort, args.apiIp];
5656
}
57-
57+
5858
if (args.metricsSocket) {
5959
listen.metricsSocket = [args.metricsSocket];
60-
log.warn(
60+
logger.warn(
6161
"Metrics server will listen on UNIX domain socket, --metrics-ip and --metrics-port options will be ignored."
6262
);
6363
} else if (args.metricsPort) {

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"c8": "^10.1.3",
1919
"jasmine": "^5.6.0",
2020
"node-fetch": "^2.7.0",
21-
"ws": "^8.4.0"
21+
"ws": "^8.4.0",
22+
"tmp": "^0.2"
2223
},
2324
"engines": {
2425
"node": ">= 18"

test/api_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe("API Tests", function () {
1111
var listenOptions = {
1212
port: port,
1313
apiPort: 8903,
14-
ip: '127.0.0.1'
14+
ip: "127.0.0.1",
1515
};
1616
var proxy;
1717
var apiUrl = "http://" + listenOptions.ip + ":" + listenOptions.apiPort + "/api/routes";

test/proxy_spec.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import fs from "node:fs";
22
import path from "node:path";
3+
import tmp from "tmp"
34
import { fileURLToPath } from "node:url";
45
import fetch from "node-fetch";
56
import WebSocket from "ws";
67

78
import { ConfigurableProxy } from "../lib/configproxy.js";
89
import * as util from "../lib/testutil.js";
10+
import http from "node:http";
911

1012
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
1113

@@ -15,7 +17,7 @@ describe("Proxy Tests", function () {
1517
var port = 8902;
1618
var listenOptions = {
1719
port: port,
18-
ip: '127.0.0.1'
20+
ip: "127.0.0.1",
1921
};
2022
var testPort = port + 10;
2123
var proxy;
@@ -343,7 +345,7 @@ describe("Proxy Tests", function () {
343345

344346
it("custom error target", function (done) {
345347
var listenOptions = {
346-
port: 55550
348+
port: 55550,
347349
};
348350
util
349351
.setupProxy(listenOptions, { errorTarget: "http://127.0.0.1:55565" }, [])
@@ -412,7 +414,7 @@ describe("Proxy Tests", function () {
412414

413415
it("backend error", function (done) {
414416
var listenOptions = {
415-
port: 55550
417+
port: 55550,
416418
};
417419
util
418420
.setupProxy(listenOptions, { errorTarget: "http://127.0.0.1:55565" }, [])
@@ -442,7 +444,7 @@ describe("Proxy Tests", function () {
442444

443445
it("Redirect location with rewriting", function (done) {
444446
var listenOptions = {
445-
port: 55556
447+
port: 55556,
446448
};
447449
var options = {
448450
protocolRewrite: "https",
@@ -466,7 +468,9 @@ describe("Proxy Tests", function () {
466468
)
467469
)
468470
.then(() =>
469-
fetch("http://127.0.0.1:" + listenOptions.port + "/external/urlpath/", { redirect: "manual" })
471+
fetch("http://127.0.0.1:" + listenOptions.port + "/external/urlpath/", {
472+
redirect: "manual",
473+
})
470474
)
471475
.then((res) => {
472476
expect(res.status).toEqual(301);
@@ -494,7 +498,7 @@ describe("Proxy Tests", function () {
494498
return;
495499
}
496500
var listenOptions = {
497-
port: 55556
501+
port: 55556,
498502
};
499503
var testPort = listenOptions.port + 20;
500504
var options = {

0 commit comments

Comments
 (0)