mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
Add a list of for file uploads
This commit is contained in:
@ -20,31 +20,43 @@ test("uploading one file", function() {
|
||||
this.stub(bootbox, "alert");
|
||||
|
||||
ok(!validUpload([1, 2]));
|
||||
ok(bootbox.alert.calledOnce);
|
||||
ok(bootbox.alert.calledWith(Em.String.i18n('post.errors.too_many_uploads')));
|
||||
});
|
||||
|
||||
test("ensures an image upload", function() {
|
||||
var html = { type: "text/html" };
|
||||
test("ensures an authorized upload", function() {
|
||||
var html = { name: "unauthorized.html" };
|
||||
var extensions = Discourse.SiteSettings.authorized_extensions.replace(/\|/g, ", ");
|
||||
this.stub(bootbox, "alert");
|
||||
|
||||
ok(!validUpload([html]));
|
||||
ok(bootbox.alert.calledOnce);
|
||||
ok(bootbox.alert.calledWith(Em.String.i18n('post.errors.upload_not_authorized', { authorized_extensions: extensions })));
|
||||
});
|
||||
|
||||
test("prevents files that are too big from being uploaded", function() {
|
||||
var image = { type: "image/png", size: 10 * 1024 };
|
||||
var image = { name: "image.png", size: 10 * 1024 };
|
||||
Discourse.SiteSettings.max_upload_size_kb = 5;
|
||||
this.stub(bootbox, "alert");
|
||||
|
||||
ok(!validUpload([image]));
|
||||
ok(bootbox.alert.calledOnce);
|
||||
ok(bootbox.alert.calledWith(Em.String.i18n('post.errors.upload_too_large', { max_size_kb: 5 })));
|
||||
});
|
||||
|
||||
test("allows valid uploads to go through", function() {
|
||||
var image = { type: "image/png", size: 10 * 1024 };
|
||||
var image = { name: "image.png", size: 10 * 1024 };
|
||||
Discourse.SiteSettings.max_upload_size_kb = 15;
|
||||
this.stub(bootbox, "alert");
|
||||
|
||||
ok(validUpload([image]));
|
||||
ok(!bootbox.alert.calledOnce);
|
||||
});
|
||||
|
||||
var isAuthorized = function (filename) {
|
||||
return utils.isAuthorizedUpload({ name: filename });
|
||||
};
|
||||
|
||||
test("isAuthorizedUpload", function() {
|
||||
ok(isAuthorized("image.png"));
|
||||
ok(isAuthorized("image.jpg"));
|
||||
ok(!isAuthorized("image.txt"));
|
||||
ok(!isAuthorized(""));
|
||||
});
|
||||
|
Reference in New Issue
Block a user