correct specs

This commit is contained in:
Sam
2018-08-20 12:41:46 +10:00
parent 9c3ba98ef1
commit d7b1919ead
5 changed files with 16 additions and 7 deletions

View File

@@ -82,7 +82,7 @@ class UploadCreator
# otherwise validation will fail and we can not save # otherwise validation will fail and we can not save
# TODO decide if we only run the validation on the extension # TODO decide if we only run the validation on the extension
if File.extname(@filename) != ".#{image_type}" if File.extname(@filename) != ".#{image_type}"
fixed_original_filename = "#{@filename}.fixed.#{image_type}" fixed_original_filename = "#{@filename}_fixed.#{image_type}"
end end
end end

1
spec/fixtures/images/not_an_image vendored Normal file
View File

@@ -0,0 +1 @@
abcd

View File

@@ -41,7 +41,7 @@ RSpec.describe UploadCreator do
expect(upload.extension).to eq('png') expect(upload.extension).to eq('png')
expect(File.extname(upload.url)).to eq('.png') expect(File.extname(upload.url)).to eq('.png')
expect(upload.original_filename).to eq('png_as.bin.fixed.png') expect(upload.original_filename).to eq('png_as.bin_fixed.png')
end end
end end
@@ -65,7 +65,7 @@ RSpec.describe UploadCreator do
expect(upload.extension).to eq('jpeg') expect(upload.extension).to eq('jpeg')
expect(File.extname(upload.url)).to eq('.jpeg') expect(File.extname(upload.url)).to eq('.jpeg')
expect(upload.original_filename).to eq('logo.png.fixed.jpeg') expect(upload.original_filename).to eq('logo.png_fixed.jpeg')
end end
end end
end end

View File

@@ -53,8 +53,7 @@ describe Upload do
it "should create an invalid upload when the filename is blank" do it "should create an invalid upload when the filename is blank" do
SiteSetting.authorized_extensions = "*" SiteSetting.authorized_extensions = "*"
created_upload = UploadCreator.new(attachment, nil).create_for(user_id)
created_upload = UploadCreator.new(image, nil).create_for(user_id)
expect(created_upload.valid?).to eq(false) expect(created_upload.valid?).to eq(false)
end end

View File

@@ -206,13 +206,22 @@ describe UploadsController do
expect(response.headers["Content-Disposition"]).to eq("attachment; filename=\"logo.png\"") expect(response.headers["Content-Disposition"]).to eq("attachment; filename=\"logo.png\"")
end end
it "handles file without extension" do it "handles image without extension" do
SiteSetting.authorized_extensions = "*" SiteSetting.authorized_extensions = "*"
upload = upload_file("image_no_extension") upload = upload_file("image_no_extension")
get "/uploads/#{site}/#{upload.sha1}.json" get "/uploads/#{site}/#{upload.sha1}.json"
expect(response.status).to eq(200) expect(response.status).to eq(200)
expect(response.headers["Content-Disposition"]).to eq("attachment; filename=\"image_no_extension\"") expect(response.headers["Content-Disposition"]).to eq("attachment; filename=\"image_no_extension_fixed.png\"")
end
it "handles file without extension" do
SiteSetting.authorized_extensions = "*"
upload = upload_file("not_an_image")
get "/uploads/#{site}/#{upload.sha1}.json"
expect(response.status).to eq(200)
expect(response.headers["Content-Disposition"]).to eq("attachment; filename=\"not_an_image\"")
end end
context "prevent anons from downloading files" do context "prevent anons from downloading files" do