|
5 | 5 | validateImageUrl, |
6 | 6 | isExternalImageUrl, |
7 | 7 | getProxiedImageUrl, |
8 | | - proxyImagesInHtml, |
9 | 8 | } from '../../src/common/imageProxy'; |
10 | 9 |
|
11 | 10 | const configureCloudinary = () => { |
@@ -153,24 +152,6 @@ describe('imageProxy', () => { |
153 | 152 | expect(validateImageUrl(longUrl)).toBe('URL exceeds maximum length'); |
154 | 153 | }); |
155 | 154 |
|
156 | | - it('should return error for file:// protocol', () => { |
157 | | - expect(validateImageUrl('file:///etc/passwd')).toBe( |
158 | | - 'Only HTTP and HTTPS protocols are allowed', |
159 | | - ); |
160 | | - }); |
161 | | - |
162 | | - it('should return error for ftp:// protocol', () => { |
163 | | - expect(validateImageUrl('ftp://example.com/image.png')).toBe( |
164 | | - 'Only HTTP and HTTPS protocols are allowed', |
165 | | - ); |
166 | | - }); |
167 | | - |
168 | | - it('should return error for javascript: protocol', () => { |
169 | | - expect(validateImageUrl('javascript:alert(1)')).toBe( |
170 | | - 'Only HTTP and HTTPS protocols are allowed', |
171 | | - ); |
172 | | - }); |
173 | | - |
174 | 155 | it('should return error for private IP addresses', () => { |
175 | 156 | expect(validateImageUrl('http://127.0.0.1/image.png')).toBe( |
176 | 157 | 'Private IP addresses are not allowed', |
@@ -269,62 +250,4 @@ describe('imageProxy', () => { |
269 | 250 | expect(result).toMatch(/s--[A-Za-z0-9_-]+--/); |
270 | 251 | }); |
271 | 252 | }); |
272 | | - |
273 | | - describe('proxyImagesInHtml', () => { |
274 | | - beforeEach(() => { |
275 | | - process.env.CLOUDINARY_URL = 'cloudinary://test:test@daily-now'; |
276 | | - configureCloudinary(); |
277 | | - }); |
278 | | - |
279 | | - it('should return empty string for empty input', () => { |
280 | | - expect(proxyImagesInHtml('')).toBe(''); |
281 | | - }); |
282 | | - |
283 | | - it('should return null for null input', () => { |
284 | | - expect(proxyImagesInHtml(null as unknown as string)).toBe(null); |
285 | | - }); |
286 | | - |
287 | | - it('should proxy external image URLs in img tags', () => { |
288 | | - const html = '<p>Hello</p><img src="https://example.com/image.png">'; |
289 | | - const result = proxyImagesInHtml(html); |
290 | | - |
291 | | - expect(result).toContain('media.daily.dev'); |
292 | | - expect(result).toContain('/image/fetch/'); |
293 | | - // The original URL is included in the Cloudinary fetch URL path (this is expected) |
294 | | - expect(result).toContain('src="https://media.daily.dev'); |
295 | | - }); |
296 | | - |
297 | | - it('should not modify images from allowed domains', () => { |
298 | | - const html = '<img src="https://media.daily.dev/image.png">'; |
299 | | - const result = proxyImagesInHtml(html); |
300 | | - |
301 | | - expect(result).toBe(html); |
302 | | - }); |
303 | | - |
304 | | - it('should handle multiple images', () => { |
305 | | - const html = |
306 | | - '<img src="https://example.com/1.png"><img src="https://evil.com/2.gif">'; |
307 | | - const result = proxyImagesInHtml(html); |
308 | | - |
309 | | - // Both images should be proxied through Cloudinary |
310 | | - expect(result.match(/media\.daily\.dev/g)?.length).toBe(2); |
311 | | - expect(result).toContain('/image/fetch/'); |
312 | | - }); |
313 | | - |
314 | | - it('should preserve other attributes on img tags', () => { |
315 | | - const html = |
316 | | - '<img alt="test" src="https://example.com/image.png" class="photo">'; |
317 | | - const result = proxyImagesInHtml(html); |
318 | | - |
319 | | - expect(result).toContain('alt="test"'); |
320 | | - expect(result).toContain('class="photo"'); |
321 | | - }); |
322 | | - |
323 | | - it('should handle img tags with single quotes', () => { |
324 | | - const html = "<img src='https://example.com/image.png'>"; |
325 | | - const result = proxyImagesInHtml(html); |
326 | | - |
327 | | - expect(result).toContain('media.daily.dev'); |
328 | | - }); |
329 | | - }); |
330 | 253 | }); |
0 commit comments