Skip to content

Commit

Permalink
fix ts errors in testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollon77 authored and joeferner committed Nov 25, 2023
1 parent 6e58756 commit ea3d072
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions test/01_proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,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 @@ -121,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 @@ -305,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 @@ -364,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 @@ -380,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 @@ -399,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 @@ -459,6 +463,7 @@ describe("proxy", function () {
close: false,
};

assert.ok(proxy);
proxy.onWebSocketConnection((ctx, callback) => {
stats.connection = true;
return callback();
Expand Down

0 comments on commit ea3d072

Please sign in to comment.