Skip to content

Commit

Permalink
Set config secure to true by default
Browse files Browse the repository at this point in the history
  • Loading branch information
const-cloudinary committed Apr 1, 2024
1 parent 672491d commit fcaa68c
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 99 deletions.
1 change: 0 additions & 1 deletion lib/cloudinary/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ def self.included(base)
private

def cloudinary_url_internal(source, options = {})
options[:ssl_detected] = request.ssl? if defined?(request) && request && request.respond_to?(:ssl?)
if defined?(CarrierWave::Uploader::Base) && source.is_a?(CarrierWave::Uploader::Base)
if source.version_name.present?
options[:transformation] = Cloudinary::Utils.build_array(source.transformation) + Cloudinary::Utils.build_array(options[:transformation])
Expand Down
5 changes: 1 addition & 4 deletions lib/cloudinary/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ class Cloudinary::Utils
secure_distribution
shorten
sign_url
ssl_detected
type
url_suffix
use_root_path
Expand Down Expand Up @@ -707,9 +706,7 @@ def self.build_distribution_domain(options = {})
cloud_name = config_option_consume(options, :cloud_name) || raise(CloudinaryException, "Must supply cloud_name in tag or in configuration")

source = options.delete(:source)
secure = options.delete(:secure)
ssl_detected = options.delete(:ssl_detected)
secure = ssl_detected || Cloudinary.config.secure if secure.nil?
secure = config_option_consume(options, :secure, true)
private_cdn = config_option_consume(options, :private_cdn)
secure_distribution = config_option_consume(options, :secure_distribution)
cname = config_option_consume(options, :cname)
Expand Down
1 change: 1 addition & 0 deletions spec/auth_token_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
Cloudinary.class_variable_set :@@config, nil
Cloudinary.config_from_url 'cloudinary://a:b@test123'
Cloudinary.config :private_cdn => true
Cloudinary.config :secure => false
Cloudinary.config.auth_token = { :key => KEY, :duration => 300, :start_time => 11111111 }

end
Expand Down
24 changes: 12 additions & 12 deletions spec/cloudinary_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
ActionView::Base.new(ActionView::LookupContext.new([]), {}, nil)
}
let(:cloud_name) {DUMMY_CLOUD}
let(:root_path) {"http://res.cloudinary.com/#{cloud_name}"}
let(:root_path) {"https://res.cloudinary.com/#{cloud_name}"}
let(:upload_path) {"#{root_path}/image/upload"}

let(:options) { {} }
Expand Down Expand Up @@ -71,7 +71,7 @@
it "should use data-src for responsive_width" do
expect(test_tag.name).to match( 'img')
expect(test_tag['class']).to eq("cld-responsive")
expect(test_tag['data-src']).to eq( "http://res.cloudinary.com/test/image/upload/c_limit,w_auto/sample.jpg")
expect(test_tag['data-src']).to eq( "https://res.cloudinary.com/test/image/upload/c_limit,w_auto/sample.jpg")
end
end

Expand All @@ -80,7 +80,7 @@
it "should use data-src for dpr auto" do
expect(test_tag.name).to match( 'img')
expect(test_tag['class']).to eq( 'cld-hidpi')
expect(test_tag['data-src']).to eq( "http://res.cloudinary.com/test/image/upload/dpr_auto/sample.jpg")
expect(test_tag['data-src']).to eq( "https://res.cloudinary.com/test/image/upload/dpr_auto/sample.jpg")
end
end

Expand All @@ -90,14 +90,14 @@
expect(test_tag.name).to match( 'img')
expect(test_tag['class']).to be_nil
expect(test_tag['data-src']).to be_nil
expect(test_tag['src']).to eq( "http://res.cloudinary.com/test/image/upload/dpr_auto,w_auto/sample.jpg")
expect(test_tag['src']).to eq( "https://res.cloudinary.com/test/image/upload/dpr_auto,w_auto/sample.jpg")
end
it "should override :responsive" do
Cloudinary.config.responsive = true
expect(test_tag.name).to match( 'img')
expect(test_tag['class']).to be_nil
expect(test_tag['data-src']).to be_nil
expect(test_tag['src']).to eq( "http://res.cloudinary.com/test/image/upload/dpr_auto,w_auto/sample.jpg")
expect(test_tag['src']).to eq( "https://res.cloudinary.com/test/image/upload/dpr_auto,w_auto/sample.jpg")
end
end
context "as option" do
Expand All @@ -117,13 +117,13 @@
it "should use normal responsive behaviour" do
expect(test_tag.name).to match( 'img')
expect(test_tag['class']).to eq( 'cld-responsive')
expect(test_tag['data-src']).to eq( "http://res.cloudinary.com/test/image/upload/w_auto/sample.jpg")
expect(test_tag['data-src']).to eq( "https://res.cloudinary.com/test/image/upload/w_auto/sample.jpg")
end
end
context "width" do
let(:options) { {:dpr => :auto, :cloud_name => "test", :width => "auto:breakpoints", :client_hints => true}}
it "supports auto width" do
expect(test_tag['src']).to eq( "http://res.cloudinary.com/test/image/upload/dpr_auto,w_auto:breakpoints/sample.jpg")
expect(test_tag['src']).to eq( "https://res.cloudinary.com/test/image/upload/dpr_auto,w_auto:breakpoints/sample.jpg")
end
end
end
Expand Down Expand Up @@ -242,10 +242,10 @@ def source_url(t)
tag = helper.cl_source_tag(PUBLIC_ID, srcset: {breakpoints: breakpoint_list})
expect(tag).to eql(
"<source srcset=\"" +
"http://res.cloudinary.com/#{DUMMY_CLOUD}/image/upload/c_scale,w_100/sample.jpg 100w, " +
"http://res.cloudinary.com/#{DUMMY_CLOUD}/image/upload/c_scale,w_200/sample.jpg 200w, " +
"http://res.cloudinary.com/#{DUMMY_CLOUD}/image/upload/c_scale,w_300/sample.jpg 300w, " +
"http://res.cloudinary.com/#{DUMMY_CLOUD}/image/upload/c_scale,w_399/sample.jpg 399w" +
"https://res.cloudinary.com/#{DUMMY_CLOUD}/image/upload/c_scale,w_100/sample.jpg 100w, " +
"https://res.cloudinary.com/#{DUMMY_CLOUD}/image/upload/c_scale,w_200/sample.jpg 200w, " +
"https://res.cloudinary.com/#{DUMMY_CLOUD}/image/upload/c_scale,w_300/sample.jpg 300w, " +
"https://res.cloudinary.com/#{DUMMY_CLOUD}/image/upload/c_scale,w_399/sample.jpg 399w" +
"\">")
end

Expand All @@ -268,7 +268,7 @@ def source_url(t)
:type => "authenticated",
:version => "1486020273",
:auth_token => {key: KEY, start_time: 11111111, duration: 300}
expect(tag).to match /<img.*src="http:\/\/res.cloudinary.com\/#{DUMMY_CLOUD}\/image\/authenticated\/v1486020273\/sample.jpg\?__cld_token__=st=11111111~exp=11111411~hmac=9bd6f41e2a5893da8343dc8eb648de8bf73771993a6d1457d49851250caf3b80.*>/
expect(tag).to match /<img.*src="https:\/\/res.cloudinary.com\/#{DUMMY_CLOUD}\/image\/authenticated\/v1486020273\/sample.jpg\?__cld_token__=st=11111111~exp=11111411~hmac=9bd6f41e2a5893da8343dc8eb648de8bf73771993a6d1457d49851250caf3b80.*>/

end

Expand Down
2 changes: 1 addition & 1 deletion spec/image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def expected_srcset(public_id, path, common_trans, breakpoints)
end

let(:cloud_name) {COMMON_TRANS[:cloud_name]}
let(:root_path) {"http://res.cloudinary.com/#{cloud_name}"}
let(:root_path) {"https://res.cloudinary.com/#{cloud_name}"}
let(:upload_path) {"#{root_path}/image/upload"}

let(:options) {COMMON_TRANS}
Expand Down
14 changes: 7 additions & 7 deletions spec/rake_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ def differ
allow(Cloudinary.config).to receive(:static_file_support).and_return(true)
subject.invoke

expect(['logo1.png', '/images/logo1.png']).to be_asset_mapped_by_cloudinary_url_to('http://res.cloudinary.com/test/image/asset/logo1-7dc60722d4653261648038b579fdb89e.png')
expect('images/logo1.png').not_to be_asset_mapped_by_cloudinary_url_to('http://res.cloudinary.com/test/image/asset/logo1-7dc60722d4653261648038b579fdb89e.png')
expect('1.js').to be_asset_mapped_by_cloudinary_url_to('http://res.cloudinary.com/test/raw/asset/1-b01de57adb485efdde843154d030644e.js')
expect(['javascripts/1.js', '/javascripts/1.js']).not_to be_asset_mapped_by_cloudinary_url_to('http://res.cloudinary.com/test/raw/asset/1-b01de57adb485efdde843154d030644e.js')
expect('1.css').to be_asset_mapped_by_cloudinary_url_to('http://res.cloudinary.com/test/raw/asset/1-f24cc6123afd401ab86d8596cabc619f.css')
expect(['stylesheets/1.css', '/stylesheets/1.css']).not_to be_asset_mapped_by_cloudinary_url_to('http://res.cloudinary.com/test/raw/asset/1-f24cc6123afd401ab86d8596cabc619f.css')
expect(['logo1.png', '/images/logo1.png']).to be_asset_mapped_by_cloudinary_url_to('https://res.cloudinary.com/test/image/asset/logo1-7dc60722d4653261648038b579fdb89e.png')
expect('images/logo1.png').not_to be_asset_mapped_by_cloudinary_url_to('https://res.cloudinary.com/test/image/asset/logo1-7dc60722d4653261648038b579fdb89e.png')
expect('1.js').to be_asset_mapped_by_cloudinary_url_to('https://res.cloudinary.com/test/raw/asset/1-b01de57adb485efdde843154d030644e.js')
expect(['javascripts/1.js', '/javascripts/1.js']).not_to be_asset_mapped_by_cloudinary_url_to('https://res.cloudinary.com/test/raw/asset/1-b01de57adb485efdde843154d030644e.js')
expect('1.css').to be_asset_mapped_by_cloudinary_url_to('https://res.cloudinary.com/test/raw/asset/1-f24cc6123afd401ab86d8596cabc619f.css')
expect(['stylesheets/1.css', '/stylesheets/1.css']).not_to be_asset_mapped_by_cloudinary_url_to('https://res.cloudinary.com/test/raw/asset/1-f24cc6123afd401ab86d8596cabc619f.css')

# without :type => 'asset'
expect(Cloudinary::Utils.cloudinary_url('logo1.png')).not_to include('7dc60722d4653261648038b579fdb89e')
Expand All @@ -153,7 +153,7 @@ def differ
allow(Cloudinary.config).to receive(:static_image_support).and_return(true)
subject.invoke

expect(['logo1.png', '/images/logo1.png']).to be_asset_mapped_by_cloudinary_url_to('http://res.cloudinary.com/test/image/asset/logo1-7dc60722d4653261648038b579fdb89e.png')
expect(['logo1.png', '/images/logo1.png']).to be_asset_mapped_by_cloudinary_url_to('https://res.cloudinary.com/test/image/asset/logo1-7dc60722d4653261648038b579fdb89e.png')
end
end

Expand Down
Loading

0 comments on commit fcaa68c

Please sign in to comment.