mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
de9864db30
- Moved upload validation mw from shared to api as it is not shared (except within the API) - Co-located the code with the upload middleware, as it's small and gives us a nice API of .upload.single and .upload.validation - This file is only used in one part of the app, this updates the code structure to reflect this - This is one of many similar changes needed to make it easier to refactor to the existing setup
43 lines
1.7 KiB
JavaScript
43 lines
1.7 KiB
JavaScript
const should = require('should');
|
|
const validation = require('../../../../../core/server/web/api/middleware/upload')._test;
|
|
|
|
describe('web utils', function () {
|
|
describe('checkFileExists', function () {
|
|
it('should return true if file exists in input', function () {
|
|
validation.checkFileExists({mimetype: 'file', path: 'path'}).should.be.true();
|
|
});
|
|
|
|
it('should return false if file does not exist in input', function () {
|
|
validation.checkFileExists({}).should.be.false();
|
|
});
|
|
|
|
it('should return false if file is incorrectly structured', function () {
|
|
validation.checkFileExists({type: 'file'}).should.be.false();
|
|
});
|
|
});
|
|
|
|
describe('checkFileIsValid', function () {
|
|
it('returns true if file has valid extension and type', function () {
|
|
validation.checkFileIsValid({
|
|
name: 'test.txt',
|
|
mimetype: 'text',
|
|
ext: '.txt'
|
|
}, ['text'], ['.txt']).should.be.true();
|
|
|
|
validation.checkFileIsValid({
|
|
name: 'test.jpg',
|
|
mimetype: 'jpeg',
|
|
ext: '.jpg'
|
|
}, ['text', 'jpeg'], ['.txt', '.jpg']).should.be.true();
|
|
});
|
|
|
|
it('returns false if file has invalid extension', function () {
|
|
validation.checkFileIsValid({name: 'test.txt', mimetype: 'text'}, ['text'], ['.tar']).should.be.false();
|
|
validation.checkFileIsValid({name: 'test', mimetype: 'text'}, ['text'], ['.txt']).should.be.false();
|
|
});
|
|
|
|
it('returns false if file has invalid type', function () {
|
|
validation.checkFileIsValid({name: 'test.txt', mimetype: 'text'}, ['archive'], ['.txt']).should.be.false();
|
|
});
|
|
});
|
|
});
|