Skip to content

Commit

Permalink
Merge branch 'joeferner:master' into fixtests
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollon77 authored Nov 25, 2023
2 parents dbecd82 + 90bca40 commit 6f6a7b9
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 86 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,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 @@ -50,13 +50,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
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
HTTP Man In The Middle (MITM) Proxy written in node.js. Supports capturing and modifying the request and response data.

[![NPM version](http://img.shields.io/npm/v/http-mitm-proxy.svg)](https://www.npmjs.com/package/http-mitm-proxy)
[![](https://david-dm.org/joeferner/node-http-mitm-proxy.svg)](https://david-dm.org/joeferner/node-http-mitm-proxy)
[![Downloads](https://img.shields.io/npm/dm/http-mitm-proxy.svg)](https://www.npmjs.com/package/http-mitm-proxy)
![Test Status](https://github.com/joeferner/node-http-mitm-proxy/workflows/Tests/badge.svg)
[![Test Status](https://github.com/joeferner/node-http-mitm-proxy/workflows/Tests/badge.svg)](https://github.com/joeferner/node-http-mitm-proxy/actions)

# Install

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.

0 comments on commit 6f6a7b9

Please sign in to comment.