mirror of
https://github.com/redmine/redmine.git
synced 2026-05-06 06:07:08 +02:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user