|
|
|
@ -220,6 +220,13 @@ describe('Upload Controllers', function () {
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should not allow non image uploads', function (done) {
|
|
|
|
|
socketUser.updateCover({ uid: 1 }, { uid: 1, file: { path: '../../text.txt' } }, function (err) {
|
|
|
|
|
assert.equal(err.message, '[[error:invalid-data]]');
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should not allow non image uploads', function (done) {
|
|
|
|
|
socketUser.updateCover({ uid: 1 }, { uid: 1, imageData: 'data:text/html;base64,PHN2Zy9vbmxvYWQ9YWxlcnQoMik+' }, function (err) {
|
|
|
|
|
assert.equal(err.message, '[[error:invalid-image]]');
|
|
|
|
@ -234,6 +241,13 @@ describe('Upload Controllers', function () {
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should not allow non image uploads', function (done) {
|
|
|
|
|
socketUser.uploadCroppedPicture({ uid: 1 }, { uid: 1, file: { path: '../../text.txt' } }, function (err) {
|
|
|
|
|
assert.equal(err.message, '[[error:invalid-data]]');
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should not allow non image uploads', function (done) {
|
|
|
|
|
socketUser.uploadCroppedPicture({ uid: 1 }, { uid: 1, imageData: 'data:text/html;base64,PHN2Zy9vbmxvYWQ9YWxlcnQoMik+' }, function (err) {
|
|
|
|
|
assert.equal(err.message, '[[error:invalid-image]]');
|
|
|
|
@ -396,5 +410,33 @@ describe('Upload Controllers', function () {
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should upload regular file', function (done) {
|
|
|
|
|
helpers.uploadFile(nconf.get('url') + '/api/admin/upload/file', path.join(__dirname, '../test/files/test.png'), {
|
|
|
|
|
params: JSON.stringify({
|
|
|
|
|
folder: 'system',
|
|
|
|
|
}),
|
|
|
|
|
}, jar, csrf_token, function (err, res, body) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
assert.equal(res.statusCode, 200);
|
|
|
|
|
assert(Array.isArray(body));
|
|
|
|
|
assert.equal(body[0].url, '/assets/uploads/system/test.png');
|
|
|
|
|
assert(file.existsSync(path.join(nconf.get('upload_path'), 'system', 'test.png')));
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should fail to upload regular file in wrong directory', function (done) {
|
|
|
|
|
helpers.uploadFile(nconf.get('url') + '/api/admin/upload/file', path.join(__dirname, '../test/files/test.png'), {
|
|
|
|
|
params: JSON.stringify({
|
|
|
|
|
folder: '../../system',
|
|
|
|
|
}),
|
|
|
|
|
}, jar, csrf_token, function (err, res, body) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
assert.equal(res.statusCode, 500);
|
|
|
|
|
assert.strictEqual(body.error, '[[error:invalid-path]]');
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|