@@ -7,16 +7,6 @@ import { createDiscordRestClient } from "./client.js";
77import { createDiscordRequestClient } from "./proxy-request-client.js" ;
88
99const makeProxyFetchMock = vi . hoisted ( ( ) => vi . fn ( ) ) ;
10- const proxyEnvKeys = [
11- "OPENCLAW_PROXY_URL" ,
12- "HTTP_PROXY" ,
13- "HTTPS_PROXY" ,
14- "ALL_PROXY" ,
15- "http_proxy" ,
16- "https_proxy" ,
17- "all_proxy" ,
18- ] as const ;
19-
2010vi . mock ( "openclaw/plugin-sdk/fetch-runtime" , async ( ) => {
2111 const actual = await vi . importActual < typeof import ( "openclaw/plugin-sdk/fetch-runtime" ) > (
2212 "openclaw/plugin-sdk/fetch-runtime" ,
@@ -36,9 +26,6 @@ vi.mock("openclaw/plugin-sdk/fetch-runtime", async () => {
3626describe ( "createDiscordRestClient proxy support" , ( ) => {
3727 beforeEach ( ( ) => {
3828 vi . unstubAllEnvs ( ) ;
39- for ( const key of proxyEnvKeys ) {
40- vi . stubEnv ( key , undefined ) ;
41- }
4229 makeProxyFetchMock . mockClear ( ) ;
4330 } ) ;
4431
@@ -67,8 +54,7 @@ describe("createDiscordRestClient proxy support", () => {
6754 expect ( requestClient . customFetch ) . toBe ( requestClient . options ?. fetch ) ;
6855 } ) ;
6956
70- it ( "accepts the configured process proxy DNS host" , ( ) => {
71- vi . stubEnv ( "HTTPS_PROXY" , "http://mitm-proxy:8080" ) ;
57+ it ( "accepts configured DNS proxy hosts" , ( ) => {
7258 const cfg = {
7359 channels : {
7460 discord : {
@@ -89,13 +75,12 @@ describe("createDiscordRestClient proxy support", () => {
8975 expect ( requestClient . customFetch ) . toBe ( requestClient . options ?. fetch ) ;
9076 } ) ;
9177
92- it ( "accepts a proxy URL that matches ALL_PROXY" , ( ) => {
93- vi . stubEnv ( "ALL_PROXY" , "http://mitm-proxy:8080" ) ;
78+ it ( "accepts configured HTTPS proxy hosts" , ( ) => {
9479 const cfg = {
9580 channels : {
9681 discord : {
9782 token : "Bot test-token" ,
98- proxy : "http ://mitm- proxy:8080 " ,
83+ proxy : "https ://proxy.example:8443 " ,
9984 } ,
10085 } ,
10186 } as OpenClawConfig ;
@@ -106,60 +91,17 @@ describe("createDiscordRestClient proxy support", () => {
10691 options ?: { fetch ?: typeof fetch } ;
10792 } ;
10893
109- expect ( makeProxyFetchMock ) . toHaveBeenCalledWith ( "http ://mitm- proxy:8080 " ) ;
94+ expect ( makeProxyFetchMock ) . toHaveBeenCalledWith ( "https ://proxy.example:8443 " ) ;
11095 expect ( requestClient . options ?. fetch ) . toBe ( makeProxyFetchMock . mock . results [ 0 ] ?. value ) ;
11196 expect ( requestClient . customFetch ) . toBe ( requestClient . options ?. fetch ) ;
11297 } ) ;
11398
114- it ( "rejects a configured process proxy host when credentials do not match" , ( ) => {
115- vi . stubEnv ( "HTTPS_PROXY" , "http://user:secret@mitm-proxy:8080" ) ;
116- const cfg = {
117- channels : {
118- discord : {
119- token : "Bot test-token" ,
120- proxy : "http://mitm-proxy:8080" ,
121- } ,
122- } ,
123- } as OpenClawConfig ;
124-
125- const { rest } = createDiscordRestClient ( { cfg } ) ;
126- const requestClient = rest as unknown as {
127- options ?: { fetch ?: typeof fetch } ;
128- } ;
129-
130- expect ( makeProxyFetchMock ) . not . toHaveBeenCalledWith ( "http://mitm-proxy:8080" ) ;
131- expect ( requestClient . options ?. fetch ) . toBeUndefined ( ) ;
132- } ) ;
133-
134- it ( "rejects a shadowed uppercase proxy env URL" , ( ) => {
135- vi . stubEnv ( "HTTPS_PROXY" , "http://mitm-proxy:8080" ) ;
136- vi . stubEnv ( "https_proxy" , "http://active-proxy:8080" ) ;
137- const cfg = {
138- channels : {
139- discord : {
140- token : "Bot test-token" ,
141- proxy : "http://mitm-proxy:8080" ,
142- } ,
143- } ,
144- } as OpenClawConfig ;
145-
146- const { rest } = createDiscordRestClient ( { cfg } ) ;
147- const requestClient = rest as unknown as {
148- options ?: { fetch ?: typeof fetch } ;
149- } ;
150-
151- expect ( makeProxyFetchMock ) . not . toHaveBeenCalledWith ( "http://mitm-proxy:8080" ) ;
152- expect ( requestClient . options ?. fetch ) . toBeUndefined ( ) ;
153- } ) ;
154-
155- it ( "rejects stale OPENCLAW_PROXY_URL when the active process proxy differs" , ( ) => {
156- vi . stubEnv ( "OPENCLAW_PROXY_URL" , "http://stale-proxy:8080" ) ;
157- vi . stubEnv ( "HTTPS_PROXY" , "http://active-proxy:8080" ) ;
99+ it ( "accepts configured proxy URLs with credentials" , ( ) => {
158100 const cfg = {
159101 channels : {
160102 discord : {
161103 token : "Bot test-token" ,
162- proxy : "http://stale -proxy:8080" ,
104+ proxy : "http://user:secret@mitm -proxy:8080" ,
163105 } ,
164106 } ,
165107 } as OpenClawConfig ;
@@ -169,11 +111,11 @@ describe("createDiscordRestClient proxy support", () => {
169111 options ?: { fetch ?: typeof fetch } ;
170112 } ;
171113
172- expect ( makeProxyFetchMock ) . not . toHaveBeenCalledWith ( "http://stale -proxy:8080" ) ;
173- expect ( requestClient . options ?. fetch ) . toBeUndefined ( ) ;
114+ expect ( makeProxyFetchMock ) . toHaveBeenCalledWith ( "http://user:secret@mitm -proxy:8080" ) ;
115+ expect ( requestClient . options ?. fetch ) . toBe ( makeProxyFetchMock . mock . results [ 0 ] ?. value ) ;
174116 } ) ;
175117
176- it ( "falls back to direct fetch when the Discord proxy URL is arbitrary DNS " , ( ) => {
118+ it ( "accepts arbitrary configured DNS proxy hosts " , ( ) => {
177119 const cfg = {
178120 channels : {
179121 discord : {
@@ -188,8 +130,8 @@ describe("createDiscordRestClient proxy support", () => {
188130 options ?: { fetch ?: typeof fetch } ;
189131 } ;
190132
191- expect ( makeProxyFetchMock ) . not . toHaveBeenCalledWith ( "http://proxy.test:8080" ) ;
192- expect ( requestClient . options ?. fetch ) . toBeUndefined ( ) ;
133+ expect ( makeProxyFetchMock ) . toHaveBeenCalledWith ( "http://proxy.test:8080" ) ;
134+ expect ( requestClient . options ?. fetch ) . toBe ( makeProxyFetchMock . mock . results [ 0 ] ?. value ) ;
193135 } ) ;
194136
195137 it ( "does not inject fetch when no proxy is configured" , ( ) => {
@@ -228,7 +170,7 @@ describe("createDiscordRestClient proxy support", () => {
228170 expect ( requestClient . options ?. fetch ) . toBeUndefined ( ) ;
229171 } ) ;
230172
231- it ( "falls back to direct fetch when the Discord proxy URL is a non-loopback IP" , ( ) => {
173+ it ( "accepts configured non-loopback IP proxy URLs " , ( ) => {
232174 const cfg = {
233175 channels : {
234176 discord : {
@@ -243,8 +185,8 @@ describe("createDiscordRestClient proxy support", () => {
243185 options ?: { fetch ?: typeof fetch } ;
244186 } ;
245187
246- expect ( makeProxyFetchMock ) . not . toHaveBeenCalledWith ( "http://10.0.0.10:8080" ) ;
247- expect ( requestClient . options ?. fetch ) . toBeUndefined ( ) ;
188+ expect ( makeProxyFetchMock ) . toHaveBeenCalledWith ( "http://10.0.0.10:8080" ) ;
189+ expect ( requestClient . options ?. fetch ) . toBe ( makeProxyFetchMock . mock . results [ 0 ] ?. value ) ;
248190 } ) ;
249191
250192 it ( "accepts IPv6 loopback Discord proxy URLs" , ( ) => {
0 commit comments