Skip to content

Commit

Permalink
test: update 'proxy' dependency to v2 (#28895)
Browse files Browse the repository at this point in the history
This won't fix it yet, but prepare for a smaller version bump once the
upstream fix has been merged.
#28701.
  • Loading branch information
mxschmitt authored Jan 8, 2024
1 parent 1d8c6d4 commit 0f3bd98
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 28 deletions.
59 changes: 39 additions & 20 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"mime": "^3.0.0",
"ncp": "^2.0.0",
"node-stream-zip": "^1.15.0",
"proxy": "^1.0.2",
"proxy": "^2.1.1",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"socksv5": "0.0.6",
Expand Down
15 changes: 8 additions & 7 deletions tests/config/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
* limitations under the License.
*/

import type { IncomingMessage, Server } from 'http';
import type { IncomingMessage } from 'http';
import type { Socket } from 'net';
import createProxy from 'proxy';
import type { ProxyServer } from 'proxy';
import { createProxy } from 'proxy';

export class TestProxy {
readonly PORT: number;
Expand All @@ -25,7 +26,7 @@ export class TestProxy {
connectHosts: string[] = [];
requestUrls: string[] = [];

private readonly _server: Server;
private readonly _server: ProxyServer;
private readonly _sockets = new Set<Socket>();
private _handlers: { event: string, handler: (...args: any[]) => void }[] = [];

Expand Down Expand Up @@ -66,11 +67,11 @@ export class TestProxy {
}

setAuthHandler(handler: (req: IncomingMessage) => boolean) {
(this._server as any).authenticate = (req: IncomingMessage, callback) => {
this._server.authenticate = (req: IncomingMessage) => {
try {
callback(null, handler(req));
return handler(req);
} catch (e) {
callback(e, false);
return false;
}
};
}
Expand All @@ -81,7 +82,7 @@ export class TestProxy {
for (const { event, handler } of this._handlers)
this._server.removeListener(event, handler);
this._handlers = [];
(this._server as any).authenticate = undefined;
this._server.authenticate = undefined;
}

private _prependHandler(event: string, handler: (...args: any[]) => void) {
Expand Down

0 comments on commit 0f3bd98

Please sign in to comment.