summaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2015-11-01 10:41:02 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2015-11-01 10:41:02 +0000
commitdd1c5f8900bb95a47209e6a1efea8ea51950fdd4 (patch)
treee745e020f2e1d97874fedbabb5b314a75aefdfa9 /test/unit
parente009780eb3f51e3809393bcf8e0f88cf6e638f2a (diff)
downloadredmine-dd1c5f8900bb95a47209e6a1efea8ea51950fdd4.tar.gz
redmine-dd1c5f8900bb95a47209e6a1efea8ea51950fdd4.zip
Files upload restriction by files extensions (#20008).
git-svn-id: http://svn.redmine.org/redmine/trunk@14792 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/attachment_test.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/unit/attachment_test.rb b/test/unit/attachment_test.rb
index eaaa1459f..db274dbb9 100644
--- a/test/unit/attachment_test.rb
+++ b/test/unit/attachment_test.rb
@@ -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