2020-04-22 09:21:41 +03:00
|
|
|
const should = require('should');
|
|
|
|
const uploadValidation = require('../../../../../core/server/web/shared/middlewares/validation/upload')._test;
|
2017-12-14 23:25:51 +03:00
|
|
|
|
|
|
|
describe('web utils', function () {
|
|
|
|
describe('checkFileExists', function () {
|
|
|
|
it('should return true if file exists in input', function () {
|
2020-04-22 09:21:41 +03:00
|
|
|
uploadValidation.checkFileExists({mimetype: 'file', path: 'path'}).should.be.true();
|
2017-12-14 23:25:51 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should return false if file does not exist in input', function () {
|
2020-04-22 09:21:41 +03:00
|
|
|
uploadValidation.checkFileExists({}).should.be.false();
|
2017-12-14 23:25:51 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should return false if file is incorrectly structured', function () {
|
2020-04-22 09:21:41 +03:00
|
|
|
uploadValidation.checkFileExists({type: 'file'}).should.be.false();
|
2017-12-14 23:25:51 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('checkFileIsValid', function () {
|
|
|
|
it('returns true if file has valid extension and type', function () {
|
2020-04-22 09:21:41 +03:00
|
|
|
uploadValidation.checkFileIsValid({
|
2018-08-30 19:30:36 +03:00
|
|
|
name: 'test.txt',
|
|
|
|
mimetype: 'text',
|
|
|
|
ext: '.txt'
|
|
|
|
}, ['text'], ['.txt']).should.be.true();
|
|
|
|
|
2020-04-22 09:21:41 +03:00
|
|
|
uploadValidation.checkFileIsValid({
|
2017-12-14 23:25:51 +03:00
|
|
|
name: 'test.jpg',
|
2018-08-30 19:30:36 +03:00
|
|
|
mimetype: 'jpeg',
|
|
|
|
ext: '.jpg'
|
2017-12-14 23:25:51 +03:00
|
|
|
}, ['text', 'jpeg'], ['.txt', '.jpg']).should.be.true();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns false if file has invalid extension', function () {
|
2020-04-22 09:21:41 +03:00
|
|
|
uploadValidation.checkFileIsValid({name: 'test.txt', mimetype: 'text'}, ['text'], ['.tar']).should.be.false();
|
|
|
|
uploadValidation.checkFileIsValid({name: 'test', mimetype: 'text'}, ['text'], ['.txt']).should.be.false();
|
2017-12-14 23:25:51 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('returns false if file has invalid type', function () {
|
2020-04-22 09:21:41 +03:00
|
|
|
uploadValidation.checkFileIsValid({name: 'test.txt', mimetype: 'text'}, ['archive'], ['.txt']).should.be.false();
|
2017-12-14 23:25:51 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|