@@ -199,6 +199,55 @@ describe("HEIC input image normalization", () => {
199199 mimeType : "image/jpeg" ,
200200 } ,
201201 } ,
202+ {
203+ name : "converts sniffed HEIC sequence images using the existing HEIC allowlist" ,
204+ source : {
205+ type : "base64" ,
206+ data : Buffer . from ( "heic-sequence-source" ) . toString ( "base64" ) ,
207+ mediaType : "image/heic" ,
208+ } as const ,
209+ limits : createImageSourceLimits ( [ "image/heic" , "image/jpeg" ] ) ,
210+ detectedMime : "image/heic-sequence" ,
211+ convertedBytes : Buffer . from ( "jpeg-heic-sequence" ) ,
212+ expectedImage : {
213+ type : "image" ,
214+ data : Buffer . from ( "jpeg-heic-sequence" ) . toString ( "base64" ) ,
215+ mimeType : "image/jpeg" ,
216+ } ,
217+ } ,
218+ {
219+ name : "converts sniffed HEIF sequence images using the existing HEIF allowlist" ,
220+ source : {
221+ type : "base64" ,
222+ data : Buffer . from ( "heif-sequence-source" ) . toString ( "base64" ) ,
223+ mediaType : "image/heif" ,
224+ } as const ,
225+ limits : createImageSourceLimits ( [ "image/heif" , "image/jpeg" ] ) ,
226+ detectedMime : "image/heif-sequence" ,
227+ convertedBytes : Buffer . from ( "jpeg-heif-sequence" ) ,
228+ expectedImage : {
229+ type : "image" ,
230+ data : Buffer . from ( "jpeg-heif-sequence" ) . toString ( "base64" ) ,
231+ mimeType : "image/jpeg" ,
232+ } ,
233+ } ,
234+ {
235+ name : "converts fetched HEIC sequence images using the existing HEIC allowlist" ,
236+ source : {
237+ type : "url" ,
238+ url : "https://example.com/photo.heic" ,
239+ } as const ,
240+ limits : createImageSourceLimits ( [ "image/heic" , "image/jpeg" ] , true ) ,
241+ detectedMime : "image/heic-sequence" ,
242+ convertedBytes : Buffer . from ( "jpeg-url-sequence" ) ,
243+ fetchedContentType : "image/heic-sequence" ,
244+ fetchedBody : Buffer . from ( "heic-url-sequence" ) ,
245+ expectedImage : {
246+ type : "image" ,
247+ data : Buffer . from ( "jpeg-url-sequence" ) . toString ( "base64" ) ,
248+ mimeType : "image/jpeg" ,
249+ } ,
250+ } ,
202251 {
203252 name : "keeps declared MIME for non-HEIC images after validation" ,
204253 source : {
@@ -273,6 +322,7 @@ describe("HEIC input image normalization", () => {
273322 mediaType : "image/png" ,
274323 } ,
275324 limits : createImageSourceLimits ( [ "image/png" , "image/jpeg" ] ) ,
325+ detectedMime : "application/pdf" ,
276326 expectedError : "Unsupported image MIME type: application/pdf" ,
277327 } ,
278328 {
@@ -282,13 +332,36 @@ describe("HEIC input image normalization", () => {
282332 url : "https://example.com/photo.png" ,
283333 } ,
284334 limits : createImageSourceLimits ( [ "image/png" , "image/jpeg" ] , true ) ,
335+ detectedMime : "application/pdf" ,
285336 expectedError : "Unsupported image MIME type: application/pdf" ,
286337 fetchedUrl : "https://example.com/photo.png" ,
287338 fetchedContentType : "image/png" ,
288339 fetchedBody : Buffer . from ( "%PDF-1.4\n" ) ,
289340 } ,
341+ {
342+ name : "rejects sequence images when their canonical HEIC MIME is not allowed" ,
343+ source : {
344+ type : "base64" as const ,
345+ data : Buffer . from ( "heic-sequence-source" ) . toString ( "base64" ) ,
346+ mediaType : "image/heic-sequence" ,
347+ } ,
348+ limits : createImageSourceLimits ( [ "image/png" , "image/jpeg" ] ) ,
349+ detectedMime : "image/heic-sequence" ,
350+ expectedError : "Unsupported image MIME type" ,
351+ } ,
352+ {
353+ name : "rejects spoofed HEIC sequence metadata when detected bytes are not an image" ,
354+ source : {
355+ type : "base64" as const ,
356+ data : Buffer . from ( "%PDF-1.4\n" ) . toString ( "base64" ) ,
357+ mediaType : "image/heic-sequence" ,
358+ } ,
359+ limits : createImageSourceLimits ( [ "image/heic" , "image/jpeg" ] ) ,
360+ detectedMime : "application/pdf" ,
361+ expectedError : "Unsupported image MIME type: application/pdf" ,
362+ } ,
290363 ] as const ) ( "$name" , async ( testCase ) => {
291- detectMimeMock . mockResolvedValueOnce ( "application/pdf" ) ;
364+ detectMimeMock . mockResolvedValueOnce ( testCase . detectedMime ) ;
292365 await expectRejectedImageMimeCase ( testCase ) ;
293366 expect ( convertHeicToJpegMock ) . not . toHaveBeenCalled ( ) ;
294367 } ) ;
0 commit comments