dragonfly 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of dragonfly might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/History.md +7 -0
- data/README.md +1 -1
- data/lib/dragonfly/app.rb +6 -1
- data/lib/dragonfly/image_magick/processors/thumb.rb +5 -5
- data/lib/dragonfly/job.rb +2 -2
- data/lib/dragonfly/job/fetch_url.rb +4 -4
- data/lib/dragonfly/server.rb +4 -3
- data/lib/dragonfly/url_mapper.rb +1 -1
- data/lib/dragonfly/version.rb +1 -1
- data/lib/rails/generators/dragonfly/templates/initializer.rb.erb +0 -1
- data/spec/dragonfly/app_spec.rb +1 -5
- data/spec/dragonfly/image_magick/plugin_spec.rb +3 -3
- data/spec/dragonfly/job_spec.rb +1 -1
- data/spec/dragonfly/model/model_spec.rb +1 -1
- data/spec/dragonfly/server_spec.rb +25 -21
- data/spec/dragonfly/url_mapper_spec.rb +3 -3
- data/spec/functional/configuration_spec.rb +12 -0
- data/spec/functional/model_urls_spec.rb +12 -20
- data/spec/functional/remote_on_the_fly_spec.rb +3 -3
- data/spec/functional/urls_spec.rb +6 -5
- data/spec/spec_helper.rb +1 -0
- data/spec/support/rack_helpers.rb +7 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c7ef9f7d15b8aa06c44ce7e52c5da69be5c43ee
|
4
|
+
data.tar.gz: 9daf8a467a894251790c3f2a40ddfde9fcc36808
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ba7140e8176f2bc9609343fe5b73be21c9e0a010dc91498faff2fe7b87622ca7f143cd26230884a162635669d968c02c2e309eaa8ccd19fdb2738ab98679cf5
|
7
|
+
data.tar.gz: cdadf8324dae8dc6cf359bbb0fb106e859d418edd95a177844146a6edd11d8bd8affa48432de8116aca2eb8b738dae615874f8c7b8e32394d17f291872817370
|
data/History.md
CHANGED
data/README.md
CHANGED
data/lib/dragonfly/app.rb
CHANGED
@@ -103,10 +103,15 @@ module Dragonfly
|
|
103
103
|
obj.server.add_to_fetch_url_whitelist(patterns)
|
104
104
|
end
|
105
105
|
|
106
|
-
writer :dragonfly_url, :
|
106
|
+
writer :dragonfly_url, :verify_urls, :url_format, :url_host, :url_path_prefix,
|
107
107
|
:for => :server
|
108
108
|
meth :before_serve, :for => :server
|
109
109
|
|
110
|
+
def protect_from_dos_attacks(boolean)
|
111
|
+
verify_urls(boolean)
|
112
|
+
Dragonfly.warn("configuration option protect_from_dos_attacks is deprecated - use verify_urls instead")
|
113
|
+
end
|
114
|
+
|
110
115
|
def method_missing(meth, *args)
|
111
116
|
raise NoMethodError, "no method '#{meth}' for App configuration - but the configuration API has changed! see docs at http://markevans.github.io/dragonfly for details"
|
112
117
|
end
|
@@ -16,9 +16,9 @@ module Dragonfly
|
|
16
16
|
}
|
17
17
|
|
18
18
|
# Geometry string patterns
|
19
|
-
RESIZE_GEOMETRY =
|
20
|
-
CROPPED_RESIZE_GEOMETRY =
|
21
|
-
CROP_GEOMETRY =
|
19
|
+
RESIZE_GEOMETRY = /\A\d*x\d*[><%^!]?\z|\A\d+@\z/ # e.g. '300x200!'
|
20
|
+
CROPPED_RESIZE_GEOMETRY = /\A(\d+)x(\d+)#(\w{1,2})?\z/ # e.g. '20x50#ne'
|
21
|
+
CROP_GEOMETRY = /\A(\d+)x(\d+)([+-]\d+)?([+-]\d+)?(\w{1,2})?\z/ # e.g. '30x30+10+10'
|
22
22
|
|
23
23
|
def update_url(url_attributes, geometry, opts={})
|
24
24
|
format = opts['format']
|
@@ -57,9 +57,9 @@ module Dragonfly
|
|
57
57
|
height = opts['height']
|
58
58
|
gravity = GRAVITIES[opts['gravity']]
|
59
59
|
x = "#{opts['x'] || 0}"
|
60
|
-
x = '+' + x unless x[
|
60
|
+
x = '+' + x unless x[/\A[+-]/]
|
61
61
|
y = "#{opts['y'] || 0}"
|
62
|
-
y = '+' + y unless y[
|
62
|
+
y = '+' + y unless y[/\A[+-]/]
|
63
63
|
|
64
64
|
"#{"-gravity #{gravity} " if gravity}-crop #{width}x#{height}#{x}#{y} +repage"
|
65
65
|
end
|
data/lib/dragonfly/job.rb
CHANGED
@@ -153,9 +153,9 @@ module Dragonfly
|
|
153
153
|
def sha
|
154
154
|
unless app.secret
|
155
155
|
raise CannotGenerateSha, "A secret is required to sign and verify Dragonfly job requests. "\
|
156
|
-
"Use `secret '...'` or
|
156
|
+
"Use `secret '...'` or `verify_urls false` (not recommended!) in your config."
|
157
157
|
end
|
158
|
-
|
158
|
+
OpenSSL::HMAC.hexdigest('SHA256', app.secret, to_unique_s)[0,16]
|
159
159
|
end
|
160
160
|
|
161
161
|
def validate_sha!(sha)
|
@@ -27,16 +27,16 @@ module Dragonfly
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def url
|
30
|
-
@url ||= uri =~
|
30
|
+
@url ||= uri =~ /\A\w+:[^\d]/ ? uri : "http://#{uri}"
|
31
31
|
end
|
32
32
|
|
33
33
|
def filename
|
34
34
|
return if data_uri?
|
35
|
-
@filename ||= parse_url(url).path[/[^\/]
|
35
|
+
@filename ||= parse_url(url).path[/[^\/]+\z/]
|
36
36
|
end
|
37
37
|
|
38
38
|
def data_uri?
|
39
|
-
uri =~
|
39
|
+
uri =~ /\Adata:/
|
40
40
|
end
|
41
41
|
|
42
42
|
def apply
|
@@ -71,7 +71,7 @@ module Dragonfly
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def update_from_data_uri
|
74
|
-
mime_type, b64_data = uri.scan(
|
74
|
+
mime_type, b64_data = uri.scan(/\Adata:([^;]+);base64,(.*)$/)[0]
|
75
75
|
if mime_type && b64_data
|
76
76
|
data = Base64.decode64(b64_data)
|
77
77
|
ext = app.ext_for(mime_type)
|
data/lib/dragonfly/server.rb
CHANGED
@@ -20,9 +20,10 @@ module Dragonfly
|
|
20
20
|
self.url_format = '/:job/:name'
|
21
21
|
@fetch_file_whitelist = Whitelist.new
|
22
22
|
@fetch_url_whitelist = Whitelist.new
|
23
|
+
@verify_urls = true
|
23
24
|
end
|
24
25
|
|
25
|
-
attr_accessor :
|
26
|
+
attr_accessor :verify_urls, :url_host, :url_path_prefix, :dragonfly_url
|
26
27
|
|
27
28
|
attr_reader :url_format, :fetch_file_whitelist, :fetch_url_whitelist
|
28
29
|
|
@@ -53,7 +54,7 @@ module Dragonfly
|
|
53
54
|
elsif (params = url_mapper.params_for(env["PATH_INFO"], env["QUERY_STRING"])) && params['job']
|
54
55
|
job = Job.deserialize(params['job'], app)
|
55
56
|
validate_job!(job)
|
56
|
-
job.validate_sha!(params['sha']) if
|
57
|
+
job.validate_sha!(params['sha']) if verify_urls
|
57
58
|
response = Response.new(job, env)
|
58
59
|
catch(:halt) do
|
59
60
|
if before_serve_callback && response.will_be_served?
|
@@ -83,7 +84,7 @@ module Dragonfly
|
|
83
84
|
params = job.url_attributes.extract(url_mapper.params_in_url)
|
84
85
|
params.merge!(stringify_keys(opts))
|
85
86
|
params['job'] = job.serialize
|
86
|
-
params['sha'] = job.sha if
|
87
|
+
params['sha'] = job.sha if verify_urls
|
87
88
|
url = url_mapper.url_for(params)
|
88
89
|
"#{host}#{path_prefix}#{url}"
|
89
90
|
end
|
data/lib/dragonfly/url_mapper.rb
CHANGED
data/lib/dragonfly/version.rb
CHANGED
data/spec/dragonfly/app_spec.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'rack/mock'
|
3
3
|
|
4
|
-
def request(app, path)
|
5
|
-
Rack::MockRequest.new(app).get(path)
|
6
|
-
end
|
7
|
-
|
8
4
|
describe Dragonfly::App do
|
9
5
|
|
10
6
|
describe ".instance" do
|
@@ -172,7 +168,7 @@ describe Dragonfly::App do
|
|
172
168
|
let (:job) { app.fetch('eggs') }
|
173
169
|
|
174
170
|
it "should give the server url by default" do
|
175
|
-
app.url_for(job).should =~ %r{^/\w
|
171
|
+
app.url_for(job).should =~ %r{^/\w+}
|
176
172
|
end
|
177
173
|
it "should allow configuring" do
|
178
174
|
app.configure do
|
@@ -72,7 +72,7 @@ describe "a configured imagemagick app" do
|
|
72
72
|
describe "convert" do
|
73
73
|
it "sanity check with format" do
|
74
74
|
thumb = image.convert('-resize 1x1!', 'format' => 'jpg')
|
75
|
-
thumb.url.should =~ /^\/beach\.jpg
|
75
|
+
thumb.url.should =~ /^\/beach\.jpg\?.*job=\w+/
|
76
76
|
thumb.width.should == 1
|
77
77
|
thumb.format.should == 'jpeg'
|
78
78
|
thumb.meta['format'].should == 'jpg'
|
@@ -80,7 +80,7 @@ describe "a configured imagemagick app" do
|
|
80
80
|
|
81
81
|
it "sanity check without format" do
|
82
82
|
thumb = image.convert('-resize 1x1!')
|
83
|
-
thumb.url.should =~ /^\/beach\.png
|
83
|
+
thumb.url.should =~ /^\/beach\.png\?.*job=\w+/
|
84
84
|
thumb.width.should == 1
|
85
85
|
thumb.format.should == 'png'
|
86
86
|
thumb.meta['format'].should be_nil
|
@@ -90,7 +90,7 @@ describe "a configured imagemagick app" do
|
|
90
90
|
describe "encode" do
|
91
91
|
it "sanity check" do
|
92
92
|
thumb = image.encode('jpg')
|
93
|
-
thumb.url.should =~ /^\/beach\.jpg
|
93
|
+
thumb.url.should =~ /^\/beach\.jpg\?.*job=\w+/
|
94
94
|
thumb.format.should == 'jpeg'
|
95
95
|
thumb.meta['format'].should == 'jpg'
|
96
96
|
end
|
data/spec/dragonfly/job_spec.rb
CHANGED
@@ -1110,7 +1110,7 @@ describe "models" do
|
|
1110
1110
|
|
1111
1111
|
it "should give the correct url" do
|
1112
1112
|
@item.retained_preview_image = @pending_string
|
1113
|
-
@item.preview_image.url.should =~ %r{^/\w+/dog.biscuit
|
1113
|
+
@item.preview_image.url.should =~ %r{^/\w+/dog.biscuit}
|
1114
1114
|
end
|
1115
1115
|
|
1116
1116
|
it "should raise an error if the pending string contains a non-magic attr method" do
|
@@ -1,10 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'rack/mock'
|
3
3
|
|
4
|
-
def request(app, path)
|
5
|
-
Rack::MockRequest.new(app).get(path)
|
6
|
-
end
|
7
|
-
|
8
4
|
describe Dragonfly::Server do
|
9
5
|
|
10
6
|
describe "responses" do
|
@@ -32,8 +28,8 @@ describe Dragonfly::Server do
|
|
32
28
|
'/name.ext'
|
33
29
|
].each do |suffix|
|
34
30
|
|
35
|
-
it "should return successfully when given the url with suffix #{suffix.inspect}" do
|
36
|
-
url = "/media/#{@job.serialize}#{suffix}"
|
31
|
+
it "should return successfully when given the url with suffix #{suffix.inspect} and the correct sha parameter" do
|
32
|
+
url = "/media/#{@job.serialize}#{suffix}?sha=#{@job.sha}"
|
37
33
|
response = request(@server, url)
|
38
34
|
response.status.should == 200
|
39
35
|
response.body.should == 'HELLO THERE'
|
@@ -42,16 +38,16 @@ describe Dragonfly::Server do
|
|
42
38
|
|
43
39
|
end
|
44
40
|
|
45
|
-
it "should return successfully
|
46
|
-
@server.
|
47
|
-
url = "/media/#{@job.serialize}
|
41
|
+
it "should return successfully without a sha if protection is off" do
|
42
|
+
@server.verify_urls = false
|
43
|
+
url = "/media/#{@job.serialize}"
|
48
44
|
response = request(@server, url)
|
49
45
|
response.status.should == 200
|
50
46
|
response.body.should == 'HELLO THERE'
|
51
47
|
end
|
52
48
|
|
53
49
|
it "should return a cacheable response" do
|
54
|
-
url = "/media/#{@job.serialize}"
|
50
|
+
url = "/media/#{@job.serialize}?sha=#{@job.sha}"
|
55
51
|
response = request(@server, url)
|
56
52
|
response.status.should == 200
|
57
53
|
response.headers['Cache-Control'].should == "public, max-age=31536000"
|
@@ -59,7 +55,7 @@ describe Dragonfly::Server do
|
|
59
55
|
|
60
56
|
it "should return successfully even if the job is in the query string" do
|
61
57
|
@server.url_format = '/'
|
62
|
-
url = "/?job=#{@job.serialize}"
|
58
|
+
url = "/?job=#{@job.serialize}&sha=#{@job.sha}"
|
63
59
|
response = request(@server, url)
|
64
60
|
response.status.should == 200
|
65
61
|
response.body.should == 'HELLO THERE'
|
@@ -67,15 +63,13 @@ describe Dragonfly::Server do
|
|
67
63
|
end
|
68
64
|
|
69
65
|
describe "unsuccessful requests" do
|
70
|
-
it "should return a 400 if no sha given
|
71
|
-
@server.protect_from_dos_attacks = true
|
66
|
+
it "should return a 400 if no sha given" do
|
72
67
|
url = "/media/#{@job.serialize}"
|
73
68
|
response = request(@server, url)
|
74
69
|
response.status.should == 400
|
75
70
|
end
|
76
71
|
|
77
|
-
it "should return a 400 if wrong sha given
|
78
|
-
@server.protect_from_dos_attacks = true
|
72
|
+
it "should return a 400 if wrong sha given" do
|
79
73
|
url = "/media/#{@job.serialize}?sha=asdfs"
|
80
74
|
response = request(@server, url)
|
81
75
|
response.status.should == 400
|
@@ -137,6 +131,10 @@ describe Dragonfly::Server do
|
|
137
131
|
response.content_type.should == 'text/plain'
|
138
132
|
end
|
139
133
|
|
134
|
+
before do
|
135
|
+
@server.verify_urls = false
|
136
|
+
end
|
137
|
+
|
140
138
|
describe "fetch_file" do
|
141
139
|
it "should return a 403 Forbidden when someone uses fetch_file " do
|
142
140
|
assert_forbidden @app.fetch_file('samples/egg.png')
|
@@ -197,6 +195,7 @@ describe Dragonfly::Server do
|
|
197
195
|
describe "params" do
|
198
196
|
before(:each) do
|
199
197
|
server.url_format = '/media/:job/:zoo'
|
198
|
+
server.verify_urls = false
|
200
199
|
end
|
201
200
|
it "substitutes the relevant params" do
|
202
201
|
server.url_for(job).should == "/media/#{job.serialize}"
|
@@ -220,6 +219,7 @@ describe Dragonfly::Server do
|
|
220
219
|
describe "basename" do
|
221
220
|
before(:each) do
|
222
221
|
server.url_format = '/:job/:basename'
|
222
|
+
server.verify_urls = false
|
223
223
|
end
|
224
224
|
it "should use the name" do
|
225
225
|
job.url_attributes.name = 'hello.egg'
|
@@ -233,6 +233,7 @@ describe Dragonfly::Server do
|
|
233
233
|
describe "ext" do
|
234
234
|
before(:each) do
|
235
235
|
server.url_format = '/:job.:ext'
|
236
|
+
server.verify_urls = false
|
236
237
|
end
|
237
238
|
it "should use the name" do
|
238
239
|
job.url_attributes.name = 'hello.egg'
|
@@ -245,6 +246,10 @@ describe Dragonfly::Server do
|
|
245
246
|
end
|
246
247
|
|
247
248
|
describe "host" do
|
249
|
+
before do
|
250
|
+
server.verify_urls = false
|
251
|
+
end
|
252
|
+
|
248
253
|
it "should add the host to the url if configured" do
|
249
254
|
server.url_host = 'http://some.server:4000'
|
250
255
|
server.url_for(job).should == "http://some.server:4000/#{job.serialize}"
|
@@ -263,6 +268,7 @@ describe Dragonfly::Server do
|
|
263
268
|
describe "path_prefix" do
|
264
269
|
before do
|
265
270
|
server.url_format = '/media/:job'
|
271
|
+
server.verify_urls = false
|
266
272
|
end
|
267
273
|
|
268
274
|
it "adds the path_prefix to the url if configured" do
|
@@ -280,11 +286,8 @@ describe Dragonfly::Server do
|
|
280
286
|
end
|
281
287
|
end
|
282
288
|
|
283
|
-
describe "
|
284
|
-
|
285
|
-
server.protect_from_dos_attacks = true
|
286
|
-
end
|
287
|
-
it "should generate the correct url" do
|
289
|
+
describe "URL verification" do
|
290
|
+
it "should generate a URL with a sha parameter by default" do
|
288
291
|
server.url_for(job).should == "/#{job.serialize}?sha=#{job.sha}"
|
289
292
|
end
|
290
293
|
end
|
@@ -309,7 +312,7 @@ describe Dragonfly::Server do
|
|
309
312
|
end
|
310
313
|
|
311
314
|
it "should be called before serving" do
|
312
|
-
response = request(@server, "/#{@job.serialize}")
|
315
|
+
response = request(@server, "/#{@job.serialize}?sha=#{@job.sha}")
|
313
316
|
response.body.should == 'TEST'
|
314
317
|
@x.should == 'TEST'
|
315
318
|
end
|
@@ -326,6 +329,7 @@ describe Dragonfly::Server do
|
|
326
329
|
@server.before_serve do |job, env|
|
327
330
|
throw :halt, [200, {}, ['hello']]
|
328
331
|
end
|
332
|
+
@server.verify_urls = false
|
329
333
|
end
|
330
334
|
|
331
335
|
it 'return the specified response instead of job.result' do
|
@@ -24,7 +24,7 @@ describe Dragonfly::UrlMapper do
|
|
24
24
|
describe "url_regexp" do
|
25
25
|
it "should return a regexp with non-greedy optional groups that include the preceding slash/dot/dash" do
|
26
26
|
url_mapper = Dragonfly::UrlMapper.new('/media/:job/:basename-:size.:format')
|
27
|
-
url_mapper.url_regexp.should == %r{
|
27
|
+
url_mapper.url_regexp.should == %r{\A/media(/[^\/\-\.]+?)?(/[^\/\-\.]+?)?(\-[^\/\-\.]+?)?(\.[^\/\-\.]+?)?\z}
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should allow setting custom patterns in the url" do
|
@@ -33,12 +33,12 @@ describe Dragonfly::UrlMapper do
|
|
33
33
|
:size => '\d',
|
34
34
|
:format => '[^\.]'
|
35
35
|
)
|
36
|
-
url_mapper.url_regexp.should == %r{
|
36
|
+
url_mapper.url_regexp.should == %r{\A/media(/\w+?)?(\-\d+?)?(\.[^\.]+?)?\z}
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should make optional match patterns (ending in ?) apply to the whole group including the preceding seperator" do
|
40
40
|
url_mapper = Dragonfly::UrlMapper.new('/media/:job', :job => '\w')
|
41
|
-
url_mapper.url_regexp.should == %r{
|
41
|
+
url_mapper.url_regexp.should == %r{\A/media(/\w+?)?\z}
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -16,4 +16,16 @@ describe "configuration" do
|
|
16
16
|
end
|
17
17
|
app.fetch_url_whitelist.should include 'http://something'
|
18
18
|
end
|
19
|
+
|
20
|
+
describe "deprecations" do
|
21
|
+
it "protect_from_dos_attacks" do
|
22
|
+
Dragonfly.should_receive(:warn).with(/deprecated/)
|
23
|
+
expect {
|
24
|
+
app.configure do
|
25
|
+
protect_from_dos_attacks false
|
26
|
+
end
|
27
|
+
}.to change(app.server, :verify_urls)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
19
31
|
end
|
@@ -34,72 +34,64 @@ describe "model urls" do
|
|
34
34
|
it "should include the name in the url if it has the magic attribute" do
|
35
35
|
@item.preview_image = new_tempfile
|
36
36
|
@item.save!
|
37
|
-
@item.preview_image.url.should =~ %r{^/media/\w+/hello\.txt
|
37
|
+
@item.preview_image.url.should =~ %r{^/media/\w+/hello\.txt}
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should still include the name in the url if it has the magic attribute on reload" do
|
41
41
|
@item.preview_image = new_tempfile
|
42
42
|
@item.save!
|
43
43
|
item = @item_class.find(@item.id)
|
44
|
-
item.preview_image.url.should =~ %r{^/media/\w+/hello\.txt
|
44
|
+
item.preview_image.url.should =~ %r{^/media/\w+/hello\.txt}
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should work for other magic attributes in the url" do
|
48
48
|
@app.server.url_format = '/:job/:some_analyser_method'
|
49
49
|
@item.preview_image = new_tempfile
|
50
50
|
@item.save!
|
51
|
-
@item.preview_image.url.should =~ %r{^/\w+/53
|
52
|
-
@item_class.find(@item.id).preview_image.url.should =~ %r{^/\w+/53
|
51
|
+
@item.preview_image.url.should =~ %r{^/\w+/53}
|
52
|
+
@item_class.find(@item.id).preview_image.url.should =~ %r{^/\w+/53}
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should work without the name if the name magic attr doesn't exist" do
|
56
56
|
@item.other_image = new_tempfile
|
57
57
|
@item.save!
|
58
58
|
item = @item_class.find(@item.id)
|
59
|
-
item.other_image.url.should =~ %r{^/media/\w
|
59
|
+
item.other_image.url.should =~ %r{^/media/\w+}
|
60
60
|
end
|
61
61
|
|
62
62
|
it "should not add the name when there's no magic attr, even if the name is set (for consistency)" do
|
63
63
|
@item.other_image = new_tempfile
|
64
64
|
@item.save!
|
65
65
|
@item.other_image.name = 'test.txt'
|
66
|
-
@item.other_image.url.should =~ %r{^/media/\w
|
66
|
+
@item.other_image.url.should =~ %r{^/media/\w+}
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should include the name in the url even if it has no ext" do
|
70
70
|
@item.preview_image = new_tempfile("hello", 'hello')
|
71
71
|
@item.save!
|
72
72
|
item = @item_class.find(@item.id)
|
73
|
-
item.preview_image.url.should =~ %r{^/media/\w+/hello
|
73
|
+
item.preview_image.url.should =~ %r{^/media/\w+/hello}
|
74
74
|
end
|
75
75
|
|
76
76
|
it "should change the ext when there's an encoding step" do
|
77
77
|
@item.preview_image = new_tempfile
|
78
78
|
@item.save!
|
79
79
|
item = @item_class.find(@item.id)
|
80
|
-
item.preview_image.encode(:bum).url.should =~ %r{^/media/\w+/hello\.bum
|
80
|
+
item.preview_image.encode(:bum).url.should =~ %r{^/media/\w+/hello\.bum}
|
81
81
|
end
|
82
82
|
|
83
83
|
it "should not include the name if it has none" do
|
84
84
|
@item.preview_image = "HELLO"
|
85
85
|
@item.save!
|
86
86
|
item = @item_class.find(@item.id)
|
87
|
-
item.preview_image.url.should =~ %r{^/media/\w
|
87
|
+
item.preview_image.url.should =~ %r{^/media/\w+}
|
88
88
|
end
|
89
89
|
|
90
90
|
it "should have an ext when there's an encoding step but no name" do
|
91
91
|
@item.preview_image = "HELLO"
|
92
92
|
@item.save!
|
93
93
|
item = @item_class.find(@item.id)
|
94
|
-
item.preview_image.encode(:bum).url.should =~ %r{^/media/\w+/file\.bum
|
95
|
-
end
|
96
|
-
|
97
|
-
it "should work as normal with dos protection" do
|
98
|
-
@app.server.protect_from_dos_attacks = true
|
99
|
-
@item.preview_image = new_tempfile
|
100
|
-
@item.save!
|
101
|
-
item = @item_class.find(@item.id)
|
102
|
-
item.preview_image.url.should =~ %r{^/media/\w+/hello\.txt\?sha=\w+$}
|
94
|
+
item.preview_image.encode(:bum).url.should =~ %r{^/media/\w+/file\.bum}
|
103
95
|
end
|
104
96
|
|
105
97
|
it "should allow configuring the url" do
|
@@ -109,14 +101,14 @@ describe "model urls" do
|
|
109
101
|
@item.preview_image = new_tempfile
|
110
102
|
@item.save!
|
111
103
|
item = @item_class.find(@item.id)
|
112
|
-
item.preview_image.url.should =~ %r{^/img/\w
|
104
|
+
item.preview_image.url.should =~ %r{^/img/\w+}
|
113
105
|
end
|
114
106
|
|
115
107
|
it "should still get params from magic attributes even when chained" do
|
116
108
|
@item.preview_image = new_tempfile
|
117
109
|
@item.save!
|
118
110
|
item = @item_class.find(@item.id)
|
119
|
-
item.preview_image.thumb('30x30').url.should =~ %r{^/media/\w+/hello\.txt
|
111
|
+
item.preview_image.thumb('30x30').url.should =~ %r{^/media/\w+/hello\.txt}
|
120
112
|
end
|
121
113
|
|
122
114
|
end
|
@@ -32,17 +32,17 @@ describe "remote on-the-fly urls" do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should give the url for the server" do
|
35
|
-
@job.url.should == "/#{@job.serialize}"
|
35
|
+
@job.url.should == "/#{@job.serialize}?sha=#{@job.sha}"
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should store the content when first called" do
|
39
39
|
File.exist?('tmp/dragonfly_test_urls/yay.txt').should be_false
|
40
|
-
@app
|
40
|
+
request(@app, @job.url)
|
41
41
|
File.read('tmp/dragonfly_test_urls/yay.txt').should == 'TEST'
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should point to the external url the second time" do
|
45
|
-
@app
|
45
|
+
request(@app, @job.url)
|
46
46
|
@job.url.should == '/dragonfly_test_urls/yay.txt'
|
47
47
|
end
|
48
48
|
|
@@ -2,17 +2,18 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "urls" do
|
4
4
|
|
5
|
-
def request(app, path)
|
6
|
-
Rack::MockRequest.new(app).get(path)
|
7
|
-
end
|
8
|
-
|
9
5
|
def job_should_match(array)
|
10
6
|
Dragonfly::Response.should_receive(:new).with do |job, env|
|
11
7
|
job.to_a.should == array
|
12
8
|
end.and_return(double('response', :to_response => [200, {'Content-Type' => 'text/plain'}, ["OK"]]))
|
13
9
|
end
|
14
10
|
|
15
|
-
let (:app) {
|
11
|
+
let (:app) {
|
12
|
+
test_app.configure{
|
13
|
+
processor(:thumb){}
|
14
|
+
verify_urls false
|
15
|
+
}
|
16
|
+
}
|
16
17
|
|
17
18
|
it "works with old marshalled urls (including with tildes in them)" do
|
18
19
|
app.allow_legacy_urls = true
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dragonfly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Evans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -234,6 +234,7 @@ files:
|
|
234
234
|
- spec/support/argument_matchers.rb
|
235
235
|
- spec/support/image_matchers.rb
|
236
236
|
- spec/support/model_helpers.rb
|
237
|
+
- spec/support/rack_helpers.rb
|
237
238
|
- spec/support/simple_matchers.rb
|
238
239
|
- tmp/.gitignore
|
239
240
|
homepage: http://github.com/markevans/dragonfly
|
@@ -321,4 +322,5 @@ test_files:
|
|
321
322
|
- spec/support/argument_matchers.rb
|
322
323
|
- spec/support/image_matchers.rb
|
323
324
|
- spec/support/model_helpers.rb
|
325
|
+
- spec/support/rack_helpers.rb
|
324
326
|
- spec/support/simple_matchers.rb
|