Commit 784ba24a authored by suman rajan 's avatar suman rajan

New upstream version 1.3.1

parent 6599f776
......@@ -5,6 +5,22 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
## 1.3.1 - 2018-12-29
### Fixed
* Fix `#url_options_supported?` causing nil error(@mshibuya [0b9a64a1](https://github.com/carrierwaveuploader/carrierwave/commit/0b9a64a1bb9f20d1de154dc3bf2e2dd988210220), [#2361](https://github.com/carrierwaveuploader/carrierwave/issues/2361))
## 1.3.0 - 2018-12-24
### Added
* Query parameter support for fog-google(@stanhu [#2332](https://github.com/carrierwaveuploader/carrierwave/pull/2332))
* Jets Turbine Support(@tongueroo [#2355](https://github.com/carrierwaveuploader/carrierwave/pull/2355))
* Add `allowed_types` to `content_type_whitelist_error`(@mhluska [#2270](https://github.com/carrierwaveuploader/carrierwave/pull/2270))
### Fixed
* S3 HTTPS url causes certificate issue when bucket name contains period(@ransombriggs [#2359](https://github.com/carrierwaveuploader/carrierwave/pull/2359))
* Failed to get image dimensions when image is cached but not stored yet(@artygus [#2349](https://github.com/carrierwaveuploader/carrierwave/pull/2349))
* Only include `x-amz-acl` header for AWS(@stanhu [#2356](https://github.com/carrierwaveuploader/carrierwave/pull/2356))
* Remove old caches when no space is left on disk(@dosuken123 [#2342](https://github.com/carrierwaveuploader/carrierwave/pull/2342))
## 1.2.3 - 2018-06-30
### Fixed
* Fix reading whole content of large files into memory on storing(@dosuken123 [#2314](https://github.com/carrierwaveuploader/carrierwave/pull/2314))
......
......@@ -89,7 +89,7 @@ a migration:
rails g migration add_avatar_to_users avatar:string
rake db:migrate
rails db:migrate
Open your model file and mount the uploader:
......@@ -144,12 +144,12 @@ example, create a migration like this:
#### For databases with ActiveRecord json data type support (e.g. PostgreSQL, MySQL)
rails g migration add_avatars_to_users avatars:json
rake db:migrate
rails db:migrate
#### For database without ActiveRecord json data type support (e.g. SQLite)
rails g migration add_avatars_to_users avatars:string
rake db:migrate
rails db:migrate
__Note__: JSON datatype doesn't exists in SQLite adapter, that's why you can use a string datatype which will be serialized in model.
......@@ -923,7 +923,7 @@ errors:
carrierwave_download_error: could not be downloaded
extension_whitelist_error: "You are not allowed to upload %{extension} files, allowed types: %{allowed_types}"
extension_blacklist_error: "You are not allowed to upload %{extension} files, prohibited types: %{prohibited_types}"
content_type_whitelist_error: "You are not allowed to upload %{content_type} files"
content_type_whitelist_error: "You are not allowed to upload %{content_type} files, allowed types: %{allowed_types}"
content_type_blacklist_error: "You are not allowed to upload %{content_type} files"
rmagick_processing_error: "Failed to manipulate with rmagick, maybe it is not an image?"
mini_magick_processing_error: "Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: %{e}"
......
......@@ -34,7 +34,7 @@ Gem::Specification.new do |s|
s.add_development_dependency "rspec", "~> 3.4"
s.add_development_dependency "webmock"
s.add_development_dependency "fog-aws"
s.add_development_dependency "fog-google", "<= 0.1.0"
s.add_development_dependency "fog-google", "~> 1.7.1"
s.add_development_dependency "fog-local"
s.add_development_dependency "fog-rackspace"
s.add_development_dependency "mini_magick", ">= 3.6.0"
......
......@@ -34,6 +34,26 @@ if defined?(Merb)
Dir.glob(File.join(Merb.load_paths[:uploaders])).each {|f| require f }
end
elsif defined?(Jets)
module CarrierWave
class Turbine < Jets::Turbine
initializer "carrierwave.setup_paths" do |app|
CarrierWave.root = Jets.root.to_s
CarrierWave.tmp_path = "/tmp/carrierwave"
CarrierWave.configure do |config|
config.cache_dir = "/tmp/carrierwave/uploads/tmp"
end
end
initializer "carrierwave.active_record" do
ActiveSupport.on_load :active_record do
require 'carrierwave/orm/activerecord'
end
end
end
end
elsif defined?(Rails)
module CarrierWave
......
......@@ -6,7 +6,7 @@ en:
carrierwave_download_error: could not be downloaded
extension_whitelist_error: "You are not allowed to upload %{extension} files, allowed types: %{allowed_types}"
extension_blacklist_error: "You are not allowed to upload %{extension} files, prohibited types: %{prohibited_types}"
content_type_whitelist_error: "You are not allowed to upload %{content_type} files"
content_type_whitelist_error: "You are not allowed to upload %{content_type} files, allowed types: %{allowed_types}"
content_type_blacklist_error: "You are not allowed to upload %{content_type} files"
rmagick_processing_error: "Failed to manipulate with rmagick, maybe it is not an image?"
mini_magick_processing_error: "Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: %{e}"
......
......@@ -341,11 +341,7 @@ module CarrierWave
end
def mini_magick_image
if url
::MiniMagick::Image.open(url)
else
::MiniMagick::Image.open(current_path)
end
::MiniMagick::Image.read(read)
end
end # MiniMagick
......
......@@ -66,7 +66,7 @@ module CarrierWave
#
def cache!(new_file)
new_file.move_to(::File.expand_path(uploader.cache_path, uploader.root), uploader.permissions, uploader.directory_permissions, true)
rescue Errno::EMLINK => e
rescue Errno::EMLINK, Errno::ENOSPC => e
raise(e) if @cache_called
@cache_called = true
......
......@@ -192,8 +192,14 @@ module CarrierWave
local_file = local_directory.files.new(:key => path)
expire_at = ::Fog::Time.now + @uploader.fog_authenticated_url_expiration
case @uploader.fog_credentials[:provider]
when 'AWS'
local_file.url(expire_at, options)
when 'AWS', 'Google'
# Older versions of fog-google do not support options as a parameter
if url_options_supported?(local_file)
local_file.url(expire_at, options)
else
warn "Options hash not supported in #{local_file.class}. You may need to upgrade your Fog provider."
local_file.url(expire_at)
end
when 'Rackspace'
connection.get_object_https_url(@uploader.fog_directory, path, expire_at, options)
when 'OpenStack'
......@@ -352,15 +358,19 @@ module CarrierWave
end
else
# AWS/Google optimized for speed over correctness
case @uploader.fog_credentials[:provider].to_s
case fog_provider
when 'AWS'
# check if some endpoint is set in fog_credentials
if @uploader.fog_credentials.has_key?(:endpoint)
"#{@uploader.fog_credentials[:endpoint]}/#{@uploader.fog_directory}/#{encoded_path}"
else
protocol = @uploader.fog_use_ssl_for_aws ? "https" : "http"
subdomain_regex = /^(?:[a-z]|\d(?!\d{0,2}(?:\d{1,3}){3}$))(?:[a-z0-9\.]|(?![\-])|\-(?![\.])){1,61}[a-z0-9]$/
valid_subdomain = @uploader.fog_directory.to_s =~ subdomain_regex && !(protocol == 'https' && @uploader.fog_directory =~ /\./)
# if directory is a valid subdomain, use that style for access
if @uploader.fog_directory.to_s =~ /^(?:[a-z]|\d(?!\d{0,2}(?:\d{1,3}){3}$))(?:[a-z0-9\.]|(?![\-])|\-(?![\.])){1,61}[a-z0-9]$/
if valid_subdomain
s3_subdomain = @uploader.fog_aws_accelerate ? "s3-accelerate" : "s3"
"#{protocol}://#{@uploader.fog_directory}.#{s3_subdomain}.amazonaws.com/#{encoded_path}"
else
......@@ -466,7 +476,15 @@ module CarrierWave
end
def acl_header
{'x-amz-acl' => @uploader.fog_public ? 'public-read' : 'private'}
if fog_provider == 'AWS'
{ 'x-amz-acl' => @uploader.fog_public ? 'public-read' : 'private' }
else
{}
end
end
def fog_provider
@uploader.fog_credentials[:provider].to_s
end
def read_source_file(file_body)
......@@ -479,6 +497,11 @@ module CarrierWave
file_body.close
end
end
def url_options_supported?(local_file)
parameters = local_file.method(:url).parameters
parameters.count == 2 && parameters[1].include?(:options)
end
end
end # Fog
......
......@@ -35,7 +35,7 @@ module CarrierWave
def check_content_type_whitelist!(new_file)
content_type = new_file.content_type
if content_type_whitelist && !whitelisted_content_type?(content_type)
raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.content_type_whitelist_error", content_type: content_type)
raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.content_type_whitelist_error", content_type: content_type, allowed_types: Array(content_type_whitelist).join(", "))
end
end
......
module CarrierWave
VERSION = "1.2.3"
VERSION = "1.3.1"
end
......@@ -164,6 +164,30 @@ describe CarrierWave::ActiveRecord do
expect(@event.reload.image).to be_blank
end
context "with CarrierWave::MiniMagick" do
before(:each) do
@uploader.send(:include, CarrierWave::MiniMagick)
end
it "has width and height" do
@event.image = stub_file('landscape.jpg')
expect(@event.image.width).to eq 640
expect(@event.image.height).to eq 480
end
end
context "with CarrierWave::RMagick", :rmagick => true do
before(:each) do
@uploader.send(:include, CarrierWave::RMagick)
end
it "has width and height" do
@event.image = stub_file('landscape.jpg')
expect(@event.image.width).to eq 640
expect(@event.image.height).to eq 480
end
end
end
describe '#image=' do
......@@ -681,12 +705,10 @@ describe CarrierWave::ActiveRecord do
expect(File.exist?(public_path('uploads/old.jpeg'))).to be_truthy
end
pending do
it "should only delete the file once when the file is removed" do
@event.remove_image = true
expect_any_instance_of(CarrierWave::SanitizedFile).to receive(:delete).exactly(1).times
expect(@event.save).to be_truthy
end
pending("should only delete the file once when the file is removed") do
@event.remove_image = true
expect_any_instance_of(CarrierWave::SanitizedFile).to receive(:delete).exactly(1).times
expect(@event.save).to be_truthy
end
end
......
......@@ -10,7 +10,6 @@ describe CarrierWave::MiniMagick do
before do
FileUtils.cp(landscape_file_path, landscape_copy_file_path)
allow(instance).to receive(:cached?).and_return true
allow(instance).to receive(:url).and_return nil
allow(instance).to receive(:file).and_return(CarrierWave::SanitizedFile.new(landscape_copy_file_path))
end
......
......@@ -12,6 +12,10 @@ describe CarrierWave::SanitizedFile do
FileUtils.cp(file_path('test.jpg'), file_path('llama.jpg'))
end
after do
FileUtils.rm_rf(file_path("new_dir"))
end
after(:all) do
if File.exist?(file_path('llama.jpg'))
FileUtils.rm(file_path('llama.jpg'))
......@@ -301,7 +305,6 @@ describe CarrierWave::SanitizedFile do
sanitized_file.move_to(file_path("new_dir","gurr.png"), nil, 0775)
expect(sanitized_file).to have_directory_permissions(0775)
FileUtils.rm_rf(file_path("new_dir"))
end
it "should return itself" do
......@@ -395,7 +398,6 @@ describe CarrierWave::SanitizedFile do
new_file = sanitized_file.copy_to(file_path("new_dir", "gurr.png"), nil, 0755)
expect(new_file).to have_directory_permissions(0755)
FileUtils.rm_rf(file_path("new_dir"))
end
it "should preserve the file's content type" do
......
......@@ -40,7 +40,14 @@ describe CarrierWave::Storage::File do
describe '#cache!' do
context "when FileUtils.mkdir_p raises Errno::EMLINK" do
before { fake_failed_mkdir_p }
before { fake_failed_mkdir_p(Errno::EMLINK) }
after { storage.cache!(sanitized_temp_file) }
it { is_expected.to receive(:clean_cache!).with(600) }
end
context "when FileUtils.mkdir_p raises Errno::ENOSPC" do
before { fake_failed_mkdir_p(Errno::ENOSPC) }
after { storage.cache!(sanitized_temp_file) }
it { is_expected.to receive(:clean_cache!).with(600) }
......
......@@ -3,6 +3,7 @@ def fog_tests(fog_credentials)
shared_examples_for "#{fog_credentials[:provider]} storage" do
before do
WebMock.disable! unless Fog.mocking?
CarrierWave.configure do |config|
config.reset_config
config.fog_provider = "fog/#{fog_credentials[:provider].downcase}"
......@@ -34,6 +35,7 @@ end
CarrierWave.configure do |config|
config.reset_config
end
WebMock.enable! unless Fog.mocking?
end
describe '#cache_stored_file!' do
......@@ -44,6 +46,28 @@ end
end
end
context '#acl_header' do
let(:store_path) { 'uploads/test+.jpg' }
before do
allow(@uploader).to receive(:store_path).and_return(store_path)
end
it 'includes acl_header when necessary' do
if file.is_a?(CarrierWave::Storage::Fog::File)
if @provider == 'AWS'
expect(@storage.connection).to receive(:copy_object)
.with(anything, anything, anything, anything, { "x-amz-acl"=>"public-read" }).and_call_original
else
expect(@storage.connection).to receive(:copy_object)
.with(anything, anything, anything, anything, {}).and_call_original
end
end
@storage.store!(file)
end
end
describe '#store!' do
let(:store_path) { 'uploads/test+.jpg' }
......@@ -88,19 +112,19 @@ end
context "directory is a valid subdomain" do
before do
allow(@uploader).to receive(:fog_directory).and_return('assets.site.com')
allow(@uploader).to receive(:fog_directory).and_return('assets-site-com')
end
it "should use a subdomain URL for AWS" do
if @provider == 'AWS'
expect(@fog_file.public_url).to include('https://assets.site.com.s3.amazonaws.com')
expect(@fog_file.public_url).to include('https://assets-site-com.s3.amazonaws.com')
end
end
it "should use accelerate domain if fog_aws_accelerate is true" do
if @provider == 'AWS'
allow(@uploader).to receive(:fog_aws_accelerate).and_return(true)
expect(@fog_file.public_url).to include('https://assets.site.com.s3-accelerate.amazonaws.com')
expect(@fog_file.public_url).to include('https://assets-site-com.s3-accelerate.amazonaws.com')
end
end
end
......@@ -112,6 +136,22 @@ end
end
end
it "should not use a subdomain URL for AWS if https && the directory is not accessible over https as a virtual hosted bucket" do
if @provider == 'AWS'
allow(@uploader).to receive(:fog_use_ssl_for_aws).and_return(true)
allow(@uploader).to receive(:fog_directory).and_return('foo.bar')
expect(@fog_file.public_url).to include('https://s3.amazonaws.com/foo.bar')
end
end
it "should use a subdomain URL for AWS if http && the directory is not accessible over https as a virtual hosted bucket" do
if @provider == 'AWS'
allow(@uploader).to receive(:fog_use_ssl_for_aws).and_return(false)
allow(@uploader).to receive(:fog_directory).and_return('foo.bar')
expect(@fog_file.public_url).to include('http://foo.bar.s3.amazonaws.com/')
end
end
it "should use https as a default protocol" do
if @provider == 'AWS'
expect(@fog_file.public_url).to start_with 'https://'
......@@ -305,7 +345,7 @@ end
end
describe '#clean_cache!' do
let(:today) { '2016/10/09 10:00:00'.to_time }
let(:today) { Time.now.round }
let(:five_days_ago) { today.ago(5.days) }
let(:three_days_ago) { today.ago(3.days) }
let(:yesterday) { today.yesterday }
......@@ -393,7 +433,7 @@ end
it "should not be available at public URL" do
unless Fog.mocking? || fog_credentials[:provider] == 'Local'
expect(running{ open(@fog_file.public_url) }).to raise_error
expect(running{ open(@fog_file.public_url) }).to raise_error OpenURI::HTTPError
end
end
......@@ -408,9 +448,24 @@ end
end
it "should handle query params" do
if @provider == 'AWS' && !Fog.mocking?
headers = Excon.get(@fog_file.url(:query => {"response-content-disposition" => "attachment"})).headers
expect(headers["Content-Disposition"]).to eq("attachment")
if ['AWS', 'Google'].include?(@provider)
url = @fog_file.url(:query => {"response-content-disposition" => "attachment"})
expect(url).to match(/response-content-disposition=attachment/)
unless Fog.mocking?
# Workaround for S3 SignatureDoesNotMatch issue
# https://github.com/excon/excon/issues/475
Excon.defaults[:omit_default_port] = true
response = Excon.get(url)
expect(response.status).to be 200
expect(response.headers["Content-Disposition"]).to eq("attachment")
end
end
end
it "should not use #file to get signed url" do
if ['AWS', 'Google'].include?(@provider)
allow(@fog_file).to receive(:file).and_return(nil)
expect { @fog_file.url }.not_to raise_error
end
end
end
......
module FileUtilsHelper
# NOTE: Make FileUtils.mkdir_p to raise `Errno::EMLINK` only once
def fake_failed_mkdir_p
# NOTE: Make FileUtils.mkdir_p to raise error only once
def fake_failed_mkdir_p(error)
original_mkdir_p = FileUtils.method(:mkdir_p)
mkdir_p_called = false
allow(FileUtils).to receive(:mkdir_p) do |args|
......@@ -8,7 +8,7 @@ module FileUtilsHelper
original_mkdir_p.call(*args)
else
mkdir_p_called = true
raise Errno::EMLINK
raise error
end
end
end
......
......@@ -41,6 +41,12 @@ describe CarrierWave::Uploader do
expect { uploader.cache!(bork_file) }.to raise_error(CarrierWave::IntegrityError)
end
it "raises an integrity error which lists the allowed content types" do
allow(uploader).to receive(:content_type_whitelist).and_return(['image/gif', 'image/jpg'])
expect { uploader.cache!(bork_file) }.to raise_error(CarrierWave::IntegrityError, %r{(?:image/gif|image/jpg)})
end
end
context "when the whitelist is a single value" do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment