mirror of
https://github.com/nestjs/nest.git
synced 2026-02-22 15:31:40 +00:00
Compare commits
85 Commits
fix/patter
...
v10.4.22
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e88b270cb5 | ||
|
|
58ebae0877 | ||
|
|
a2d4a75865 | ||
|
|
99a1f7f3d3 | ||
|
|
178df3d627 | ||
|
|
3f10aab750 | ||
|
|
44969b12ae | ||
|
|
d492171fd1 | ||
|
|
b9ec98fee7 | ||
|
|
fd11464a6e | ||
|
|
cd2bd3e1b4 | ||
|
|
d96149c87b | ||
|
|
2e55ee1883 | ||
|
|
e7f9ade559 | ||
|
|
a74f89ac10 | ||
|
|
5a59810c9c | ||
|
|
3d4fa469c9 | ||
|
|
79cd7bc949 | ||
|
|
5ab165a60d | ||
|
|
eb0f29d3b7 | ||
|
|
f8021ab3e9 | ||
|
|
0402529e56 | ||
|
|
5ce44905c0 | ||
|
|
e3a69525ce | ||
|
|
82f9fed477 | ||
|
|
9e9c3c1c6e | ||
|
|
421a5802ff | ||
|
|
2e9f312e9d | ||
|
|
9da1249256 | ||
|
|
ae40d669e5 | ||
|
|
dc2a3c0d31 | ||
|
|
c4fb432637 | ||
|
|
6c8aec63b4 | ||
|
|
bce9a49214 | ||
|
|
2b9e132f6a | ||
|
|
cb0d6506b3 | ||
|
|
6196ab2150 | ||
|
|
0ac7959927 | ||
|
|
983216b10e | ||
|
|
312a54ae2e | ||
|
|
a28fc033f4 | ||
|
|
07b4b3829e | ||
|
|
0b7af8ab07 | ||
|
|
6953b7a79e | ||
|
|
1f20f52731 | ||
|
|
08840c57df | ||
|
|
cddbcd1897 | ||
|
|
890fde4ef0 | ||
|
|
5ae8168617 | ||
|
|
38a77e2336 | ||
|
|
d90cc8dcf2 | ||
|
|
2260e00bab | ||
|
|
cda46a219a | ||
|
|
23308c7d4a | ||
|
|
f37603a708 | ||
|
|
d57f934a3c | ||
|
|
059592944b | ||
|
|
5feec1f861 | ||
|
|
ca1bd82bf9 | ||
|
|
7f37b492c9 | ||
|
|
c6240a0840 | ||
|
|
a203e07f48 | ||
|
|
315fe55648 | ||
|
|
14c6cd0e02 | ||
|
|
d51f9b6c9d | ||
|
|
18750bd800 | ||
|
|
f6f4baf53d | ||
|
|
010607f172 | ||
|
|
69fd0e9ddf | ||
|
|
579d68a6ec | ||
|
|
dd19ac8f06 | ||
|
|
c571796093 | ||
|
|
100d3c0dc8 | ||
|
|
db2fe5b5aa | ||
|
|
30e4acae29 | ||
|
|
4a2c6e020e | ||
|
|
b03302cf26 | ||
|
|
fdebabd003 | ||
|
|
e1229b124d | ||
|
|
4d21f1e491 | ||
|
|
0ff055834c | ||
|
|
d7a6952f19 | ||
|
|
ac04c340f3 | ||
|
|
598ee4f265 | ||
|
|
3dc367bbb1 |
@@ -1,7 +1,5 @@
|
||||
{
|
||||
"lerna": "2.4.0",
|
||||
"packages": [
|
||||
"packages/*"
|
||||
],
|
||||
"version": "10.4.15"
|
||||
"packages": ["packages/*"],
|
||||
"version": "10.4.22",
|
||||
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
|
||||
}
|
||||
|
||||
52761
package-lock.json
generated
52761
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
22
package.json
22
package.json
@@ -41,12 +41,13 @@
|
||||
"lint:packages": "eslint 'packages/**/**.ts' --ignore-pattern 'packages/**/*.spec.ts'",
|
||||
"lint:spec": "eslint 'packages/**/**.spec.ts'",
|
||||
"prerelease": "gulp copy-misc",
|
||||
"publish": "npm run prerelease && npm run build:prod && ./node_modules/.bin/lerna publish --force-publish --access public --exact -m \"chore(@nestjs) publish %s release\"",
|
||||
"publish": "npm run prerelease && npm run build:prod && ./node_modules/.bin/lerna publish --force-publish --exact -m \"chore(release): publish %s release\"",
|
||||
"prepublishOnly": "npm run changelog | pbcopy",
|
||||
"publish:beta": "npm run prerelease && npm run build:prod && ./node_modules/.bin/lerna publish --npm-tag=beta --access public -m \"chore(@nestjs) publish %s release\"",
|
||||
"publish:next": "npm run prerelease && npm run build:prod && ./node_modules/.bin/lerna publish --npm-tag=next --access public --skip-git -m \"chore(@nestjs) publish %s release\"",
|
||||
"publish:rc": "npm run prerelease && npm run build:prod && ./node_modules/.bin/lerna publish --npm-tag=rc --access public -m \"chore(@nestjs) publish %s release\"",
|
||||
"publish:test": "npm run prerelease && npm run build:prod && ./node_modules/.bin/lerna publish --force-publish --access public --npm-tag=test --skip-git -m \"chore(@nestjs) publish %s release\"",
|
||||
"publish:legacy": "npm run prerelease && npm run build:prod && ./node_modules/.bin/lerna publish --npm-tag=legacy --force-publish -m \"chore(release): publish %s release\"",
|
||||
"publish:beta": "npm run prerelease && npm run build:prod && ./node_modules/.bin/lerna publish --npm-tag=beta -m \"chore(release): publish %s release\"",
|
||||
"publish:next": "npm run prerelease && npm run build:prod && ./node_modules/.bin/lerna publish --npm-tag=next --skip-git -m \"chore(release): publish %s release\"",
|
||||
"publish:rc": "npm run prerelease && npm run build:prod && ./node_modules/.bin/lerna publish --npm-tag=rc -m \"chore(release): publish %s release\"",
|
||||
"publish:test": "npm run prerelease && npm run build:prod && ./node_modules/.bin/lerna publish --force-publish --npm-tag=test --skip-git -m \"chore(release): publish %s release\"",
|
||||
"prepare": "husky"
|
||||
},
|
||||
"lint-staged": {
|
||||
@@ -63,9 +64,10 @@
|
||||
"class-transformer": "0.5.1",
|
||||
"class-validator": "0.14.1",
|
||||
"cors": "2.8.5",
|
||||
"express": "4.21.2",
|
||||
"express": "4.22.1",
|
||||
"fast-json-stringify": "6.0.0",
|
||||
"fast-safe-stringify": "2.1.1",
|
||||
"file-type": "20.4.1",
|
||||
"iterare": "1.2.1",
|
||||
"object-hash": "3.0.0",
|
||||
"path-to-regexp": "3.3.0",
|
||||
@@ -74,7 +76,7 @@
|
||||
"socket.io": "4.8.1",
|
||||
"tslib": "2.8.1",
|
||||
"uid": "2.0.2",
|
||||
"uuid": "11.0.3"
|
||||
"uuid": "11.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@apollo/server": "4.11.2",
|
||||
@@ -111,7 +113,7 @@
|
||||
"amqp-connection-manager": "4.1.14",
|
||||
"amqplib": "0.10.5",
|
||||
"artillery": "2.0.21",
|
||||
"body-parser": "1.20.3",
|
||||
"body-parser": "1.20.4",
|
||||
"bytes": "3.1.2",
|
||||
"cache-manager": "5.7.6",
|
||||
"cache-manager-redis-store": "3.0.1",
|
||||
@@ -131,8 +133,8 @@
|
||||
"fancy-log": "2.0.0",
|
||||
"fastify": "4.28.1",
|
||||
"graphql": "16.9.0",
|
||||
"graphql-tools": "9.0.5",
|
||||
"graphql-subscriptions": "2.0.0",
|
||||
"graphql-tools": "9.0.5",
|
||||
"gulp": "5.0.0",
|
||||
"gulp-clang-format": "1.0.27",
|
||||
"gulp-clean": "0.4.0",
|
||||
@@ -145,7 +147,7 @@
|
||||
"ioredis": "5.4.1",
|
||||
"json-loader": "0.5.7",
|
||||
"kafkajs": "2.2.4",
|
||||
"lerna": "2.11.0",
|
||||
"lerna": "9.0.3",
|
||||
"lerna-changelog": "2.2.0",
|
||||
"light-my-request": "6.3.0",
|
||||
"lint-staged": "15.2.10",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@nestjs/common",
|
||||
"version": "10.4.15",
|
||||
"version": "10.4.22",
|
||||
"description": "Nest - modern, fast, powerful node.js web framework (@common)",
|
||||
"author": "Kamil Mysliwiec",
|
||||
"homepage": "https://nestjs.com",
|
||||
@@ -18,6 +18,7 @@
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"file-type": "20.4.1",
|
||||
"iterare": "1.2.1",
|
||||
"tslib": "2.8.1",
|
||||
"uid": "2.0.2"
|
||||
@@ -35,5 +36,6 @@
|
||||
"class-transformer": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"gitHead": "a2d4a7586573f5965935525be5ce757fc502b154"
|
||||
}
|
||||
|
||||
@@ -3,14 +3,19 @@ import { IFile } from './interfaces';
|
||||
|
||||
export type FileTypeValidatorOptions = {
|
||||
fileType: string | RegExp;
|
||||
|
||||
/**
|
||||
* If `true`, the validator will skip the magic numbers validation.
|
||||
* This can be useful when you can't identify some files as there are no common magic numbers available for some file types.
|
||||
* @default false
|
||||
*/
|
||||
skipMagicNumbersValidation?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* Defines the built-in FileType File Validator. It validates incoming files mime-type
|
||||
* matching a string or a regular expression. Note that this validator uses a naive strategy
|
||||
* to check the mime-type and could be fooled if the client provided a file with renamed extension.
|
||||
* (for instance, renaming a 'malicious.bat' to 'malicious.jpeg'). To handle such security issues
|
||||
* with more reliability, consider checking against the file's [magic-numbers](https://en.wikipedia.org/wiki/Magic_number_%28programming%29)
|
||||
* Defines the built-in FileTypeValidator. It validates incoming files by examining
|
||||
* their magic numbers using the file-type package, providing more reliable file type validation
|
||||
* than just checking the mimetype string.
|
||||
*
|
||||
* @see [File Validators](https://docs.nestjs.com/techniques/file-upload#validators)
|
||||
*
|
||||
@@ -20,19 +25,42 @@ export class FileTypeValidator extends FileValidator<
|
||||
FileTypeValidatorOptions,
|
||||
IFile
|
||||
> {
|
||||
buildErrorMessage(): string {
|
||||
buildErrorMessage(file?: IFile): string {
|
||||
if (file?.mimetype) {
|
||||
return `Validation failed (current file type is ${file.mimetype}, expected type is ${this.validationOptions.fileType})`;
|
||||
}
|
||||
return `Validation failed (expected type is ${this.validationOptions.fileType})`;
|
||||
}
|
||||
|
||||
isValid(file?: IFile): boolean {
|
||||
async isValid(file?: IFile): Promise<boolean> {
|
||||
if (!this.validationOptions) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (
|
||||
!!file &&
|
||||
'mimetype' in file &&
|
||||
!!file.mimetype.match(this.validationOptions.fileType)
|
||||
);
|
||||
const isFileValid = !!file && 'mimetype' in file;
|
||||
|
||||
if (this.validationOptions.skipMagicNumbersValidation) {
|
||||
return (
|
||||
isFileValid && !!file.mimetype.match(this.validationOptions.fileType)
|
||||
);
|
||||
}
|
||||
|
||||
if (!isFileValid || !file.buffer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
const { fileTypeFromBuffer } = (await eval(
|
||||
'import ("file-type")',
|
||||
)) as typeof import('file-type');
|
||||
|
||||
const fileType = await fileTypeFromBuffer(file.buffer);
|
||||
|
||||
return (
|
||||
!!fileType && !!fileType.mime.match(this.validationOptions.fileType)
|
||||
);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export interface IFile {
|
||||
mimetype: string;
|
||||
size: number;
|
||||
buffer?: Buffer;
|
||||
}
|
||||
|
||||
@@ -1,89 +1,195 @@
|
||||
import { expect } from 'chai';
|
||||
import { IFile } from '../../../../common/pipes/file/interfaces';
|
||||
import { FileTypeValidator } from '../../../pipes';
|
||||
|
||||
describe('FileTypeValidator', () => {
|
||||
describe('isValid', () => {
|
||||
it('should return true when the file mimetype is the same as the specified', () => {
|
||||
it('should return true when the file buffer matches the specified type', async () => {
|
||||
const fileTypeValidator = new FileTypeValidator({
|
||||
fileType: 'image/jpeg',
|
||||
});
|
||||
|
||||
const jpegBuffer = Buffer.from([
|
||||
0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46,
|
||||
]);
|
||||
const requestFile = {
|
||||
mimetype: 'image/jpeg',
|
||||
} as any;
|
||||
buffer: jpegBuffer,
|
||||
} as IFile;
|
||||
|
||||
expect(fileTypeValidator.isValid(requestFile)).to.equal(true);
|
||||
expect(await fileTypeValidator.isValid(requestFile)).to.equal(true);
|
||||
});
|
||||
|
||||
it('should return true when the file mimetype ends with the specified option type', () => {
|
||||
it('should return true when the file buffer matches the specified file extension', async () => {
|
||||
const fileTypeValidator = new FileTypeValidator({
|
||||
fileType: 'jpeg',
|
||||
});
|
||||
|
||||
const jpegBuffer = Buffer.from([
|
||||
0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46,
|
||||
]);
|
||||
const requestFile = {
|
||||
mimetype: 'image/jpeg',
|
||||
} as any;
|
||||
|
||||
expect(fileTypeValidator.isValid(requestFile)).to.equal(true);
|
||||
buffer: jpegBuffer,
|
||||
} as IFile;
|
||||
expect(await fileTypeValidator.isValid(requestFile)).to.equal(true);
|
||||
});
|
||||
|
||||
it('should return true when the file mimetype matches the specified regexp', () => {
|
||||
it('should return true when the file buffer matches the specified regexp', async () => {
|
||||
const fileTypeValidator = new FileTypeValidator({
|
||||
fileType: /word/,
|
||||
fileType: /^image\//,
|
||||
});
|
||||
|
||||
const jpegBuffer = Buffer.from([
|
||||
0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46,
|
||||
]);
|
||||
const requestFile = {
|
||||
mimetype: 'application/msword',
|
||||
} as any;
|
||||
mimetype: 'image/jpeg',
|
||||
buffer: jpegBuffer,
|
||||
} as IFile;
|
||||
|
||||
expect(fileTypeValidator.isValid(requestFile)).to.equal(true);
|
||||
expect(await fileTypeValidator.isValid(requestFile)).to.equal(true);
|
||||
});
|
||||
|
||||
it('should return false when the file mimetype is different from the specified', () => {
|
||||
it('should return false when the file buffer does not match the specified type', async () => {
|
||||
const fileTypeValidator = new FileTypeValidator({
|
||||
fileType: 'image/jpeg',
|
||||
});
|
||||
|
||||
const pngBuffer = Buffer.from([
|
||||
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,
|
||||
]);
|
||||
const requestFile = {
|
||||
mimetype: 'image/jpeg', // Spoofed mimetype
|
||||
buffer: pngBuffer,
|
||||
} as IFile;
|
||||
|
||||
expect(await fileTypeValidator.isValid(requestFile)).to.equal(false);
|
||||
});
|
||||
|
||||
it('should return false when the file buffer does not match the specified file extension', async () => {
|
||||
const fileTypeValidator = new FileTypeValidator({
|
||||
fileType: 'jpeg',
|
||||
});
|
||||
|
||||
const pngBuffer = Buffer.from([
|
||||
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,
|
||||
]);
|
||||
const requestFile = {
|
||||
mimetype: 'image/png',
|
||||
} as any;
|
||||
buffer: pngBuffer,
|
||||
} as IFile;
|
||||
|
||||
expect(fileTypeValidator.isValid(requestFile)).to.equal(false);
|
||||
expect(await fileTypeValidator.isValid(requestFile)).to.equal(false);
|
||||
});
|
||||
|
||||
it('should return false when the file mimetype does not match the provided regexp', () => {
|
||||
it('should return false when no buffer is provided', async () => {
|
||||
const fileTypeValidator = new FileTypeValidator({
|
||||
fileType: /mp4/,
|
||||
fileType: 'image/jpeg',
|
||||
});
|
||||
|
||||
const requestFile = {
|
||||
mimetype: 'image/png',
|
||||
} as any;
|
||||
mimetype: 'image/jpeg',
|
||||
} as IFile;
|
||||
|
||||
expect(fileTypeValidator.isValid(requestFile)).to.equal(false);
|
||||
expect(await fileTypeValidator.isValid(requestFile)).to.equal(false);
|
||||
});
|
||||
|
||||
it('should return false when the file mimetype was not provided', () => {
|
||||
it('should return false when no file is provided', async () => {
|
||||
const fileTypeValidator = new FileTypeValidator({
|
||||
fileType: 'image/jpeg',
|
||||
});
|
||||
|
||||
const requestFile = {} as any;
|
||||
|
||||
expect(fileTypeValidator.isValid(requestFile)).to.equal(false);
|
||||
expect(await fileTypeValidator.isValid()).to.equal(false);
|
||||
});
|
||||
|
||||
it('should return false when no file provided', () => {
|
||||
it('should return false when no buffer is provided', async () => {
|
||||
const fileTypeValidator = new FileTypeValidator({
|
||||
fileType: 'image/jpeg',
|
||||
});
|
||||
|
||||
expect(fileTypeValidator.isValid()).to.equal(false);
|
||||
const requestFile = {
|
||||
mimetype: 'image/jpeg',
|
||||
} as IFile;
|
||||
|
||||
expect(await fileTypeValidator.isValid(requestFile)).to.equal(false);
|
||||
});
|
||||
|
||||
it('should return true when the file buffer matches the specified regexp', async () => {
|
||||
const fileTypeValidator = new FileTypeValidator({
|
||||
fileType: /^image\//,
|
||||
});
|
||||
|
||||
const jpegBuffer = Buffer.from([
|
||||
0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46,
|
||||
]);
|
||||
const requestFile = {
|
||||
mimetype: 'image/jpeg',
|
||||
buffer: jpegBuffer,
|
||||
} as IFile;
|
||||
|
||||
expect(await fileTypeValidator.isValid(requestFile)).to.equal(true);
|
||||
});
|
||||
|
||||
it('should return true when no validation options are provided', async () => {
|
||||
const fileTypeValidator = new FileTypeValidator({} as any);
|
||||
const jpegBuffer = Buffer.from([
|
||||
0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46,
|
||||
]);
|
||||
const requestFile = {
|
||||
mimetype: 'image/jpeg',
|
||||
buffer: jpegBuffer,
|
||||
} as IFile;
|
||||
|
||||
expect(await fileTypeValidator.isValid(requestFile)).to.equal(true);
|
||||
});
|
||||
|
||||
it('should skip magic numbers validation when the skipMagicNumbersValidation is true', async () => {
|
||||
const fileTypeValidator = new FileTypeValidator({
|
||||
fileType: 'image/jpeg',
|
||||
skipMagicNumbersValidation: true,
|
||||
});
|
||||
|
||||
const requestFile = {
|
||||
mimetype: 'image/jpeg',
|
||||
} as IFile;
|
||||
|
||||
expect(await fileTypeValidator.isValid(requestFile)).to.equal(true);
|
||||
});
|
||||
|
||||
it('should return false when the file buffer does not match any known type', async () => {
|
||||
const fileTypeValidator = new FileTypeValidator({
|
||||
fileType: 'unknown/type',
|
||||
});
|
||||
|
||||
const unknownBuffer = Buffer.from([
|
||||
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
|
||||
]);
|
||||
const requestFile = {
|
||||
mimetype: 'unknown/type',
|
||||
buffer: unknownBuffer,
|
||||
} as IFile;
|
||||
|
||||
expect(await fileTypeValidator.isValid(requestFile)).to.equal(false);
|
||||
});
|
||||
|
||||
it('should return false when the buffer is empty', async () => {
|
||||
const fileTypeValidator = new FileTypeValidator({
|
||||
fileType: 'image/jpeg',
|
||||
});
|
||||
|
||||
const emptyBuffer = Buffer.from([]);
|
||||
const requestFile = {
|
||||
mimetype: 'image/jpeg',
|
||||
buffer: emptyBuffer,
|
||||
} as IFile;
|
||||
|
||||
expect(await fileTypeValidator.isValid(requestFile)).to.equal(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildErrorMessage', () => {
|
||||
it('should return a string with the format "Validation failed (expected type is #fileType)"', () => {
|
||||
it('should return a string with the format "Validation failed (expected type is #fileType)"', async () => {
|
||||
const fileType = 'image/jpeg';
|
||||
const fileTypeValidator = new FileTypeValidator({
|
||||
fileType,
|
||||
@@ -93,5 +199,85 @@ describe('FileTypeValidator', () => {
|
||||
`Validation failed (expected type is ${fileType})`,
|
||||
);
|
||||
});
|
||||
|
||||
it('should include the file type in the error message when a file is provided', async () => {
|
||||
const currentFileType = 'image/png';
|
||||
const fileType = 'image/jpeg';
|
||||
const fileTypeValidator = new FileTypeValidator({
|
||||
fileType,
|
||||
});
|
||||
|
||||
const file = { mimetype: currentFileType } as IFile;
|
||||
|
||||
expect(fileTypeValidator.buildErrorMessage(file)).to.equal(
|
||||
`Validation failed (current file type is ${currentFileType}, expected type is ${fileType})`,
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle regexp file type in error message', async () => {
|
||||
const fileTypeValidator = new FileTypeValidator({
|
||||
fileType: /^image\//,
|
||||
});
|
||||
const file = { mimetype: 'application/pdf' } as IFile;
|
||||
|
||||
expect(fileTypeValidator.buildErrorMessage(file)).to.equal(
|
||||
`Validation failed (current file type is application/pdf, expected type is /^image\\//)`,
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle file extension in error message', async () => {
|
||||
const fileTypeValidator = new FileTypeValidator({
|
||||
fileType: 'jpeg',
|
||||
});
|
||||
const file = { mimetype: 'image/png' } as IFile;
|
||||
|
||||
expect(fileTypeValidator.buildErrorMessage(file)).to.equal(
|
||||
'Validation failed (current file type is image/png, expected type is jpeg)',
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle regexp file type in error message', async () => {
|
||||
const fileTypeValidator = new FileTypeValidator({
|
||||
fileType: /^image\//,
|
||||
});
|
||||
const file = { mimetype: 'application/pdf' } as IFile;
|
||||
|
||||
expect(fileTypeValidator.buildErrorMessage(file)).to.equal(
|
||||
`Validation failed (current file type is application/pdf, expected type is /^image\\//)`,
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle file extension in error message', async () => {
|
||||
const fileTypeValidator = new FileTypeValidator({
|
||||
fileType: 'jpeg',
|
||||
});
|
||||
const file = { mimetype: 'image/png' } as IFile;
|
||||
|
||||
expect(fileTypeValidator.buildErrorMessage(file)).to.equal(
|
||||
'Validation failed (current file type is image/png, expected type is jpeg)',
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle regexp file type in error message', async () => {
|
||||
const fileTypeValidator = new FileTypeValidator({
|
||||
fileType: /^image\//,
|
||||
});
|
||||
const file = { mimetype: 'application/pdf' } as IFile;
|
||||
|
||||
expect(fileTypeValidator.buildErrorMessage(file)).to.equal(
|
||||
`Validation failed (current file type is application/pdf, expected type is /^image\\//)`,
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle file extension in error message', async () => {
|
||||
const fileTypeValidator = new FileTypeValidator({
|
||||
fileType: 'jpeg',
|
||||
});
|
||||
const file = { mimetype: 'image/png' } as IFile;
|
||||
|
||||
expect(fileTypeValidator.buildErrorMessage(file)).to.equal(
|
||||
'Validation failed (current file type is image/png, expected type is jpeg)',
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { expect } from 'chai';
|
||||
import {
|
||||
FileTypeValidator,
|
||||
FileValidator,
|
||||
MaxFileSizeValidator,
|
||||
ParseFilePipeBuilder,
|
||||
FileTypeValidator,
|
||||
} from '../../../pipes';
|
||||
|
||||
describe('ParseFilePipeBuilder', () => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@nestjs/core",
|
||||
"version": "10.4.15",
|
||||
"version": "10.4.22",
|
||||
"description": "Nest - modern, fast, powerful node.js web framework (@core)",
|
||||
"author": "Kamil Mysliwiec",
|
||||
"license": "MIT",
|
||||
@@ -36,7 +36,7 @@
|
||||
"uid": "2.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nestjs/common": "10.4.15"
|
||||
"@nestjs/common": "^10.4.22"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@nestjs/common": "^10.0.0",
|
||||
@@ -56,5 +56,6 @@
|
||||
"@nestjs/platform-express": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"gitHead": "a2d4a7586573f5965935525be5ce757fc502b154"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@nestjs/microservices",
|
||||
"version": "10.4.15",
|
||||
"version": "10.4.22",
|
||||
"description": "Nest - modern, fast, powerful node.js web framework (@microservices)",
|
||||
"author": "Kamil Mysliwiec",
|
||||
"license": "MIT",
|
||||
@@ -22,8 +22,8 @@
|
||||
"tslib": "2.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nestjs/common": "10.4.15",
|
||||
"@nestjs/core": "10.4.15"
|
||||
"@nestjs/common": "^10.4.22",
|
||||
"@nestjs/core": "^10.4.22"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@grpc/grpc-js": "*",
|
||||
@@ -68,5 +68,6 @@
|
||||
"amqp-connection-manager": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"gitHead": "a2d4a7586573f5965935525be5ce757fc502b154"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@nestjs/platform-express",
|
||||
"version": "10.4.15",
|
||||
"version": "10.4.22",
|
||||
"description": "Nest - modern, fast, powerful node.js web framework (@platform-express)",
|
||||
"author": "Kamil Mysliwiec",
|
||||
"license": "MIT",
|
||||
@@ -18,18 +18,19 @@
|
||||
"access": "public"
|
||||
},
|
||||
"dependencies": {
|
||||
"body-parser": "1.20.3",
|
||||
"body-parser": "1.20.4",
|
||||
"cors": "2.8.5",
|
||||
"express": "4.21.2",
|
||||
"multer": "1.4.4-lts.1",
|
||||
"express": "4.22.1",
|
||||
"multer": "2.0.2",
|
||||
"tslib": "2.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nestjs/common": "10.4.15",
|
||||
"@nestjs/core": "10.4.15"
|
||||
"@nestjs/common": "^10.4.22",
|
||||
"@nestjs/core": "^10.4.22"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@nestjs/common": "^10.0.0",
|
||||
"@nestjs/core": "^10.0.0"
|
||||
}
|
||||
},
|
||||
"gitHead": "a2d4a7586573f5965935525be5ce757fc502b154"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@nestjs/platform-fastify",
|
||||
"version": "10.4.15",
|
||||
"version": "10.4.22",
|
||||
"description": "Nest - modern, fast, powerful node.js web framework (@platform-fastify)",
|
||||
"author": "Kamil Mysliwiec",
|
||||
"license": "MIT",
|
||||
@@ -39,5 +39,6 @@
|
||||
"@fastify/view": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"gitHead": "a2d4a7586573f5965935525be5ce757fc502b154"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@nestjs/platform-socket.io",
|
||||
"version": "10.4.15",
|
||||
"version": "10.4.22",
|
||||
"description": "Nest - modern, fast, powerful node.js web framework (@platform-socket.io)",
|
||||
"author": "Kamil Mysliwiec",
|
||||
"license": "MIT",
|
||||
@@ -25,5 +25,6 @@
|
||||
"@nestjs/common": "^10.0.0",
|
||||
"@nestjs/websockets": "^10.0.0",
|
||||
"rxjs": "^7.1.0"
|
||||
}
|
||||
},
|
||||
"gitHead": "a2d4a7586573f5965935525be5ce757fc502b154"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@nestjs/platform-ws",
|
||||
"version": "10.4.15",
|
||||
"version": "10.4.22",
|
||||
"description": "Nest - modern, fast, powerful node.js web framework (@platform-ws)",
|
||||
"author": "Kamil Mysliwiec",
|
||||
"license": "MIT",
|
||||
@@ -25,5 +25,6 @@
|
||||
"@nestjs/common": "^10.0.0",
|
||||
"@nestjs/websockets": "^10.0.0",
|
||||
"rxjs": "^7.1.0"
|
||||
}
|
||||
},
|
||||
"gitHead": "a2d4a7586573f5965935525be5ce757fc502b154"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@nestjs/testing",
|
||||
"version": "10.4.15",
|
||||
"version": "10.4.22",
|
||||
"description": "Nest - modern, fast, powerful node.js web framework (@testing)",
|
||||
"author": "Kamil Mysliwiec",
|
||||
"license": "MIT",
|
||||
@@ -33,5 +33,6 @@
|
||||
"@nestjs/platform-express": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"gitHead": "a2d4a7586573f5965935525be5ce757fc502b154"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@nestjs/websockets",
|
||||
"version": "10.4.15",
|
||||
"version": "10.4.22",
|
||||
"description": "Nest - modern, fast, powerful node.js web framework (@websockets)",
|
||||
"author": "Kamil Mysliwiec",
|
||||
"license": "MIT",
|
||||
@@ -18,8 +18,8 @@
|
||||
"tslib": "2.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nestjs/common": "10.4.15",
|
||||
"@nestjs/core": "10.4.15"
|
||||
"@nestjs/common": "^10.4.22",
|
||||
"@nestjs/core": "^10.4.22"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@nestjs/common": "^10.0.0",
|
||||
@@ -32,5 +32,6 @@
|
||||
"@nestjs/platform-socket.io": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"gitHead": "a2d4a7586573f5965935525be5ce757fc502b154"
|
||||
}
|
||||
|
||||
@@ -32,14 +32,14 @@ describe('E2E FileTest', () => {
|
||||
it('should allow for file uploads that pass validation', async () => {
|
||||
return request(app.getHttpServer())
|
||||
.post('/file/pass-validation')
|
||||
.attach('file', './package.json')
|
||||
.attach('file', './resources/nestjs.jpg')
|
||||
.field('name', 'test')
|
||||
.expect(201)
|
||||
.expect({
|
||||
body: {
|
||||
name: 'test',
|
||||
},
|
||||
file: readFileSync('./package.json').toString(),
|
||||
file: readFileSync('./resources/nestjs.jpg').toString(),
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
"test:watch": "jest --watch",
|
||||
"test:cov": "jest --coverage",
|
||||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
||||
"test:e2e": "jest --config ./e2e/jest-e2e.json"
|
||||
"test:e2e": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest --config ./e2e/jest-e2e.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nestjs/common": "10.4.13",
|
||||
|
||||
BIN
sample/29-file-upload/resources/nestjs.jpg
Normal file
BIN
sample/29-file-upload/resources/nestjs.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 274 KiB |
@@ -40,7 +40,7 @@ export class AppController {
|
||||
@UploadedFile(
|
||||
new ParseFilePipeBuilder()
|
||||
.addFileTypeValidator({
|
||||
fileType: 'json',
|
||||
fileType: 'jpeg',
|
||||
})
|
||||
.build({
|
||||
fileIsRequired: false,
|
||||
|
||||
Reference in New Issue
Block a user