diff --git a/lib/carrierwave/storage/fog.rb b/lib/carrierwave/storage/fog.rb index 94a1bd8a1..7e97c0bb3 100644 --- a/lib/carrierwave/storage/fog.rb +++ b/lib/carrierwave/storage/fog.rb @@ -376,7 +376,12 @@ def public_url 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}" + if !@uploader.fog_aws_fips + "#{@uploader.fog_credentials[:endpoint]}/#{@uploader.fog_directory}/#{encoded_path}" + else + warn 'Use of options :endpoint and :fog_aws_fips=true together will fail, as FIPS endpoints do not support path-style URLs.' + nil + end else protocol = @uploader.fog_use_ssl_for_aws ? "https" : "http" diff --git a/spec/storage/fog_helper.rb b/spec/storage/fog_helper.rb index f41a79c3a..43c554439 100644 --- a/spec/storage/fog_helper.rb +++ b/spec/storage/fog_helper.rb @@ -362,9 +362,11 @@ def check_file describe "CarrierWave::Storage::Fog::File" do let(:store_path) { 'uploads/test.jpg' } let(:fog_public) { true } + let(:endpoint) { nil } before do allow(@uploader).to receive(:store_path).and_return(store_path) allow(@uploader).to receive(:fog_public).and_return(fog_public) + allow(@uploader).to receive(:endpoint).and_return(endpoint) @fog_file = @storage.store!(CarrierWave::SanitizedFile.new(stub_file('test.jpg', 'image/jpeg'))) end @@ -504,6 +506,20 @@ def check_file expect(@fog_file.public_url).to include("https://#{CARRIERWAVE_DIRECTORY}.s3-accelerate.amazonaws.com") end + it 'returns nil when both :endpoint and :fog_aws_fips=true' do + allow(@uploader).to receive(:fog_credentials).and_return(@uploader.fog_credentials.merge(endpoint: 'https://custom-endpoint.example.com')) + allow(@uploader).to receive(:fog_directory).and_return('SiteAssets') + allow(@uploader).to receive(:fog_aws_fips).and_return(true) + expect(@fog_file.url).to be nil + end + + it 'returns endpoint+bucket when :endpoint and !:fog_aws_fips' do + allow(@uploader).to receive(:fog_credentials).and_return(@uploader.fog_credentials.merge(endpoint: 'https://custom-endpoint.example.com')) + allow(@uploader).to receive(:fog_directory).and_return('SiteAssets') + allow(@uploader).to receive(:fog_aws_fips).and_return(false) + expect(@fog_file.url).to include('https://custom-endpoint.example.com/SiteAssets') + end + context 'when the directory is not a valid subdomain' do it "should not use a subdomain URL for AWS" do allow(@uploader).to receive(:fog_directory).and_return('SiteAssets')