X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fhelpers%2Fimage.ts;h=7c5da69b57ae797ac4842775646fc20dd5876def;hb=073deef8862f462de5f159a57877ef415ebe4c69;hp=9fe9aa4cba8c07bc4fea281183dc97aacfafbef8;hpb=c4fa01f7c45b66b112ebd08abce744b7c4041feb;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/helpers/image.ts b/server/tests/helpers/image.ts index 9fe9aa4cb..7c5da69b5 100644 --- a/server/tests/helpers/image.ts +++ b/server/tests/helpers/image.ts @@ -4,8 +4,9 @@ import 'mocha' import { expect } from 'chai' import { readFile, remove } from 'fs-extra' import { join } from 'path' +import { execPromise } from '@server/helpers/core-utils' +import { buildAbsoluteFixturePath, root } from '@shared/core-utils' import { processImage } from '../../../server/helpers/image-utils' -import { buildAbsoluteFixturePath, root } from '../../../shared/extra-utils' async function checkBuffers (path1: string, path2: string, equals: boolean) { const [ buf1, buf2 ] = await Promise.all([ @@ -20,40 +21,77 @@ async function checkBuffers (path1: string, path2: string, equals: boolean) { } } +async function hasTitleExif (path: string) { + const result = JSON.parse(await execPromise(`exiftool -json ${path}`)) + + return result[0]?.Title === 'should be removed' +} + describe('Image helpers', function () { const imageDestDir = join(root(), 'test-images') - const imageDest = join(imageDestDir, 'test.jpg') + + const imageDestJPG = join(imageDestDir, 'test.jpg') + const imageDestPNG = join(imageDestDir, 'test.png') + const thumbnailSize = { width: 223, height: 122 } it('Should skip processing if the source image is okay', async function () { const input = buildAbsoluteFixturePath('thumbnail.jpg') - await processImage(input, imageDest, thumbnailSize, true) + await processImage({ path: input, destination: imageDestJPG, newSize: thumbnailSize, keepOriginal: true }) - await checkBuffers(input, imageDest, true) + await checkBuffers(input, imageDestJPG, true) }) it('Should not skip processing if the source image does not have the appropriate extension', async function () { const input = buildAbsoluteFixturePath('thumbnail.png') - await processImage(input, imageDest, thumbnailSize, true) + await processImage({ path: input, destination: imageDestJPG, newSize: thumbnailSize, keepOriginal: true }) - await checkBuffers(input, imageDest, false) + await checkBuffers(input, imageDestJPG, false) }) it('Should not skip processing if the source image does not have the appropriate size', async function () { const input = buildAbsoluteFixturePath('preview.jpg') - await processImage(input, imageDest, thumbnailSize, true) + await processImage({ path: input, destination: imageDestJPG, newSize: thumbnailSize, keepOriginal: true }) - await checkBuffers(input, imageDest, false) + await checkBuffers(input, imageDestJPG, false) }) it('Should not skip processing if the source image does not have the appropriate size', async function () { const input = buildAbsoluteFixturePath('thumbnail-big.jpg') - await processImage(input, imageDest, thumbnailSize, true) + await processImage({ path: input, destination: imageDestJPG, newSize: thumbnailSize, keepOriginal: true }) + + await checkBuffers(input, imageDestJPG, false) + }) + + it('Should strip exif for a jpg file that can not be copied', async function () { + const input = buildAbsoluteFixturePath('exif.jpg') + expect(await hasTitleExif(input)).to.be.true + + await processImage({ path: input, destination: imageDestJPG, newSize: { width: 100, height: 100 }, keepOriginal: true }) + await checkBuffers(input, imageDestJPG, false) + + expect(await hasTitleExif(imageDestJPG)).to.be.false + }) + + it('Should strip exif for a jpg file that could be copied', async function () { + const input = buildAbsoluteFixturePath('exif.jpg') + expect(await hasTitleExif(input)).to.be.true + + await processImage({ path: input, destination: imageDestJPG, newSize: thumbnailSize, keepOriginal: true }) + await checkBuffers(input, imageDestJPG, false) + + expect(await hasTitleExif(imageDestJPG)).to.be.false + }) + + it('Should strip exif for png', async function () { + const input = buildAbsoluteFixturePath('exif.png') + expect(await hasTitleExif(input)).to.be.true - await checkBuffers(input, imageDest, false) + await processImage({ path: input, destination: imageDestPNG, newSize: thumbnailSize, keepOriginal: true }) + expect(await hasTitleExif(imageDestPNG)).to.be.false }) after(async function () { - await remove(imageDest) + await remove(imageDestDir) }) })