From 9752d1b449c173256b5f89ef6d9e8f7ea65be9aa Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Mon, 18 Jan 2016 11:21:26 -0200 Subject: [PATCH] Removing old url support --- lib/thumbor/cascade.rb | 2 +- lib/thumbor/crypto_url.rb | 17 +-- spec/thumbor/cascade_spec.rb | 183 -------------------------------- spec/thumbor/crypto_url_spec.rb | 182 ------------------------------- spec/util/thumbor.rb | 7 -- 5 files changed, 2 insertions(+), 389 deletions(-) delete mode 100644 spec/util/thumbor.rb diff --git a/lib/thumbor/cascade.rb b/lib/thumbor/cascade.rb index 3266f49..18e3d13 100644 --- a/lib/thumbor/cascade.rb +++ b/lib/thumbor/cascade.rb @@ -15,7 +15,7 @@ class Cascade :flop, :halign, :valign, :smart, :fit_in, :adaptive_fit_in, :full_fit_in, :adaptive_full_fit_in, - :old, :trim] + :trim] extend Forwardable diff --git a/lib/thumbor/crypto_url.rb b/lib/thumbor/crypto_url.rb index 18f495f..b15bf60 100644 --- a/lib/thumbor/crypto_url.rb +++ b/lib/thumbor/crypto_url.rb @@ -201,17 +201,7 @@ def url_safe_base64(str) Base64.encode64(str).gsub('+', '-').gsub('/', '_').gsub!(/[\n]/, '') end - def generate_old(options) - url = pad(url_for(options)) - cipher = OpenSSL::Cipher::Cipher.new('aes-128-ecb').encrypt - cipher.key = computed_key - encrypted = cipher.update(url) - based = url_safe_base64(encrypted) - - "/#{based}/#{options[:image]}" - end - - def generate_new(options) + def generate(options) thumbor_path = "" image_options = url_for(options, false) @@ -227,10 +217,5 @@ def generate_new(options) end thumbor_path end - - def generate(options) - return generate_old(options) if options[:old] - generate_new(options) - end end end diff --git a/spec/thumbor/cascade_spec.rb b/spec/thumbor/cascade_spec.rb index ace375b..bdad091 100644 --- a/spec/thumbor/cascade_spec.rb +++ b/spec/thumbor/cascade_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' require 'json' require 'ruby-thumbor' -require 'util/thumbor' describe Thumbor::Cascade do let(:image_url) { 'my.domain.com/some/image/url.jpg' } @@ -312,186 +311,4 @@ expect(url).to eq '/q0DiFg-5-eFZIqyN3lRoCvg2K0s=/filters:quality(20):brightness(10)/my.domain.com/some/image/url.jpg' end end - - describe "#generate :old => true" do - - subject { Thumbor::Cascade.new(key, image_url).old(true) } - - it "should create a new instance passing key and keep it" do - url = subject.width(300).height(200).generate - expect(url).to eq '/qkLDiIbvtiks0Up9n5PACtmpOfX6dPXw4vP4kJU-jTfyF6y1GJBJyp7CHYh1H3R2/' << image_url - end - - it "should allow thumbor to decrypt it properly" do - url = subject.width(300).height(200).generate - - encrypted = url.split('/')[1] - - decrypted = decrypt_in_thumbor(encrypted) - - expect(decrypted["horizontal_flip"]).to be_falsy - expect(decrypted["vertical_flip"]).to be_falsy - expect(decrypted["smart"]).to be_falsy - expect(decrypted["meta"]).to be_falsy - expect(decrypted["fit_in"]).to be_falsy - expect(decrypted["crop"]["left"]).to eq 0 - expect(decrypted["crop"]["top"]).to eq 0 - expect(decrypted["crop"]["right"]).to eq 0 - expect(decrypted["crop"]["bottom"]).to eq 0 - expect(decrypted["valign"]).to eq 'middle' - expect(decrypted["halign"]).to eq 'center' - expect(decrypted["image_hash"]).to eq image_md5 - expect(decrypted["width"]).to eq 300 - expect(decrypted["height"]).to eq 200 - - end - - it "should allow thumbor to decrypt it properly with meta" do - url = subject.width(300).height(200).meta(true).generate - - encrypted = url.split('/')[1] - - decrypted = decrypt_in_thumbor(encrypted) - - expect(decrypted["meta"]).to be_truthy - expect(decrypted["image_hash"]).to eq image_md5 - expect(decrypted["width"]).to eq 300 - expect(decrypted["height"]).to eq 200 - - end - - it "should allow thumbor to decrypt it properly with smart" do - url = subject.width(300).height(200).meta(true).smart(true).generate - - encrypted = url.split('/')[1] - - decrypted = decrypt_in_thumbor(encrypted) - - expect(decrypted["meta"]).to be_truthy - expect(decrypted["smart"]).to be_truthy - expect(decrypted["image_hash"]).to eq image_md5 - expect(decrypted["width"]).to eq 300 - expect(decrypted["height"]).to eq 200 - - end - - it "should allow thumbor to decrypt it properly with fit-in" do - url = subject.width(300).height(200).fit_in(true).generate - - encrypted = url.split('/')[1] - - decrypted = decrypt_in_thumbor(encrypted) - - expect(decrypted["fit_in"]).to be_truthy - expect(decrypted["image_hash"]).to eq image_md5 - expect(decrypted["width"]).to eq 300 - expect(decrypted["height"]).to eq 200 - - end - - it "should allow thumbor to decrypt it properly with flip" do - url = subject.width(300).height(200).meta(true).smart(true).flip(true).generate - - encrypted = url.split('/')[1] - - decrypted = decrypt_in_thumbor(encrypted) - - expect(decrypted["meta"]).to be_truthy - expect(decrypted["smart"]).to be_truthy - expect(decrypted["image_hash"]).to eq image_md5 - expect(decrypted["width"]).to eq 300 - expect(decrypted["height"]).to eq 200 - expect(decrypted["horizontal_flip"]).to be_truthy - - end - - it "should allow thumbor to decrypt it properly with flop" do - url = subject.width(300).height(200).meta(true).smart(true).flip(true).flop(true).generate - - encrypted = url.split('/')[1] - - decrypted = decrypt_in_thumbor(encrypted) - - expect(decrypted["meta"]).to be_truthy - expect(decrypted["smart"]).to be_truthy - expect(decrypted["image_hash"]).to eq image_md5 - expect(decrypted["width"]).to eq 300 - expect(decrypted["height"]).to eq 200 - expect(decrypted["horizontal_flip"]).to be_truthy - expect(decrypted["vertical_flip"]).to be_truthy - - end - - it "should allow thumbor to decrypt it properly with halign" do - url = subject.width(300).height(200).meta(true).smart(true).flip(true).flop(true). - halign(:left).generate - - encrypted = url.split('/')[1] - - decrypted = decrypt_in_thumbor(encrypted) - - expect(decrypted["meta"]).to be_truthy - expect(decrypted["smart"]).to be_truthy - expect(decrypted["image_hash"]).to eq image_md5 - expect(decrypted["width"]).to eq 300 - expect(decrypted["height"]).to eq 200 - expect(decrypted["horizontal_flip"]).to be_truthy - expect(decrypted["vertical_flip"]).to be_truthy - expect(decrypted["halign"]).to eq "left" - - end - - it "should allow thumbor to decrypt it properly with valign" do - url = subject.width(300).height(200).meta(true).smart(true).flip(true).flop(true). - halign(:left).valign(:top).generate - - encrypted = url.split('/')[1] - - decrypted = decrypt_in_thumbor(encrypted) - - expect(decrypted["meta"]).to be_truthy - expect(decrypted["smart"]).to be_truthy - expect(decrypted["image_hash"]).to eq image_md5 - expect(decrypted["width"]).to eq 300 - expect(decrypted["height"]).to eq 200 - expect(decrypted["horizontal_flip"]).to be_truthy - expect(decrypted["vertical_flip"]).to be_truthy - expect(decrypted["halign"]).to eq "left" - expect(decrypted["valign"]).to eq "top" - - end - - it "should allow thumbor to decrypt it properly with cropping" do - url = subject.width(300).height(200).crop([10, 20, 30, 40]).generate - - encrypted = url.split('/')[1] - - decrypted = decrypt_in_thumbor(encrypted) - - expect(decrypted["horizontal_flip"]).to be_falsy - expect(decrypted["vertical_flip"]).to be_falsy - expect(decrypted["smart"]).to be_falsy - expect(decrypted["meta"]).to be_falsy - expect(decrypted["crop"]["left"]).to eq 10 - expect(decrypted["crop"]["top"]).to eq 20 - expect(decrypted["crop"]["right"]).to eq 30 - expect(decrypted["crop"]["bottom"]).to eq 40 - expect(decrypted["valign"]).to eq 'middle' - expect(decrypted["halign"]).to eq 'center' - expect(decrypted["image_hash"]).to eq image_md5 - expect(decrypted["width"]).to eq 300 - expect(decrypted["height"]).to eq 200 - - end - - it "should allow thumbor to decrypt it properly with filters" do - url = subject.quality_filter(20).brightness_filter(10).generate - - encrypted = url.split('/')[1] - - decrypted = decrypt_in_thumbor(encrypted) - - expect(decrypted["filters"]).to eq "quality(20):brightness(10)" - end - end end diff --git a/spec/thumbor/crypto_url_spec.rb b/spec/thumbor/crypto_url_spec.rb index dc03951..6c0f49a 100644 --- a/spec/thumbor/crypto_url_spec.rb +++ b/spec/thumbor/crypto_url_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' require 'json' require 'ruby-thumbor' -require 'util/thumbor' image_url = 'my.domain.com/some/image/url.jpg' image_md5 = 'f33af67e41168e80fcc5b00f8bd8061a' @@ -290,187 +289,6 @@ end end - describe "#generate :old => true" do - - it "should create a new instance passing key and keep it" do - url = subject.generate :width => 300, :height => 200, :image => image_url, :old => true - - expect(url).to eq('/qkLDiIbvtiks0Up9n5PACtmpOfX6dPXw4vP4kJU-jTfyF6y1GJBJyp7CHYh1H3R2/' << image_url) - end - - it "should allow thumbor to decrypt it properly" do - url = subject.generate :width => 300, :height => 200, :image => image_url, :old => true - - encrypted = url.split('/')[1] - - decrypted = decrypt_in_thumbor(encrypted) - - expect(decrypted["horizontal_flip"]).to be_falsy - expect(decrypted["vertical_flip"]).to be_falsy - expect(decrypted["smart"]).to be_falsy - expect(decrypted["meta"]).to be_falsy - expect(decrypted["fit_in"]).to be_falsy - expect(decrypted["crop"]["left"]).to eq(0) - expect(decrypted["crop"]["top"]).to eq(0) - expect(decrypted["crop"]["right"]).to eq(0) - expect(decrypted["crop"]["bottom"]).to eq(0) - expect(decrypted["valign"]).to eq('middle') - expect(decrypted["halign"]).to eq('center') - expect(decrypted["image_hash"]).to eq(image_md5) - expect(decrypted["width"]).to eq(300) - expect(decrypted["height"]).to eq(200) - - end - - it "should allow thumbor to decrypt it properly with meta" do - url = subject.generate :width => 300, :height => 200, :meta => true, :image => image_url, :old => true - - encrypted = url.split('/')[1] - - decrypted = decrypt_in_thumbor(encrypted) - - expect(decrypted["meta"]).to be_truthy - expect(decrypted["image_hash"]).to eq(image_md5) - expect(decrypted["width"]).to eq(300) - expect(decrypted["height"]).to eq(200) - - end - - it "should allow thumbor to decrypt it properly with smart" do - url = subject.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true, :old => true - - encrypted = url.split('/')[1] - - decrypted = decrypt_in_thumbor(encrypted) - - expect(decrypted["meta"]).to be_truthy - expect(decrypted["smart"]).to be_truthy - expect(decrypted["image_hash"]).to eq(image_md5) - expect(decrypted["width"]).to eq(300) - expect(decrypted["height"]).to eq(200) - - end - - it "should allow thumbor to decrypt it properly with fit-in" do - url = subject.generate :width => 300, :height => 200, :fit_in => true, :image => image_url, :old => true - - encrypted = url.split('/')[1] - - decrypted = decrypt_in_thumbor(encrypted) - - expect(decrypted["fit_in"]).to be_truthy - expect(decrypted["image_hash"]).to eq(image_md5) - expect(decrypted["width"]).to eq(300) - expect(decrypted["height"]).to eq(200) - - end - - it "should allow thumbor to decrypt it properly with flip" do - url = subject.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true, :flip => true, :old => true - - encrypted = url.split('/')[1] - - decrypted = decrypt_in_thumbor(encrypted) - - expect(decrypted["meta"]).to be_truthy - expect(decrypted["smart"]).to be_truthy - expect(decrypted["image_hash"]).to eq(image_md5) - expect(decrypted["width"]).to eq(300) - expect(decrypted["height"]).to eq(200) - expect(decrypted["horizontal_flip"]).to be_truthy - - end - - it "should allow thumbor to decrypt it properly with flop" do - url = subject.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true, :flip => true, :flop => true, :old => true - - encrypted = url.split('/')[1] - - decrypted = decrypt_in_thumbor(encrypted) - - expect(decrypted["meta"]).to be_truthy - expect(decrypted["smart"]).to be_truthy - expect(decrypted["image_hash"]).to eq(image_md5) - expect(decrypted["width"]).to eq(300) - expect(decrypted["height"]).to eq(200) - expect(decrypted["horizontal_flip"]).to be_truthy - expect(decrypted["vertical_flip"]).to be_truthy - - end - - it "should allow thumbor to decrypt it properly with halign" do - url = subject.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true, :flip => true, :flop => true, - :halign => :left, :old => true - - encrypted = url.split('/')[1] - - decrypted = decrypt_in_thumbor(encrypted) - - expect(decrypted["meta"]).to be_truthy - expect(decrypted["smart"]).to be_truthy - expect(decrypted["image_hash"]).to eq(image_md5) - expect(decrypted["width"]).to eq(300) - expect(decrypted["height"]).to eq(200) - expect(decrypted["horizontal_flip"]).to be_truthy - expect(decrypted["vertical_flip"]).to be_truthy - expect(decrypted["halign"]).to eq('left') - - end - - it "should allow thumbor to decrypt it properly with valign" do - url = subject.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true, :flip => true, :flop => true, - :halign => :left, :valign => :top, :old => true - - encrypted = url.split('/')[1] - - decrypted = decrypt_in_thumbor(encrypted) - - expect(decrypted["meta"]).to be_truthy - expect(decrypted["smart"]).to be_truthy - expect(decrypted["image_hash"]).to eq(image_md5) - expect(decrypted["width"]).to eq(300) - expect(decrypted["height"]).to eq(200) - expect(decrypted["horizontal_flip"]).to be_truthy - expect(decrypted["vertical_flip"]).to be_truthy - expect(decrypted["halign"]).to eq('left') - expect(decrypted["valign"]).to eq('top') - - end - - it "should allow thumbor to decrypt it properly with cropping" do - url = subject.generate :width => 300, :height => 200, :image => image_url, :crop => [10, 20, 30, 40], :old => true - - encrypted = url.split('/')[1] - - decrypted = decrypt_in_thumbor(encrypted) - - expect(decrypted["horizontal_flip"]).to be_falsy - expect(decrypted["vertical_flip"]).to be_falsy - expect(decrypted["smart"]).to be_falsy - expect(decrypted["meta"]).to be_falsy - expect(decrypted["crop"]["left"]).to eq(10) - expect(decrypted["crop"]["top"]).to eq(20) - expect(decrypted["crop"]["right"]).to eq(30) - expect(decrypted["crop"]["bottom"]).to eq(40) - expect(decrypted["valign"]).to eq('middle') - expect(decrypted["halign"]).to eq('center') - expect(decrypted["image_hash"]).to eq(image_md5) - expect(decrypted["width"]).to eq(300) - expect(decrypted["height"]).to eq(200) - - end - - it "should allow thumbor to decrypt it properly with filters" do - url = subject.generate :filters => ["quality(20)", "brightness(10)"], :image => image_url, :old => true - - encrypted = url.split('/')[1] - - decrypted = decrypt_in_thumbor(encrypted) - - expect(decrypted["filters"]).to eq("quality(20):brightness(10)") - end - end - describe "without security key" do subject { Thumbor::CryptoURL.new nil } it "should generate a unsafe url" do diff --git a/spec/util/thumbor.rb b/spec/util/thumbor.rb deleted file mode 100644 index 81d6726..0000000 --- a/spec/util/thumbor.rb +++ /dev/null @@ -1,7 +0,0 @@ -def decrypt_in_thumbor(str) - command = "python -c 'from thumbor.crypto import Cryptor; cr = Cryptor(\"my-security-keymy\"); print cr.decrypt(\"" << str << "\")'" - result = Array.new - IO.popen(command) { |f| result.push(f.gets) } - result = result.join('').strip - JSON.parse(result.gsub('"', "@@@").gsub("'", '"').gsub("@@@", '\\"').gsub('True', 'true').gsub('False', 'false').gsub('None', 'null')) -end