Files upload restriction by files extensions (#20008).

git-svn-id: http://svn.redmine.org/redmine/trunk@14792 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2015-11-01 10:41:02 +00:00
parent e009780eb3
commit dd1c5f8900
6 changed files with 81 additions and 1 deletions

View File

@@ -122,6 +122,45 @@ class AttachmentTest < ActiveSupport::TestCase
end
end
def test_extension_should_be_validated_against_allowed_extensions
with_settings :attachment_extensions_allowed => "txt, png" do
a = Attachment.new(:container => Issue.find(1),
:file => mock_file_with_options(:original_filename => "test.png"),
:author => User.find(1))
assert_save a
a = Attachment.new(:container => Issue.find(1),
:file => mock_file_with_options(:original_filename => "test.jpeg"),
:author => User.find(1))
assert !a.save
end
end
def test_extension_should_be_validated_against_denied_extensions
with_settings :attachment_extensions_denied => "txt, png" do
a = Attachment.new(:container => Issue.find(1),
:file => mock_file_with_options(:original_filename => "test.jpeg"),
:author => User.find(1))
assert_save a
a = Attachment.new(:container => Issue.find(1),
:file => mock_file_with_options(:original_filename => "test.png"),
:author => User.find(1))
assert !a.save
end
end
def test_valid_extension_should_be_case_insensitive
with_settings :attachment_extensions_allowed => "txt, Png" do
assert Attachment.valid_extension?(".pnG")
assert !Attachment.valid_extension?(".jpeg")
end
with_settings :attachment_extensions_denied => "txt, Png" do
assert !Attachment.valid_extension?(".pnG")
assert Attachment.valid_extension?(".jpeg")
end
end
def test_description_length_should_be_validated
a = Attachment.new(:description => 'a' * 300)
assert !a.save