|
1 | 1 | import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
2 | 2 | import "../test-support/browser-security.mock.js"; |
3 | 3 | import type { OpenClawConfig } from "../config/config.js"; |
| 4 | +import type { BrowserControlAuth } from "./control-auth.js"; |
4 | 5 | import type { BrowserDispatchResponse } from "./routes/dispatcher.js"; |
5 | 6 | |
| 7 | +type BridgeAuth = NonNullable< |
| 8 | +ReturnType<typeof import("./bridge-auth-registry.js").getBridgeAuthForPort> |
| 9 | +>; |
| 10 | + |
6 | 11 | vi.mock("openclaw/plugin-sdk/ssrf-runtime", async () => { |
7 | 12 | const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/ssrf-runtime")>( |
8 | 13 | "openclaw/plugin-sdk/ssrf-runtime", |
@@ -36,11 +41,10 @@ const mocks = vi.hoisted(() => ({
|
36 | 41 | }, |
37 | 42 | }, |
38 | 43 | })), |
39 | | -resolveBrowserControlAuth: vi.fn(() => ({ |
| 44 | +resolveBrowserControlAuth: vi.fn<() => BrowserControlAuth>(() => ({ |
40 | 45 | token: "loopback-token", |
41 | | -password: undefined, |
42 | 46 | })), |
43 | | -getBridgeAuthForPort: vi.fn(() => null), |
| 47 | +getBridgeAuthForPort: vi.fn<(port: number) => BridgeAuth | undefined>(() => undefined), |
44 | 48 | startBrowserControlServiceFromConfig: vi.fn(async () => ({ ok: true })), |
45 | 49 | dispatch: vi.fn(async (): Promise<BrowserDispatchResponse> => okDispatchResponse()), |
46 | 50 | })); |
@@ -143,9 +147,8 @@ describe("fetchBrowserJson loopback auth", () => {
|
143 | 147 | mocks.dispatch.mockReset().mockResolvedValue(okDispatchResponse()); |
144 | 148 | mocks.resolveBrowserControlAuth.mockReset().mockReturnValue({ |
145 | 149 | token: "loopback-token", |
146 | | -password: undefined, |
147 | 150 | }); |
148 | | -mocks.getBridgeAuthForPort.mockReset().mockReturnValue(null); |
| 151 | +mocks.getBridgeAuthForPort.mockReset().mockReturnValue(undefined); |
149 | 152 | }); |
150 | 153 | |
151 | 154 | afterEach(() => { |
@@ -209,10 +212,7 @@ describe("fetchBrowserJson loopback auth", () => {
|
209 | 212 | }); |
210 | 213 | |
211 | 214 | it("does not treat explicit port zero as the default loopback bridge port", async () => { |
212 | | -mocks.resolveBrowserControlAuth.mockReturnValueOnce({ |
213 | | -token: undefined, |
214 | | -password: undefined, |
215 | | -}); |
| 215 | +mocks.resolveBrowserControlAuth.mockReturnValueOnce({}); |
216 | 216 | mocks.getBridgeAuthForPort.mockReturnValueOnce({ token: "bridge-token" }); |
217 | 217 | const fetchMock = stubJsonFetchOk(); |
218 | 218 | |
|