Skip to content

Commit

Permalink
Merge pull request #1097 from golemfactory/bugfix/JST-1092
Browse files Browse the repository at this point in the history
fix(tcp-proxy): throw an error when users try to use proxy in browser
  • Loading branch information
SewerynKras authored Oct 11, 2024
2 parents 2c70207 + 9ef96fd commit 98bdb31
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 0 additions & 1 deletion package-lock.json

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

15 changes: 15 additions & 0 deletions src/network/tcp-proxy.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
jest.mock("../shared/utils", () => ({
checkAndThrowUnsupportedInBrowserError: () => {
throw new GolemUserError("Not supported in browser");
},
}));

import { GolemUserError } from "../shared/error/golem-error";

import { TcpProxy } from "./tcp-proxy";

describe("TCP Proxy in browser", () => {
test("Uses the checkAndThrowUnsupportedInBrowserError util to throw when the function detects browser environment", () => {
expect(() => new TcpProxy("ws://fake.url", "fake-app-key")).toThrow("Not supported in browser");
});
});
6 changes: 4 additions & 2 deletions src/network/tcp-proxy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import net from "net";
import { WebSocket } from "ws";
import { EventEmitter } from "eventemitter3";
import { defaultLogger, Logger } from "../shared/utils";
import { checkAndThrowUnsupportedInBrowserError, defaultLogger, Logger } from "../shared/utils";
import { Buffer } from "buffer";

export interface TcpProxyEvents {
Expand Down Expand Up @@ -64,8 +64,10 @@ export class TcpProxy {
/**
* Additional options of the proxy
*/
options: Partial<TcpProxyOptions>,
options: Partial<TcpProxyOptions> = {},
) {
checkAndThrowUnsupportedInBrowserError("TCP Proxy");

this.heartBeatSec = options.heartBeatSec ?? 10;
this.logger = options.logger ? options.logger.child("tcp-proxy") : defaultLogger("tcp-proxy");

Expand Down

0 comments on commit 98bdb31

Please sign in to comment.