ruby-thumbor 0.7.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -1
- data/Rakefile +1 -1
- data/lib/ruby-thumbor.rb +28 -9
- data/spec/ruby-thumbor_spec.rb +68 -37
- data/tasks/rspec.rake +0 -8
- metadata +5 -2
data/README.rdoc
CHANGED
data/Rakefile
CHANGED
data/lib/ruby-thumbor.rb
CHANGED
@@ -4,15 +4,17 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
4
4
|
require 'openssl'
|
5
5
|
require 'base64'
|
6
6
|
require 'digest/md5'
|
7
|
+
require 'cgi'
|
7
8
|
|
8
9
|
module Thumbor
|
9
|
-
VERSION = '0.
|
10
|
+
VERSION = '1.0.0'
|
10
11
|
|
11
12
|
class CryptoURL
|
12
|
-
attr_accessor :key
|
13
|
+
attr_accessor :key, :computed_key
|
13
14
|
|
14
15
|
def initialize(key)
|
15
|
-
@key =
|
16
|
+
@key = key
|
17
|
+
@computed_key = (key * 16)[0..15]
|
16
18
|
end
|
17
19
|
|
18
20
|
def pad(s)
|
@@ -53,7 +55,7 @@ module Thumbor
|
|
53
55
|
end
|
54
56
|
end
|
55
57
|
|
56
|
-
def url_for(options)
|
58
|
+
def url_for(options, include_hash = true)
|
57
59
|
if not options[:image]
|
58
60
|
raise 'image is a required argument.'
|
59
61
|
end
|
@@ -103,8 +105,10 @@ module Thumbor
|
|
103
105
|
url_parts.push("filters:#{ filter_parts.join(':') }")
|
104
106
|
end
|
105
107
|
|
106
|
-
|
107
|
-
|
108
|
+
if include_hash
|
109
|
+
image_hash = Digest::MD5.hexdigest(options[:image])
|
110
|
+
url_parts.push(image_hash)
|
111
|
+
end
|
108
112
|
|
109
113
|
return url_parts.join('/')
|
110
114
|
end
|
@@ -113,14 +117,29 @@ module Thumbor
|
|
113
117
|
Base64.encode64(str).gsub('+', '-').gsub('/', '_').gsub!(/[\n]/, '')
|
114
118
|
end
|
115
119
|
|
116
|
-
def
|
120
|
+
def generate_old(options)
|
117
121
|
url = pad(url_for(options))
|
118
122
|
cipher = OpenSSL::Cipher::Cipher.new('aes-128-ecb').encrypt
|
119
|
-
cipher.key = @
|
123
|
+
cipher.key = @computed_key
|
120
124
|
encrypted = cipher.update(url)
|
121
125
|
based = url_safe_base64(encrypted)
|
122
126
|
|
123
|
-
|
127
|
+
"/#{based}/#{options[:image]}"
|
128
|
+
end
|
129
|
+
|
130
|
+
def generate_new(options)
|
131
|
+
url_options = url_for(options, false)
|
132
|
+
url = "#{url_options}/#{options[:image]}"
|
133
|
+
|
134
|
+
signature = OpenSSL::HMAC.digest('sha1', @key, url)
|
135
|
+
signature = url_safe_base64(signature)
|
136
|
+
|
137
|
+
"/#{signature}/#{url}"
|
138
|
+
end
|
139
|
+
|
140
|
+
def generate(options)
|
141
|
+
return generate_old(options) if options[:old]
|
142
|
+
generate_new(options)
|
124
143
|
end
|
125
144
|
end
|
126
145
|
|
data/spec/ruby-thumbor_spec.rb
CHANGED
@@ -6,7 +6,7 @@ image_md5 = 'f33af67e41168e80fcc5b00f8bd8061a'
|
|
6
6
|
key = 'my-security-key'
|
7
7
|
|
8
8
|
def decrypt_in_thumbor(str)
|
9
|
-
command = "python -c 'from thumbor.crypto import
|
9
|
+
command = "python -c 'from thumbor.crypto import Cryptor; cr = Cryptor(\"my-security-keymy\"); print cr.decrypt(\"" << str << "\")'"
|
10
10
|
result = Array.new
|
11
11
|
IO.popen(command) { |f| result.push(f.gets) }
|
12
12
|
result = result.join('').strip
|
@@ -17,7 +17,7 @@ describe Thumbor::CryptoURL, "#new" do
|
|
17
17
|
|
18
18
|
it "should create a new instance passing key and keep it" do
|
19
19
|
crypto = Thumbor::CryptoURL.new key
|
20
|
-
crypto.
|
20
|
+
crypto.computed_key.should == 'my-security-keym'
|
21
21
|
end
|
22
22
|
|
23
23
|
end
|
@@ -200,18 +200,68 @@ end
|
|
200
200
|
|
201
201
|
describe Thumbor::CryptoURL, "#generate" do
|
202
202
|
|
203
|
+
before :each do
|
204
|
+
@crypto = Thumbor::CryptoURL.new key
|
205
|
+
end
|
206
|
+
|
203
207
|
it "should create a new instance passing key and keep it" do
|
204
|
-
|
208
|
+
url = @crypto.generate :width => 300, :height => 200, :image => image_url
|
209
|
+
|
210
|
+
url.should == '/TQfyd3H36Z3srcNcLOYiM05YNO8=/300x200/my.domain.com/some/image/url.jpg'
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should create a new instance passing key and keep it" do
|
214
|
+
url = @crypto.generate :width => 300, :height => 200, :meta => true, :image => image_url
|
215
|
+
|
216
|
+
url.should == '/YBQEWd3g_WRMnVEG73zfzcr8Zj0=/meta/300x200/my.domain.com/some/image/url.jpg'
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should create a new instance passing key and keep it" do
|
220
|
+
url = @crypto.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true
|
221
|
+
|
222
|
+
url.should == '/jP89J0qOWHgPlm_lOA28GtOh5GU=/meta/300x200/smart/my.domain.com/some/image/url.jpg'
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should create a new instance passing key and keep it" do
|
226
|
+
url = @crypto.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true, :fit_in => true
|
227
|
+
|
228
|
+
url.should == '/zrrOh_TtTs4kiLLEQq1w4bcTYdc=/meta/fit-in/300x200/smart/my.domain.com/some/image/url.jpg'
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should create a new instance passing key and keep it" do
|
232
|
+
url = @crypto.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true, :fit_in => true, :flip => true
|
233
|
+
|
234
|
+
url.should == '/4t1XK1KH43cOb1QJ9tU00-W2_k8=/meta/fit-in/-300x200/smart/my.domain.com/some/image/url.jpg'
|
235
|
+
end
|
236
|
+
|
237
|
+
it "should create a new instance passing key and keep it" do
|
238
|
+
url = @crypto.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true, :fit_in => true, :flip => true, :flop => true
|
239
|
+
|
240
|
+
url.should == '/HJnvjZU69PkPOhyZGu-Z3Uc_W_A=/meta/fit-in/-300x-200/smart/my.domain.com/some/image/url.jpg'
|
241
|
+
end
|
242
|
+
|
243
|
+
it "should create a new instance passing key and keep it" do
|
244
|
+
url = @crypto.generate :filters => ["quality(20)", "brightness(10)"], :image => image_url
|
245
|
+
|
246
|
+
url.should == '/q0DiFg-5-eFZIqyN3lRoCvg2K0s=/filters:quality(20):brightness(10)/my.domain.com/some/image/url.jpg'
|
247
|
+
end
|
248
|
+
|
249
|
+
end
|
250
|
+
|
251
|
+
describe Thumbor::CryptoURL, "#generate :old => true" do
|
205
252
|
|
206
|
-
|
253
|
+
before :each do
|
254
|
+
@crypto = Thumbor::CryptoURL.new key
|
255
|
+
end
|
256
|
+
|
257
|
+
it "should create a new instance passing key and keep it" do
|
258
|
+
url = @crypto.generate :width => 300, :height => 200, :image => image_url, :old => true
|
207
259
|
|
208
260
|
url.should == '/qkLDiIbvtiks0Up9n5PACtmpOfX6dPXw4vP4kJU-jTfyF6y1GJBJyp7CHYh1H3R2/' << image_url
|
209
261
|
end
|
210
262
|
|
211
263
|
it "should allow thumbor to decrypt it properly" do
|
212
|
-
|
213
|
-
|
214
|
-
url = crypto.generate :width => 300, :height => 200, :image => image_url
|
264
|
+
url = @crypto.generate :width => 300, :height => 200, :image => image_url, :old => true
|
215
265
|
|
216
266
|
encrypted = url.split('/')[1]
|
217
267
|
|
@@ -235,9 +285,7 @@ describe Thumbor::CryptoURL, "#generate" do
|
|
235
285
|
end
|
236
286
|
|
237
287
|
it "should allow thumbor to decrypt it properly with meta" do
|
238
|
-
|
239
|
-
|
240
|
-
url = crypto.generate :width => 300, :height => 200, :meta => true, :image => image_url
|
288
|
+
url = @crypto.generate :width => 300, :height => 200, :meta => true, :image => image_url, :old => true
|
241
289
|
|
242
290
|
encrypted = url.split('/')[1]
|
243
291
|
|
@@ -251,9 +299,7 @@ describe Thumbor::CryptoURL, "#generate" do
|
|
251
299
|
end
|
252
300
|
|
253
301
|
it "should allow thumbor to decrypt it properly with smart" do
|
254
|
-
|
255
|
-
|
256
|
-
url = crypto.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true
|
302
|
+
url = @crypto.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true, :old => true
|
257
303
|
|
258
304
|
encrypted = url.split('/')[1]
|
259
305
|
|
@@ -268,10 +314,7 @@ describe Thumbor::CryptoURL, "#generate" do
|
|
268
314
|
end
|
269
315
|
|
270
316
|
it "should allow thumbor to decrypt it properly with fit-in" do
|
271
|
-
|
272
|
-
crypto = Thumbor::CryptoURL.new key
|
273
|
-
|
274
|
-
url = crypto.generate :width => 300, :height => 200, :fit_in => true, :image => image_url
|
317
|
+
url = @crypto.generate :width => 300, :height => 200, :fit_in => true, :image => image_url, :old => true
|
275
318
|
|
276
319
|
encrypted = url.split('/')[1]
|
277
320
|
|
@@ -285,9 +328,7 @@ describe Thumbor::CryptoURL, "#generate" do
|
|
285
328
|
end
|
286
329
|
|
287
330
|
it "should allow thumbor to decrypt it properly with flip" do
|
288
|
-
|
289
|
-
|
290
|
-
url = crypto.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true, :flip => true
|
331
|
+
url = @crypto.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true, :flip => true, :old => true
|
291
332
|
|
292
333
|
encrypted = url.split('/')[1]
|
293
334
|
|
@@ -303,9 +344,7 @@ describe Thumbor::CryptoURL, "#generate" do
|
|
303
344
|
end
|
304
345
|
|
305
346
|
it "should allow thumbor to decrypt it properly with flop" do
|
306
|
-
|
307
|
-
|
308
|
-
url = crypto.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true, :flip => true, :flop => true
|
347
|
+
url = @crypto.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true, :flip => true, :flop => true, :old => true
|
309
348
|
|
310
349
|
encrypted = url.split('/')[1]
|
311
350
|
|
@@ -322,10 +361,8 @@ describe Thumbor::CryptoURL, "#generate" do
|
|
322
361
|
end
|
323
362
|
|
324
363
|
it "should allow thumbor to decrypt it properly with halign" do
|
325
|
-
|
326
|
-
|
327
|
-
url = crypto.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true, :flip => true, :flop => true,
|
328
|
-
:halign => :left
|
364
|
+
url = @crypto.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true, :flip => true, :flop => true,
|
365
|
+
:halign => :left, :old => true
|
329
366
|
|
330
367
|
encrypted = url.split('/')[1]
|
331
368
|
|
@@ -343,10 +380,8 @@ describe Thumbor::CryptoURL, "#generate" do
|
|
343
380
|
end
|
344
381
|
|
345
382
|
it "should allow thumbor to decrypt it properly with valign" do
|
346
|
-
|
347
|
-
|
348
|
-
url = crypto.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true, :flip => true, :flop => true,
|
349
|
-
:halign => :left, :valign => :top
|
383
|
+
url = @crypto.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true, :flip => true, :flop => true,
|
384
|
+
:halign => :left, :valign => :top, :old => true
|
350
385
|
|
351
386
|
encrypted = url.split('/')[1]
|
352
387
|
|
@@ -365,9 +400,7 @@ describe Thumbor::CryptoURL, "#generate" do
|
|
365
400
|
end
|
366
401
|
|
367
402
|
it "should allow thumbor to decrypt it properly with cropping" do
|
368
|
-
|
369
|
-
|
370
|
-
url = crypto.generate :width => 300, :height => 200, :image => image_url, :crop => [10, 20, 30, 40]
|
403
|
+
url = @crypto.generate :width => 300, :height => 200, :image => image_url, :crop => [10, 20, 30, 40], :old => true
|
371
404
|
|
372
405
|
encrypted = url.split('/')[1]
|
373
406
|
|
@@ -390,9 +423,7 @@ describe Thumbor::CryptoURL, "#generate" do
|
|
390
423
|
end
|
391
424
|
|
392
425
|
it "should allow thumbor to decrypt it properly with filters" do
|
393
|
-
|
394
|
-
|
395
|
-
url = crypto.generate :filters => ["quality(20)", "brightness(10)"], :image => image_url
|
426
|
+
url = @crypto.generate :filters => ["quality(20)", "brightness(10)"], :image => image_url, :old => true
|
396
427
|
|
397
428
|
encrypted = url.split('/')[1]
|
398
429
|
|
data/tasks/rspec.rake
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-thumbor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdoc
|
@@ -98,6 +98,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
98
98
|
- - ! '>='
|
99
99
|
- !ruby/object:Gem::Version
|
100
100
|
version: '0'
|
101
|
+
segments:
|
102
|
+
- 0
|
103
|
+
hash: 632787892230243515
|
101
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
105
|
none: false
|
103
106
|
requirements:
|