diff options
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/fixtures/banner-resized.jpg | bin | 88780 -> 59947 bytes | |||
-rw-r--r-- | server/tests/fixtures/exif.jpg | bin | 0 -> 10877 bytes | |||
-rw-r--r-- | server/tests/fixtures/exif.png | bin | 0 -> 21059 bytes | |||
-rw-r--r-- | server/tests/helpers/image.ts | 58 | ||||
-rw-r--r-- | server/tests/helpers/markdown.ts | 6 | ||||
-rw-r--r-- | server/tests/shared/checks.ts | 12 |
6 files changed, 60 insertions, 16 deletions
diff --git a/server/tests/fixtures/banner-resized.jpg b/server/tests/fixtures/banner-resized.jpg index 13ea422cb..952732d61 100644 --- a/server/tests/fixtures/banner-resized.jpg +++ b/server/tests/fixtures/banner-resized.jpg | |||
Binary files differ | |||
diff --git a/server/tests/fixtures/exif.jpg b/server/tests/fixtures/exif.jpg new file mode 100644 index 000000000..2997b38e9 --- /dev/null +++ b/server/tests/fixtures/exif.jpg | |||
Binary files differ | |||
diff --git a/server/tests/fixtures/exif.png b/server/tests/fixtures/exif.png new file mode 100644 index 000000000..a1a0113f8 --- /dev/null +++ b/server/tests/fixtures/exif.png | |||
Binary files 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' | |||
4 | import { expect } from 'chai' | 4 | import { expect } from 'chai' |
5 | import { readFile, remove } from 'fs-extra' | 5 | import { readFile, remove } from 'fs-extra' |
6 | import { join } from 'path' | 6 | import { join } from 'path' |
7 | import { execPromise } from '@server/helpers/core-utils' | ||
7 | import { buildAbsoluteFixturePath, root } from '@shared/core-utils' | 8 | import { buildAbsoluteFixturePath, root } from '@shared/core-utils' |
8 | import { processImage } from '../../../server/helpers/image-utils' | 9 | import { processImage } from '../../../server/helpers/image-utils' |
9 | 10 | ||
@@ -20,40 +21,77 @@ async function checkBuffers (path1: string, path2: string, equals: boolean) { | |||
20 | } | 21 | } |
21 | } | 22 | } |
22 | 23 | ||
24 | async function hasTitleExif (path: string) { | ||
25 | const result = JSON.parse(await execPromise(`exiftool -json ${path}`)) | ||
26 | |||
27 | return result[0]?.Title === 'should be removed' | ||
28 | } | ||
29 | |||
23 | describe('Image helpers', function () { | 30 | describe('Image helpers', function () { |
24 | const imageDestDir = join(root(), 'test-images') | 31 | const imageDestDir = join(root(), 'test-images') |
25 | const imageDest = join(imageDestDir, 'test.jpg') | 32 | |
33 | const imageDestJPG = join(imageDestDir, 'test.jpg') | ||
34 | const imageDestPNG = join(imageDestDir, 'test.png') | ||
35 | |||
26 | const thumbnailSize = { width: 223, height: 122 } | 36 | const thumbnailSize = { width: 223, height: 122 } |
27 | 37 | ||
28 | it('Should skip processing if the source image is okay', async function () { | 38 | it('Should skip processing if the source image is okay', async function () { |
29 | const input = buildAbsoluteFixturePath('thumbnail.jpg') | 39 | const input = buildAbsoluteFixturePath('thumbnail.jpg') |
30 | await processImage(input, imageDest, thumbnailSize, true) | 40 | await processImage(input, imageDestJPG, thumbnailSize, true) |
31 | 41 | ||
32 | await checkBuffers(input, imageDest, true) | 42 | await checkBuffers(input, imageDestJPG, true) |
33 | }) | 43 | }) |
34 | 44 | ||
35 | it('Should not skip processing if the source image does not have the appropriate extension', async function () { | 45 | it('Should not skip processing if the source image does not have the appropriate extension', async function () { |
36 | const input = buildAbsoluteFixturePath('thumbnail.png') | 46 | const input = buildAbsoluteFixturePath('thumbnail.png') |
37 | await processImage(input, imageDest, thumbnailSize, true) | 47 | await processImage(input, imageDestJPG, thumbnailSize, true) |
38 | 48 | ||
39 | await checkBuffers(input, imageDest, false) | 49 | await checkBuffers(input, imageDestJPG, false) |
40 | }) | 50 | }) |
41 | 51 | ||
42 | it('Should not skip processing if the source image does not have the appropriate size', async function () { | 52 | it('Should not skip processing if the source image does not have the appropriate size', async function () { |
43 | const input = buildAbsoluteFixturePath('preview.jpg') | 53 | const input = buildAbsoluteFixturePath('preview.jpg') |
44 | await processImage(input, imageDest, thumbnailSize, true) | 54 | await processImage(input, imageDestJPG, thumbnailSize, true) |
45 | 55 | ||
46 | await checkBuffers(input, imageDest, false) | 56 | await checkBuffers(input, imageDestJPG, false) |
47 | }) | 57 | }) |
48 | 58 | ||
49 | it('Should not skip processing if the source image does not have the appropriate size', async function () { | 59 | it('Should not skip processing if the source image does not have the appropriate size', async function () { |
50 | const input = buildAbsoluteFixturePath('thumbnail-big.jpg') | 60 | const input = buildAbsoluteFixturePath('thumbnail-big.jpg') |
51 | await processImage(input, imageDest, thumbnailSize, true) | 61 | await processImage(input, imageDestJPG, thumbnailSize, true) |
62 | |||
63 | await checkBuffers(input, imageDestJPG, false) | ||
64 | }) | ||
65 | |||
66 | it('Should strip exif for a jpg file that can not be copied', async function () { | ||
67 | const input = buildAbsoluteFixturePath('exif.jpg') | ||
68 | expect(await hasTitleExif(input)).to.be.true | ||
69 | |||
70 | await processImage(input, imageDestJPG, { width: 100, height: 100 }, true) | ||
71 | await checkBuffers(input, imageDestJPG, false) | ||
72 | |||
73 | expect(await hasTitleExif(imageDestJPG)).to.be.false | ||
74 | }) | ||
75 | |||
76 | it('Should strip exif for a jpg file that could be copied', async function () { | ||
77 | const input = buildAbsoluteFixturePath('exif.jpg') | ||
78 | expect(await hasTitleExif(input)).to.be.true | ||
79 | |||
80 | await processImage(input, imageDestJPG, thumbnailSize, true) | ||
81 | await checkBuffers(input, imageDestJPG, false) | ||
82 | |||
83 | expect(await hasTitleExif(imageDestJPG)).to.be.false | ||
84 | }) | ||
85 | |||
86 | it('Should strip exif for png', async function () { | ||
87 | const input = buildAbsoluteFixturePath('exif.png') | ||
88 | expect(await hasTitleExif(input)).to.be.true | ||
52 | 89 | ||
53 | await checkBuffers(input, imageDest, false) | 90 | await processImage(input, imageDestPNG, thumbnailSize, true) |
91 | expect(await hasTitleExif(imageDestPNG)).to.be.false | ||
54 | }) | 92 | }) |
55 | 93 | ||
56 | after(async function () { | 94 | after(async function () { |
57 | await remove(imageDest) | 95 | await remove(imageDestDir) |
58 | }) | 96 | }) |
59 | }) | 97 | }) |
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 () { | |||
30 | 30 | ||
31 | expect(result).to.equal('Hello coucou') | 31 | expect(result).to.equal('Hello coucou') |
32 | }) | 32 | }) |
33 | |||
34 | it('Should convert tags to plain text', function () { | ||
35 | const result = mdToOneLinePlainText(`#déconversion\n#newage\n#histoire`) | ||
36 | |||
37 | expect(result).to.equal('#déconversion #newage #histoire') | ||
38 | }) | ||
33 | }) | 39 | }) |
34 | }) | 40 | }) |
diff --git a/server/tests/shared/checks.ts b/server/tests/shared/checks.ts index 9ecc84b5d..dcc16d7ea 100644 --- a/server/tests/shared/checks.ts +++ b/server/tests/shared/checks.ts | |||
@@ -25,21 +25,21 @@ async function expectLogDoesNotContain (server: PeerTubeServer, str: string) { | |||
25 | expect(content.toString()).to.not.contain(str) | 25 | expect(content.toString()).to.not.contain(str) |
26 | } | 26 | } |
27 | 27 | ||
28 | async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') { | 28 | async function testImage (url: string, imageName: string, imageHTTPPath: string, extension = '.jpg') { |
29 | const res = await makeGetRequest({ | 29 | const res = await makeGetRequest({ |
30 | url, | 30 | url, |
31 | path: imagePath, | 31 | path: imageHTTPPath, |
32 | expectedStatus: HttpStatusCode.OK_200 | 32 | expectedStatus: HttpStatusCode.OK_200 |
33 | }) | 33 | }) |
34 | 34 | ||
35 | const body = res.body | 35 | const body = res.body |
36 | 36 | ||
37 | const data = await readFile(join(root(), 'server', 'tests', 'fixtures', imageName + extension)) | 37 | const data = await readFile(join(root(), 'server', 'tests', 'fixtures', imageName + extension)) |
38 | const minLength = body.length - ((30 * body.length) / 100) | 38 | const minLength = data.length - ((40 * data.length) / 100) |
39 | const maxLength = body.length + ((30 * body.length) / 100) | 39 | const maxLength = data.length + ((40 * data.length) / 100) |
40 | 40 | ||
41 | expect(data.length).to.be.above(minLength, 'the generated image is way smaller than the recorded fixture') | 41 | expect(body.length).to.be.above(minLength, 'the generated image is way smaller than the recorded fixture') |
42 | expect(data.length).to.be.below(maxLength, 'the generated image is way larger than the recorded fixture') | 42 | expect(body.length).to.be.below(maxLength, 'the generated image is way larger than the recorded fixture') |
43 | } | 43 | } |
44 | 44 | ||
45 | async function testFileExistsOrNot (server: PeerTubeServer, directory: string, filePath: string, exist: boolean) { | 45 | async function testFileExistsOrNot (server: PeerTubeServer, directory: string, filePath: string, exist: boolean) { |