@@ -49,7 +49,8 @@ describe('RemoteStorage', () => {
4949 sessionToken : global . fakeTVMResponse . sessionToken ,
5050 expiration : new Date ( global . fakeTVMResponse . expiration )
5151 } ,
52- region : 'us-east-1'
52+ region : 'us-east-1' ,
53+ requestHandler : expect . any ( Object )
5354 } )
5455 rs . bucket = global . fakeTVMResponse . Bucket
5556 } )
@@ -59,13 +60,122 @@ describe('RemoteStorage', () => {
5960 expect ( S3 ) . toHaveBeenCalledWith ( {
6061 credentials : {
6162 accessKeyId : global . fakeTVMResponse . accessKeyId ,
62- secretAccessKey : global . fakeTVMResponse . secretAccessKey
63+ secretAccessKey : global . fakeTVMResponse . secretAccessKey ,
64+ sessionToken : undefined ,
65+ expiration : undefined
6366 } ,
64- region : 'us-east-1'
67+ region : 'us-east-1' ,
68+ requestHandler : expect . any ( Object )
6569 } )
6670 rs . bucket = global . fakeTVMResponse . Bucket
6771 } )
6872
73+ describe ( 'Proxy configuration' , ( ) => {
74+ const originalEnv = process . env
75+
76+ beforeEach ( ( ) => {
77+ // Clear environment variables before each test
78+ delete process . env . https_proxy
79+ delete process . env . HTTPS_PROXY
80+ delete process . env . http_proxy
81+ delete process . env . HTTP_PROXY
82+ } )
83+
84+ afterAll ( ( ) => {
85+ // Restore original environment
86+ process . env = originalEnv
87+ } )
88+
89+ test ( 'Constructor uses HTTPS_PROXY when set (uppercase)' , async ( ) => {
90+ process . env . HTTPS_PROXY = 'http://proxy.example.com:8080'
91+ // eslint-disable-next-line no-new
92+ new RemoteStorage ( global . fakeTVMResponse )
93+
94+ expect ( S3 ) . toHaveBeenCalledWith ( expect . objectContaining ( {
95+ requestHandler : expect . any ( Object ) ,
96+ credentials : expect . any ( Object ) ,
97+ region : 'us-east-1'
98+ } ) )
99+ } )
100+
101+ test ( 'Constructor uses https_proxy when set (lowercase)' , async ( ) => {
102+ process . env . https_proxy = 'http://proxy.example.com:3128'
103+ // eslint-disable-next-line no-new
104+ new RemoteStorage ( global . fakeTVMResponse )
105+
106+ expect ( S3 ) . toHaveBeenCalledWith ( expect . objectContaining ( {
107+ requestHandler : expect . any ( Object ) ,
108+ credentials : expect . any ( Object ) ,
109+ region : 'us-east-1'
110+ } ) )
111+ } )
112+
113+ test ( 'Constructor uses HTTP_PROXY when HTTPS_PROXY not set' , async ( ) => {
114+ process . env . HTTP_PROXY = 'http://proxy.example.com:8080'
115+ // eslint-disable-next-line no-new
116+ new RemoteStorage ( global . fakeTVMResponse )
117+
118+ expect ( S3 ) . toHaveBeenCalledWith ( expect . objectContaining ( {
119+ requestHandler : expect . any ( Object ) ,
120+ credentials : expect . any ( Object ) ,
121+ region : 'us-east-1'
122+ } ) )
123+ } )
124+
125+ test ( 'Constructor uses http_proxy when other proxy vars not set' , async ( ) => {
126+ process . env . http_proxy = 'http://proxy.example.com:3128'
127+ // eslint-disable-next-line no-new
128+ new RemoteStorage ( global . fakeTVMResponse )
129+
130+ expect ( S3 ) . toHaveBeenCalledWith ( expect . objectContaining ( {
131+ requestHandler : expect . any ( Object ) ,
132+ credentials : expect . any ( Object ) ,
133+ region : 'us-east-1'
134+ } ) )
135+ } )
136+
137+ test ( 'Constructor prioritizes HTTPS_PROXY over HTTP_PROXY' , async ( ) => {
138+ process . env . HTTPS_PROXY = 'http://https-proxy.example.com:8080'
139+ process . env . HTTP_PROXY = 'http://http-proxy.example.com:8080'
140+ // eslint-disable-next-line no-new
141+ new RemoteStorage ( global . fakeTVMResponse )
142+
143+ expect ( S3 ) . toHaveBeenCalledWith ( expect . objectContaining ( {
144+ requestHandler : expect . any ( Object ) ,
145+ credentials : expect . any ( Object ) ,
146+ region : 'us-east-1'
147+ } ) )
148+ } )
149+
150+ test ( 'Constructor prioritizes https_proxy over HTTP_PROXY' , async ( ) => {
151+ process . env . https_proxy = 'http://https-proxy.example.com:3128'
152+ process . env . HTTP_PROXY = 'http://http-proxy.example.com:8080'
153+ // eslint-disable-next-line no-new
154+ new RemoteStorage ( global . fakeTVMResponse )
155+
156+ expect ( S3 ) . toHaveBeenCalledWith ( expect . objectContaining ( {
157+ requestHandler : expect . any ( Object ) ,
158+ credentials : expect . any ( Object ) ,
159+ region : 'us-east-1'
160+ } ) )
161+ } )
162+
163+ test ( 'Constructor always includes requestHandler with ProxyAgent' , async ( ) => {
164+ // eslint-disable-next-line no-new
165+ new RemoteStorage ( global . fakeTVMResponse )
166+
167+ expect ( S3 ) . toHaveBeenCalledWith ( {
168+ credentials : expect . any ( Object ) ,
169+ region : 'us-east-1' ,
170+ requestHandler : expect . any ( Object )
171+ } )
172+
173+ // ProxyAgent handles proxy detection automatically via proxy-from-env
174+ const s3CallArgs = S3 . mock . calls [ S3 . mock . calls . length - 1 ] [ 0 ]
175+ expect ( s3CallArgs ) . toHaveProperty ( 'requestHandler' )
176+ } )
177+ } )
178+
69179 test ( 'folderExists missing prefix' , async ( ) => {
70180 const rs = new RemoteStorage ( global . fakeTVMResponse )
71181 await expect ( rs . folderExists ( ) ) . rejects . toEqual ( expect . objectContaining ( { message : 'prefix must be a valid string' } ) )
0 commit comments