Skip to content

Commit

Permalink
Removing old url support
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermef committed Jan 18, 2016
1 parent 807fefd commit 9752d1b
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 389 deletions.
2 changes: 1 addition & 1 deletion lib/thumbor/cascade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 1 addition & 16 deletions lib/thumbor/crypto_url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
183 changes: 0 additions & 183 deletions spec/thumbor/cascade_spec.rb
Original file line number Diff line number Diff line change
@@ -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' }
Expand Down Expand Up @@ -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

0 comments on commit 9752d1b

Please sign in to comment.