From 2f19481147b12e2ae503ed3d1f28621c94447ac3 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 7 Mar 2022 11:48:53 +0100 Subject: Optimize markdown renderer --- server/tests/helpers/markdown.ts | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'server/tests') diff --git a/server/tests/helpers/markdown.ts b/server/tests/helpers/markdown.ts index 0488a1a05..8177477f6 100644 --- a/server/tests/helpers/markdown.ts +++ b/server/tests/helpers/markdown.ts @@ -30,5 +30,11 @@ describe('Markdown helpers', function () { expect(result).to.equal('Hello coucou') }) + + it('Should convert tags to plain text', function () { + const result = mdToOneLinePlainText(`#déconversion\n#newage\n#histoire`) + + expect(result).to.equal('#déconversion #newage #histoire') + }) }) }) -- cgit v1.2.3 From 0c058f256a195b92f124be10109c95d1fbe93ad8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 7 Mar 2022 17:16:54 +0100 Subject: Remove exif tags when processing images --- server/tests/fixtures/exif.jpg | Bin 0 -> 10877 bytes server/tests/fixtures/exif.png | Bin 0 -> 21059 bytes server/tests/helpers/image.ts | 58 ++++++++++++++++++++++++++++++++++------- 3 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 server/tests/fixtures/exif.jpg create mode 100644 server/tests/fixtures/exif.png (limited to 'server/tests') diff --git a/server/tests/fixtures/exif.jpg b/server/tests/fixtures/exif.jpg new file mode 100644 index 000000000..2997b38e9 Binary files /dev/null and b/server/tests/fixtures/exif.jpg differ diff --git a/server/tests/fixtures/exif.png b/server/tests/fixtures/exif.png new file mode 100644 index 000000000..a1a0113f8 Binary files /dev/null and b/server/tests/fixtures/exif.png differ diff --git a/server/tests/helpers/image.ts b/server/tests/helpers/image.ts index 64bd373cc..475ca8fb2 100644 --- a/server/tests/helpers/image.ts +++ b/server/tests/helpers/image.ts @@ -4,6 +4,7 @@ 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' @@ -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(input, imageDestJPG, thumbnailSize, 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(input, imageDestJPG, thumbnailSize, 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(input, imageDestJPG, thumbnailSize, 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(input, imageDestJPG, thumbnailSize, 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(input, imageDestJPG, { width: 100, height: 100 }, 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(input, imageDestJPG, thumbnailSize, 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(input, imageDestPNG, thumbnailSize, true) + expect(await hasTitleExif(imageDestPNG)).to.be.false }) after(async function () { - await remove(imageDest) + await remove(imageDestDir) }) }) -- cgit v1.2.3 From 4c6d99e5b69b29e19d53ede14414b76beef815e2 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 8 Mar 2022 08:50:38 +0100 Subject: Fix channel tests --- server/tests/fixtures/banner-resized.jpg | Bin 88780 -> 59947 bytes server/tests/shared/checks.ts | 12 ++++++------ 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'server/tests') diff --git a/server/tests/fixtures/banner-resized.jpg b/server/tests/fixtures/banner-resized.jpg index 13ea422cb..952732d61 100644 Binary files a/server/tests/fixtures/banner-resized.jpg and b/server/tests/fixtures/banner-resized.jpg differ diff --git a/server/tests/shared/checks.ts b/server/tests/shared/checks.ts index 9ecc84b5d..8c8260088 100644 --- a/server/tests/shared/checks.ts +++ b/server/tests/shared/checks.ts @@ -25,21 +25,21 @@ async function expectLogDoesNotContain (server: PeerTubeServer, str: string) { expect(content.toString()).to.not.contain(str) } -async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') { +async function testImage (url: string, imageName: string, imageHTTPPath: string, extension = '.jpg') { const res = await makeGetRequest({ url, - path: imagePath, + path: imageHTTPPath, expectedStatus: HttpStatusCode.OK_200 }) const body = res.body const data = await readFile(join(root(), 'server', 'tests', 'fixtures', imageName + extension)) - const minLength = body.length - ((30 * body.length) / 100) - const maxLength = body.length + ((30 * body.length) / 100) + const minLength = data.length - ((30 * data.length) / 100) + const maxLength = data.length + ((30 * data.length) / 100) - expect(data.length).to.be.above(minLength, 'the generated image is way smaller than the recorded fixture') - expect(data.length).to.be.below(maxLength, 'the generated image is way larger than the recorded fixture') + expect(body.length).to.be.above(minLength, 'the generated image is way smaller than the recorded fixture') + expect(body.length).to.be.below(maxLength, 'the generated image is way larger than the recorded fixture') } async function testFileExistsOrNot (server: PeerTubeServer, directory: string, filePath: string, exist: boolean) { -- cgit v1.2.3 From c47c3bcb0a9265d2a414ec96075052f8619d3f21 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 8 Mar 2022 09:18:43 +0100 Subject: Fix multiple servers tests --- server/tests/api/videos/multiple-servers.ts | 2 +- server/tests/shared/checks.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'server/tests') diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index ecdd36613..854958f80 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -207,7 +207,7 @@ describe('Test multiple servers', function () { }, { resolution: 720, - size: 788000 + size: 750000 } ], thumbnailfile: 'thumbnail', diff --git a/server/tests/shared/checks.ts b/server/tests/shared/checks.ts index 8c8260088..dcc16d7ea 100644 --- a/server/tests/shared/checks.ts +++ b/server/tests/shared/checks.ts @@ -35,8 +35,8 @@ async function testImage (url: string, imageName: string, imageHTTPPath: string, const body = res.body const data = await readFile(join(root(), 'server', 'tests', 'fixtures', imageName + extension)) - const minLength = data.length - ((30 * data.length) / 100) - const maxLength = data.length + ((30 * data.length) / 100) + const minLength = data.length - ((40 * data.length) / 100) + const maxLength = data.length + ((40 * data.length) / 100) expect(body.length).to.be.above(minLength, 'the generated image is way smaller than the recorded fixture') expect(body.length).to.be.below(maxLength, 'the generated image is way larger than the recorded fixture') -- cgit v1.2.3