Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nodejs upgrade #298

Merged
merged 3 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ jobs:
node-version: [14.x]

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2.2.0
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

Expand All @@ -46,13 +46,13 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [14.x, 16.x]
node-version: [14.x, 16.x, 18.x, 20.x]
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2.2.0
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

Expand Down
109 changes: 61 additions & 48 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 19 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,29 @@
],
"license": "MIT",
"engines": {
"node": ">=8.0 <=16"
"node": ">=16"
},
"devDependencies": {
"@types/mocha": "10.0.x",
"@types/node": "18.11.x",
"cross-env": "7.0.x",
"mocha": "10.2.x",
"node-static": "0.7.x",
"prettier": "2.8.x",
"@types/mocha": "^10.0.6",
"@types/node": "^20.10.0",
"cross-env": "^7.0.3",
"mocha": "^10.2.0",
"node-static": "^0.7.11",
"prettier": "^3.1.0",
"request": "^2.88.2",
"rimraf": "3.0.x",
"ts-mocha": "10.0.x",
"ts-node": "10.9.x",
"typescript": "4.9.x"
"rimraf": "^3.0.2",
"ts-mocha": "^10.0.0",
"ts-node": "^10.9.1",
"typescript": "^5.3.2"
},
"dependencies": {
"async": "3.2.x",
"debug": "4.3.x",
"mkdirp": "1.0.x",
"node-forge": "1.3.x",
"semaphore": "1.1.x",
"uuid": "9.0.x",
"ws": "8.11.x",
"yargs": "17.6.x"
"async": "^3.2.5",
"debug": "^4.3.4",
"mkdirp": "^1.0.4",
"node-forge": "^1.3.1",
"semaphore": "^1.1.0",
"uuid": "^9.0.1",
"ws": "^8.14.2",
"yargs": "^17.7.2"
}
}
34 changes: 22 additions & 12 deletions test/01_proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import http from "http";
import net from "net";
import nodeStatic from "node-static";
import WebSocket from "ws";
import { Proxy } from "../lib/proxy";
import { Proxy } from "../";
import dns from "dns";

const fileStaticA = new nodeStatic.Server(`${__dirname}/wwwA`);
const fileStaticB = new nodeStatic.Server(`${__dirname}/wwwB`);
Expand All @@ -19,6 +20,10 @@ const testWSPort = 40007;
const testUrlA = `http://${testHost}:${testPortA}`;
const testUrlB = `http://${testHost}:${testPortB}`;

if (typeof dns.setDefaultResultOrder === "function") {
dns.setDefaultResultOrder("ipv4first");
}

const getHttp = (url, cb) => {
request({ url }, (err, resp, body) => {
cb(err, resp, body);
Expand Down Expand Up @@ -58,12 +63,12 @@ const countString = (str, substr, cb) => {

describe("proxy", function () {
this.timeout(30000);
let srvA = null;
let srvB = null;
let proxy = null;
let srvA: http.Server | null = null;
let srvB: http.Server | null = null;
let proxy: Proxy | null = null;
const testHashes = {};
const testFiles = ["1024.bin"];
let wss = null;
let wss: WebSocket.Server | null = null;

before((done) => {
testFiles.forEach((val) => {
Expand Down Expand Up @@ -116,23 +121,23 @@ describe("proxy", function () {
});

afterEach(() => {
proxy.close();
proxy?.close();
proxy = null;
});

after(() => {
srvA.close();
srvA?.close();
srvA = null;
srvB.close();
srvB?.close();
srvB = null;
wss.close();
wss?.close();
wss = null;
});

describe("ca server", () => {
it("should generate a root CA file", (done) => {
fs.access(`${__dirname}/../.http-mitm-proxy/certs/ca.pem`, (err) => {
let rtv = null;
let rtv: string | boolean | null = null;
if (err) {
rtv = `${__dirname}/../.http-mitm-proxy/certs/ca.pem ${err}`;
} else {
Expand Down Expand Up @@ -300,13 +305,14 @@ describe("proxy", function () {

describe("host match", () => {
it("proxy and modify AAA 5 times if hostA", (done) => {
assert.ok(proxy);
proxy.onRequest((ctx, callback) => {
const testHostNameA = `127.0.0.1:${testPortA}`;
if (ctx.clientToProxyRequest.headers.host === testHostNameA) {
const chunks = [];
const chunks: Buffer[] = [];
ctx.onResponseData((ctx, chunk, callback) => {
chunks.push(chunk);
return callback(null, null);
return callback(null, undefined);
});
ctx.onResponseEnd((ctx, callback) => {
let body = Buffer.concat(chunks).toString();
Expand Down Expand Up @@ -359,6 +365,7 @@ describe("proxy", function () {
});

it("should use chunked transfer encoding when global onResponseData is active", (done) => {
assert.ok(proxy);
proxy.onResponseData((ctx, chunk, callback) => {
callback(null, chunk);
});
Expand All @@ -375,6 +382,7 @@ describe("proxy", function () {
});

it("should use chunked transfer encoding when context onResponseData is active", (done) => {
assert.ok(proxy);
proxy.onResponse((ctx, callback) => {
ctx.onResponseData((ctx, chunk, callback) => {
callback(null, chunk);
Expand All @@ -394,6 +402,7 @@ describe("proxy", function () {
});

it("should use chunked transfer encoding when context ResponseFilter is active", (done) => {
assert.ok(proxy);
proxy.onResponse((ctx, callback) => {
ctx.addResponseFilter(zlib.createGzip());
callback(null);
Expand Down Expand Up @@ -454,6 +463,7 @@ describe("proxy", function () {
close: false,
};

assert.ok(proxy);
proxy.onWebSocketConnection((ctx, callback) => {
stats.connection = true;
return callback();
Expand Down
Empty file added test/mocha.setup.js
Empty file.