forked from mirror/misskey
不要なプロパティを削除する処理を隠蔽してanyを排除
This commit is contained in:
parent
65919a4929
commit
7f1fb71d6e
@ -12,7 +12,7 @@ import { ModuleMocker } from 'jest-mock';
|
|||||||
import { Test } from '@nestjs/testing';
|
import { Test } from '@nestjs/testing';
|
||||||
import { afterAll, beforeAll, describe, test } from '@jest/globals';
|
import { afterAll, beforeAll, describe, test } from '@jest/globals';
|
||||||
import { GlobalModule } from '@/GlobalModule.js';
|
import { GlobalModule } from '@/GlobalModule.js';
|
||||||
import { FileInfoService } from '@/core/FileInfoService.js';
|
import {FileInfo, FileInfoService} from '@/core/FileInfoService.js';
|
||||||
//import { DI } from '@/di-symbols.js';
|
//import { DI } from '@/di-symbols.js';
|
||||||
import { AiService } from '@/core/AiService.js';
|
import { AiService } from '@/core/AiService.js';
|
||||||
import { LoggerService } from '@/core/LoggerService.js';
|
import { LoggerService } from '@/core/LoggerService.js';
|
||||||
@ -28,6 +28,15 @@ const moduleMocker = new ModuleMocker(global);
|
|||||||
describe('FileInfoService', () => {
|
describe('FileInfoService', () => {
|
||||||
let app: TestingModule;
|
let app: TestingModule;
|
||||||
let fileInfoService: FileInfoService;
|
let fileInfoService: FileInfoService;
|
||||||
|
const strip = (fileInfo: FileInfo): Omit<Partial<FileInfo>, 'warnings' | 'blurhash' | 'sensitive' | 'porn'> => {
|
||||||
|
const fi: Partial<FileInfo> = fileInfo;
|
||||||
|
delete fi.warnings;
|
||||||
|
delete fi.sensitive;
|
||||||
|
delete fi.blurhash;
|
||||||
|
delete fi.porn;
|
||||||
|
|
||||||
|
return fi;
|
||||||
|
}
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
app = await Test.createTestingModule({
|
app = await Test.createTestingModule({
|
||||||
@ -63,11 +72,7 @@ describe('FileInfoService', () => {
|
|||||||
|
|
||||||
test('Empty file', async () => {
|
test('Empty file', async () => {
|
||||||
const path = `${resources}/emptyfile`;
|
const path = `${resources}/emptyfile`;
|
||||||
const info = await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }) as any;
|
const info = strip(await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }));
|
||||||
delete info.warnings;
|
|
||||||
delete info.blurhash;
|
|
||||||
delete info.sensitive;
|
|
||||||
delete info.porn;
|
|
||||||
assert.deepStrictEqual(info, {
|
assert.deepStrictEqual(info, {
|
||||||
size: 0,
|
size: 0,
|
||||||
md5: 'd41d8cd98f00b204e9800998ecf8427e',
|
md5: 'd41d8cd98f00b204e9800998ecf8427e',
|
||||||
@ -84,11 +89,7 @@ describe('FileInfoService', () => {
|
|||||||
describe('IMAGE', () => {
|
describe('IMAGE', () => {
|
||||||
test('Generic JPEG', async () => {
|
test('Generic JPEG', async () => {
|
||||||
const path = `${resources}/192.jpg`;
|
const path = `${resources}/192.jpg`;
|
||||||
const info = await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }) as any;
|
const info = strip(await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }));
|
||||||
delete info.warnings;
|
|
||||||
delete info.blurhash;
|
|
||||||
delete info.sensitive;
|
|
||||||
delete info.porn;
|
|
||||||
assert.deepStrictEqual(info, {
|
assert.deepStrictEqual(info, {
|
||||||
size: 5131,
|
size: 5131,
|
||||||
md5: '8c9ed0677dd2b8f9f7472c3af247e5e3',
|
md5: '8c9ed0677dd2b8f9f7472c3af247e5e3',
|
||||||
@ -104,11 +105,7 @@ describe('FileInfoService', () => {
|
|||||||
|
|
||||||
test('Generic APNG', async () => {
|
test('Generic APNG', async () => {
|
||||||
const path = `${resources}/anime.png`;
|
const path = `${resources}/anime.png`;
|
||||||
const info = await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }) as any;
|
const info = strip(await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }));
|
||||||
delete info.warnings;
|
|
||||||
delete info.blurhash;
|
|
||||||
delete info.sensitive;
|
|
||||||
delete info.porn;
|
|
||||||
assert.deepStrictEqual(info, {
|
assert.deepStrictEqual(info, {
|
||||||
size: 1868,
|
size: 1868,
|
||||||
md5: '08189c607bea3b952704676bb3c979e0',
|
md5: '08189c607bea3b952704676bb3c979e0',
|
||||||
@ -124,11 +121,7 @@ describe('FileInfoService', () => {
|
|||||||
|
|
||||||
test('Generic AGIF', async () => {
|
test('Generic AGIF', async () => {
|
||||||
const path = `${resources}/anime.gif`;
|
const path = `${resources}/anime.gif`;
|
||||||
const info = await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }) as any;
|
const info = strip(await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }));
|
||||||
delete info.warnings;
|
|
||||||
delete info.blurhash;
|
|
||||||
delete info.sensitive;
|
|
||||||
delete info.porn;
|
|
||||||
assert.deepStrictEqual(info, {
|
assert.deepStrictEqual(info, {
|
||||||
size: 2248,
|
size: 2248,
|
||||||
md5: '32c47a11555675d9267aee1a86571e7e',
|
md5: '32c47a11555675d9267aee1a86571e7e',
|
||||||
@ -144,11 +137,7 @@ describe('FileInfoService', () => {
|
|||||||
|
|
||||||
test('PNG with alpha', async () => {
|
test('PNG with alpha', async () => {
|
||||||
const path = `${resources}/with-alpha.png`;
|
const path = `${resources}/with-alpha.png`;
|
||||||
const info = await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }) as any;
|
const info = strip(await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }));
|
||||||
delete info.warnings;
|
|
||||||
delete info.blurhash;
|
|
||||||
delete info.sensitive;
|
|
||||||
delete info.porn;
|
|
||||||
assert.deepStrictEqual(info, {
|
assert.deepStrictEqual(info, {
|
||||||
size: 3772,
|
size: 3772,
|
||||||
md5: 'f73535c3e1e27508885b69b10cf6e991',
|
md5: 'f73535c3e1e27508885b69b10cf6e991',
|
||||||
@ -164,11 +153,7 @@ describe('FileInfoService', () => {
|
|||||||
|
|
||||||
test('Generic SVG', async () => {
|
test('Generic SVG', async () => {
|
||||||
const path = `${resources}/image.svg`;
|
const path = `${resources}/image.svg`;
|
||||||
const info = await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }) as any;
|
const info = strip(await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }));
|
||||||
delete info.warnings;
|
|
||||||
delete info.blurhash;
|
|
||||||
delete info.sensitive;
|
|
||||||
delete info.porn;
|
|
||||||
assert.deepStrictEqual(info, {
|
assert.deepStrictEqual(info, {
|
||||||
size: 505,
|
size: 505,
|
||||||
md5: 'b6f52b4b021e7b92cdd04509c7267965',
|
md5: 'b6f52b4b021e7b92cdd04509c7267965',
|
||||||
@ -185,11 +170,7 @@ describe('FileInfoService', () => {
|
|||||||
test('SVG with XML definition', async () => {
|
test('SVG with XML definition', async () => {
|
||||||
// https://github.com/misskey-dev/misskey/issues/4413
|
// https://github.com/misskey-dev/misskey/issues/4413
|
||||||
const path = `${resources}/with-xml-def.svg`;
|
const path = `${resources}/with-xml-def.svg`;
|
||||||
const info = await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }) as any;
|
const info = strip(await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }));
|
||||||
delete info.warnings;
|
|
||||||
delete info.blurhash;
|
|
||||||
delete info.sensitive;
|
|
||||||
delete info.porn;
|
|
||||||
assert.deepStrictEqual(info, {
|
assert.deepStrictEqual(info, {
|
||||||
size: 544,
|
size: 544,
|
||||||
md5: '4b7a346cde9ccbeb267e812567e33397',
|
md5: '4b7a346cde9ccbeb267e812567e33397',
|
||||||
@ -205,11 +186,7 @@ describe('FileInfoService', () => {
|
|||||||
|
|
||||||
test('Dimension limit', async () => {
|
test('Dimension limit', async () => {
|
||||||
const path = `${resources}/25000x25000.png`;
|
const path = `${resources}/25000x25000.png`;
|
||||||
const info = await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }) as any;
|
const info = strip(await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }));
|
||||||
delete info.warnings;
|
|
||||||
delete info.blurhash;
|
|
||||||
delete info.sensitive;
|
|
||||||
delete info.porn;
|
|
||||||
assert.deepStrictEqual(info, {
|
assert.deepStrictEqual(info, {
|
||||||
size: 75933,
|
size: 75933,
|
||||||
md5: '268c5dde99e17cf8fe09f1ab3f97df56',
|
md5: '268c5dde99e17cf8fe09f1ab3f97df56',
|
||||||
@ -225,11 +202,7 @@ describe('FileInfoService', () => {
|
|||||||
|
|
||||||
test('Rotate JPEG', async () => {
|
test('Rotate JPEG', async () => {
|
||||||
const path = `${resources}/rotate.jpg`;
|
const path = `${resources}/rotate.jpg`;
|
||||||
const info = await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }) as any;
|
const info = strip(await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }));
|
||||||
delete info.warnings;
|
|
||||||
delete info.blurhash;
|
|
||||||
delete info.sensitive;
|
|
||||||
delete info.porn;
|
|
||||||
assert.deepStrictEqual(info, {
|
assert.deepStrictEqual(info, {
|
||||||
size: 12624,
|
size: 12624,
|
||||||
md5: '68d5b2d8d1d1acbbce99203e3ec3857e',
|
md5: '68d5b2d8d1d1acbbce99203e3ec3857e',
|
||||||
@ -247,11 +220,7 @@ describe('FileInfoService', () => {
|
|||||||
describe('AUDIO', () => {
|
describe('AUDIO', () => {
|
||||||
test('MP3', async () => {
|
test('MP3', async () => {
|
||||||
const path = `${resources}/kick_gaba7.mp3`;
|
const path = `${resources}/kick_gaba7.mp3`;
|
||||||
const info = await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }) as any;
|
const info = strip(await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }));
|
||||||
delete info.warnings;
|
|
||||||
delete info.blurhash;
|
|
||||||
delete info.sensitive;
|
|
||||||
delete info.porn;
|
|
||||||
delete info.width;
|
delete info.width;
|
||||||
delete info.height;
|
delete info.height;
|
||||||
delete info.orientation;
|
delete info.orientation;
|
||||||
@ -267,11 +236,7 @@ describe('FileInfoService', () => {
|
|||||||
|
|
||||||
test('WAV', async () => {
|
test('WAV', async () => {
|
||||||
const path = `${resources}/kick_gaba7.wav`;
|
const path = `${resources}/kick_gaba7.wav`;
|
||||||
const info = await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }) as any;
|
const info = strip(await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }));
|
||||||
delete info.warnings;
|
|
||||||
delete info.blurhash;
|
|
||||||
delete info.sensitive;
|
|
||||||
delete info.porn;
|
|
||||||
delete info.width;
|
delete info.width;
|
||||||
delete info.height;
|
delete info.height;
|
||||||
delete info.orientation;
|
delete info.orientation;
|
||||||
@ -287,11 +252,7 @@ describe('FileInfoService', () => {
|
|||||||
|
|
||||||
test('AAC', async () => {
|
test('AAC', async () => {
|
||||||
const path = `${resources}/kick_gaba7.aac`;
|
const path = `${resources}/kick_gaba7.aac`;
|
||||||
const info = await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }) as any;
|
const info = strip(await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }));
|
||||||
delete info.warnings;
|
|
||||||
delete info.blurhash;
|
|
||||||
delete info.sensitive;
|
|
||||||
delete info.porn;
|
|
||||||
delete info.width;
|
delete info.width;
|
||||||
delete info.height;
|
delete info.height;
|
||||||
delete info.orientation;
|
delete info.orientation;
|
||||||
@ -307,11 +268,7 @@ describe('FileInfoService', () => {
|
|||||||
|
|
||||||
test('FLAC', async () => {
|
test('FLAC', async () => {
|
||||||
const path = `${resources}/kick_gaba7.flac`;
|
const path = `${resources}/kick_gaba7.flac`;
|
||||||
const info = await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }) as any;
|
const info = strip(await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }));
|
||||||
delete info.warnings;
|
|
||||||
delete info.blurhash;
|
|
||||||
delete info.sensitive;
|
|
||||||
delete info.porn;
|
|
||||||
delete info.width;
|
delete info.width;
|
||||||
delete info.height;
|
delete info.height;
|
||||||
delete info.orientation;
|
delete info.orientation;
|
||||||
@ -327,11 +284,7 @@ describe('FileInfoService', () => {
|
|||||||
|
|
||||||
test('MPEG-4 AUDIO (M4A)', async () => {
|
test('MPEG-4 AUDIO (M4A)', async () => {
|
||||||
const path = `${resources}/kick_gaba7.m4a`;
|
const path = `${resources}/kick_gaba7.m4a`;
|
||||||
const info = await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }) as any;
|
const info = strip(await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }));
|
||||||
delete info.warnings;
|
|
||||||
delete info.blurhash;
|
|
||||||
delete info.sensitive;
|
|
||||||
delete info.porn;
|
|
||||||
delete info.width;
|
delete info.width;
|
||||||
delete info.height;
|
delete info.height;
|
||||||
delete info.orientation;
|
delete info.orientation;
|
||||||
@ -347,11 +300,7 @@ describe('FileInfoService', () => {
|
|||||||
|
|
||||||
test('WEBM AUDIO', async () => {
|
test('WEBM AUDIO', async () => {
|
||||||
const path = `${resources}/kick_gaba7.webm`;
|
const path = `${resources}/kick_gaba7.webm`;
|
||||||
const info = await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }) as any;
|
const info = strip(await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }));
|
||||||
delete info.warnings;
|
|
||||||
delete info.blurhash;
|
|
||||||
delete info.sensitive;
|
|
||||||
delete info.porn;
|
|
||||||
delete info.width;
|
delete info.width;
|
||||||
delete info.height;
|
delete info.height;
|
||||||
delete info.orientation;
|
delete info.orientation;
|
||||||
|
Loading…
Reference in New Issue
Block a user